Repository navigation
Description
Description
OpenCode agent: a successful run is marked failed when opencode run exits non-zero, and the log excerpt in the error hides the cause
Description
The built-in opencode installed agent raises NonZeroAgentExitCodeError whenever opencode run exits non-zero, even when the session finished normally. In my case the agent wrote its answer file, read it back to check it, and ended with step_finish / reason: "stop". The process still exited with code 1, because opencode hit an uncaught EPIPE: broken pipe, write after a write tool call. That is an upstream opencode bug: .
The real fix belongs upstream, but two things on the Harbor side made this hard to diagnose and handle.
1. The exception message cuts out the part of the log that matters
The NonZeroAgentExitCodeError message includes the agent's stdout, with the middle truncated:
stdout: {"type":"step_start", ... [17801 chars truncated] ... {"type":"step_finish", ... "reason":"stop", ...}}
stderr: None
The EPIPE stack trace was inside the truncated section, so the error only showed a clean start and a clean finish. I had to open the full opencode.txt to find the cause.
2. There's no way to tolerate a known-bad exit code
opencode's exit code isn't reliable right now. There are open upstream reports of it exiting 0 on errors and non-zero on success (e.g. #2489, #14625, #26588). Other harnesses have added an option to ignore opencode's exit code and decide success by checking the result instead (e.g. AgentWorkforce/relay#602).
Setup
- Harbor: 0.25.0, Python 3.12, macOS (aarch64) host, Linux task container
- Model:
Qwen/Qwen3.6-35B-A3Bvia@ai-sdk/openai-compatible
Traceback
File ".../harbor/agents/installed/opencode.py", line 908, in run
await self.exec_as_agent(
File ".../harbor/agents/installed/base.py", line 1081, in exec_as_agent
return await self._exec(
File ".../harbor/agents/installed/base.py", line 1048, in _exec
raise self._classify_exec_error(command, result)
harbor.agents.installed.base.NonZeroAgentExitCodeError: Command failed (exit 1): ...
Related issue: harbor-framework/harbor#4019
Plugins
No response
OpenCode version
Don't know exactly, but at least 1.18.7 (#42553)
Steps to reproduce
Check harbor-framework/harbor#4019
Screenshot
No response
Operating System
macOS (aarch64) host, Linux task container
Terminal
No response
Activity
opencodejr commentedon Oct 31, 2026
Thanks for the detailed write-up and the Harbor cross-reference!
This report is about OpenCode v1 (1.18.x). v1 now only gets fixes for critical bugs: data loss, security problems, or breakage with no workaround. Here the session finishes and writes its output, and only the exit code is wrong. Checking the result instead of the exit code works around it, so this is unlikely to be fixed in v1.
Please try OpenCode v2 (
@opencode/cli, upgrade withopencode upgrade --major). A fair amount of broken-pipe / EPIPE handling has gone into v2, for example:opencode run --format jsonI haven't checked whether v2 still has this exact bug. If you can still get
opencode runto exit non-zero after an EPIPE on v2, please reply here with the v2 version (opencode --version) and the stack trace from the log. Please also reply if you think this is critical on v1. The log truncation and exit-code tolerance points belong to Harbor and are covered by harbor-framework/harbor#4019.opencodejr commentedon Nov 1, 2026
Closing this as not planned, since we haven't heard back. This was reported against OpenCode v1 (1.18.x). The EPIPE makes
opencode runexit 1, but the session still finishes and writes its output, and checking the result instead of the exit code works around it. v1 only gets fixes for critical bugs, so this one won't be fixed there.If you see
opencode runexit non-zero after an EPIPE on OpenCode v2 (@opencode/cli), please open a new issue withopencode --versionand the stack trace from the log. The log truncation and exit-code tolerance points are tracked on the Harbor side in harbor-framework/harbor#4019. Thanks again for the detailed report!opencode: accept exit 1 when the run stream ended in a stop step_finish