From 34065155380e6cfab623659bce3c108544a7b434 Mon Sep 17 00:00:00 2001 From: zerone0x Date: Tue, 3 Mar 2026 04:19:10 +0100 Subject: [PATCH] fix(run): exit with non-zero code on session error in run command 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 #15558 --- packages/opencode/src/cli/cmd/run.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index f3781f1abd86..7b4a3fa2cf20 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -582,10 +582,7 @@ export const RunCommand = cmd({ } await share(sdk, sessionID) - loop().catch((e) => { - console.error(e) - process.exit(1) - }) + const loopDone = loop() if (args.command) { await sdk.session.command({ @@ -606,6 +603,13 @@ export const RunCommand = cmd({ parts: [...files, { type: "text", text: message }], }) } + + await loopDone.catch((e) => { + console.error(e) + process.exit(1) + }) + + if (error) process.exit(1) } if (args.attach) {