Skip to content

feat(opencode): read the failure class from the ACP errorName - #710

Closed
Ancienttwo wants to merge 2 commits into
botiverse:mainfrom
Ancienttwo:feat/opencode-failure-outcome
Closed

Ancienttwo wants to merge 2 commits into
botiverse:mainfrom
Ancienttwo:feat/opencode-failure-outcome

Conversation

@Ancienttwo

Copy link
Copy Markdown
Contributor

OpenCode answers a failed prompt with JSON-RPC -32603 and a structured data.errorName, but the opencode profile had no failureOutcome reader. As a result, quota and rate-limit failures fell through to the text rules and were reported as unknown.

This adds a reader in runtimes/opencode/failure.ts, following the Grok reader (runtimes/grok/failure.ts). It maps data.errorName through a closed table:

  • provider.free-limit, provider.go-limit, provider.budget-limit, provider.model-budget-limit and provider.quota map to quota.
  • provider.rate-limit maps to rate_limited.
  • Any other name maps to unknown.

The reader never reads message text. It reports no scope, because FailedTurn quota has no scope field and only provider.model-budget-limit carries a scope signal; a separate issue will propose an optional scope field. The names come from OpenCode v2.2.6: packages/cli/src/acp/error.ts:119-126 and packages/core/src/session/to-session-error.ts:39-49.

Tests: one case per name, plus one unknown name, in tests/failure-mapping.test.ts. Typecheck, lint and the failure-mapping suite (60 tests) pass. The full suite has 8 failures in login/* and the account-query deadline tests, which also fail on a clean main.

Not covered: a live provider.rate-limit recording. Only provider.free-limit has been observed live.

opencode answers a failed prompt with JSON-RPC -32603 and data.errorName. Map the limit names to quota and provider.rate-limit to rate_limited through a closed table; any other name is unknown. The message text is not read.
@stamp-build

stamp-build Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for this. Reading OpenCode's own errorName instead of its message is the right direction, and the closed table is the right shape. One change is needed before it can go in, plus two small additions.

Change: an unmapped or missing errorName must fall back to the generic rules, not become unknown.

As written, every -32603 now returns a failure from the reader, so classifyFailure(reason) never runs for OpenCode. Today that text fallback is what classifies most OpenCode prompt failures, and the recorded evidence shows several of them carry no name from your table:

  • invalid key: -32603 "Internal error: invalid x-api-key", data {service: "session", errorName: "APIError"} is auth today and would become unknown;
  • the provider 401 / 429 / billing / 5xx answers come back as -32603 "Internal error: <provider message>" and are classified by their words today.

(docs/spec/runtime-matrix.md, section "opencode, kimi, grok, antigravity (ACP)", rows "missing login" through "server error, overloaded".) The reader is also attached to the profile both release lines share, so v1 hits the same path.

Please return null when errorName is absent or not in ERROR_NAMES, so acpFailureOutcome applies the generic rules exactly as before, and only a known name overrides the words. The table can stay closed.

Tests to add in tests/failure-mapping.test.ts:

  • errorName: "APIError" with message "Internal error: invalid x-api-key" stays auth;
  • a -32603 with no data and a rate-limit message stays rate_limited (the text rule);
  • keep your seven cases, but give the unknown-name case a message that the text rules would classify, and assert it follows the text rather than unknown.

Docs, same PR: add one line to the OpenCode failure rows in docs/spec/runtime-matrix.md (the oar row of that table) saying that a known data.errorName (the six names, from 2.2.6 source) decides the class before the words, and the same sentence in docs/runtimes/opencode.md where failures are described. State that only provider.free-limit was observed live.

On the 8 local failures: main is green in CI and locally here (3,783 tests), so those are likely timing-sensitive on your machine; they are not caused by this PR.

Since this is a fork PR, our CI cannot run on it directly. Once the change is in, a maintainer will carry your commit (authorship kept) into a branch our CI runs on, and close this PR with credit when it merges.


Cindy commented through Stamp · server open-agent-runtime · reviewed head 443a6ce
View in Stamp →

The reader returned unknown for any -32603 whose errorName was absent or not in the table, so the text rules never ran for opencode (an APIError invalid key became unknown instead of auth). Return null instead, so only a known name overrides the words. Tests and the runtime-matrix and opencode pages say so.
@Ancienttwo

Copy link
Copy Markdown
Contributor Author

Thanks, Cindy. Pushed b986c78.

  • The reader now returns null when errorName is absent or not in ERROR_NAMES, so acpFailureOutcome applies the generic text rules as before. Only the six known names override the words. The table stays closed.
  • Tests: APIError with "Internal error: invalid x-api-key" stays auth; a -32603 with no data and a rate-limit message stays rate_limited; an unlisted name with a rate-limit message follows the words. The six known-name cases are kept, now with a message the text rules would not classify the same way.
  • Docs: the oar cell of the opencode column in docs/spec/runtime-matrix.md and a short paragraph in docs/runtimes/opencode.md say a known data.errorName decides the class before the words, and that only provider.free-limit was observed live.

Typecheck and lint pass, and tests/failure-mapping.test.ts passes. A full local run still shows timing-sensitive failures in the login, account-query-deadline and sea-trial tests; the sea-trial file passes when run alone.

stamp-build Bot added a commit that referenced this pull request Nov 10, 2026
…ck (#711)

<!-- stamp:review:v1 -->
<sup><img
src="https://cdn.slock.ai/avatars/6aabf32c-20bc-4cba-b55a-2aa72b60999b/8ba4452ceb890f1930886ef4286fdb99.webp"
width="16" height="16" align="absmiddle" alt=""> <b>Otter</b> from
open-agent-runtime opened this pull request through
Stamp</sup><br><sup><a
href="https://stamp.build/review?receipt=prc_35be8645901fe32fb60cd6bed864e923"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img
src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg"
width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp
→</a></sup>

---
<!-- /stamp:review:v1 -->

OpenCode prompt errors with one of six known `data.errorName` values now
use that native class before the message text. Missing, unlisted and
non-string names keep the existing text fallback, preserving
authentication, rate-limit and billing failures. Inherited object keys
cannot become failure classes. The reader applies to both OpenCode
profiles; open errors and the public interface are unchanged.

Carries Ancienttwo's [PR
#710](#710), preserving both commit
authors. The follow-up adds the own-property guard, fallback and session
regressions, and [source references, native results and reproduction
commands](https://github.com/botiverse/oar/blob/6545984540d263709cbd6425b711bbb6bd58cc06/experiments/opencode-error-names/README.md).
Native 2.2.6 `provider.rate-limit` was captured with a local scripted
provider; the other four quota names remain source-derived, separate
from the contributor's reported `provider.free-limit` observation.

Validation on Linux:
- Complete check: 3,802 tests and 18 mock behavior cases passed; both
package builds passed.
- OpenCode 1.19.5: 17 behavior and 10 vendor checks passed. OpenCode
2.2.6: 15 behavior and 4 failure-class vendor checks passed. Capability
skips and the v1-only vendor boundary are documented.
- Three inherited-name regressions fail without the guard; both session
regressions fail without the reader registration. The native probe
retains auth, named rate-limit and fallback billing outcomes. No paid
provider was used.

Cross-platform validation is pending this PR's CI.

Co-authored-by: Ancienttwo
<[email protected]>

---------

Co-authored-by: Ancienttwo <[email protected]>
Co-authored-by: Otter <[email protected]>
@stamp-build

stamp-build Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Closed by Otter, an agent of open-agent-runtime that did not open it, through Stamp.

Reason:

Thanks @⁠Ancienttwo for the contribution and the fallback revision. Your changes have been incorporated through #711 and merged into main as c0f258d, with your author credit preserved.

The landed patch also guards against inherited object keys; unknown names continue to use the existing text rules. All 39 CI checks passed. Closing this PR because the contribution is integrated on main; it has not been published in a release yet.


Otter commented through Stamp · server open-agent-runtime · head when posted b986c78
View in Stamp →

@stamp-build stamp-build Bot closed this Nov 10, 2026
@stamp-build stamp-build Bot mentioned this pull request Nov 10, 2026
stamp-build Bot added a commit that referenced this pull request Nov 10, 2026
<!-- stamp:review:v1 -->
<sup><img src="https://api.raft.build/api/avatars/pixel/bXVn.svg" width="16" height="16" align="absmiddle" alt=""> <b>Cindy</b> from open-agent-runtime opened this pull request through Stamp</sup><br><sup><a href="https://stamp.build/review?receipt=prc_63320bc32e280f94a8c9147d127f6446"><picture><source media="(prefers-color-scheme: dark)" srcset="https://stamp.build/assets/brand/stamp-glyph-dark.d907ffcadb44.svg"><img src="https://stamp.build/assets/brand/stamp-glyph-light.58a2c10ed108.svg" width="13" height="12" align="absmiddle" alt=""></picture> View in Stamp →</a></sup>

---
<!-- /stamp:review:v1 -->

Minor release: Grok steers without cancelling and reports the turns it runs on its own; Grok and OpenCode failures say more precisely why a turn failed; Codex is found on Windows when it is not on PATH.

## Grok: steer by interjection, and Grok's own turns (#716)
- `steer()` on Grok now sends `_x.ai/interject`: the input joins the running turn at its next safe point and the turn is not cancelled. Before, a steer was `session/prompt` with `_meta.sendNow`, which cancelled the running prompt and re-ran its work.
- What changes for a host: `steer()` is `accepted` once Grok answers `{status: "queued"}` (15 s deadline) and can now be rejected `runtime_refused` (Grok's error) or `error` (delivery); with no turn running it is rejected `no_active_turn` and nothing is sent. Its record is a frame `_x.ai/interject`, not a second `session/prompt` answer with its own outcome, and the turn ends once, with the prompt's answer. A steer carries no `outputSchema`; the turn keeps its prompt's.
- An interjection that misses the turn's last safe point is not lost: Grok runs it after the prompt's `turn_ended` as its own turn (`turn_active` without an `inputId`, so it cannot be tied to the steer).
- Turns Grok runs without a prompt from OAR (a finished sub-agent waking its parent, an interjection that missed its turn, and others) are now turns: `turn_active` at their start, `turn_ended` at their end, their usage billed once. A host folding the stream goes back to idle afterwards instead of staying busy. While such a turn runs, `prompt()` is `busy`, held input waits, `steer()` reaches it and `abort()` cancels it.
- OAR names each prompt it sends (`_meta.promptId`); Grok's queue reports now give OAR prompts `input_queued` and `turn_active` with their input id.
- A Grok turn that starts before OAR has recorded the previous prompt's answer is reported right after that prompt's `turn_ended`, so a host waiting on the prompt gets the prompt's end and the session stays busy until Grok's own end.
- An abort clears interjections Grok has not taken yet. Grok reports neither taking nor clearing one, so OAR reports no `input_dropped` for them.
- Evidence: Grok 1.0.77 on Linux against a local provider ([probe](https://github.com/botiverse/oar/blob/main/experiments/grok-interject/README.md)).

## Failure classes
- **Grok (#717):** every HTTP 429 used to be `rate_limited`. A 429 whose provider error type names a quota (`insufficient_quota`) or Grok's own free-allowance code is now `quota` (`credit_balance_exhausted` is `billing`); others stay `rate_limited`, with `status` 429. For other API errors Grok keeps the provider status in `data.http_status`, and it now decides when Grok's own retry type is the generic `api`: 402 `billing`, 400 `invalid_request`, 401 `auth`, 404 `model_unavailable`, 503/529 `overloaded` (all were `provider`), with that `status` on the outcome; Grok's specific retry types (`auth`, `context_length`) still decide. Failures of Grok's own turns carry no status.
- **OpenCode (#711, from Ancienttwo's #710):** a prompt error with one of OpenCode's known `data.errorName` values (`provider.rate-limit`, `provider.free-limit`, `provider.quota` and other budget limits) uses that class before the message text; unknown names keep the text rules.

## Codex on Windows (#719)
- When Codex is not on PATH, OAR now also looks for npm's global shim (`%APPDATA%\npm\codex.cmd`) and then the Codex Desktop CLI under `%LOCALAPPDATA%`, after `OAR_CODEX_BIN` and PATH. There is no version comparison: the first that passes `codex app-server --help` wins, so a Desktop CLI older than the one on PATH is never chosen over it. No native Windows run in this release; the locations follow Raft's own Codex driver.

## Record retention (#714, fixes #713)
- With `retainedBytes`, a rejected control (for example an idle `abort()`) no longer elides the payload of the newest native frame. Retention now protects the newest frame, not the last record, as documented; older frames are still elided once a newer frame arrives.

## Other
- Design decision recorded: OAR does not drive Claude Code's interactive `/limit-reset` to offer Claude limit resets (#721; upstream request anthropics/claude-code#108851).
- Docs: weekly pass (#706 to #709), including `PromptRun` README examples that now compile and the documented `oar run` exit codes; Qwen 0.27.0 verification (#705).
- Test and evidence updates: Pi 1.5.2 clean-install pairing (#715) and RPC version expectations (#718), November 9 native checks (#712), OpenCode error-name evidence (#711). Grok CI still pins 1.0.70, where the #716 vendor jobs passed; the new behavior was also run against 1.0.77 locally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Cindy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant