fix(run): exit with non-zero code on session error#15787
Closed
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Closed
fix(run): exit with non-zero code on session error#15787zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Conversation
When opencode run encounters a session.error event (e.g., invalid model specified via --model), the process exits with code 0 instead of 1. Root cause: loop() was fired and forgotten (.catch only), so after sdk.session.prompt() returned, execute() exited immediately without waiting for the event loop. Even when loop() ran and set the `error` variable, process.exit(1) was never called. Fix: - Store the loop() promise instead of .catch()-ing it immediately - Await loopDone after the prompt/command call - Call process.exit(1) if error was set during the session Fixes anomalyco#15558
Contributor
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
Contributor
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
This was referenced Mar 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
opencode runencounters a session error (e.g., an invalid model specified via--model), the process exits with code 0 instead of 1.Root Cause
loop()was fired with.catch()(not awaited), so aftersdk.session.prompt()returned,execute()completed immediately without waiting for the event loop to finish. Even when the loop ran and set theerrorvariable from asession.errorevent,process.exit(1)was never called becauseerrorwas scoped inside the unawaited promise.Fix
loop()promise asloopDoneinstead of calling.catch()immediatelyloopDoneafter the prompt/command is submitted (the loop terminates naturally when the session reaches idle state)process.exit(1)if theerrorvariable was set during the sessionThis preserves the existing behavior of printing errors to stderr and calling
process.exit(1)on unexpected loop exceptions.Fixes #15558