From eefaa9f8cd5047d995ee59260b5f7391779a381f Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sat, 4 Apr 2026 07:49:20 -0700 Subject: [PATCH] fix: sidebar chat resets idle timer + shutdown kills sidebar-agent Two fixes for the "browser died while chatting" problem: 1. /sidebar-command now calls resetIdleTimer(). Previously only CLI commands reset it, so the server would shut down after 30 min even while the user was actively chatting in the sidebar. 2. shutdown() now pkills the sidebar-agent daemon. Previously the agent survived server shutdown, kept polling a dead server, and spawned confused claude processes that auto-started headless browsers. Co-Authored-By: Claude Opus 4.6 (1M context) --- browse/src/server.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/browse/src/server.ts b/browse/src/server.ts index dc4beb14..279108dd 100644 --- a/browse/src/server.ts +++ b/browse/src/server.ts @@ -915,6 +915,15 @@ async function shutdown() { isShuttingDown = true; console.log('[browse] Shutting down...'); + // Kill the sidebar-agent daemon process (spawned by cli.ts, detached). + // Without this, the agent keeps polling a dead server and spawns confused + // claude processes that auto-start headless browsers. + try { + const { spawnSync } = require('child_process'); + spawnSync('pkill', ['-f', 'sidebar-agent\\.ts'], { stdio: 'ignore', timeout: 3000 }); + } catch (err: any) { + console.warn('[browse] Failed to kill sidebar-agent:', err.message); + } // Clean up CDP inspector sessions try { detachSession(); } catch (err: any) { console.warn('[browse] Failed to detach CDP session:', err.message); @@ -1265,6 +1274,7 @@ async function start() { if (!validateAuth(req)) { return new Response(JSON.stringify({ error: 'Unauthorized' }), { status: 401, headers: { 'Content-Type': 'application/json' } }); } + resetIdleTimer(); // Sidebar chat is real user activity const body = await req.json(); const msg = body.message?.trim(); if (!msg) {