fix(extension): keep user-opened tabs free & fix agent-tab leak on session stop (issue #57) - #66
Open
iAstro wants to merge 1 commit into
Open
fix(extension): keep user-opened tabs free & fix agent-tab leak on session stop (issue #57)#66iAstro wants to merge 1 commit into
iAstro 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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