feat(opencode): dynamic quota windows — length-driven display, present-window policy, reset credits#46
Closed
iceteaSA wants to merge 2 commits into
Closed
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 18 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
iceteaSA
force-pushed
the
feat/dynamic-quota-windows
branch
from
July 16, 2026 18:56
f0fe8dd to
de571ff
Compare
…-window policy, per-account reset credits) OpenAI removed the 5h usage window; the live wire now sends a single 7-day window in the primary slot with the window length on every source. Carry the window length onto the quota window type and derive the display label and pacing ruler from it instead of the slot name, render only the windows that are actually present, evaluate killswitch/quota policy across present windows only (an absent window is not-applicable, not unknown), and surface the wham-only rate_limit_reset_credits.available_count per account in the sidebar and the /openai-quota modal. Slot names primary/secondary remain the stable keys for storage, marks, thresholds, and mid-stream reset attribution.
iceteaSA
force-pushed
the
feat/dynamic-quota-windows
branch
from
July 16, 2026 19:47
de571ff to
ab061e8
Compare
…-window policy, per-account reset credits) OpenAI removed the 5h usage window; the live wire now sends a single 7-day window in the primary slot with the window length on every source. Carry the window length onto the quota window type and derive the display label and pacing ruler from it instead of the slot name, render only the windows that are actually present, evaluate killswitch/quota policy across present windows only (an absent window is not-applicable, not unknown), and surface the wham-only rate_limit_reset_credits.available_count per account in the sidebar and the /openai-quota modal. Slot names primary/secondary remain the stable keys for storage, marks, thresholds, and mid-stream reset attribution. A retired window is detected by its explicit zero-length marker, not by the absence of optional metadata.
Contributor
|
Superseded by the integrated implementation prepared for main. It retains length-driven quota windows and reset credits, while atomically rejecting malformed header frames, preserving legacy 5h/7d snapshots, and deriving killswitch Retry-After from policy-violating windows only. Thank you for the implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OpenAI removed the 5-hour usage window. Captured live against a
team-plan account, all three quota sources (HTTPx-codex-*headers, the WScodex.rate_limitsframe, andwham/usage) now report a single 7-day window in theprimaryslot, withsecondarynull/zeroed:The plugin hardcodes
primary ≡ 5h/secondary ≡ 7din display, pacing, and policy, so today it:5hin the sidebar (5h: 20% 7d: —),FIVE_HOUR_MS) → wrong deficit/reserve math,failClosedOnUnknownQuotaaccounts, because an absent window reads as "unknown quota" rather than "not applicable".The key realization: every source already sends the window length (
x-codex-*-window-minutes/ WSwindow_minutes/ whamlimit_window_seconds) — the code just discarded it.Fix
Make the windows dynamic while keeping the slot names as stable keys.
7dand paces over 7 days whether it arrives asprimaryorsecondary.FIVE_HOUR_MS/SEVEN_DAY_MSand the literal5h:/7d:text are gone.quotaSnapshotPassesPolicyandkillswitchPassesPolicy, an absent window is skipped (not-applicable), while a present-but-past-reset window still counts as unknown for fail-closed. Thresholds stay keyed by slot.rate_limit_reset_credits.available_countas a top-level sidebarresets: Nrow, preserved across per-turn header/WS pushes (which don't carry it) and attributed to the account that actually served.Design principle: key vs. semantics
The slot names
primary/secondarystay the stable keys for storage, quota-manager rate-limit marks, killswitch thresholds, and mid-stream reset attribution — none of those change. The window length drives only the human-facing label and the pacing ruler. So if OpenAI shifts a window's length, moves it between slots, or drops/re-adds one, display and pacing follow automatically while thresholds and marks keep working.Scope / compatibility
resolveMidStreamRateLimitResetAtis unchanged (it was already correct and slot-keyed).5h/1waliases for backward-compatible reads; only the human-facing labels became length-aware.Testing
bun run build·bun run typecheck·bunx biome check src— all clean.bun test— 604 pass / 0 fail (36 new tests: length normalization across all three sources incl. seconds→minutes and zero-placeholder-as-absence, label boundaries, one-vs-two-vs-zero window rendering, present-window policy under fail-open/fail-closed for both policy functions, reset-credit preservation + active-account attribution, and a deterministic WS ordering test for served-account attribution).killswitchPassesPolicy) that still blocked on an absent window, the header path's zero-placeholder rendering a phantom window, the mid-stream mark-clear requiring both windows, window-presence detection counting metadata as a window, and a fallback merge resurrecting a wire-absent window — all fixed and re-confirmed; a follow-up round fixed WS sidebar attribution so a fallback turn'sresetscount publishes against the fallback, not the previously-active account.Operator check after merge
Restart, send one Codex request, and confirm the sidebar shows a single
7drow with the correct percent + countdown, a sane 7-day pacing projection, no phantom5hrow, and aresets:line when the plan suppliesavailable_count.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Make quota windows dynamic and present-only across the UI and policy, and surface per-account reset credits from
wham. Header/WS quota pushes are treated as complete frames so window sets replace cleanly; “all retired” clears windows, and reset credits persist across turns and follow the served account.New Features
windowMinutes/limit_window_seconds; no fixed5h/7d.resetCreditsAvailable(rate_limit_reset_credits.available_count) asresets: Nper account in the sidebar and quota command; preserved across header/WS turns and attributed to the serving account.Bug Fixes
5h; pace over the reported length.whamseconds → minutes correctly.Written for commit ab061e8. Summary will update on new commits.