From c98ef05c0332382669874b09743b8f3011c3b6e7 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Mon, 20 Apr 2026 07:17:31 +0800 Subject: [PATCH] fix(sidebar-agent): evict tool-use registry entries on tool_result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit toolUseRegistry was append-only. Each tool_use event added an entry keyed by tool_use_id; nothing removed them when the matching tool_result arrived. Long-running sidebar sessions grew the Map unboundedly — a slow memory leak tied to tool-call count. Delete the entry when we handle its tool_result. One-line fix. Co-Authored-By: Claude Opus 4.7 (1M context) --- browse/src/sidebar-agent.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/browse/src/sidebar-agent.ts b/browse/src/sidebar-agent.ts index 71bdc609..9aebf3fc 100644 --- a/browse/src/sidebar-agent.ts +++ b/browse/src/sidebar-agent.ts @@ -367,6 +367,7 @@ async function handleStreamEvent(event: any, tabId?: number, canaryCtx?: CanaryC // fires, onToolResultBlock handles kill + emit. toolResultScanCtx.scan(toolName, text).catch(() => {}); } + if (block.tool_use_id) toolUseRegistry.delete(block.tool_use_id); } } }