Skip to content

SPEC-023: Errors and diagnostics

  • Status: Implemented
  • Milestone: v0.11 "Errors and diagnostics"
  • Owners: lead maintainer

1. Purpose

When something goes wrong, every user, new or experienced, should see what happened, where, and what to do next, in plain words, the same way in the terminal, the log, the replay page, reports and experiments. Today most problems are handled well, but real runs showed gaps: - Gemini's error list printed as raw Python text. - OpenRouter's real 429 reason was dropped. - A judge failure appeared as ValueError: ... with no fix. - A forfeit didn't say why. - A debate's normal end read like a result. - An unexpected crash printed a full traceback.

This spec gives every user-facing problem one structured form, a stable code, a fix and a docs page, and requires every surface to show it.

2. Terms

Keywords MUST, SHOULD and MAY follow RFC 2119. - Error record: the structured form of one problem: code, what, fix, and when known where and docs. - Code: a stable dotted name for a kind of problem, such as provider.rate_limited. - Catalog: the one list, in the code, of every code with its kind, default fix and docs anchor. - Explanation: the error record (or, for a normal end, a short note) that says why a run ended. - Surface: anywhere a user reads results: the terminal, the log, the replay and live pages, summaries, reports and experiment status.

3. Requirements

The error record

  • ERR-001 Every problem shown to a user MUST be an error record: code, what (one plain sentence), fix (what to do), and when known where (a file and field, an agent and step, or a log path) and docs (a link to the Troubleshooting section for the code). It MUST be plain data, so the log, pages and reports carry the same record.
  • ERR-002 Codes MUST come from one catalog in the code. Each catalog entry has the code, its kind (config, environment, provider, agent, world, evaluator or internal), a default fix and its docs anchor. Renaming or removing a code MUST be listed as a breaking change in the changelog.
  • ERR-003 Error text MUST be written for people: no Python exception class names, no printed Python dicts or lists, and no tracebacks unless --debug is given. what MUST be at most 300 characters, and secrets MUST be redacted (SEC-002).
  • ERR-004 The catalog MUST contain at least:
Kind Codes
config config.invalid, config.missing_key, config.missing_extra
environment environment.runtime_missing, environment.not_writable
provider provider.auth, provider.model_not_found, provider.rate_limited, provider.quota, provider.bad_request, provider.no_structured_output, provider.unavailable, provider.unreachable, provider.timeout
agent agent.format, agent.crashed
human human.no_terminal, human.not_here (SPEC-027)
world world.rejected, world.bug
evaluator evaluator.invalid_result, evaluator.bug
internal internal.bug

Provider errors

  • ERR-005 Provider error bodies MUST be read whatever their shape, and the provider's own message shown as one clean line. Shapes to read include:
  • an object whose error is an object or a string;
  • a list of such objects, as Gemini sends;
  • OpenRouter's nested metadata, keeping the upstream provider's name and its message;
  • Anthropic's error type;
  • plain text and HTML pages.
  • ERR-006 A provider error MUST map to a code by its status and message:
Status or message Code
401 or 403 provider.auth
404, or a message saying the model does not exist or is no longer available provider.model_not_found
429 provider.rate_limited, or provider.quota when the message is about quota, credits or billing
400 or 422 for a constrained agent, naming response_format, json_schema or structured output provider.no_structured_output (SPEC-025 REL-005)
other 400 or 422 provider.bad_request
5xx provider.unavailable
connection refused, or host not found provider.unreachable
no reply in time provider.timeout

Presets MAY replace the default fix for a code. The existing hints of ADP-024 and HFM-003 become such replacements. - ERR-007 Every provider code's fix MUST name a concrete action. For provider.model_not_found it SHOULD say how to list the service's models when the service supports it (for an OpenAI-compatible service: GET <base_url>/models). For provider.rate_limited on a free model, it SHOULD mention free-tier limits.

Why a run ended

  • ERR-008 run_end MUST carry explanation:
  • forfeit: the agent, how many rejected moves in a row, the most common rejection, and what to try (wrap: [format_hints], json_mode: true, a higher limits.max_illegal);
  • aborted: the provider's error record;
  • a limit: which limit was reached, its value, and the setting to raise;
  • world_error: a world.bug record naming the world's file and line when known;
  • finished with no winner: "no winner" or, when the world's describe() says decided_by: "judge", that this world needs the judge evaluator to name a winner.
  • ERR-009 The terminal's end-of-run line MUST show the explanation: the result, then on the next line the fix when there is one, for example forfeit: llama wins: qwen sent 3 rejected moves in a row and try: wrap: [format_hints], json_mode: true, or limits.max_illegal: 5.

Agent, world and evaluator errors

  • ERR-010 Every agent_error and provider_error event MUST carry code and fix. A step_result that rejects a move MUST carry code: "world.rejected", keeping the world's own message as error.
  • ERR-011 The judge evaluator MUST try once more, with a note that shows the verdict's shape, when its verdict is invalid. It MUST report evaluator.invalid_result with a fix (a larger model, json_mode: true) only when the second try fails too.
  • ERR-012 Evaluator failures MUST be shown with the evaluator's name and a code, for example judge: evaluator.invalid_result: the judge answered "passed" instead of a verdict -> use a larger judge model, never as an exception class name.

Crashes

  • ERR-013 The CLI MUST catch every unexpected exception and print an internal.bug record with the AgentPlay version, the log path when a run had started, and a link for reporting the bug, then exit with code 1. With --debug it MUST also print the traceback. A log already open MUST still end with run_end (RUN-013).

Surfaces

  • ERR-014 The replay and live pages MUST end a run with a banner showing the explanation (what, fix and docs link), and MUST show the code and fix of every rejected move and error in the turn list.
  • ERR-015 Multi-run summaries, reports and experiment status MUST group errors by code, with the count, the fix and the first log where each happened.
  • ERR-016 agentplaykit doctor failures MUST use the same records (environment.*, config.missing_extra).

Docs, tests and compatibility

  • ERR-017 The docs MUST have a Troubleshooting page with one section per code, whose anchor is the code, and every record's docs link MUST point to its section. A test MUST check that every catalog code has a section.
  • ERR-018 Tests MUST pin the exact text shown for each code in representative cases, and MUST include error bodies in the real shapes of OpenAI, OpenRouter, Gemini, Anthropic, Ollama and Hugging Face, covering every shape of ERR-005 (written from each service's error format, or copied from real runs where available, as ADP-016's fixtures are).
  • ERR-019 All additions to the log MUST be additive, so log_version stays 1. Logs written before this spec MUST still show in the viewer and reports, with codes inferred where the old text allows and unknown otherwise.

4. Acceptance criteria

Requirement Test ID Notes
ERR-001..004 ERR-001..ERR-004 record shape; catalog completeness and kinds; no reprs or class names in any message; redaction
ERR-005..007 ERR-005..ERR-007 recorded bodies per provider and shape; status and message mapping table; preset fix replacements
ERR-008..009 ERR-008, ERR-009 an explanation for each end reason; the terminal lines, pinned
ERR-010..012 ERR-010..ERR-012 codes in events; the judge retry with a scripted judge; evaluator messages
ERR-013 ERR-013 a crashing plugin and a crashing internal function; with and without --debug
ERR-014..016 ERR-014..ERR-016 banner and turn list in a browser test; grouped errors in summary, report and status; doctor
ERR-017..019 ERR-017..ERR-019 every code documented; golden texts; old logs still render

5. Examples

What you saw before, and what you would see:

before:  x: provider error (attempt 1): 404 from https://generativelanguage.googleapis.com/...:
         [{'error': {'code': 404, 'message': 'This model models/gemini-2.5-flash is no longer
         available to new users. ...
after:   aborted: provider.model_not_found: gemini-2.5-flash is no longer available to new users
           (Gemini says: "use models/gemini-3.8-flash")
           try: change model to one your key can use; list them with
                GET https://generativelanguage.googleapis.com/v1beta/openai/models
           docs: https://agentplay.itejas.dev/troubleshooting/#provider.model_not_found
before:  aborted: no result
after:   aborted: provider.rate_limited: OpenRouter's upstream provider (Google AI Studio)
           rate-limited the free model google/gemma-4-31b-it:free
           try: wait a minute, pick another :free model, or add credits to raise free limits
before:  finished: draw in 16 steps
after:   finished: no winner in 16 steps; this world needs the judge evaluator to name one

In the log:

{"type": "run_end", "reason": "forfeit", "outcome": {"winners": ["llama"]},
 "explanation": {"code": "world.rejected", "what": "qwen sent 3 rejected moves in a row",
   "fix": "try wrap: [format_hints], json_mode: true, or limits.max_illegal: 5",
   "where": {"agent": "qwen", "step": 2},
   "docs": "https://agentplay.itejas.dev/troubleshooting/#world.rejected"}}

6. Open questions

  • A --json option that prints error records as JSON for scripts and CI.
  • Translations of the error text.
  • Whether internal.bug should offer to open a pre-filled GitHub issue.

7. Change log

  • 2026-12-01: Initial draft.
  • 2026-12-01: Accepted by the lead maintainer for v0.11. The catalog also has limit.* codes (for runs that reach a limit) and run.interrupted; a normal end's explanation is a note (what, optional fix) without a code.
  • 2026-12-03: Implemented in v0.11.0; every requirement has a test.
  • 2026-12-03: Added provider.no_structured_output (ERR-006), with SPEC-025.
  • 2026-12-04: Added the human codes (ERR-004), with SPEC-027.

Changes to other specs on acceptance

  • SPEC-001: describe() MAY include decided_by: "judge" (ERR-008).
  • SPEC-003: code and fix on agent_error, provider_error and rejecting step_result events, and run_end.explanation (additive).
  • SPEC-007, CLI-007: the error line ends with the code, as error: <what> (<where>) -> <fix> [<code>]; the end-of-run lines of ERR-009; the crash handling of ERR-013.
  • SPEC-009: ADP-012, ADP-024 and HFM-003 hints become preset fixes in the catalog (ERR-006).
  • SPEC-010, EVL-013: the judge's one retry (ERR-011).
  • SPEC-012, SPEC-013 and SPEC-019: the banner and the grouped errors (ERR-014, ERR-015).
  • Roadmap: benchmark suites (SPEC-020) move to v0.12, and behaviour and strategy (SPEC-021, SPEC-022) to v0.13.
  • 2026-12-01: ERR-018 says the provider error bodies follow each service's real shapes (written from their formats, or copied from real runs where available), rather than claiming every one was recorded.