From 8536eeb60a02981325ea97ffdd943b39a952913a Mon Sep 17 00:00:00 2001 From: JOUNGWOOK KWON Date: Thu, 16 Apr 2026 19:34:14 +0900 Subject: [PATCH] fix: remove flag+empty-value pairs to prevent --permission-mode arg parsing error The claude-agent-sdk generates --setting-sources with an empty string value when settingSources defaults to []. Simply filtering empty strings (as before) leaves --setting-sources without a value, causing the next flag --permission-mode to be consumed as its value, resulting in "Invalid setting source" exit code 1. Fix: remove the entire flag+empty-value pair instead of just the empty string. Also includes: reset completed session on resume (mac sleep/resume fix). Co-Authored-By: Claude Sonnet 4.6 --- src/services/worker/ProcessRegistry.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/services/worker/ProcessRegistry.ts b/src/services/worker/ProcessRegistry.ts index cd7dab89..e4888d26 100644 --- a/src/services/worker/ProcessRegistry.ts +++ b/src/services/worker/ProcessRegistry.ts @@ -416,7 +416,23 @@ export function createPidCapturingSpawn(sessionDbId: number) { // causing subsequent flags to be consumed as values for the preceding flag. // The Agent SDK may produce empty-string args (e.g., settingSources defaults to [] // which joins to ""). Node preserves these, but Bun drops them, breaking CLI parsing. - const args = spawnOptions.args.filter(arg => arg !== ''); + // + // FIX: Simply filtering empty strings has the same effect as Bun dropping them — + // it leaves the preceding flag (e.g. --setting-sources) without a value, causing + // the next flag (e.g. --permission-mode) to be consumed as that value. + // Instead, we must remove the entire flag+empty-value pair. + const args: string[] = []; + for (let i = 0; i < spawnOptions.args.length; i++) { + const arg = spawnOptions.args[i]; + if (arg === '') continue; // skip standalone empty strings + // If this is a --flag followed by an empty string, skip both (remove the pair entirely) + if (arg.startsWith('--') && i + 1 < spawnOptions.args.length && spawnOptions.args[i + 1] === '') { + i++; // skip the empty value too + continue; + } + args.push(arg); + } + const child = useCmdWrapper ? spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...args], {