Skip to content

Per-task turn cap and cost/token budget #236

Closed

Description

@vicgupta

Goal

Add cheap hard limits per task: a maximum number of turns and a maximum cost/token budget, instead of complex stuck-detection (see Harness Engineering, Part 4: "skip stuck-detection machinery, but ship cheap caps").

Behavior

  • First check what already exists on main (step/turn limits, usage tracking, pricing) and extend rather than duplicate.
  • max_turns: stop the loop cleanly after N model turns.
  • Budget: max total tokens and/or max cost in USD per task from provider-reported usage; cost uses a configurable per-model price table (unknown model → token budget only, warn once).
  • Warn the model once at ~80% of a budget so it can wrap up; at 100%, stop cleanly with a clear message and defined exit status, recorded in output, JSON events, trajectory and OpenTelemetry if enabled.
  • Subagents/workers count against the parent's budget.
  • Flags + config keys consistent with existing patterns; sensible defaults (turn cap on, cost cap off unless set).

Tests

  • Turn cap stops at N.
  • Token budget stops the run; 80% warning injected once.
  • Cost computed from usage + price table.
  • Worker usage counts toward the parent.
  • Unknown model price → token budget fallback.

Do not refactor unrelated code. No CHANGELOG edits.

Activity

  1. added
    amf:readyReady for amf to turn into a pull request
    and removed
    amf:readyReady for amf to turn into a pull request
    on Oct 30, 2026
  2. vicgupta commented on Oct 30, 2026

    @vicgupta
    OwnerAuthor

    Slice in progress: #246 adds the token budget (--token-limit / token_limit, status TokenLimitExceeded), the one-time 80% budget warning (message + budget.warning event), and delegate/worker token accounting against the parent's budget. Step limit, cost limit with a price table, and the unpriced-model warning were already on main.

    Still left for this issue:

    • Decide on and add a default-on turn cap (needs telling an unset step_limit apart from an explicit 0, and changes behaviour for existing configs).
    • Show the token limit in the --check limits line and in init-config output.
    • Forward --token-limit through eval, attempts and workflow stages where the other limits are forwarded.
  3. added a commit that references this issue on Oct 30, 2026
  4. added
    amf:readyReady for amf to turn into a pull request
    and removed on Oct 30, 2026
  5. vicgupta commented on Oct 30, 2026

    @vicgupta
    OwnerAuthor

    Decision from Vic: keep the turn cap off by default (no default-on turn cap). Remaining work for this issue: show the token limit in --check output and init-config, and pass --token-limit through eval, attempts and workflow stages.

  6. added and removed
    amf:readyReady for amf to turn into a pull request
    on Oct 30, 2026
  7. added
    amf:doneamf opened a pull request for this issue
    and removed on Oct 30, 2026
  8. added a commit that references this issue on Oct 30, 2026
    061dbcc
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

    amf:doneamf opened a pull request for this issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions