fix(run): set non-zero exit code on session error#26588
fix(run): set non-zero exit code on session error#26588cokekitten wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Based on my search results, I found one related PR that addresses a similar issue: Potential Related PR:
The current PR (26588) appears to be addressing a specific edge case where |
|
For visibility: #14625 (open since 2026-02-22) takes a different approach to the same bug — it converts |
Issue for this PR
Closes #26509
Type of change
What does this PR do?
opencode run -m <invalid-model> "<prompt>"printed the error but exited0,breaking shell scripts that key off
$?. Without a prompt the same commandexits
1, so the bug only hits the prompt path.In
run.ts, the non-interactive path runsloop()as fire-and-forget. When asession.errorevent arrives, the handler stores the message locally and printsit — but never propagates it to the process exit code. After the session goes
idle the loop breaks, the event subscription closes, the event loop drains, and
Node exits
0.Fix: set
process.exitCode = 1in thesession.errorbranch. Same pattern usedelsewhere in the CLI for soft-failure exits (
thread.ts:126,222,attach.ts:54,81). UsingexitCoderather thanprocess.exit(1)lets the loopfinish, the subscription tear down, and stdout flush before Node exits — relevant
for
--format jsonconsumers.Refs older duplicates that were never actually closed by a fix: #15558, #17854,
#2489. PR #15787 took a different approach (await
loopDonethenprocess.exit(1))but was auto-closed by the template-compliance bot before any human review.
How did you verify your code works?
Manual repro on dev tree (also reproduces on installed 1.14.41):
```
$ bun --conditions=browser packages/opencode/src/index.ts run -m invalid-model "test"
Error: Model not found: invalid-model/
$ echo $?
1 # was 0 before the fix
```
No-prompt path still exits `1` (no regression):
```
$ bun --conditions=browser packages/opencode/src/index.ts run -m invalid-model </dev/null
Error: You must provide a message or a command
$ echo $?
1
```
`bun run typecheck` passes; `bunx oxlint` reports no new warnings.
Screenshots / recordings
N/A — CLI exit code change.
Checklist