From 3d92684e0417b9fb8dae01c83a57cbc450df9ae3 Mon Sep 17 00:00:00 2001 From: biswanath-cmd Date: Wed, 15 Apr 2026 13:28:11 +0530 Subject: [PATCH] fix: filter empty string args before Bun spawn() to prevent CLI parsing errors (#1781) Bun's child_process.spawn() silently drops empty string arguments from argv, unlike Node which preserves them. When the Agent SDK defaults settingSources to [] (empty array), [].join(",") produces "" which gets pushed as ["--setting-sources", ""]. Bun drops the "", causing --permission-mode to be consumed as the value for --setting-sources: Error processing --setting-sources: Invalid setting source: --permission-mode This caused 100% observation failure (exit code 1 on every SDK subprocess spawn), resulting in 0 observations stored across all sessions. The fix filters empty string args before passing to spawn(), making the behavior consistent between Node and Bun runtimes. Fixes #1779 Related: #1660 Co-authored-by: bswnth48 <69203760+bswnth48@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) --- src/services/worker/ProcessRegistry.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/services/worker/ProcessRegistry.ts b/src/services/worker/ProcessRegistry.ts index f261e6d0..0f59371b 100644 --- a/src/services/worker/ProcessRegistry.ts +++ b/src/services/worker/ProcessRegistry.ts @@ -388,15 +388,21 @@ export function createPidCapturingSpawn(sessionDbId: number) { const useCmdWrapper = process.platform === 'win32' && spawnOptions.command.endsWith('.cmd'); const env = sanitizeEnv(spawnOptions.env ?? process.env); + // Filter empty string args: Bun's spawn() silently drops empty strings from argv, + // 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 !== ''); + const child = useCmdWrapper - ? spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...spawnOptions.args], { + ? spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...args], { cwd: spawnOptions.cwd, env, stdio: ['pipe', 'pipe', 'pipe'], signal: spawnOptions.signal, windowsHide: true }) - : spawn(spawnOptions.command, spawnOptions.args, { + : spawn(spawnOptions.command, args, { cwd: spawnOptions.cwd, env, stdio: ['pipe', 'pipe', 'pipe'],