Skip to content

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
Tencent:mainfrom
iAstro:fix/issue-57-user-tab-freedom
Open

fix(extension): keep user-opened tabs free & fix agent-tab leak on session stop (issue #57)#66
iAstro wants to merge 1 commit into
Tencent:mainfrom
iAstro:fix/issue-57-user-tab-freedom

Conversation

@iAstro

@iAstro iAstro commented Aug 6, 2026

Copy link
Copy Markdown

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:

  1. 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_stop decides 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.

    • Now the release decision excludes any tab still tracked in agentCreatedTabs. A failed-to-close agent tab forces the window to close instead of release, so it is destroyed with the window.
  2. 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.

    • Added userTabs tracking plus a pendingAgentTabCount counter consumed by chrome.tabs.onCreated to reliably tell apart "agent-created via tool.tab_create" from "user-created via Chrome UI" (the counter is incremented before chrome.tabs.create, so ordering races are avoided).
    • User tabs are pushed a hidden overlay state and never show the control mask.
  3. No more control-mask flash on user tabs (decide before showing)
    The content script used to receive the window-level control state on its first overlay.ready ping, then get corrected to hidden ~1–2s later — a visible flash.

    • Added overlayStateForTab / pushOverlayStateForTab that decide per-tab state before sending it, so a user tab receives hidden on its very first ping.

Test plan

  • manager.test.ts: classifyNewTab returns initializing (home tab), agent (pending tool.tab_create), user (no pending), and matches multiple pending agent tabs to multiple onCreated events.
  • session.test.ts: regression test — when an agent tab fails to close, the window is closed (not released) and the tab does not leak.
  • All 25 manager + session unit tests pass.
  • Manual: in an Agent window, open a tab via Cmd+T, navigate to a URL → tab stays free to operate (no control mask, no flash). On session_stop, all agent tabs close and the window is released only when genuine user tabs remain.

Files changed

  • apps/extension/src/tools/session.ts
  • apps/extension/src/session-manager/manager.ts
  • apps/extension/src/tools/tabs.ts
  • apps/extension/src/entrypoints/background.ts
  • apps/extension/src/session-manager/__tests__/manager.test.ts
  • apps/extension/src/tools/__tests__/session.test.ts

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants