Skip to content

[Bug]: OpenCode 2 thread stays stuck in running forever when turn.steers misses a session.inbox.delivered event (unbounded turn.heldEnd) #41261

Closed as not planned

Description

@Realauster

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Run a thread on the OpenCode 2 provider (opencode v2.3.2).
  2. During an active turn, inject multiple mid-turn steers (for example, launching multiple async delegate_task children while the parent turn remains active so T3 delivers delegated-completion notifications via provider-turn.steer -> OpenCode2Adapter.steerTurn, back-to-back across a step boundary).
  3. 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:

  • endExecution withholds completion whenever turn.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.steers is only pruned by live SSE session.inbox.delivered / session.inbox.cancelled events (or backfill if the SSE stream disconnects and reconnects).
  • When session.execution.succeeded arrives while turn.steers still holds stale ID(s), there is no inbox/message-list reconciliation check and no timer bounding turn.heldEnd (unlike the bounded hold added for Antigravity in fix(antigravity): bound silent post-settle background command holds #40858).

Interrupting the stuck thread proves the exact state:

  1. POST /api/session/<sid>/interrupt returns HTTP 200 with interrupted: false (OpenCode is already idle).
  2. OpenCode2Adapter.interruptTurn takes its !reply.value.interrupted && state.active === turn && turn.heldEnd !== undefined branch.
  3. finishTurn moves turn.steers into state.strandedSteers and cancelStrandedSteers sends DELETE /api/session/<sid>/inbox/<inboxID> for the two stale delegated-completion steer IDs — both return 404 Not Found because 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.

Activity

  1. juliusmarminge commented on Nov 23, 2026

    @juliusmarminge
    Member

    I tried to reproduce this on the current build and could not.

    Commit b1ce608 (origin/main). Installed OpenCode 2.3.2 (npm @opencode/cli@2.3.2) 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_:...): two back-to-back steers sent when the final step started streaming text, and again right as the final step ended. In both, OpenCode emitted session.inbox.enqueued and then session.inbox.delivered for every steer id, steer POSTs took 5-30 ms, and GET /inbox was empty afterwards. Not tried: the reporter's model opencode-go/deepseek-v4.1-flash, which the hub does not offer, and the reporter's 2990 ms steer POST latency, which suggests OpenCode was under load.

    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.

  2. Realauster commented on Nov 23, 2026

    @Realauster
    Author

    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:

    1. 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:4 at 2990 ms right across a tool-failure/step boundary, followed immediately by ordinal:5 at 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 by DELETE /api/session/<sid>/inbox/<id> returning 404 for both on interrupt), yet turn.steers still held both IDs when session.execution.succeeded arrived.
    2. 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 calls refreshGoal(state) (with INVENTORY_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 though backfill at lines 3624–3628 already does this on SSE reconnect) and no timeout bounding turn.heldEnd. So any single missed/dropped session.inbox.delivered event permanently wedges the thread in running until manual Stop.
      • This is directly reproducible in a unit test (OpenCode2AdapterV2.test.ts): call steerTurn, omit session.inbox.delivered (while the steer message is already present in message.list / absent from inbox), then emit session.execution.succeeded — the turn stays running forever.

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions