Skip to content

Dream: price-weight the shared minute ceiling and pause instead of discarding a pass - #21933

Merged
Git-on-my-level merged 2 commits into
mainfrom
lane/dream-minute-headroom
Oct 16, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
lane/dream-minute-headroom

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

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_budget stop. Just before it, the same sweep ran 26 turns ($0.57), hit dream_minute_headroom, and the whole pass was discarded and restarted.

  • The shared minute ceiling (DREAM_AGENT_TOKENS_PER_MINUTE, 2M) counted raw prompt tokens, so every resent cached prefix counted in full. The minute hold in dream_turns.reserve and its settlement now count reserved-capacity burndown (cached input 0.1, output 5x for gemini-3.8-flash) instead of raw tokens.
  • A full minute now pauses the pass until the next minute and retries (up to 3 times, only while at least a minute of deadline remains) instead of ending it as waiting and redoing the work. Other reserve errors and exhausted retries behave as before.

Product invariants

  • INV-MEM-4: no change to verification or apply authority.

Verification

  • New tests/unit/test_dream_minute_headroom.py: one refusal pauses (≤61s) and the pass completes; persistent refusal still ends waiting; a 90%-cached 200k prompt holds under a third of its raw size.
  • All tests/unit/test_dream_*.py pass.

Failure-Class: none

🤖 Generated with Claude Code

…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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T21:35:52.044577Z 5469f81 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +244 to +245
str(exc) != 'dream_minute_headroom'
or attempt == MINUTE_HEADROOM_RETRIES

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +145 to +148
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)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +229 to +231
cached_tokens=(
min(cached_estimate, estimate) if type(cached_estimate) is int and cached_estimate >= 0 else None
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 6812f29 into main Oct 16, 2026
57 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/dream-minute-headroom branch October 16, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant