Skip to content

SPEC-004: Runner

  • Status: Implemented
  • Milestone: M1
  • Owners: lead maintainer

1. Purpose

Define how an episode runs: turn order, limits, illegal moves, forfeits and error handling. The runner is the only part that connects worlds, agents, messages and the log.

2. Terms

  • Step: one agent action applied via step. Round: in a simultaneous world, one set of actions applied together.
  • Illegal move: a step returning ok=false. Model failure: AgentError. Provider error: ProviderError (SPEC-002).

3. Requirements

Lifecycle

  • RUN-001 The runner MUST: validate inputs; call world.reset(seed) and agent.reset(...); write run_start; loop turns until world.done() or a limit; write run_end.
  • RUN-002 Each turn the runner MUST ask to_act(), send each listed agent a Request (SPEC-002), apply the Reply via step, and log events per SPEC-003.
  • RUN-003 For simultaneous worlds the runner MUST collect all actions from the round's agents before applying any, then apply in to_act() order. Each agent MUST see only the state from before the round.
  • RUN-004 Seeds: the run seed MUST derive per-agent seeds deterministically (agent id and run seed), recorded in the log.

Limits (on by default)

  • RUN-005 Limits max_steps (default 200), max_seconds (default 600) and max_cost_usd (default 1.00) MUST apply unless explicitly set otherwise; a scenario MAY set a limit to null only with an explicit value.
  • RUN-006 When a limit is reached the runner MUST stop before the next agent call, write limit_hit, and end with the matching reason (step_limit, time_limit, budget_exceeded).
  • RUN-007 Cost MUST be checked before each call against cumulative cost; a call whose reported cost pushes the total over the cap ends the run after that call.

Illegal moves and forfeits

  • RUN-008 On an illegal move the runner MUST send the error back to the agent in its next Request and let it retry; the world state is unchanged.
  • RUN-009 After max_illegal consecutive illegal moves by one agent (default 3), the runner MUST log forfeit and end the run with reason forfeit (two-agent worlds: the other agent wins in outcome; the world decides scores).
  • RUN-010 A model failure (AgentError) MUST count as an illegal move.

Errors

  • RUN-011 A ProviderError MUST be logged as provider_error, never counted as an illegal move or forfeit. After retries are exhausted the run ends with reason aborted and the log says which provider failed.
  • RUN-012 An exception from the world (a bug) MUST be logged, end the run with world_error, and surface a short message naming the world and method.
  • RUN-013 An exception from an evaluator MUST NOT change the run log or result of the episode.
  • RUN-014 User mistakes (bad scenario, missing key) MUST produce a one-line error naming the file, field and fix, not a stack trace (SPEC-007).

Messages and isolation

  • RUN-015 Messages from say MUST be delivered through the bus (SPEC-008) and appear in the next Request inbox of recipients.
  • RUN-016 The runner MUST pass agents plain data copies; agents MUST NOT hold references to world state.
  • RUN-018 In a simultaneous round every Request MUST carry the step number at the start of the round; the applied actions then take consecutive step numbers in to_act order. An agent whose action was illegal stays in to_act and acts again, alone, before the round resolves.
  • RUN-019 When an agent reports cost_usd: null, the runner MUST log one warning for that agent and enforce max_tokens (default 200000, total input plus output tokens of all agents); exceeding it ends the run with budget_exceeded after a limit_hit with limit "tokens".
  • RUN-020 For each entry in a reply's meta.retries the runner MUST log a provider_error (retryable true) before that reply's action.
  • RUN-021 The runner MUST call close() on every agent that has it, and on the world when it has one, when the episode ends, including on errors and interruptions (Ctrl+C).
  • RUN-022 A world that declares outcome_on_limit: true in describe() MUST have outcome() called when the run ends by a limit (step_limit, time_limit, budget_exceeded); run_end.outcome records it and the reason stays the limit (SPEC-014 SBX-003).
  • RUN-017 Each Request MUST include last_error: the error from that agent's previous illegal move or agent error, or null (how RUN-008 sends the error back).

4. Acceptance criteria

Requirement Test ID Notes
RUN-001..004 RUN-001..RUN-004 tic-tac-toe run end to end
RUN-005..007 RUN-005..RUN-007 fake agent with cost per call
RUN-008..010 RUN-008..RUN-010 agent that always plays illegally
RUN-011..014 RUN-011..RUN-014 429 fixture; buggy world
RUN-015..016 RUN-015, RUN-016

5. Open questions

  • Per-call timeout vs. whole-run timeout (draft: whole-run only plus adapter timeouts).
  • Should forfeits be configurable per scenario? (Yes via max_illegal.)

6. Change log

  • 2026-11-30: Initial draft.
  • 2026-11-30: Accepted by the lead maintainer.
  • 2026-11-30: Added RUN-017 (last_error field), already implemented in M1.
  • 2026-11-30: Added RUN-018 (step numbers in simultaneous rounds).
  • 2026-11-30: Added RUN-019 (token cap for unknown cost), RUN-020 (retries logged), RUN-021 (agents closed).
  • 2026-11-30: Implemented in v0.1.0; every requirement has a test (PRO-004, PRO-011).
  • 2026-11-30: The reference world ox is renamed tic-tac-toe (ADR-0006); no alias.
  • 2026-12-01: RUN-021 covers the world's close(); added RUN-022 (outcome_on_limit), with SPEC-014.