Skip to content

Governed runs (beyond codex): aggregate attempts, time, tokens, spend, and descendant tool budgets #217

Description

@yxlyx

Parent

#216

Problem

A goal turn has several local caps, but no aggregate budget controls the whole run:

  • Agent.runTurn() repeats model/tool rounds with while (true).
  • max_tokens = 16000 limits one response, not cumulative tokens.
  • --max-tool-calls defaults to unlimited and counts only root calls; descendant subagent/workflow tool activity is not comprehensively charged.
  • request/idle watchdogs do not bound total run wall time;
  • cost is measured but never used as a stop condition;
  • network retry limits are transport policy, not goal-attempt limits.

A production run must know before each action whether enough budget remains.

Proposal

Introduce a harness-owned RunBudget/RunUsage envelope for governed /goal and /loop runs. At minimum support:

  • max_attempts / outer verifier retries;
  • max_model_rounds;
  • max_elapsed_ms using a monotonic deadline;
  • aggregate input, cached-input, reasoning, and output token ceilings;
  • max_usd for priced providers plus an explicit policy for unpriced/subscription providers;
  • aggregate tool-call ceiling across root, subagent, workflow, and MCP descendants;
  • optional concurrency ceiling.

Expose policy through terminal CLI flags/slash controls and TUI session persistence. Use finite documented defaults for governed runs; allow ordinary interactive chat to preserve its current behavior if clearly distinguished. This issue is exclusively TUI/harness scope.

Enforcement requirements

  • Check budget before every model request and tool dispatch/reservation.
  • Parallel work must reserve atomically so a batch cannot overshoot through races.
  • Descendants inherit a non-widenable slice of the parent's remaining budget.
  • Retries and verifier calls are charged, including failed API attempts where usage/cost is knowable.
  • On exhaustion, cancel/stop descendants and emit a structured terminal reason rather than asking the model to stop voluntarily.
  • The agent may request escalation but may not increase its own budget.

Acceptance criteria

  • Governed runs start with finite defaults for every supported aggregate dimension.
  • TUI users can lower limits through CLI flags or slash controls; widening an active run requires explicit human approval.
  • Root + nested usage is visible as used/remaining values.
  • A deliberately non-terminating tool loop stops at the configured model-round/tool/time ceiling.
  • A subagent fan-out cannot exceed the parent's tool/token/cost allocation.
  • Parallel reservations are race-safe and bounded.
  • Exhaustion emits a machine-readable exhausted event with the exact dimension and used/limit values.
  • Tests cover each limit independently and simultaneous-limit races.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions