Thread session stuck in `running` after turn interrupt — stop button becomes a no-op #4713
Version: 0.0.29-nightly.20260727.915 · macOS · provider claudeAgent
When a turn is interrupted, the turn projection is finalized correctly but no follow-up thread.session-set event is emitted. The session projection stays running with active_turn_id still pointing at the now-terminal turn.
From that point the thread is unrecoverable from the UI: every stop press emits a thread.turn-interrupt-requested event that is recorded as accepted in orchestration_command_receipts, but the orchestrator has no active turn left to act on, so nothing happens. There is no visible signal that the turn already ended.
Observed timeline#
One thread, times UTC:
21:00:35.001—thread.session-set→running, turn06dd4ca921:02:41— turn interrupted: sub-agents emittask.completed/status: stopped,projection_turns.state = interrupted,completed_atset21:02:41onwards — no furtherthread.session-set; session projection frozen atrunning21:04→05:42(next day) — 40+thread.turn-interrupt-requested, allaccepted, no effect
The provider child process stayed alive for 9 hours, in state R, RSS growing from 394 MB to 737 MB.
Detection query#
This returns rows only in the broken state:
SELECT s.thread_id, tu.state, tu.completed_at
FROM projection_thread_sessions s
JOIN projection_turns tu ON tu.turn_id = s.active_turn_id
WHERE s.status = 'running'
AND tu.state IN ('interrupted','completed','error')
AND tu.completed_at IS NOT NULL;
Workaround#
SIGTERM the provider child process whose --resume matches the thread's resume cursor. The adapter then emits thread.session-set → stopped with lastError: "Claude runtime stream failed.", and the turn is finalized as error. The thread is fully resumable afterwards, with history intact.
Suggested fix#
Emit the session transition on the interrupt path itself, rather than relying solely on provider stream termination. A secondary guard — refusing to hold active_turn_id on a turn already in a terminal state — would make the desync self-correcting.
Reproduced the exact projection state from #4713 on
0.0.33(server--mode web, provideropencode, Linux, Android client), with one extra twist: the provider process itself died mid-turn, so there was never a terminal event for the adapter to consume.What we saw
opencode servewas killed while three turns were active. t3code-web kept running.- After restart, snapshot reconciliation republished most threads as
completed, but three stayedrunningforever. Inprojection_thread_sessionseach hadstatus='running'and a non-nullactive_turn_idpointing at turns whose underlying messages no longer existed. - The stop button appended
thread.turn-interrupt-requestedtoorchestration_eventsevery press (10 in a row at one point), but no follow-upsession-setever fired. The interrupt handler has nothing to act on when the turn is already gone from the provider, so it neither settles the thread nor surfaces an error. Mobile just shows Working and queues prompts indefinitely.
Manual repair (no data loss)
Appending a corrective
thread.session-setevent per thread directly toorchestration_eventsworked:INSERT INTO orchestration_events (event_id, aggregate_kind, stream_id, stream_version, event_type, occurred_at, actor_kind, payload_json, metadata_json) VALUES ( <uuid>, 'thread', '<threadId>', <max_stream_version + 1>, 'thread.session-set', <now>, 'provider', json_object('threadId', <threadId>, 'session', json_object( 'threadId', <threadId>, 'status', 'stopped', 'providerName', 'opencode', 'providerInstanceId', 'opencode', 'runtimeMode', 'full-access', 'activeTurnId', NULL, 'lastError', NULL, 'updatedAt', <now>)), '{}');The running server ignores externally appended rows, so a
t3code-webrestart is needed to replay them. After replay the projections settle tostopped, the relay picks up the new state, and the mobile client drops the Working badge on reconnect.Relation to open PRs
- #7463 would have prevented this (reconcile persisted bindings against the provider before accepting commands). One gap worth covering: reconciliation should not trust a non-null
active_turn_idalone — ours survived a restart because the column was set even though the provider had no such turn. - #7376 / #7412 cover the stop-button side: an interrupt that finds no live turn should emit the terminal
session-setitself instead of waiting for an event that will never arrive.
Happy to test nightlies containing any of these.
Hit this on
0.0.33(Linux aarch64, providerclaudeAgent), with a variant worth folding into the detection query: the session froze inrunningwithactive_turn_idNULL, so the join in the issue body returns nothing for it.The trigger here was sending a second message while the first turn was still streaming, then pressing stop.
Timeline (UTC, 2026-08-24)#
23:28:25.269— turnb5ca1cbcstarts23:30:29.650—thread.message-sent+thread.turn-start-requestedfrom the client whileb5ca1cbcis still streaming. Newprojection_turnsrow lands asstate = pending,turn_idNULL,started_atNULL23:30:31.270—thread.turn-interrupt-requestedcarryingturnId = b5ca1cbc. That turn finalizes correctly:state = interrupted,completed_atset23:30:32.075— lastthread.session-set. Session projection left atstatus = running,active_turn_idNULL, andupdated_atnever moves again23:30:37→23:33:25— 14 ×thread.turn-interrupt-requested, payload with noturnId, all accepted, none produce any further event
The projections then have no way out. In
apps/server/src/orchestration/Layers/ProjectionPipeline.ts, an interrupt event without aturnIdis an explicit no-op in the turns projector; the pending row is promoted only when athread.session-setarrives withstatus = runningand a non-nullactiveTurnId, and cleared only when the session status reacheserror/stopped/interrupted. The finalsession-setwasrunningwith NULL, the one combination that does neither. So the queued turn sitspendingforever, the session sitsrunningforever, and the UI spins.That final
running+ NULL event also matches the mapping described in #7589: the runtime had just been handed the queued message (delivered at23:30:31.298per its transcript), so it reported busy, with no turn owning the state.Difference from the report above: the provider child went idle rather than hot. The first no-turnId interrupt did reach the runtime and killed the queued prompt (
[Request interrupted by user]at23:30:37.720is the transcript's last line), and from then on the process sat in stateSat ~0% CPU with a flat RSS. Nothing was running, only the projections said otherwise.Detection#
Widening the query to catch the NULL case:
SELECT s.thread_id, s.status, s.active_turn_id, tu.state, tu.requested_at FROM projection_thread_sessions s LEFT JOIN projection_turns tu ON tu.thread_id = s.thread_id AND (tu.turn_id = s.active_turn_id OR (s.active_turn_id IS NULL AND tu.state = 'pending')) WHERE s.status = 'running' AND (tu.state IN ('interrupted','completed','error') OR tu.state = 'pending');Notes#
Restarting the server does not clear it, as expected: there is no terminal event for the queued turn, and projections replay incrementally from
projection_state.last_applied_sequencerather than being rebuilt on boot. Recovering the thread took two direct writes with the server stopped,projection_turns.statetointerruptedandprojection_thread_sessions.statustostopped, after which the thread was usable again with its history intact.Happy to test a patch on this box if the queued-turn path gets picked up (#7240 / #7582 look adjacent).
Note
🤖 GPT-5.6 Sol responding on behalf of Theo
The August 23 OpenCode report adds two runtime and projection disagreement cases to this issue.
Two concurrent sessions received repeated
finish_reason: network_errorevents. Stop requests were recorded, but T3 persisted both sessions as running again. The provider runtimes later reported stopped while T3 still showed Working after an app restart, retainedactiveTurnId, and required manual turn and session repair. A later Continue attempt produced five more network retries and a terminal runtime error. T3 then reported the session as error while the provider runtime still reported running.Keep two separate acceptance checks. First, a successful abort with no terminal session transition must clear the active turn and leave the session in a terminal or ready state. Second, a terminal provider error must reconcile the provider runtime and T3 projection instead of leaving T3 error with the runtime still running. The
network_errortrigger does not prove that the original interrupt call was rejected. These remaining bugs are not fixed.Note
🤖 GPT-5.6 Sol responding on behalf of Theo
A July 24 report adds a live-provider Stop condition to this issue: the model was still running, Stop did nothing, and the only available action was a cooperative
stop pleasemessage. This differs from the older stored-state case where the provider process had already exited.The source thread also records this family of failures with Cursor on NixOS and local Linux, plus OpenCode. Those earlier comments do not prove that every case had a live provider process, so keep them as provider coverage for the live Stop acceptance test, not as proof of one cause.
Acceptance requires Stop to terminate an actively executing provider turn and settle its turn and session state. Please verify that condition for OpenCode and Cursor. The live-provider Stop bug remains open here.
https://github.com/pingdotgg/t3code/issues/8895 adds confirmed OpenCode reproductions on nightlies 1236 and 1246, across desktop and mobile. Abort succeeds, OpenCode reports idle, and the turn becomes interrupted, but the durable session stays running with activeTurnId set and no pending requests. This matches the successful-abort acceptance case above. Proposed fix: https://github.com/pingdotgg/t3code/pull/8859. Consolidating that report here; the bug remains open.
Two more
claudeAgentreproductions today on0.0.37(macOS, desktop, local), plus a finding about the proposed fix that I think blocks it from closing this issue.PR #8859 cannot fire for
claudeAgent#Every branch that PR adds to
ProviderRuntimeIngestion.tsis gated onevent.type === "turn.aborted"— theshouldApplyThreadLifecycleearly return, the lifecycle-statuscase, thenextActiveTurnIdreset, and the message/plan finalization.But only two adapters ever emit that event:
$ grep -rn 'type: "turn.aborted"' --include="*.ts" apps/server/src | grep -v '\.test\.ts' apps/server/src/provider/Layers/CodexAdapter.ts:1081 apps/server/src/provider/Layers/OpenCodeAdapter.ts:1426 apps/server/src/provider/Layers/OpenCodeAdapter.ts:2837 apps/server/src/provider/Layers/OpenCodeAdapter.ts:2886ClaudeAdapter.tsemitsturn.started,turn.completed,session.configured,session.state.changed, andsession.exited— neverturn.aborted. On a successful interrupt it emits nothing at all, which is precisely the failure mode in the issue body.So #8859 fixes the OpenCode/Codex shape (consistent with its test, which drives
provider: opencode), but theclaudeAgentreports in this thread would survive that merge unchanged. Worth not closing this issue on it.Reproduction A — interrupt mid-subagent (known shape)#
Times UTC, thread on
claudeAgent:17:32:30.830— turn8859559astarts, two subagents in flight17:33:26.827— stop pressed;projection_turns.state = interrupted,completed_atset17:33:46.287— both subagents emittask.completed/status: stopped— the interrupt succeeded- then silence. No terminal provider event, no
thread.session-set 17:35:32,17:41:32— two more stops, both accepted, no effect
Session frozen at
runningwithactive_turn_idon the terminal turn. Because the interrupt succeeded,recoverInterruptFailureinProviderCommandReactor.tsnever runs, and that is the only place on the interrupt path that transitions the session.Reproduction B — no interrupt involved (new shape)#
This one has neither an interrupt nor a provider death as its trigger, so I don't think it is covered by any fix currently proposed here.
23:56:11.291— user message; turna413e777starts23:56:12.813—thread.session-set→running,activeTurnId = a413e77723:56:29→00:21:14— the thread keeps working normally. Messages stream, tools run, later turns (ea666fef,381dd9fa,9d151b26,a5232082) reachcompleted. Roughly 40thread.session-setevents in this window, and every one of them re-assertsactiveTurnId = a413e777, which is never finalized.00:21:14.019— final assistant message. Agent is done; CLI writes nothing further (transcript mtime confirms).00:21→00:39— thread is idle but the UI still shows a spinner, because the session projection is stillrunning.00:39:40.992— first stop, then 9 more over 5s. These finalizea413e777asinterruptedbut leave the sessionrunning, i.e. the no-op described in the issue body.
The interrupt here is the reaction to the false spinner, not its cause.
activeTurnIdhad already been stale for ~45 minutes on a healthy, productive thread.This is the case the issue's own suggested secondary guard would catch — refusing to hold
active_turn_idon a turn already in a terminal state would have self-corrected at23:56:29, when the next turn started. The primary fix under discussion (emitting the transition on the interrupt path) would not have caught it, since no interrupt was involved.Confirmations#
The detection query in the issue body flagged both incidents and returns clean after recovery. The
SIGTERMworkaround also behaves exactly as documented:session.exited→ sessionstopped,activeTurnIdnull,lastError: "Claude runtime stream failed.", thread fully resumable from its persisted resume cursor with history intact.
Investigated with Claude Opus 5 in T3 Code.
Confirming the OpenCode acceptance condition @t3dotgg asked for, on stable
0.0.38rather than a nightly. Stop terminates the provider turn correctly; it does not settle the session. Six reproductions across two days.Environment:
0.0.38(tagv0.0.38,c0995d2) · macOS arm64 (Darwin 25.6.0) · Node v25.9.0 · desktop app against local server · provideropencode, modelopencode/muse-spark-1.3-contributor-freeMechanism#
apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts:1589-1596gates everythread.session.setdispatch on this list:if ( event.type === "session.started" || event.type === "session.state.changed" || event.type === "session.exited" || event.type === "thread.started" || event.type === "turn.started" || event.type === "turn.completed" ) {turn.abortedis absent. OpenCode signals a user interrupt only throughturn.aborted(OpenCodeAdapter.ts:1426) and never emitssession.state.changedat all, so no event in this list ever fires on the interrupt path and the session projection stays frozen atrunningwithactiveTurnIdset.interruptOpenCodeTurn(OpenCodeAdapter.ts:1393) does set the in-memory session toready, butupdateProviderSessiononly mutatescontext.session. Nothing publishes it, so the durable projection never learns.Every subsequent Stop press then short-circuits at
OpenCodeAdapter.ts:2996(context.interruptedTurnId === interruptedTurnId) and returnsSuccesswithout callingsession.abort. The trace shows the first press producing a fullopencode.session.abort→abortOpenCodeDescendants→interruptOpenCodeTurnsubtree, and every press after it producing an 8-16ms span with no children.Reproductions#
All times UTC. Each row: abort succeeded, OpenCode reported
session.idle,projection_turns.state = interrupted, and nothread.session-setfollowed.Thread First stop Stop presses Session reached ready?How it ended 236d05e12026-09-04T01:25:23.295Z10 in 4.5s No user deleted the thread at 01:25:3113e1fc6d2026-09-04T01:28:27.747Z5 No errorat01:29:15,stoppedat01:29:24f52607d02026-09-04T01:31:06.528Z1 No errorat01:32:07,stoppedat01:32:204e6427842026-09-03T04:26:11.478Z16 No errorat04:30:37,stoppedat04:30:57Full
thread.session-sethistory for236d05e1, showing the gap:2026-09-04T01:25:09.562Z starting 2026-09-04T01:25:09.562Z starting 2026-09-04T01:25:11.283Z starting 2026-09-04T01:25:11.284Z starting 2026-09-04T01:25:11.295Z running opencode-turn-9c5b1f36-8dfc-471f-845f-158ae5b9b03f 2026-09-04T01:25:31.366Z stoppedTen
thread.turn-interrupt-requestedevents land between01:25:23.295and01:25:27.879. Not one produces a session transition. Thestoppedat the end is the user deleting the thread, not a recovery.The provider event log confirms the interrupt itself worked:
2026-09-04T01:25:23.410Z CANON turn.aborted {"reason": "Interrupted by user."} 2026-09-04T01:25:26.302Z NTIVE session.idleControl group#
Same provider, same install, turns that ended normally settle correctly:
thread 719ed003: running(turn-bef8a716) -> ready (2026-09-02T10:33:39.391Z) thread e5329413: running(turn-0ddf3910) -> ready (2026-09-02T03:37:13.362Z) thread e5329413: running(turn-7e4ed1d2) -> ready (2026-09-02T04:27:52.927Z)So the desync is specific to the interrupt path, not to OpenCode lifecycle handling generally.
On PR #8859#
@juliusmarminge — @nhorto's reading above is right that every branch in #8859 is gated on
event.type === "turn.aborted", which is why it cannot helpclaudeAgent. For the OpenCode shape it is the correct fix:turn.abortedis exactly the event this adapter emits and the only one it emits on interrupt. All four reproductions here would be caught by it.The issue body's secondary guard, refusing to hold
active_turn_idon a turn already in a terminal state, would cover both shapes and is worth keeping alongside it.Related, but distinct#
Thread
f52607d0also left three permission requests stranded:per_06a098b25001Mx8W4eIdr50KDs pending created 2026-09-04T01:30:05.502Z per_06a098b2c001f8vsp9c8qyFBY7 pending created 2026-09-04T01:30:05.503Z per_06a098b3d001PGBcrrUq9VT4n8 pending created 2026-09-04T01:30:05.503Z per_06a098b3d003pCnt9AlEoWsK01 resolved accept 2026-09-04T01:30:09.674Zprojection_threads.pending_approval_countis still3for that thread.interruptOpenCodeTurnnever clearscontext.pendingPermissionsor emitsapproval.resolvedfor them. That looks like #7113 rather than this issue, noting it here only because the same Stop press produced both.Also cross-linking #8998, which is an independent OpenCode Stop report still on
needs-triageand appears to be this same defect.
Reported from a
t3 triagesession. Diagnosis by Claude Opus 5 in Claude Code, against thev0.0.38source tree.Pro tip until the fix is shipped : have a new agent stop the existing one. Surprisingly reliable.
Additional variant for the existing #4713/#8895 maintainer consolidation: the native provider work was aborted, but the durable lifecycle remained stranded with TurnA projected as
running. This differs from the original query's interrupted-turn case: the turn itself still appears running even though native work ended as aborted. RequestB is left projected as pending. This should broaden acceptance coverage, not be treated as proof of one identical root cause across all providers.Environment disclosure: this was observed on fork
0.0.38-f8y.20260906.80from publictotalolage/t3coderelease commit186d5e4a0d1725b942072c624b77f96ad50661b0, not on stock upstream. The live server reports this release version. The inspected source checkout has the same Git tree as the linked release commit. OpenCode1.18.28was installed. The inspected ingestion file was byte-identical to checked upstream commit223ff4490f764a74ff911589e97b9bbcd595fee8; the adapter is fork-modified, so teardown attribution remains qualified. This does not imply that the fork is entirely identical to upstream.Readonly correlation captured at
2026-09-10 10:16:23 UTC(snapshot metadata SHA002be07742a85139f444efb5cb5a101137f9dbf2166a28b601ca3467d62f0ba6):06:48:56.457Z: TurnA was requested/running; the session was set torunningwithactive_turn_id = TurnAat06:48:56.515Z.07:25:35.546Z: RequestB was created as pending, with a projected row having nullturnId,started_at, andcompleted_at.provider_session_runtime.lastSeenwas07:25:35.601Z;queued_provider_turn_startswas0. That distinguishes a projected pending row from a queued-start worker; I am not asserting whether the request reached the native provider.09:14:37.695Z: the native log canceled the main and active child work. The latest native assistant completed at09:14:37.822ZwithMessageAbortedError: Aborted; native persistence recordedmessage.updated.1at sequence31630with the same error-complete state. Native stored histories remained present.09:14:38.864Z: the canonical provider log recorded threetask.completedevents with statusstopped. Across current and numeric rotated logs, there was no corresponding TurnAturn.aborted,turn.completed, orsession.exited. Nothread.turn-interrupt-requestedappeared in the affected window, so this does not establish that a Stop button triggered the operation or that an abort API call succeeded. The initiating operation was not captured.09:14:43.484Z:settings.jsonfile mtime was close to the abort. This is supporting signal only, not proof of the initiating change.
At the snapshot, session status was still
runningwithactive_turn_id = TurnAsince 06:48; runtime status wasrunningwith last seen at 07:25; projected TurnA wasrunningwithcompleted_at = null; and projected RequestB waspendingwithstarted_at = null. There were no pending approvals or questions, and all interaction rows were resolved. All ten projectors reported the same global maximum3487320in one read transaction, indicating caught-up projections rather than a backlog. A fresh GET-only check of both current servers'/session/statusreturned no active session for the affected worktree; no cancel, resume, or restart was performed. An earlier normal turn at06:47:30.795Zhad canonicalturn.completedfollowed bythread.session-setwith statusready, providing a short control comparison.The source evidence separates state from attribution.
ProviderInstanceRegistryHydration.tswatches settings and calls reconcile;RegistryLive.tscloses a replaced entry's scope. In the fork adapter, the layer finalizer invokesstopOpenCodeContext, which marks the context stopped, aborts native work, finishes child tasks, and closes the scope. Unlike explicitstopSession, the layer finalizer/stopAllpath does not explicitly emit the mainsession.exited. The fork-onlyhandleSubscribedEventguard also short-circuits native events after the context is stopped. The source paths, child-stopped records, and settings mtime are consistent with teardown, but the initiating operation and internal flag were not instrumented, so this remains a hypothesis rather than a proven race reconstruction. Upstream also lacks an explicit terminal emission in its layer-finalizer/stopAllpath, but does not have the fork's early guard; stock upstream should not be claimed to fail identically.Relevant pinned source: fork context teardown, fork finalizer, fork post-stop event guard, and upstream ingestion terminal handling. Current ingestion recognizes both
turn.completedandturn.abortedas terminal, clears the active turn ID, and dispatches session state, matching the checked upstream file. This is therefore not the old “turn.abortedmissing from ingestion” diagnosis: this case lacks an observed canonical main terminal event altogether.Suggested acceptance coverage is provider-instance replacement or teardown while active, including a pending follow-up: durable projections should reconcile to a terminal turn and
active_turn_id = null. Assert durable projections, not only stopped children or a gone process, while preserving stale-event guards so a newer turn is not cleared. This is a proposed regression, not a test run. No new controlled reproduction or source patch was made; this comment is based on readonly production metadata plus inspected source.juliusmarminge closed this
Sign in to join this conversation.
Hit this today and traced the mechanism. Your detection query returned exactly the state you describe, so this is the same bug.
Root cause:
ClaudeAdapter.interruptTurnawaitsquery.interrupt()with no bound.query.interrupt()writes a control request to the CLI's stdin and waits for the acknowledgement. When the CLI is wedged it never sends one, so the promise never settles — and because the failure is non-resolution rather than rejection, nothing in the error path ever runs. That is why the interrupts are recordedacceptedyet produce no follow-upthread.session-set: the adapter call is still sitting there, waiting.The bounded
stopTaskloop immediately above already guards this exact hazard for child tasks, and its comment names it — "a wedged child's stopTask promise may never settle (Effect.ignore handles rejection, not non-resolution)". The parentinterrupt()call was never given the same treatment.My occurrence, for comparison with yours:
thread.turn-interrupt-requestedevents over 44 minutes, all no-opsprojection_turns.state = interruptedwithcompleted_atset on the first one;projection_thread_sessions.statusfrozen atrunningfrom then onprovider_session_runtime.last_seen_atstopped updating ~2 seconds after the turn startedOne difference worth noting: your child was state
Rwith RSS climbing 394 → 737 MB, mine was stateSat 0.4% CPU with stable RSS and no output for an hour. Spinning and idle-blocked both land in the same stuck state, which fits a stdin control request that is never answered rather than a busy loop.Two knock-on effects that I did not see mentioned here, and that make this nastier than a dead Stop button:
session.status === "running"(use-thread-outbox-drain.ts:317), so anything typed while stuck just sits there.useThreadActions.ts:214refuses to archive arunningsession with anactiveTurnId. There is no way out from the UI at all.Your
SIGTERMworkaround is right, and worth a safety note for anyone applying it: match the child by the--resumevalue in its argv, not by a worktree path or process-name pattern. #5587 reports killing a healthy sibling thread's process as collateral while hunting for the stuck one.On your suggested fix — a secondary guard refusing to hold
active_turn_idon a terminal turn would make the desync self-correcting, and that seems worth having regardless. But it would be treating the symptom: the adapter is still blocked, and the CLI process still lives. Bounding the interrupt and escalating to teardown when the runtime will not answer addresses it where it starts.Opened #7349 with that fix. It bounds the call at 10s and falls through to
stopSessionInternal, and the regression test hangs-and-times-out without it rather than just asserting the new path.Note that #5891 (open, from a maintainer) takes a different approach to the same function — dropping
interrupt()for an outrightclose()— and would supersede #7349 if merged.