Skip to content

Enforce a shared spending budget before model requests across root and subagents #55180

Open

Description

@teslashibe

What variant of Codex are you using?

Codex desktop on macOS, app 26.1013.40934 (build 20770), bundled runtime 0.163.0-alpha.10.2.

Source references below use commit 4ebc485ca321243727539187169425fcf972f2c4, the commit targeted by release tag rust-v0.163.0-alpha.10.2. The referenced files were compared with that commit. The shared-budget implementation was also checked on main at 89461ea6833832b0551ce24ee32205824d5c108d and is unchanged.

What feature would you like to see?

Extend the existing shared rollout budget so it reserves capacity before each model request, accounts for all priced usage, and prevents further automatic model work after exhaustion across the root and its descendants.

User story: As a desktop user authorizing a long-running task, I want one enforceable spending limit for the whole task so that subagents, follow-ups, retries and compaction cannot continue consuming my allowance beyond that authorization.

This is a focused implementation companion to the incident report at #55168. It supplies a runtime contract for the broader budget request at #45536; estimates, model comparisons and a new usage dashboard are outside this issue.

Observed behavior and existing ownership

The incident's fixed 36-hour response ledger recorded 8,949,499,238 input-plus-output tokens across 50,465 unique responses, including 8,788,141,824 cached input tokens. These are processed tokens, not unique text, full-price uncached tokens or a verified invoice. The inspected large goals had no configured token budget, so this does not demonstrate violation of an explicit budget. A concurrency cap alone cannot bound repeated work over time.

The runtime already has the appropriate ownership boundary:

Bounded technical specification

  1. One shared admission decision per request. Extend the existing budget owner with atomic reservation and settlement. Before dispatch, require settled usage + outstanding reservations + requested reservation <= authorized limit. Apply this to ordinary sampling, foreground/background compaction, and every retry that may incur additional provider work. Do not create a separate budget for each child or replenish the budget on follow-up.
  2. Honest units and bounds. Include cached input, uncached input, output and any other priced request component. Use authoritative provider units/rates and bounded request parameters when available. A strict spending guarantee requires a conservative pre-request upper bound or provider-enforced cap. If that contract is unavailable, expose the limit as an estimate or weighted-token limit, not a guaranteed USD/credit ceiling. Do not charge cached input at the uncached rate merely to simplify the counter.
  3. Conservative recovery. Settle each reported response once. Preserve unresolved reservations when a dispatched request times out, is cancelled, or returns no usage; missing usage is not evidence of zero cost. A retry may perform additional billable work even when local settlement is idempotent. Reconcile uncertainty before reopening capacity, and preserve budget identity, settled usage, pending reservations and exhaustion across resume/restart using existing persistence boundaries.
  4. Exhaustion closes model admission. Return a typed budget-exhausted result without another provider call. Follow-ups, nested workers and automatic goal continuations must honor the same state. Preserve completed work and stop scheduling new model requests; do not indiscriminately kill unrelated shell/MCP operations. Requests already dispatched may still incur charges. Increasing the limit must be an explicit user action, not a model decision.
  5. Explicit authorization for unattended work. Use the existing configuration/protocol surface to distinguish a finite limit from explicitly authorized unbounded operation. Missing configuration must not be presented as spending protection. Report settled, reserved and remaining units plus the stop reason without requiring a new dashboard.

Proposed change locations, reusing existing packages:

codex-rs/core/src/rollout_budget.rs             reservation and settlement
codex-rs/core/src/agent/control/               shared admission and exhaustion
codex-rs/core/src/session/                     sampling dispatch and usage hooks
codex-rs/core/src/compact_remote_v2*.rs         compaction coverage
codex-rs/ext/goal/src/                         continuation respects exhaustion
codex-rs/state/                               durable budget state and recovery

These are proposed ownership locations, not a request for a new generic scheduler or accounting framework.

Acceptance criteria

  • Three concurrent workers contend for the last request allowance: only requests with an atomic reservation reach the fake provider, and total reservations plus settled usage remain within the configured bound.
  • A single turn containing many sampling/tool cycles cannot bypass admission; nested children, resumed workers and goal continuations use the same budget.
  • Cached-heavy requests and foreground/background compaction consume the correct defined units. Goal-token totals and spending units remain separately labeled.
  • Duplicate completion delivery settles once; a retry that performs new provider work receives its own reservation. Missing usage, disconnect and cancellation retain conservative accounting.
  • Restart/resume neither resets an exhausted budget nor frees unresolved reservations. A crash between reservation and dispatch has a conservative, documented recovery path.
  • Exhaustion emits a typed result, preserves completed output, and produces no further unreserved model requests. Only an explicit limit increase permits additional spending.
  • Verify these scenarios with deterministic local/fake-provider tests; reproducing the 36-hour incident on a paid account is unnecessary.

Dependencies and exclusions

The billing-unit definition and a bounded per-request cost contract are prerequisites for claiming a strict monetary ceiling. The existing codex_rollout_budget_units field is an integration point; its presence alone does not establish that it equals credits or USD.

Related investigations, not asserted blockers or parent/child issues:

Excluded: proving incorrect billing or obtaining refunds, repairing the separate concurrency-admission race, changing model defaults, redesigning context compaction, adding a semantic progress watchdog, and estimating task cost or comparing models. Those concerns can be investigated independently of this shared request-budget contract.

Additional information

This is a proposed safeguard supported by source inspection, not an implemented patch or proof that one defect caused the entire incident. The linked incident has sanitized evidence and offline accounting reproductions available; this issue contains no raw prompts, credentials or private project contents.

Activity

  1. added
    enhancement
    app
    subagent
    rate-limits
    on Oct 19, 2026
  2. mmoemou commented on Oct 21, 2026

    @mmoemou

    A complementary acceptance-test perspective from users studying usage efficiency, separate from the hard reservation/settlement design already proposed here.

    Please keep two controls independent:

    • Hard shared root+descendant budget: authorization must be enforced before provider requests, including retries and compaction; actual charges settle against that reservation. A UX warning or “three unproductive reviews” heuristic is not a hard ceiling.
    • Progress watchdog (advisory): track accepted deliverables / changed evidence / newly discovered defects by review stage and request a human checkpoint after configurable expensive rounds without useful progress. A valid negative regression test does count as useful verification.

    A useful, fully synthetic regression matrix for the runtime budget would be:

    1. Root and two child agents race for the last reserved units: only requests inside the shared remaining budget start; no per-child fresh allowance.
    2. A request is retried or compacted: any additional potentially billable provider work needs a fresh authorization/reservation.
    3. A reservation is larger than final usage: release the unused reservation exactly once; an interrupted request follows an explicitly defined uncertainty/settlement policy.
    4. The task is paused/resumed: the spent-and-reserved ledger survives the checkpoint, and resume does not silently reset authorization.
    5. Quota percentages and locally observed input/cached-input/output counters are presented separately from authorized spend; rounded 5-hour/weekly allowance movement must not be reverse-converted into fictitious exact tokens or money.

    For progress/watchdog context, a developer discussion at #46023 raised a practical issue: real model requests can repeatedly process enormous mostly cached context while producing very little new accepted evidence. That waste remains even after replayed telemetry records are correctly deduplicated: #46023 (comment)

    Would maintainers consider publishing a schema for one root-task budget ledger and its admission/settlement outcomes, with optional non-sensitive job identifiers? That would enable independent privacy-preserving measurement without requiring end users to share prompts, repositories or raw logs.

    No private project details or executable code are offered here.

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

    appenhancementrate-limitssubagent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions