Skip to content

feat: classify runtime failures from structured fields (#227) - #237

Merged
xxchan merged 2 commits into
mainfrom
lookout/failure-classes
Oct 8, 2026
Merged

xxchan merged 2 commits into
mainfrom
lookout/failure-classes

Conversation

@xxchan

@xxchan xxchan commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Closes #227 (second step; the evidence matrix was #230).

What changes

Contract (additive)

  • FailureClass gains model_unavailable, input_too_large, rate_limited and billing.
  • A failed TurnOutcome gets two optional fields, set only where the runtime says them:
    • credential: "missing" | "rejected";
    • status: the provider's HTTP status.
  • New RuntimeFailureError { failure, credential?, status?, reason }. session() rejects with it when the open fails for one of these causes:
    • ACP -32000 on initialize, authenticate, new or resume → auth;
    • a -32602 answer to the model call → model_unavailable;
    • cursor's AuthenticationError → auth, rejected;
    • a pi model oar doesn't find → model_unavailable.
  • observe:
    • failureAdvice(failure) returns { retry: "now" | "later" | "no", userAction };
    • failureText(failure, runtimeName, credential?) covers the new classes.

Mapping. Each adapter reads the runtime's own category first, then the provider error body (code, then type), then the HTTP status. Matching words is each adapter's documented last resort.

runtime reads
claude assistant.error, then api_error_status / terminal_reason; the 400 spend limit by its words
codex codexErrorInfo, including the transport variants' httpStatusCode; for other, the code in the provider's JSON body
pi errorMessage: the status prefix and the JSON body; pi-ai's isContextOverflow
grok -32003 → rate_limited; for -32603, the final retry_state.error_type
ACP -32000 → auth (no credential); opencode by its words
  • Values a runtime declares but no run produced stay unmapped and are documented.
  • An OpenAI 429 whose code names a quota or a balance is quota / billing; only a bare 429 is rate_limited.

Fixed misclassifications (each now covered by a test)

  • claude: "Credit balance is too low" was unknown, now billing. An oversized context was unknown, now input_too_large.
  • codex: serverOverloaded was unknown, now overloaded. contextWindowExceeded was unknown, now input_too_large.

Docs

Behavior changes worth a release note

  • FailureClass has four new members: a host's exhaustive switch over it stops compiling until it handles them.
  • A 429 that names no quota or balance is now rate_limited; it was quota.
  • failureText("auth", name) without a credential now reads "could not authenticate". It used to read "is not signed in", which was wrong for a refused API key (the Raft complaint in Classify runtime failures from structured runtime fields: richer FailureClass, status, advice, and open failures #227).
  • Some opens now reject with RuntimeFailureError (still an Error, with the same message; its reason reads the message and the agent's error is its cause, both redacted like the message when the session carries credential-bearing mcpServers) where they rejected with the raw RequestError or a plain Error:
    • an ACP agent that requires auth;
    • a -32602 model answer;
    • cursor's refused key;
    • a pi model oar doesn't find.
  • A grok -32603 reason now includes its data text (the provider's answer), not only "Internal error".

Tests

  • Unit tests for every mapping, built on the observed facts: tests/failure-mapping.test.ts and tests/failure-class.test.ts (shared rules, failureAdvice).
  • A claude projection test for the wiring, and updated display-text tests.
  • Vendor tests, one per mapped cell:
    • sea-trial/vendor/failure-classes.vendor.test.ts runs in CI against the real binaries (claude 10 cells, codex 13, pi 11).
    • sea-trial/vendor/failure-classes-acp.vendor.test.ts runs locally like the other ACP vendor tests: grok 5, kimi 3, opencode 4, antigravity 3. It also pins kimi's and antigravity's completed-looking failures.
  • Two existing vendor snapshots gained status: 400.
  • pnpm run check is green (1127 tests, mock 19/19). After the rebase onto main (feat: support native disallowedTools session filters #232, fix(claude): stream partial text and reasoning without duplicate blocks #233), the claude/codex/pi vendor suites pass locally, and so do the four ACP suites.

🤖 Generated with Claude Code

exe.dev user and others added 2 commits October 8, 2026 08:59
Failed turns are classified from what each runtime says, most structured
first: the runtime's own category, then the provider's error body (code,
then type), then the HTTP status; matching words is each adapter's
documented last resort. The evidence is docs/spec/runtime-matrix.md#failure-evidence.

- FailureClass gains model_unavailable, input_too_large, rate_limited and
  billing (additive). A failed outcome carries optional `credential`
  ("missing" | "rejected", only where the runtime makes it plain) and
  `status` (the provider's HTTP status).
- claude: assistant `error` + result `api_error_status` / `terminal_reason`
  (a credit balance is billing, an oversized context input_too_large, a 401
  a rejected credential, no request sent a missing one).
- codex: `codexErrorInfo` (serverOverloaded, contextWindowExceeded and the
  transport variants' httpStatusCode); `other` reads the provider body's code.
- pi: errorMessage's status prefix and JSON body; pi-ai's isContextOverflow.
- ACP: -32000 is auth; grok's -32003 is rate_limited and its -32603 takes
  the final retry_state's error_type. An RPC error's text `data` joins the
  reason.
- session() rejects with RuntimeFailureError { failure, credential?,
  status?, reason } for an ACP -32000 while opening, a -32602 answer to the
  model call, cursor's AuthenticationError, and a pi model oar does not find.
- observe: failureAdvice(failure) gives { retry: now | later | no,
  userAction }; failureText words auth by its credential and covers the new
  classes.

A 429 that names no quota or balance is now rate_limited, not quota; auth
without a credential reads "could not authenticate" instead of "is not
signed in".

Tests: unit tests for every mapping on the observed facts, and a vendor
test per mapped cell (failure-classes.vendor.test.ts in CI for claude,
codex and pi; failure-classes-acp.vendor.test.ts locally for the ACP
runtimes, which also pins kimi's and antigravity's completed-looking
failures).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…the message

An ACP open that fails with credential-bearing mcpServers passes its error
through redactError, which only rewrote the top error's message and stack:
a RuntimeFailureError's reason (a copy) and cause (the agent's error) kept
the values. reason is now a getter on the message, redactError follows the
cause chain, and a test opens with credentials against an agent answering
-32000 with them. clean-install asserts the missing-login wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xxchan
xxchan merged commit de2dfd5 into main Oct 8, 2026
13 checks passed
@xxchan
xxchan deleted the lookout/failure-classes branch October 8, 2026 09:24
@xxchan xxchan mentioned this pull request Oct 8, 2026
xxchan added a commit that referenced this pull request Oct 8, 2026
Release OAR and CLI 0.42.0. This PR changes only the two package version
fields.

**Behavior changes**
- `FailureClass` has four new members: `model_unavailable`,
`input_too_large`, `rate_limited` and `billing` (#237). Host code with
an exhaustive `switch` over it needs the new cases.
- A 429 that names no quota or balance is now `rate_limited`; it was
`quota`. A 429 whose provider code names a quota or a balance is `quota`
or `billing`.
- `failureText("auth", name)` without a credential now reads "could not
authenticate". It used to read "is not signed in", which was wrong for a
refused key. Pass the outcome's `credential` to get "is not signed in"
(`missing`) or "credentials were rejected" (`rejected`).
- Some opens now reject with `RuntimeFailureError` (still an `Error`,
same message) where they rejected with a raw `RequestError` or a plain
`Error`: an ACP agent that requires auth, a -32602 answer to the model
call, a key cursor refuses, a pi model OAR does not find.
- A grok failure reason now includes its `data` text (the provider's
answer), not only "Internal error".
- An input with empty text and no images is now rejected `unsupported`
(`empty input: give text or images`) before anything reaches the runtime
(#239).

**New**
- Structured failure classification (#237, closes #227). Each adapter
reads the runtime's own category first, then the provider's error body
(`code`, then `type`), then the HTTP status; matching words is a
documented last resort. Fixed: claude's "Credit balance is too low" (now
`billing`) and oversized context (now `input_too_large`); codex
`serverOverloaded` (now `overloaded`) and `contextWindowExceeded` (now
`input_too_large`).
- A failed `TurnOutcome` may carry `credential` (`missing` | `rejected`)
and `status` (the provider's HTTP status), only where the runtime says
them.
- `RuntimeFailureError { failure, credential?, status?, reason }` for
opens that fail for one of these causes.
- `observe`: `failureAdvice(failure)` returns `{ retry: "now" | "later"
| "no", userAction }`.
- The per-runtime rules and known gaps are in runtime-matrix "Failure
evidence".
- `Session.resources?(): Promise<{ rss, processes } | null>` (#238,
closes #231): the host memory a session's runtime takes, in bytes, over
the runtime process, its process group and its descendants, from one
reading of the process table. Null once the process has exited, on
Windows, and when the table cannot be read whole. Absent on pi and
cursor, which run in the host process. Observation only: nothing is
recorded or signalled, and no pid leaves OAR. Concurrent calls share one
read.
- Image-only input (#239, closes #235): `prompt`, `steer` and `queue`
take `""` when `images` is non-empty. claude, codex and the ACP runtimes
no longer receive an empty text part; pi and cursor take the text as an
argument and receive `""`. grok drops images smaller than 8×8 without
saying so (its runtime page has the evidence).

Validation: all 13 checks passed on each PR's final head (#237
`772d337`, #238 `3c60fd7`, #239 `47d91ac`), and each merged tree equals
its CI tree. After this PR passes CI and merges, tag its exact squash
commit as `v0.42.0` to trigger npm trusted publishing.

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

Co-authored-by: exe.dev user <[email protected]>
Co-authored-by: Claude Opus 5.5 <[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.

Classify runtime failures from structured runtime fields: richer FailureClass, status, advice, and open failures

1 participant