[Bug]: After a fresh-context send, a background-task wake of the old Claude session routes the next message back to it
Before submitting
- [x] I searched existing issues and did not find a duplicate. Nearest: #36087 (fixed by #36103). That fix covers fresh-session scheduled runs only. This report has no schedule: a user fresh-context send plus a background-task wake from the pre-clear session.
- [x] I included enough detail to reproduce or investigate the problem.
Area
apps/server (orchestration V2, claudeAgent provider routing)
Steps to reproduce
- In a Claude thread, let a turn start a
run_in_backgroundcommand and end its turn while the command still runs. - Send a message from the web composer with fresh context. The run is recorded with
freshContext: true. T3 opens a new Claude session (query.openwith a newsessionId, noresume). - Send one or two more messages. They go to the new session, as expected.
- Let the background command from step 1 finish. Its
<task-notification>wakes the old session (the old Claude process is still alive) and creates a run on the old provider thread. - Send another message.
Expected behavior
After the fresh-context send, the conversation stays on the post-clear session. A wake from a background task of the pre-clear session does not move the thread's conversation back. Alternatively, the pre-clear session's query is closed, or its background work is stopped or reported, when the fresh-context run starts.
Actual behavior
The message from step 5 goes to the old session. That session never saw the messages from steps 2–3, so it answers without that context. In our case the agent offered options A/B in the new session, and the user's "A" went to the old session, which replied that it had never offered any option A.
Both Claude processes stay alive for the same thread: one with --resume=<old id>, one without --resume. Routing then alternates between them:
| run | trigger | provider thread |
|---|---|---|
| 302 | user message | old (ordinal 180) |
| 303 | user message, freshContext: true, sent while 302 was still running |
new (ordinal 303) |
| 304 | task-notification from the old session | old |
| 305 | user message (requested before 304 completed) | new |
| 306 | user message | new |
| 307 | task-notification from the old session | old |
| 308 | user message | old, missing the context of 303–306 |
The pattern fits "the next user message goes to the provider thread of the last completed run". It ignores the context boundary that the fresh-context run set. orchestration_v2_projection_threads.active_provider_thread_id now points at the old provider thread (ordinal 180).
Evidence from the provider event log for the thread:
21:36:11.114Zold session:result/end_turn, a background task still running.21:36:12.235Znew provider session:query.openwithsessionId: <new>, noresume. The old query is not closed.- The Claude transcript of the old session has no entries for runs 303, 305 and 306. Its next entry after run 304 is the 307 task-notification.
Impact
The thread silently loses its working context. Replies contradict the visible history, and the user cannot see that two sessions answer in turn. Every background command started before a fresh-context send can flip the thread back. This includes long test or release runs, which agents start often.
Version or commit
T3 Code 0.1.10 (server), Claude CLI via claudeAgent.
Environment
Linux server, web client, full-access thread, Opus model.
Investigated with AI assistance (Claude). The evidence comes from the provider event log, the state DB and the Claude transcripts on the affected machine.