Repository navigation
fix(server): messages after a fresh session no longer return to a pre-clear session woken by background work - #38824
Conversation
…e conversation back Repro for #38764: after a fresh-context run queued behind a turn whose session still has background work, a provider-thread update from the old session makes the next user message continue the pre-clear conversation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-clear session woken by background work A fresh run queued behind a running turn leaves the pre-clear session alive when it has background work. When that work settles, the session's provider-thread update makes it the active thread again, and the next user message continued the pre-clear conversation. A message now skips an active provider thread that predates the latest fresh start, as it already does for one a scheduled fresh run started. Fixes #38764 Co-Authored-By: Claude Opus 5.5 <[email protected]>
commented
Nov 19, 2026
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:
|
The rework brief listed no items, so the code is unchanged. PR #38824 is open at 90057a2 with mergeable_state clean. Every check run on that commit has completed: Check, Build and Typecheck, Test, Test Server shards, CodeRabbit and Changes passed, and the rest were skipped by their path filters, including all Macroscope checks. CodeRabbit reported 'No actionable comments were generated in the recent review', there are no comments on lines, and no review finding rated high or above is open, so nothing needed fixing. Because checks and reviews had already settled, I did not start a watch. The fix itself: conversationProviderThread in Orchestrator.ts skips an active provider thread that predates the latest started fresh-context run, so a user message after /clear stays in the post-clear session even when the old session's background-task update makes it active again.
Fixes #38764
Reproduction on main
Commit 00c6adb (origin/main). Ran
T3CODE_DEV_SEED=0 vp run dev(fresh database) and added a scratch git project witht3 project add. Rant3 thread start --provider claudeAgent --model claude-haiku-5-5with a prompt to remember codeword PELICAN and startsleep 150; echo BG-DONEwith run_in_background (run 1, old provider thread, ordinal 1; its pendingBackgroundTasks=1). In the web client (preview browser), sent a message that ran a 40-second foreground command (run 2, old thread). While run 2 ran, typed/clearand sent 'Remember the codeword ZEBRA' (run 3, freshContext=1, queued). Run 3 opened a new provider thread (ordinal 3) and the old session stayed alive with its background task. Sent 'Which codeword did I ask you to remember?' (run 4, new thread), and it answered ZEBRA. When the background command finished, its wake created run 5 on the OLD provider thread, and orchestration_v2_projection_threads.active_provider_thread_id moved back to the ordinal-1 thread. Then sent 'Which codeword did I ask you to remember most recently?' (run 6). It went to the OLD provider thread and answered PELICAN, the pre-clear context. Also checked: an idle-thread fresh send while background work runs is refused on main ('a fresh session would end them'), so the bug needs the queued fresh-send path the reporter used (their run 303 was sent while 302 was running). Failing test on factory/repro-38764:vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts -t "pre-clear session"fails with expected native thread ':1', received ':0'.Evidence
Linux web client, Chromium, dark theme, 1440×1000 CSS viewport, fresh databases, real Claude Haiku 5.5.
Remember PELICAN and start a background sleep; while another turn runs, queue
/clearand Remember ZEBRA. Confirm ZEBRA, wait for the old session's background wake, then ask the most recently remembered codeword. Base returns PELICAN; head returns ZEBRA. The harness blocked the requested foreground sleep on both sides, so the fresh send was queued immediately during the agent's running turn.Seed commands, browser reproduction protocol, routing export script, before routing, after routing.
Not shown:
Tests
No new local runs; the code is unchanged since the previous step. In that step: vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts passed 83/83, including the repro test. ThreadStop, SteeringCompletion and runtimeLayer passed 300 tests. vp run check:changed passed. On the PR, every CI check run on 90057a2 completed with success or skipped (gh api .../commits//check-runs).
Not in this change
Who did the work
Run by the t3code factory in T3 Code.