Problem
opencode run --format=json can exit 1 and emit an error even when an interrupted model response recovers and the execution succeeds. Scripts and CI consumers cannot distinguish a recovered step from a failed run.
Fixes #50062.
Change
failed model step
- emit fatal JSON error and set exit 1
+ allow execution to continue
execution becomes idle
- treat any historical assistant error as fatal
+ use the terminal execution event or projected idle marker
Keep V1 behavior, real execution failures, SIGINT, and local cancellation exit codes. Wait for the terminal event when the idle marker has not projected yet, even if an assistant already responded. Non-question forms still fail non-interactive runs, now with an explicit diagnostic; question cancellation remains recoverable.
Related: #52885 addresses exit status. This also removes recovered-step JSON errors and uses execution markers, not the last assistant, when terminal events lag or are missing.
Out of scope
No model retry policy, Core/API changes, or new JSON event types. Step usage reconciliation is unchanged.
Verification
bun test test/run --timeout 30000 --rerun-each 10 --only-failures: 240 pass.
- Full CLI
bun test --timeout 30000 --only-failures: 364 pass, 9 skip, 0 fail across 54 files.
- CLI
bun typecheck: pass.
- CLI
bun run typecheck:tsc: pass.
- Root
bun run check: pass with existing lint warnings.
- Regression coverage includes live/projected recovery, terminal failures after a clean assistant, delayed/missing terminal events, stream disconnection, interruption, form cancellation, and V1 behavior.
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72">
<g fill="none" stroke="currentColor" opacity=".5">
<rect x="4" y="16" width="62" height="36" rx="6"/>
<path d="M66 34h20m-4-4 4 4-4 4"/>
<rect x="86" y="16" width="66" height="36" rx="6"/>
<path d="M152 34h18m-4-4 4 4-4 4"/>
<rect x="170" y="16" width="66" height="36" rx="6"/>
</g>
<g fill="currentColor" font-family="monospace" font-size="10" text-anchor="middle">
<text x="35" y="38">retry</text><text x="119" y="38">recover</text><text x="203" y="38">exit 0</text>
</g>
<circle cx="77" cy="34" r="2" fill="currentColor" opacity=".5">
<animate attributeName="opacity" values=".2;1;.2" dur="2s" repeatCount="indefinite"/>
</circle>
</svg>
Added by the opencode bot (AI-generated).
Related: #39573
Public API: opencode run: no error event or exit 1 for recovered steps; adds an explanatory error for cancelled non-question forms (event types unchanged, backwards compatible)