fix(extension): keep user-opened tabs free & fix agent-tab leak on session stop (issue #57) - #66
fix(extension): keep user-opened tabs free & fix agent-tab leak on session stop (issue #57)#66iAstro wants to merge 1 commit into
Conversation
…ssion stop (issue Tencent#57) - session_stop: exclude tabs still tracked in agentCreatedTabs from the release decision so a tab that failed to close is no longer mistaken for a user tab (which previously kept the window open and leaked the tab). - Distinguish user-created tabs from agent-created tabs in the Agent Window via a pending-tab counter consumed by chrome.tabs.onCreated, so tabs the user opens themselves (new-tab button / Cmd+T / open in new tab) are never taken over by the BrowserSkill control mask. - background overlay: decide per-tab state BEFORE showing controls (overlayStateForTab + pushOverlayStateForTab) so a user tab receives hidden on its first overlay.ready ping instead of flashing control then hiding. - Add unit tests for classifyNewTab (agent/user/init) and the window-close-on-leak regression.
|
Thanks @iAstro — the direction is right and the release-decision fix for #57 is clean, but there are 3 blockers before this can merge: 🔴 1. TypeScript doesn't compile: 🔴 2. Core functionality is dead code in production: the session_stop rework depends on 🔴 3. Conflicts with main: #52 changed 🟡 Also worth fixing: Once 1-3 are fixed this is valuable — happy to re-review! 方向没问题,修掉这三个卡点(尤其编译错误和 dispatcher 接线)后欢迎继续。 |
Summary
Fixes issue #57 — in the Agent-controlled browser window, tabs the user opens themselves should stay fully under the user's control (not taken over by BrowserSkill), and session stop should never leak an agent-created tab.
Three concrete fixes:
Agent-tab leak on
session_stop(issue Agent window is closed entirely on task completion, destroying user-created tabs opened inside it |Agent 窗口在任务结束时被整体关闭,导致用户在窗口内自建的标签页丢失 #57 regression)tool.session_stopdecides whether to release (keep) the window by checking "are there any tabs left?". A tab that failed to close in the earlier cleanup step was still present in the window and got mistaken for a user tab → the window was released (dropOnly) and the agent tab leaked.agentCreatedTabs. A failed-to-close agent tab forces the window to close instead of release, so it is destroyed with the window.User-opened tabs are no longer taken over
Previously every tab in the Agent Window received the control mask, so a tab the user opened via the new-tab button / Cmd+T / "open in new tab" was hijacked and could not be operated freely.
userTabstracking plus apendingAgentTabCountcounter consumed bychrome.tabs.onCreatedto reliably tell apart "agent-created viatool.tab_create" from "user-created via Chrome UI" (the counter is incremented beforechrome.tabs.create, so ordering races are avoided).hiddenoverlay state and never show the control mask.No more control-mask flash on user tabs (decide before showing)
The content script used to receive the window-level
controlstate on its firstoverlay.readyping, then get corrected tohidden~1–2s later — a visible flash.overlayStateForTab/pushOverlayStateForTabthat decide per-tab state before sending it, so a user tab receiveshiddenon its very first ping.Test plan
manager.test.ts:classifyNewTabreturnsinitializing(home tab),agent(pending tool.tab_create),user(no pending), and matches multiple pending agent tabs to multipleonCreatedevents.session.test.ts: regression test — when an agent tab fails to close, the window is closed (not released) and the tab does not leak.session_stop, all agent tabs close and the window is released only when genuine user tabs remain.Files changed
apps/extension/src/tools/session.tsapps/extension/src/session-manager/manager.tsapps/extension/src/tools/tabs.tsapps/extension/src/entrypoints/background.tsapps/extension/src/session-manager/__tests__/manager.test.tsapps/extension/src/tools/__tests__/session.test.ts