Bug: provider error mid-turn leaves session status stuck at "running" — stop succeeds but never reconciles, settle permanently refused #8802
Summary#
When an opencode-provider turn dies with a provider error mid-stream (in my case Z.AI: Insufficient balance or no resource package. Please recharge.), the turn is correctly marked interrupted, but the thread's session status stays running forever. The UI shows "Working" indefinitely, the stop button appears to do nothing, and settling is refused with "This thread still needs attention. Resolve or interrupt it first, then try again." — a deadlock: you can't resolve it because it thinks it's running, and interrupting doesn't change the session status.
Environment#
- T3 Code desktop (macOS), opencode provider v1.18.21
- Model
zai/glm-5.3-flash(Z.AI), full-access runtime mode
Steps to reproduce#
- Start a turn against a provider whose API will reject the request mid-turn (e.g. exhausted Z.AI coding-plan balance).
- Turn errors out; work log shows the provider error.
- Try to click stop → no visible effect. Try to settle/snooze → refused with "still needs attention".
Expected#
A terminal turn state (interrupted/failed) should always reconcile the session status (provider_session_runtime / projection_thread_sessions) out of running, or the stale-session sweeper should catch it.
Actual (forensics from ~/.t3/userdata/)#
projection_turnsfor the thread:state = interrupted,completed_at= 9 s after start (turn is dead). ✔provider_session_runtimeandprojection_thread_sessions:status = running,last_seen_atfrozen at the moment the turn started — stillrunning> 1 h later. ✘- Clicking stop dispatched 24×
orchestration.command.thread.turn.interruptover ~40 min; every span completes successfully in 5–16 ms (interruptTurn→processDomainEvent thread.turn-interrupt-requested), but none transitions the session status. So the interrupts aren't failing (#7368/#4524) — they succeed and simply don't touch session state. stopStaleSessionsForThreadexists but never swept this zombie.- Settle command (
orchestration.command.thread.settle) is rejected because the session claims to berunning.
The only dirty state is one row pair; everything downstream (Working badge, dead stop button, settle refusal) derives from it.
Possibly related: #7368, #4524, #5742, #2173 — but those involve failing aborts or stale client projections; here all commands succeed and the server-side projection itself is the inconsistent part.
Thanks for the detailed evidence—this matches the same root cause exactly. I opened #8859 to handle authoritative
turn.abortedevents by moving the session toready, clearingactiveTurnId, and finalizing buffered output while guarding against stale aborts.We’ve tested the fix against the original reproduction and an abort during streamed output. If you’re able to test the PR branch with your macOS/OpenCode setup, could you share the result—successful or otherwise—on the PR? An independent reproduction and verification would be very helpful.
Note
🤖 GPT-6 Astra (preview) responding on behalf of Theo
This note is part of an automated cleanup pass.
The September 3 follow-up on #8998 adds a Windows Nightly observation: normal Stop leaves a thread on Thinking or Working, while dispatching thread.session.stop for that one thread clears it. The commenter reports repeated failures across unrelated threads, including after a tool entry labeled Ran node, and cannot restart other concurrent agents. Preserve this difference when checking session reconciliation. No event trace in that comment establishes turn.aborted, so it is related evidence, not proof of the same root cause. The original skill-approval hang is tracked in #4795.
Verified the original insufficient-balance / Stop reproduction on T3 Code
0.0.39-nightly.20260906.1293, which includes merged PR #9653, on 2026-09-06. This is the published nightly, without the #8859 patch.Two OpenCode “Ping” chats were tested:
zai-coding-plan/glm-5.3-flash(subscription with credits): returned “Pong”; the turn completed and the session becameready, withactiveTurnId = null.zai/glm-5.3-flash(without credits): logged two “Insufficient balance or no resource package. Please recharge.” retries. Pressing Stop cleared the running UI state.
Read-only inspection of the persisted orchestration events confirmed the failed-credit case:
Event UTC timestamp thread.turn-interrupt-requested2026-09-06T12:49:50.437Zthread.session-set:status = interrupted,activeTurnId = null,lastError = null2026-09-06T12:49:50.479ZThe durable session reconciled 42 ms after the Stop request, and the turn is also
interrupted. Both chats have zero pending approval and user-input requests. This resolves the original defect where Stop succeeded but the durable session stayedrunningwith a dangling active turn.Closing this issue as completed for the original reproduction, and closing #8859 as superseded by #9653. This test did not separately exercise settlement, follow-up reuse of the interrupted chat, or buffered assistant/plan output. It does not establish that the broader Claude, missing-event, or other reconciliation cases in #4713 are fixed; those remain separate.
hahasagined(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Fresh triage evidence for the same bug.
What happened#
Thread
b10760cc-022f-4dde-a66f-ba65472406d7stayed in a running state after the user interrupted an OpenCode turn.Turn
opencode-turn-ab5e8df4-4d96-4221-aa38-fd73d40eb912receivedMessageAbortedErrorand emitted canonicalturn.abortedwith reasonInterrupted by user.Diagnosis#
The turn projection is correct:
projection_turns.state = interruptedprojection_turns.completed_at = 2026-08-31T12:34:59.144ZThe session projections are stale:
projection_thread_sessions.status = runningprojection_thread_sessions.active_turn_idstill points to the interrupted turnprovider_session_runtime.status = runningprovider_session_runtimestill contains the interrupted turn as activeThe provider event log shows the abort at
2026-08-31T12:34:59.208Zand the canonical event at2026-08-31T12:34:59.213Z. No later durablethread.session.setevent closed the session lifecycle.In
ProviderRuntimeIngestion, lifecycle handling includesturn.completedbut notturn.aborted. The abort therefore updates the turn projection but does not set the live session toreadyor clearactiveTurnId.Steps to reproduce#
MessageAbortedError.Expected: the turn is interrupted, the session is ready, and
activeTurnIdis cleared.Actual: the turn is interrupted, but the session remains running with the old
activeTurnId. The UI stays on “Working”.Environment#
0.0.38-nightly.20260831.1236v26.4.01.18.25opencode-go/glm-5.3-flash127.0.0.1:3773npx t3@nightlyWorkaround#
None. No database changes were made.
Filed by GPT-5 via Codex triage.