Skip to content

fix(opencode): recover silent and ambiguous turns - #422

Merged
ronak-guliani merged 2 commits into
mainfrom
fix/opencode-lifecycle-recovery
Sep 18, 2026
Merged

ronak-guliani merged 2 commits into
mainfrom
fix/opencode-lifecycle-recovery

Conversation

@ronak-guliani

Copy link
Copy Markdown
Owner

Summary

  • Recover OpenCode turns when the SSE connection is established but semantic message/status events are missing, matching the production failure in thread 702ccd7e-d314-4bfc-97a2-68b100a6bb0f and anomalyco/opencode#46733.
  • Gate prompt admission on an established event connection, serialize native prompt admission, send a stable client-generated messageID, and recover ambiguous admission by checking the native transcript without resubmitting the prompt.
  • Reconcile session.messages and session.status with bounded polling/backoff, hydrate missing assistant/tool lifecycle events idempotently, emit one correlated terminal event only after native idle, and preserve interrupt/busy/session-replacement authority.
  • Preserve the existing resume/fork workspace ownership behavior and harden malformed OpenCode error-message formatting, covering pingdotgg/t3code#10805, pingdotgg/t3code#11090, pingdotgg/t3code#11613, pingdotgg/t3code#11640, and pingdotgg/t3code#12469 without importing newer upstream-only modules.

Root cause and design

The affected OpenCode session executed the prompt and completed at 2026-09-18 10:00:07 PDT, while T3 observed no assistant, tool, error, or idle events after the turn started at 2026-09-18 09:58:34 PDT. The adapter previously treated session.status idle SSE as the only completion authority, so a semantically silent but connected stream left the provider session running indefinitely.

This change separates prompt admission, native execution evidence, transcript hydration, native status, and T3 terminal projection. It does not retry promptAsync after ambiguous admission, preventing duplicate native work; it polls the transcript/status APIs instead and deduplicates replayed text/tool evidence. Busy follow-ups are rejected rather than silently submitted into a stale native session. anomalyco/opencode#46842 remains a separate upstream scheduling concern addressed here by serialized admission and native busy checks.

Testing

  • pnpm fmt:check — passed.
  • pnpm lint — passed with existing repository warnings only.
  • pnpm typecheck — passed with existing repository suggestions only.
  • pnpm exec vp test run apps/server/src/provider/Layers/OpenCodeAdapter.test.ts --no-file-parallelism — passed, 50/50 tests; repeated three times deterministically.
  • pnpm test — passed: 2,436 tests passed, 9 skipped across 282 files; server serial suite 102/102 passed.
  • Focused scenarios covered: silent SSE with transcript/status recovery, delayed evidence, event reconnect before admission, stable message IDs, busy follow-up rejection, interrupt/delayed-event ordering, replay dedupe, resume/fork workspace ownership, pending request recovery, and malformed error handling.

Evidence

  • Tested revision: 67c286280c1e412b98710bbcc2f7391425fc36f7.
  • The focused fake-runtime regression demonstrates one turn.completed after a no-semantic-event blackout and reconstructs the missing assistant text from the native transcript.
  • Real-client browser validation and PR media publication were unavailable in this coding session because no automation-capable browser surface was attached; no screenshots or recordings are claimed.

Breaking changes

  • None. OpenCode-only lifecycle behavior changes; other providers and the provider contract remain unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 18, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ronak-guliani
ronak-guliani merged commit 29c15b8 into main Sep 18, 2026
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant