[Bug]: OpenCode 2 thread stays stuck in running forever when turn.steers misses a session.inbox.delivered event (unbounded turn.heldEnd)
Before submitting
- [x] I searched existing issues and did not find a duplicate.
- [x] I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- Run a thread on the OpenCode 2 provider (
opencodev2.3.2). - During an active turn, inject multiple mid-turn steers (for example, launching multiple async
delegate_taskchildren while the parent turn remains active so T3 delivers delegated-completion notifications viaprovider-turn.steer->OpenCode2Adapter.steerTurn, back-to-back across a step boundary). - Wait for OpenCode to deliver all steers, finish generating its final assistant reply, and emit
session.execution.succeeded.
Expected behavior
Once OpenCode finishes (session.execution.succeeded) and has no pending inbox items left for that session, OpenCode2Adapter should finish the turn and transition the thread from running to completed.
If turn.steers.size > 0 when session.execution.succeeded arrives, the adapter should reconcile turn.steers against OpenCode's actual inbox / message history (similar to backfill on reconnect) or bound the turn.heldEnd hold instead of waiting forever.
Actual behavior
OpenCode delivers all steers, emits the full final assistant message, and emits session.execution.succeeded cleanly — the OpenCode session is completely idle.
However, T3 Code keeps the thread stuck in status: "running" indefinitely (observed 15+ minutes with zero further activity) because two already-delivered steers remained in turn.steers.
In packages/provider-opencode/src/server/v2/OpenCode2Adapter.ts:
endExecutionwithholds completion wheneverturn.steers.size > 0:if (end.status === "completed" && (turn.steers.size > 0 || goalHoldsTurn(state))) { turn.heldEnd = end; if (goalHoldsTurn(state) && !state.goalRefreshing) yield* refreshGoal(state); return; }turn.steersis only pruned by live SSEsession.inbox.delivered/session.inbox.cancelledevents (orbackfillif the SSE stream disconnects and reconnects).- When
session.execution.succeededarrives whileturn.steersstill holds stale ID(s), there is no inbox/message-list reconciliation check and no timer boundingturn.heldEnd(unlike the bounded hold added for Antigravity in #40858).
Interrupting the stuck thread proves the exact state:
POST /api/session/<sid>/interruptreturns HTTP 200 withinterrupted: false(OpenCode is already idle).OpenCode2Adapter.interruptTurntakes its!reply.value.interrupted && state.active === turn && turn.heldEnd !== undefinedbranch.finishTurnmovesturn.steersintostate.strandedSteersandcancelStrandedSteerssendsDELETE /api/session/<sid>/inbox/<inboxID>for the two stale delegated-completion steer IDs — both return404 Not Foundbecause OpenCode had already delivered and removed them from its inbox.
Impact
Major degradation or frequent failure
Version or commit
v0.1.12-nightly.20261122.5098 (also checked 5098...5111 diff; no OpenCode2Adapter changes)
Environment
Linux x64 (Bazzite / Fedora Atomic), T3 Code Nightly desktop app (v0.1.12-nightly.20261122.5098), OpenCode 2.3.2, model opencode-go/deepseek-v4.1-flash.
Logs or stack traces
# 1) Back-to-back delegated-completion steers during active turn (UTC):
01:28:33.900Z OpenCode2Adapter.steerTurn -> POST /api/session/<sid>/prompt (2990ms, 200) # ordinal:4
01:28:37.061Z OpenCode2Adapter.steerTurn -> POST /api/session/<sid>/prompt (7.8ms, 200) # ordinal:5
01:29:16.769Z OpenCode2Adapter.steerTurn -> POST /api/session/<sid>/prompt (38.8ms, 200) # ordinal:6 (cleared normally)
# 2) OpenCode finished cleanly (confirmed via OpenCode plugin event subscription):
01:30:10.761Z final assistant turn-item.updated written to T3
01:30:10.782Z OpenCode emitted session.execution.succeeded (session now idle)
# Thread remained status="running", activeRunId!=null for 15+ minutes until manually interrupted.
# 3) Interrupt trace proving turn.heldEnd was set and both stale steers were already gone from OpenCode's inbox:
01:45:14.801Z POST /api/session/<sid>/interrupt -> 200 (interrupted: false)
01:45:15.357Z DELETE /api/session/<sid>/inbox/msg_t3_steer_<sid>%3Amessage%3Athread%3A<tid>%3Aordinal%3A4%3A<uuid> -> 404
01:45:15.452Z DELETE /api/session/<sid>/inbox/msg_t3_steer_<sid>%3Amessage%3Athread%3A<tid>%3Aordinal%3A5%3A<uuid> -> 404
01:45:14.800Z OpenCode2Adapter.interruptTurn -> Success (thread transitioned to interrupted)
Workaround
Clicking Stop (t3_thread_interrupt) immediately hits the turn.heldEnd !== undefined branch in OpenCode2Adapter.interruptTurn, clears the stuck running state, and preserves the already-completed assistant reply.
Suggested fix: in endExecution (when end.status === "completed" and turn.steers.size > 0), check OpenCode's actual inbox/messages (or client.session.active() + inbox list) before holding turn.heldEnd indefinitely, and clear any steer IDs that are no longer pending in OpenCode's inbox.
I tried to reproduce this on the current build and could not.
Commit b1ce608be3 (origin/main). Installed OpenCode 2.3.2 (npm @opencode/[email protected]) in a scratch dir and pointed T3's OpenCode provider binaryPath at a wrapper that gives it isolated XDG data/state/cache dirs. Ran T3CODE_DEV_SEED=0 vp run dev (fresh DB) and drove the web client in a browser with model Claude Haiku 5.5 via OpenCode. Run 1: prompt running two sleep 20 bash calls; sent two steer messages back to back during the first sleep. Both showed as Steer, the agent answered 'DONE ALPHA BRAVO' and the thread completed. Run 2 (the reporter's path): agent used T3's delegate_task to start two background children (sleep 12 / sleep 14), then ran sleep 25 twice. Both children finished during the parent's sleeps, T3 steered their completions into the active OpenCode turn, the parent replied 'FINISHED' listing C1 and C2, and the thread settled (not stuck running). Runs 3 and 4 drove the OpenCode 2.3.2 HTTP API directly with T3-style steer ids (msg_t3_steer_
Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.
Thanks for testing this. Two details that explain why the quick repro did not hit it — and why the bug is still present in b1ce608be3:
-
Why the repro missed it:
- In our trace, the third steer (
ordinal:6, sent during a long-running shell tool call, 38.8 ms POST) did clear normally — matching your Run 2 (sleep 25). - The two steers that wedged the turn (
ordinal:4at 2990 ms right across a tool-failure/step boundary, followed immediately byordinal:5at 7.8 ms) arrived while OpenCode was transitioning between steps under load. Both were delivered to the model (confirmed in the model's subsequent reasoning and byDELETE /api/session/<sid>/inbox/<id>returning404for both on interrupt), yetturn.steersstill held both IDs whensession.execution.succeededarrived.
- In our trace, the third steer (
-
The code-level bug is still in
b1ce608be3(packages/provider-opencode/src/server/v2/adapter.ts):- In
endExecution(lines 3286–3292):if (end.status === "completed" && (turn.steers.size > 0 || goalHoldsTurn(state))) { turn.heldEnd = end; if (goalHoldsTurn(state) && !state.goalRefreshing) yield* refreshGoal(state); return; } - Notice
goalHoldsTurn(state)right next to it already callsrefreshGoal(state)(withINVENTORY_TIMEOUT) because OpenCode can change goal state without notifying T3. - For
turn.steers.size > 0, there is no equivalent reconciliation against OpenCode's inbox /client.message.list(even thoughbackfillat lines 3624–3628 already does this on SSE reconnect) and no timeout boundingturn.heldEnd. So any single missed/droppedsession.inbox.deliveredevent permanently wedges the thread inrunninguntil manual Stop. - This is directly reproducible in a unit test (
OpenCode2AdapterV2.test.ts): callsteerTurn, omitsession.inbox.delivered(while the steer message is already present inmessage.list/ absent from inbox), then emitsession.execution.succeeded— the turn staysrunningforever.
- In
Version: v0.1.12-nightly.20261122.5098 (confirmed identical endExecution / turn.heldEnd logic on b1ce608be3). Could this be reopened to add inbox/message reconciliation (or a bounded hold) in endExecution when turn.steers.size > 0?