Repository navigation
fix(server): a thread's later turns keep control of the preview tabs it opened - #42219
juliusmarminge wants to merge 2 commits into
Conversation
…tab (#42209) Failing repro: a finished delegate's provider session is released, so its next turn gets a new MCP credential and the tab it opened rejects evaluate, navigate and close with agentMismatch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it opened A preview tab's agent owner was the MCP credential of the session that opened it. A thread gets a new credential whenever its provider session is released (a finished delegate, the idle stop), so its next turn was refused with agentMismatch on its own tabs and could not even close them. A thread holds only one MCP credential at a time, so the owner is now the thread (environment and thread id). Tests that stood in for another agent with a second credential on the same thread now use a separate thread. Fixes #42209 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
When a delegated thread got a follow-up message, it could no longer use or close the preview tab it had opened earlier. Evaluate, navigate and close failed with
agentMismatch, so agents opened a second tab and the first stayed open until the idle sweep. Tabs were owned by the MCP credential of the session that opened them, and a thread gets a new credential whenever its provider session is released. A thread only ever holds one credential at a time, so a tab's owner is now the thread (environment and thread id). Other threads still cannot reach the tab, and tabs a person opened or controls stay protected.Fixes #42209
Reproduction on main
Commit ae45e00 (origin/main). Fresh dev server (T3CODE_DEV_SEED=0 vp run dev), scratch git project added with
t3 project add, provider claudeAgent / claude-haiku-5-5, server-side preview browser (Playwright Chromium). 1)t3 thread starton a parent thread that called delegate_task (claudeAgent, claude-haiku-5-5) with a task to preview_open({url:'https://example.com/?owner-repro=1', open:false, reuseExistingTab:false}) then preview_evaluate('navigator.userAgent') and end its turn. Both succeeded; preview_open returned control {owner:'agent', ownedByCaller:true, generation:0}. 2)t3 thread send --waitto the child thread asking for preview_evaluate('location.href'), preview_navigate to ?owner-repro=2 and preview_status on the same tabId. preview_evaluate was rejected with 'This browser tab belongs to another agent session or a human. Open your own tab.'; the agent then skipped navigate because the tab was no longer its own; preview_status returned url ?owner-repro=1 and control {owner:'agent', ownedByCaller:false, generation:0}. 3) A second follow-up asking for t3_preview_close on that tab returned PreviewAutomationControlInterruptedError reason agentMismatch ('This tab belongs to another agent session. You can read it, but open your own tab to act.'). The server trace showed McpSessionRegistry.revokeProviderSession, then revokeThread, then issue between turns, as the reporter described. Failing unit test pushed: ServerBrowser.test.ts 'the same thread's next turn can keep using and close the tab it opened' (a tab opened as providerSessionId agent-a, then evaluate/navigate/close as agent-a-next-turn on the same thread) fails on main with agentMismatch.Evidence
Create a parent and delegated child; the child opens a preview tab and finishes. Send a follow-up to that child and evaluate, navigate, inspect ownership, and close the original tab. Real web client and server-side Chromium; fresh synthetic state, 1280×800, light theme; deterministic ACP agent invokes the real MCP tools.
Scenario and deterministic agent driver. scenarios:prove exited 0: failsOnBase=true, passesOnHead=true.
Not shown:
Tests
vp test run src/preview/ServerBrowser.test.ts src/mcp/PreviewAutomationBroker.test.ts(apps/server): 143 passedvp test run src/preview/ServerBrowser.test.ts -t "next turn can keep using"without the source change: fails with reason agentMismatch, as on mainvp run typecheck(apps/server): no errorsvp run check:changed: format, lint, knip, graphql, typecheck and tests (3 files, 145 tests) all passNot in this change
Who did the work
Run by the t3code factory in T3 Code.