Repository navigation
Description
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:
LocalAgentRuntimeshares oneArc<RolloutBudget>across the root and cloned subagent controls.RolloutBudget::record_usageaccounts reported usage and then checks exhaustion. With no configuration it returnsfalse. The fallback counts weighted output and uncached input; server-providedcodex_rollout_budget_unitstake precedence when present.- Completed usage is passed to budget accounting, and exhaustion returns
SessionBudgetExceeded. Post-response accounting alone cannot reserve the remaining allowance against concurrent requests. - Goal continuation can start another idle turn. The spending decision needs to apply to model requests within turns as well as new turns: one incident coordinator produced 1,860 responses in only two turns.
- Goal token accounting excludes cached input. This is intentional behavior and must not silently become a proxy for billed credits.
Bounded technical specification
- 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. - 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.
- 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.
- 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.
- 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:
- Incident evidence: Codex desktop: 8.95B recorded tokens in 36h, context amplification and omitted compaction usage (related to #44884) #55168
- Broader task-budget product request: Enforceable task budgets and clearer usage controls in Codex #45536
- Missing response usage: A response.completed without a usage block silently skips all token totals and the rollout budget #37138
- Provider quota exhaustion admission, a separate resource condition: [Feature Request] Add a resource-scoped admission gate for provider quota exhaustion #39582
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
github-actions commentedon Oct 19, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
mmoemou commentedon Oct 21, 2026
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:
A useful, fully synthetic regression matrix for the runtime budget would be:
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.