From ee504b865c6df44bda0f704b70638cb39af1f312 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Thu, 26 Mar 2026 19:56:10 -0600 Subject: [PATCH] fix: kill stale sidebar-agent processes before starting new one Each /connect-chrome starts a new sidebar-agent subprocess with unref() but never kills the previous one. Old agents accumulate as zombies with stale auth tokens. When they pick up queue entries, their event relay fails (401), so the server never receives agent_done and marks the agent as "hung". The user sees the sidebar freeze. Fix: pkill any existing sidebar-agent.ts processes before spawning. Co-Authored-By: Claude Opus 4.6 (1M context) --- browse/src/cli.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/browse/src/cli.ts b/browse/src/cli.ts index 6d6b27c7..a24886c2 100644 --- a/browse/src/cli.ts +++ b/browse/src/cli.ts @@ -583,6 +583,14 @@ Refs: After 'snapshot', use @e1, @e2... as selectors: browseBin = process.execPath; // the compiled binary itself } + // Kill any existing sidebar-agent processes before starting a new one. + // Old agents have stale auth tokens and will silently fail to relay events, + // causing the server to mark the agent as "hung". + try { + const { spawnSync } = require('child_process'); + spawnSync('pkill', ['-f', 'sidebar-agent\\.ts'], { stdio: 'ignore', timeout: 3000 }); + } catch {} + const agentProc = Bun.spawn(['bun', 'run', agentScript], { cwd: config.projectDir, env: {