t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Tabs opened from an agent's desktop-rendered browser tab are unclaimed, so the agent can't close them

Open skyfallstatus opened this issue 1 month ago • 0 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/web (also apps/server and packages/contracts)

Steps to reproduce

Desktop app (macOS) with its local environment, so server tabs render natively.

  1. Serve this page locally (for example python3 -m http.server 8765): <a id="link" href="https://example.org/" target="_blank">open in new tab</a>
  2. Agent: preview_open({ url: "http://localhost:8765/popup.html", open: false }) gives tab A. preview_status shows A as owner: "agent", ownedByCaller: true. t3_preview_list shows A with an automationOwner.
  3. Agent: preview_act({ action: "click", selector: "#link" }) on A.
  4. A new tab B (example.org) appears with owner: "unclaimed", ownedByCaller: false. In t3_preview_list, B has no automationOwner.
  5. Agent: t3_preview_close({ tabId: B }).
  6. Agent: preview_open({ tabId: B, open: false }), then preview_status.
  7. Agent: t3_preview_close({ tabId: A }).

Expected behavior

B belongs to the agent that owns A (owner: "agent", openerTabId: A), as popups from environment-hosted server tabs already do via adoptPopup. The agent can close B with t3_preview_close.

Actual behavior

  • Step 5 fails with PreviewAutomationControlInterruptedError, reason agentMismatch: "Only the agent session that opened this tab can close it."
  • Step 6 succeeds, but B stays unclaimed.
  • Step 7 closes A. B stays open.

I reproduced all of this with the page above. I first hit it on a billing site whose "Download invoice" and "View receipt" links open a new window: five leftover tabs in one evening, across a Claude thread and a Codex thread. When the new tab's navigation turns into a download, B shows url: "" and the file appears only in B's downloads[], so the agent has to use B but can never close it.

Root cause (main 7a059b9)

This path came in with #16961 and was built for human clicks. The ownership check itself looks right. The problem is that agent-opened popups end up looking human-opened.

Impact

Major degradation or frequent failure for unattended agents.

  • These tabs look human-opened, so closeIdleAgentTabs skips them (L1275-L1286).
  • Closing the opener doesn't close them, and the eviction proposed in #24186 wouldn't either.
  • Each one holds a slot of the 32-tab server budget (L1260-L1263) until someone closes it by hand. Scheduled agents that download invoices or receipts drift toward the deadlock in #24159.

Suggested fix

  • Add openerTabId: Schema.optional(PreviewTabId) to PreviewOpenInput, and pass source.snapshot.tabId from openLinkInPreview through openUrlInPreview.
  • On the server (previewOpen → PreviewManager.open): when the opener is a runtime: "server" session in the same thread with an automationOwner, copy that owner from the server's own record, never from the client. Carry openerTabId so the new ServerTab records its opener, as adopted popups do.
  • Apply adoptPopup's per-agent limit, falling back to unclaimed rather than dropping the click.

Letting agents close any unclaimed tab would weaken the protection for human-opened tabs (#16701), so I'm not proposing that.

Version or commit

T3 Code Nightly 0.1.4-nightly.20261027.3783 (dc84b0962efa). The same code is on main 7a059b9.

Environment

macOS 27.0 (arm64), desktop app with local server, Electron 44.9.3. Both Claude and Codex threads are affected.

Workaround

Close the extra tabs with the × in the browser tab strip. Agents can still drive an unclaimed tab (preview_navigate, preview_act, reading downloads) but can't close it.

Related: #24159, #24186, #16961, #22061, #16640, #23021.

skyfallstatus avatar Oct 28 '26 02:10 skyfallstatus