fix(harness/opencode): surface stderr Error: lines on exit 0#525
Merged
fix(harness/opencode): surface stderr Error: lines on exit 0#525
Conversation
The opencode CLI sometimes prints a hard error to stderr but exits 0,
notably "Error: Model not found: …", auth errors, and APIErrors. The
provider's previous logic only flagged failures on non-zero exit, so
these cases returned RawResult(is_error=False, result=None) — silently
empty output that downstream callers interpret as "agent failed to
produce a valid result".
The bug also hid behind the diagnostic: clean_stderr is logged truncated
to 800 chars, but opencode opens stderr with the SQLite migration
prelude ("Performing one time database migration..."), pushing the real
Error: line off the end of the truncation window. Operators saw the
prelude in logs and assumed migration was the issue.
This change:
- Adds explicit detection of error-shaped stderr (Error:, Model not
found, AuthenticationError, Unauthorized, APIError) and treats them
as CRASH failures even when returncode == 0.
- Extracts the meaningful error line + a small context window via
_extract_opencode_error() so the surfaced message contains the real
cause, not the migration prelude.
- Uses the same extractor for the existing non-zero-exit branch so log
truncation can no longer hide the cause there either.
Tests: 3 new regression tests (Model not found exit 0, migration-only
stderr is not a failure, long-prelude + AuthenticationError on
non-zero exit). Full opencode + harness suite: 48/48.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
Performance
✓ No regressions detected |
Contributor
📊 Coverage gateThresholds from
✅ Gate passedNo surface regressed past the allowed threshold and the aggregate stayed above the floor. |
Contributor
📐 Patch coverage gateThreshold: 80% on lines this PR touches vs
✅ Patch gate passedEvery surface whose lines were touched by this PR has patch coverage at or above the threshold. |
AbirAbbas
added a commit
to Agent-Field/SWE-AF
that referenced
this pull request
May 4, 2026
Pulls in the OpenCodeProvider stderr-error-detection fix released in agentfield 0.1.73 (Agent-Field/agentfield#525). Without this bump the Docker image keeps resolving to the cached older agentfield, so the companion SWE-AF model-prefix fix from #55 lands but the harness still silently swallows opencode "Model not found" / auth errors at exit 0. Updates the pin in: - requirements-docker.txt (Docker build path) - requirements.txt (bare-metal install path) - pyproject.toml (was lagging at 0.1.9) Verified agentfield-0.1.73-py3-none-any.whl ships _extract_opencode_error and _OPENCODE_STDERR_ERROR_PATTERNS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
The
opencodeCLI sometimes prints a hard error to stderr but exits 0 — notably:Error: Model not found: …(invalid model id)AuthenticationError(bad/missing key)APIError(provider failure)OpenCodeProvider._execute_implonly flagged failures on non-zero exit, so these cases returnedRawResult(is_error=False, result=None)— silently empty output. Downstream callers (the schema-output retry loop inagentfield.harness._runner) then surface the failure as the much less useful "agent failed to produce a valid result".The bug is doubly hidden because
clean_stderris logged truncated to 800 chars, but opencode opens stderr with the SQLite migration prelude (Performing one time database migration…), pushing the realError:line off the end of the truncation window. Operators saw the prelude in logs and assumed migration was the issue, not the model id.This was the proximate cause of the SWE-AF Railway run
run_1777925624226_f5a637aefailing everyrun_product_managerandrun_git_initinvocation in 8–10s with no useful diagnostic. A separate companion PR (Agent-Field/SWE-AF#55) fixes the upstream model-string bug; this PR ensures opencode failures of this shape are never invisible again.Changes
sdk/python/agentfield/harness/providers/opencode.py_OPENCODE_STDERR_ERROR_PATTERNSand_extract_opencode_error()helper that pulls the meaningful failure line + a small context window out of opencode stderr, skipping the migration prelude.returncode == 0 and result_text is None and stderr matches an error pattern→ returnsis_error=True, failure_type=CRASHwith the extracted error message._extract_opencode_error()too, so log truncation can no longer hide the cause there either.sdk/python/tests/test_harness_provider_opencode.py— three new regression tests:Model not foundexit 0 → is_error=True with the model id in the message.Test plan
pytest tests/test_harness_provider_opencode.py tests/test_harness_factory.py tests/test_harness_runner.py— 48/48 pass.agentfieldrequirement to whatever version this lands in, redeploy, re-triggergithub buddy implementonAgent-Field/github-buddy#22, confirm any future opencode misconfiguration shows up with the actual error in the Railway logs (not buried under the migration prelude).Companion PR
Agent-Field/SWE-AF#55— fixes the upstream cause (default model id was missing theopenrouter/provider prefix). Both PRs are needed to fully unblock the github-buddy → SWE-AF delegation flow on Railway.🤖 Generated with Claude Code