t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: User message fails with "turn ... is still active" while a Claude background-task wake turn is running

Open iokoioko opened this issue 1 month ago • 3 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate. Related but distinct: #16557 (provider turn projection stays running), #16987 (queued messages after steers never appear), #17847 / #17625 (stale waiting/Stop state around background work). The same thread shows those symptoms too.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server (orchestration v2 turn start, Claude adapter) + apps/web (composer)

Steps to reproduce

  1. In a Claude-provider thread, have the agent start background work: Bash with run_in_background, or a background Agent.
  2. Let the turn end. Later the background job completes, and the Claude SDK starts a turn by itself to deliver the task-notification.
  3. While that wake turn is still running, send a normal user message from the composer.

Expected behavior

The wake turn counts as the active turn. The user message is queued, or steered into it, exactly as when a user-started turn is active.

Actual behavior

The message fails. The UI shows "The provider could not start this turn. Retry the turn; if it keeps failing, check the provider setup and server logs." (sometimes "Provider turn failed."), and the user has to send it again. Server trace:

ClaudeAdapterV2.startTurn  exit Failure
ProviderAdapterTurnStartError: Failed to start run run:thread:<id>:ordinal:376 on claudeAgent provider thread provider-thread:provider:claudeAgent:native-thread:pending%3Arun%3Athread%3A<id>%3Aordinal%3A363.
  [cause]: ProviderAdapterProtocolError: claudeAgent provider protocol error: Claude provider turn provider-turn:provider:claudeAgent:native-turn:turn%3Arun-attempt%3Arun%3Arun%253Athread%253A<id>%253Aordinal%253A374%3Aattempt%3A1 is still active.
orchestrationV2.providerTurnStart.start  WARN "orchestration V2 checkpoint baseline capture failed; starting provider without a baseline"

This happened 4 times in one day in a long orchestration thread that uses background shell jobs and subagents. Orchestration doesn't treat the SDK-initiated wake turn as active, so startTurn races it and the adapter rejects the new turn.

Around the same time the user sees these related symptoms (not captured in logs, probably the same root cause):

  • The square Stop button stays after the output has visibly finished. A new message then queues and sometimes never starts. Switching threads, or restarting T3, restores the idle state.
  • Queued and steer messages pile up without delivering, and a new steer lands on top of them.

The server also logged ws.orchestrationV2.projectShellItems failing with OrchestratorProjectionError: Failed to load orchestration projection for thread ..., and orchestration.subscribeThread spans ending Interrupted.

Impact

Major degradation or frequent failure

Version or commit

t3 v0.0.46-nightly.20261008.2833

Environment

Linux (Debian 13), web mode, Claude Agent provider (claude-opus-5-5)

Suggested fix

Register SDK-initiated wake turns as active turns in orchestration, and route user input that arrives during them to queue or steer instead of startTurn. Have the client derive Stop/idle from the server's turn-end event, and recover it on resubscribe.

iokoioko avatar Oct 10 '26 16:10 iokoioko

Not reproduced on main at 70e5e384da, Linux web dev server, Claude CLI 2.1.303, claude-opus-5-5.

Tried both Bash(run_in_background=true) in an empty thread and a native background Agent after adding history. Each ran sleep 25, ended the initial turn, then handled its completion notification with a foreground sleep 30. Sent a composer message during each wake: both messages queued and were answered afterward; no “still active” error, and the composer returned to idle.

Provider results (UTC):

22:30:31.810 success BACKGROUND_STARTED
22:31:28.738 success WAKE_FINISHED
22:31:31.628 success RECEIVED_USER
22:32:01.321 success AGENT_STARTED
22:33:03.974 success AGENT_WAKE_FINISHED
22:33:07.725 success RECEIVED_AGENT_USER

Does this still occur on the current nightly? If so, please include the T3 version, Claude CLI version, and a redacted provider-event/server trace covering the background completion, wake start, and failed composer send. Was the composer offering Queue or Submit when it failed? These attempts did not recreate the long-lived orchestration history in the report.

Shell wake and successful queued reply

Agent wake and successful queued reply

juliusmarminge avatar Oct 21 '26 22:10 juliusmarminge

Thanks for testing. The trace logs from then have rotated, but the state DB still has the runs for that thread (10 Oct, UTC):

15:47:37  run 374 created for the wake turn ("Background command ... completed")
15:48:29  run 374 marked failed, 52 s in; the Claude turn kept going
15:48:31  run 375 created for a second copy of the same notification (cancelled later)
15:48:43  my message -> run 376
15:48:49  run 376 failed: "provider turn ... run 374 ... is still active"
15:50:55  same message resent -> run 377 completed

So the wake turn did get a run. My report was wrong to say it wasn't treated as active. The failure needs the wake run to end as failed on the T3 side while the Claude turn is still running. In your repro the wake run completed, which may be why it didn't fail.

The same shape happened once more on 18 Oct on a 0.0.46 nightly: a wake run failed in under a second, then the next run failed 2 s later. I don't have the error text for that one.

Since 20 Oct, on 0.1.2-nightly.20261021.3499 with Claude CLI 2.1.308, about 90 wake runs, none failed, so I can't reproduce it now either. If it comes back I'll attach the trace. I don't remember whether the composer showed Queue or Submit.

iokoioko avatar Oct 22 '26 12:10 iokoioko

Retested on main at 2c8bdf6177, Linux web dev server, Claude CLI 2.1.303, Claude Opus 5.5. Background Bash and native background Agent each ran sleep 25; after completion, the parent ran foreground sleep 40. Composer sends during both wakes offered Queue and were answered afterward. The isolated state DB records both wake/user pairs as completed:

UTC       wake completed   queued user completed
shell     21:46:48.886     21:46:52.361
Agent     21:48:31.949     21:48:35.877

The corrected failure condition—T3 marking the wake failed while Claude keeps running—did not occur. Closing as currently unreproducible given these checks and your approximately 90 successful recent wakes. The historical failure cause remains unconfirmed; this is not a claim that a particular commit fixed it.

Shell wake accepts queued composer message

Native Agent wake accepts queued composer message

juliusmarminge avatar Oct 22 '26 21:10 juliusmarminge