t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: After a fresh-context send, a background-task wake of the old Claude session routes the next message back to it

Open gavalierm-agent opened this issue 1 week ago • 0 comments

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

  1. In a Claude thread, let a turn start a run_in_background command and end its turn while the command still runs.
  2. Send a message from the web composer with fresh context. The run is recorded with freshContext: true. T3 opens a new Claude session (query.open with a new sessionId, no resume).
  3. Send one or two more messages. They go to the new session, as expected.
  4. 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.
  5. 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.114Z old session: result / end_turn, a background task still running.
  • 21:36:12.235Z new provider session: query.open with sessionId: <new>, no resume. 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.

gavalierm-agent avatar Nov 18 '26 21:11 gavalierm-agent