Repository navigation
Dream: price-weight the shared minute ceiling and pause instead of discarding a pass - #21933
Conversation
…of discarding a pass The 20:00Z pass ran 26 turns, then hit dream_minute_headroom and was thrown away and restarted: the 2M tokens/minute ceiling counted every resent cached prefix at full weight. The minute hold and its settlement now use the same price-weighted tokens as the pass meter, and a full minute pauses the pass until the next minute (up to three times, within the deadline) instead of ending it as waiting and redoing the work. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be88cb4124
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| str(exc) != 'dream_minute_headroom' | ||
| or attempt == MINUTE_HEADROOM_RETRIES |
There was a problem hiding this comment.
Skip retries when the reservation can never fit
When DREAM_AGENT_TOKENS_PER_MINUTE is configured below a single turn's weighted reservation, dream_turns.reserve() raises the same dream_minute_headroom error from its tokens > caps.tokens_per_minute guard. This branch treats that permanent condition as transient shard exhaustion and sleeps across as many as three minute boundaries while retaining the owner lease and capacity slot, even though every retry must fail. Check the reservation against the configured ceiling before sleeping, or distinguish the permanent error from temporary exhaustion.
Useful? React with 👍 / 👎.
Review: the minute ceiling backstops reserved Vertex throughput, whose gemini-3.8-flash burndown counts cached input at 0.1 and output at 5. The pass meter's price weight counts output at 1, so the minute hold and settlement now add the output top-up (output/input price ratio, 5 when unverified). Tests now lock hold/settle shard totals, the raw fallback, and the 4-attempt/3-pause cap. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5469f81420
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| base = weighted if type(weighted) is int and 0 <= weighted <= charge else charge | ||
| remaining = minute_burndown_tokens( | ||
| 'gemini', 'gemini-3.8-flash', weighted_tokens=base, completion_tokens=min(completion, base) | ||
| ) |
There was a problem hiding this comment.
Retain output-weighted headroom for unknown attempts
When the gateway reports an incomplete/unknown attempt, charge_attempts() places the raw attempt ceiling in price_weighted_tokens but excludes that attempt's output from completion_tokens. This settlement therefore drops the output top-up that was reserved before dispatch—for example, a wholly unknown default-size attempt is reduced from input + 5 * 32768 to input + 32768. During provider failures, concurrent calls can consequently refund substantial provisioned-throughput usage and admit traffic beyond the configured minute ceiling; unknown attempts should retain the original hold or otherwise preserve the conservative output-weighted charge.
Useful? React with 👍 / 👎.
| cached_tokens=( | ||
| min(cached_estimate, estimate) if type(cached_estimate) is int and cached_estimate >= 0 else None | ||
| ), |
There was a problem hiding this comment.
Do not reserve against an unconfirmed cache hit
On every main-lane turn after the first, this discounts the new reservation using the previous turn's reported cached-token count. A prior implicit-cache hit does not guarantee that the next request will hit the cache, so a 180k-token prefix can reserve only 18k input-burndown tokens and then consume the full 180k when that cache entry misses or is evicted. Settlement eventually raises the counter, but concurrent requests have already been admitted and dispatched by then, allowing a cache-miss burst to exceed the configured provisioned-throughput ceiling; pre-dispatch headroom needs to treat the current turn's cache state as unconfirmed or otherwise bound this exposure.
Useful? React with 👍 / 👎.
Summary
First complete uncapped Dream pass (2026-10-16 20:00Z, allowlisted owner): 40 turns, 4.1M raw / 999k price-weighted tokens, 9 verifier calls, 8 applied, $0.82, clean
dream_input_token_budgetstop. Just before it, the same sweep ran 26 turns ($0.57), hitdream_minute_headroom, and the whole pass was discarded and restarted.DREAM_AGENT_TOKENS_PER_MINUTE, 2M) counted raw prompt tokens, so every resent cached prefix counted in full. The minute hold indream_turns.reserveand its settlement now count reserved-capacity burndown (cached input 0.1, output 5x for gemini-3.8-flash) instead of raw tokens.waitingand redoing the work. Other reserve errors and exhausted retries behave as before.Product invariants
Verification
tests/unit/test_dream_minute_headroom.py: one refusal pauses (≤61s) and the pass completes; persistent refusal still endswaiting; a 90%-cached 200k prompt holds under a third of its raw size.tests/unit/test_dream_*.pypass.Failure-Class: none
🤖 Generated with Claude Code