[bug] Accounts with monthly quotas (Codex Business) is shown as 5h in `login`
Summary
Accounts with monthly quotas (Codex Business) is shown as 5h in login, and the weekly quota is shown as 100%.
Reproduction
- Login as a Codex Business account.
- Check the quota usage.
Expected Behavior
It renders the monthly quota correctly.
Actual Behavior
It renders the 5th limit as if it is the monthly limit.
Compliance Confirmation
- [x] I am using this project for personal development workflows.
- [x] This report does not request policy bypasses or prohibited usage.
- [x] I removed any secrets/tokens from this report.
Coding Plan
Summary
- root cause is a positional label assertion, not a parsing bug:
lib/codex-manager/login-menu-data.ts+lib/ui/auth-menu-builder.tshardcodeprimary→5h/secondary→7dwhilewindowMinutes(already parsed and correct) gets thrown away. - fix by plumbing
windowMinutesthrough theExistingAccountInfo/AccountInfoview models and deriving every displayed label from the existing data-drivenformatQuotaWindowLabel, so a monthly window prints30d. - keep the two-slot primary/secondary shape; do not add a third window — the api still returns two windows, we were just mislabeling them.
- explicit gaps to close: preserve
undefinedfor absent windows (no?? 100), auditforecast.ts/preemptive-quota-scheduler.tsfor secondary-is-weekly branching and the reset-scheduling concurrency risk, and add the missing business/monthly regression tests since none exist today.
Design Choices
Design Choice 1: how do we carry window duration to the ui, and do we rename the misleading `quota5h*`/`quota7d*` fields?
Options Considered:
- keep field names, add companion
...WindowMinutesfields, derive labels dynamically at render time. small diff, but leaves permanently misleading names (quota5hLeftPercentholding a 30d value) that will re-bite the next reader. - generalize the view-model fields to
quotaPrimary*/quotaSecondary*plusquotaPrimaryWindowMinutes/quotaSecondaryWindowMinutes, and derive the display label from minutes. bigger blast radius (lib/cli.ts,lib/ui/auth-menu-builder.ts,lib/codex-manager/login-menu-data.ts, tests) but the names stop lying.
Chosen Option: 2
Rationale: the whole ticket is caused by names/labels asserting a duration they don't actually have, so removing the hardcoded window identity from the contract is the durable fix; the positional primary/secondary shape stays, only the "this is always 5h/7d" assertion goes away. the percent values already flow correctly; what's missing is the actual windowMinutes per window so the ui can label it. the field names themselves (quota5hLeftPercent, etc.) encode the wrong assumption.
💡 User Tips
Regenerate the plan with different choices with @coderabbitai <feedback>.
Implementation Steps
Phase 1: preserve real window duration through the view models
stop discarding windowMinutes between the parsed snapshot and the ui. the snapshot and cache already carry windowMinutes per window (CodexQuotaWindow in lib/quota-probe.ts, QuotaCacheWindow in lib/quota-cache.ts) — the loss happens when we project into the account-info view model. this phase widens that contract so the ui receives duration, not just a percent.
Task 1: widen the account-info contract to carry per-window duration
generalize the quota fields so a monthly window can be represented.
- update
ExistingAccountInfoinlib/cli.tsto replace/augmentquota5hLeftPercent/quota5hResetAtMs/quota7dLeftPercent/quota7dResetAtMswith primary/secondary-named fields plus awindowMinutesper window (e.g.quotaPrimaryLeftPercent,quotaPrimaryResetAtMs,quotaPrimaryWindowMinutes, and the secondary equivalents). - mirror the same shape on
AccountInfoinlib/ui/auth-menu-builder.tsso the two types stay in sync (they are duplicated today). - keep both windows optional; do not invent a value when a window is absent (see risk on the "100% weekly" artifact below).
Task 2: map by data, not by position, in the view-model builder
fix the actual mislabel source.
- update
toExistingAccountInfo()inlib/codex-manager/login-menu-data.ts(~lib/codex-manager/login-menu-data.ts:462) to copyentry.primary.windowMinutes/entry.secondary.windowMinutesthrough alongside the percent and reset fields, instead of dropping them intoquota5h*/quota7d*by position. - confirm no
?? 100/|| 100default is introduced for a missing window's percent — a missing secondary must stayundefined, not render as full.quotaLeftPercentFromUsed(undefined)already returnsundefinedinlib/quota-readiness.ts, so the plumbing must preserve that undefined rather than coercing it. - update the sort helpers in the same file (
readQuotaLeftPercent,readQuotaFloorPercent,parseLeftPercentFromQuotaSummary,compareReadyFirstAccounts) so account ordering keys off primary/secondary windows generically rather than the closed"5h" | "7d"literal set.
🤖 Prompt for AI agents
implement phase 1: preserve real window duration through the view models, so the
account-info view model stops discarding `windowMinutes` between the parsed
quota snapshot and the ui.
step 1 — widen `ExistingAccountInfo` in `lib/cli.ts`: replace/augment
`quota5hLeftPercent`/`quota5hResetAtMs`/`quota7dLeftPercent`/`quota7dResetAtMs`
with primary/secondary-named fields plus a `windowMinutes` per window (e.g.
`quotaPrimaryLeftPercent`, `quotaPrimaryResetAtMs`, `quotaPrimaryWindowMinutes`,
and secondary equivalents). mirror this exact shape on `AccountInfo` in
`lib/ui/auth-menu-builder.ts` since the two types are duplicated and must stay
in sync. keep both windows optional — never invent a value for an absent window.
step 2 — fix `toExistingAccountInfo()` in `lib/codex-manager/login-menu-data.ts`
(~line 462): copy `entry.primary.windowMinutes`/`entry.secondary.windowMinutes`
through alongside percent/reset fields instead of mapping them positionally into
`quota5h*`/`quota7d*`. verify no `?? 100` / `|| 100` fallback gets introduced
for a missing window's percent — a missing secondary must stay `undefined`
(matching how `quotaLeftPercentFromUsed(undefined)` already returns `undefined`
in `lib/quota-readiness.ts`).
step 3 — update the sort helpers in `lib/codex-manager/login-menu-data.ts`
(`readQuotaLeftPercent`, `readQuotaFloorPercent`,
`parseLeftPercentFromQuotaSummary`, `compareReadyFirstAccounts`) so account
ordering works generically off primary/secondary windows instead of the closed
`"5h" | "7d"` literal set.
Phase 2: render duration-derived labels in the auth/login menu
the ui is the only place still asserting "5h"/"7d" as literals. route every label through the existing data-driven formatter so a 43200-minute window prints 30d, not 5h.
derive the window label from windowMinutes at render time
- change
formatQuotaWindowinlib/ui/auth-menu-builder.tsso the label parameter is computed fromwindowMinutesvia the sharedformatQuotaWindowLabelrather than accepting a hardcoded"5h" | "7d"literal. - update
formatQuotaSummaryin the same file to pass each window'swindowMinutes(from the widenedAccountInfo) into that label derivation, and to skip a window entirely when its percent isundefinedinstead of emitting a filler segment. - reuse the existing label logic — do not add a fourth copy. either import
formatQuotaWindowLabelfromlib/quota-probe.ts/lib/runtime/quota-headers.tsor consolidate onformatCompactQuotaWindowLabelinlib/codex-manager/formatters/quota-formatters.ts; the label rule (%1440→d,%60→h, elsem) should have one source of truth. - update
parseLeftPercentFromSummary(and itslogin-menu-data.tstwin) so it no longer assumes the literal"5h"/"7d"tokens when scraping percentages back out of a summary string.
🤖 Prompt for AI agents
implement phase 2: render duration-derived labels in the auth/login menu. this
is the last place still asserting `"5h"`/`"7d"` as literal strings, so route
every label through the existing data-driven formatter.
- change `formatQuotaWindow` in `lib/ui/auth-menu-builder.ts` so its label is
computed from `windowMinutes` via the shared `formatQuotaWindowLabel`, instead
of accepting a hardcoded `"5h" | "7d"` literal.
- update `formatQuotaSummary` in `lib/ui/auth-menu-builder.ts` to pass each
window's `windowMinutes` (now available on the widened `AccountInfo` from phase
1) into that label derivation. when a window's percent is `undefined`, skip that
window entirely rather than emitting a filler segment.
- do not create a fourth copy of the label logic — reuse it by importing
`formatQuotaWindowLabel` from `lib/quota-probe.ts` /
`lib/runtime/quota-headers.ts`, or consolidate on
`formatCompactQuotaWindowLabel` in
`lib/codex-manager/formatters/quota-formatters.ts`. the label rule (`%1440→d`,
`%60→h`, else `m`) must have exactly one source of truth.
- update `parseLeftPercentFromSummary` and its twin in
`lib/codex-manager/login-menu-data.ts` so neither assumes the literal
`"5h"`/`"7d"` tokens when scraping percentages back out of a rendered summary
string.
Phase 3: verify downstream consumers and add regression coverage
make sure nothing else silently relies on secondary == weekly, and lock the fix in with tests since business/monthly accounts are not currently exercised anywhere.
Task 1: audit forecast + scheduler for a secondary-is-weekly assumption
- review
lib/forecast.ts(thefor (const window of [snapshot.primary, snapshot.secondary])wait-time loop) andlib/preemptive-quota-scheduler.tsfor any logic that treats the secondary window as a benign ~7d reset. a monthly window in that slot has a much longer reset horizon, so any "ignore a healthy weekly secondary" shortcut must key offwindowMinutes/resetAtMs, not the slot name. - concurrency risk to call out explicitly:
preemptive-quota-scheduler.tsschedules refresh off reset timestamps; if a monthlyresetAtMsis now honored where a weekly one was previously assumed, verify we don't schedule wildly distant or immediate wakeups. this is behavior-affecting, not just cosmetic — validate before shipping. - these files already derive labels from
windowMinutesfor display, so no label change is expected here; the audit is about branching logic, not strings.
Task 2: add regression tests for a monthly/business window
test/auth-menu-quota-bar.test.tscurrently only coversquota5hLeftPercent/quota7dLeftPercentwith hardcoded naming and no plan-type branching — add a case where a window haswindowMinutes: 43200and assert the rendered label is30d, never5h.- add a case in
test/quota-headers.test.ts(which already asserts300→5h,10080→7d,1440→1d,60→1h) exercising a monthly-scalewindowMinutesto lock the label derivation. - add a
login-menu-datatest assertingtoExistingAccountInfocarrieswindowMinutesthrough and that a missing secondary window renders as absent, not100%— this is the exact "weekly shown as 100%" symptom from the ticket and there is currently zero coverage for a one-window (business) response. - note for the follow-up agent: no fixture anywhere uses
planType: "business"or a monthly window today, so these are net-new fixtures, not edits to existing ones.
🤖 Prompt for AI agents
implement phase 3: verify downstream consumers and add regression coverage.
confirm nothing else silently assumes secondary == weekly, then lock the fix in
with tests since business/monthly accounts have zero coverage today.
audit step:
- review `lib/forecast.ts` (the `for (const window of [snapshot.primary,
snapshot.secondary])` wait-time loop) and `lib/preemptive-quota-scheduler.ts`
for logic that treats the secondary window as a benign ~7d reset. any "ignore a
healthy weekly secondary" shortcut must key off `windowMinutes`/`resetAtMs`,
never the slot name, since a monthly window in that slot has a much longer reset
horizon.
- explicitly flag and validate the concurrency risk:
`preemptive-quota-scheduler.ts` schedules refresh off reset timestamps — if a
monthly `resetAtMs` is now honored where a weekly one was previously assumed,
confirm we don't schedule wildly distant or immediate wakeups. this is
behavior-affecting, not cosmetic, and must be validated before shipping.
- these files already derive display labels from `windowMinutes`, so expect no
label/string changes here — this audit is about branching logic only.
test step:
- extend `test/auth-menu-quota-bar.test.ts` (currently only covers
`quota5hLeftPercent`/`quota7dLeftPercent` with hardcoded naming, no plan-type
branching) with a case where a window has `windowMinutes: 43200` and assert the
rendered label is `30d`, never `5h`.
- extend `test/quota-headers.test.ts` (currently asserts `300→5h`, `10080→7d`,
`1440→1d`, `60→1h`) with a monthly-scale `windowMinutes` case to lock the label
derivation.
- add a `login-menu-data` test asserting `toExistingAccountInfo` carries
`windowMinutes` through, and that a missing secondary window renders as absent
rather than `100%` — this is the exact "weekly shown as 100%" symptom from the
ticket, currently uncovered for one-window (business) responses.
- note: no fixture currently uses `planType: "business"` or a monthly window, so
these are net-new fixtures, not edits to existing ones.
Research
quota windows are parsed positionally from two header groups (x-codex-primary-*, x-codex-secondary-*) into CodexQuotaSnapshot { primary, secondary } in lib/quota-probe.ts and its runtime twin lib/runtime/quota-headers.ts, persisted as QuotaCacheEntry in lib/quota-cache.ts. the low-level label formatter formatQuotaWindowLabel(windowMinutes) (duplicated in lib/quota-probe.ts, lib/runtime/quota-headers.ts, and lib/codex-manager/formatters/quota-formatters.ts as formatCompactQuotaWindowLabel) is already data-driven and correctly emits 5h/7d/30d from windowMinutes. the bug lives above that: lib/codex-manager/login-menu-data.ts (toExistingAccountInfo, ~lib/codex-manager/login-menu-data.ts:462) maps primary → quota5h* and secondary → quota7d* by position with no windowMinutes check, and lib/ui/auth-menu-builder.ts (formatQuotaWindow/formatQuotaSummary) renders the literal "5h" | "7d" strings passed in. the type contract in lib/cli.ts (ExistingAccountInfo) and lib/ui/auth-menu-builder.ts (AccountInfo) bakes quota5hLeftPercent/quota7dLeftPercent in as fixed-window fields with no duration companion, so the ui has nothing to render a monthly label from even if it wanted to.
🚀 Next Steps
🤖 All AI agent prompts combined
Task: 1
implement phase 1: preserve real window duration through the view models, so the
account-info view model stops discarding `windowMinutes` between the parsed
quota snapshot and the ui.
step 1 — widen `ExistingAccountInfo` in `lib/cli.ts`: replace/augment
`quota5hLeftPercent`/`quota5hResetAtMs`/`quota7dLeftPercent`/`quota7dResetAtMs`
with primary/secondary-named fields plus a `windowMinutes` per window (e.g.
`quotaPrimaryLeftPercent`, `quotaPrimaryResetAtMs`, `quotaPrimaryWindowMinutes`,
and secondary equivalents). mirror this exact shape on `AccountInfo` in
`lib/ui/auth-menu-builder.ts` since the two types are duplicated and must stay
in sync. keep both windows optional — never invent a value for an absent window.
step 2 — fix `toExistingAccountInfo()` in `lib/codex-manager/login-menu-data.ts`
(~line 462): copy `entry.primary.windowMinutes`/`entry.secondary.windowMinutes`
through alongside percent/reset fields instead of mapping them positionally into
`quota5h*`/`quota7d*`. verify no `?? 100` / `|| 100` fallback gets introduced
for a missing window's percent — a missing secondary must stay `undefined`
(matching how `quotaLeftPercentFromUsed(undefined)` already returns `undefined`
in `lib/quota-readiness.ts`).
step 3 — update the sort helpers in `lib/codex-manager/login-menu-data.ts`
(`readQuotaLeftPercent`, `readQuotaFloorPercent`,
`parseLeftPercentFromQuotaSummary`, `compareReadyFirstAccounts`) so account
ordering works generically off primary/secondary windows instead of the closed
`"5h" | "7d"` literal set.
===============================================================================
Task: 2
implement phase 2: render duration-derived labels in the auth/login menu. this
is the last place still asserting `"5h"`/`"7d"` as literal strings, so route
every label through the existing data-driven formatter.
- change `formatQuotaWindow` in `lib/ui/auth-menu-builder.ts` so its label is
computed from `windowMinutes` via the shared `formatQuotaWindowLabel`, instead
of accepting a hardcoded `"5h" | "7d"` literal.
- update `formatQuotaSummary` in `lib/ui/auth-menu-builder.ts` to pass each
window's `windowMinutes` (now available on the widened `AccountInfo` from phase
1) into that label derivation. when a window's percent is `undefined`, skip that
window entirely rather than emitting a filler segment.
- do not create a fourth copy of the label logic — reuse it by importing
`formatQuotaWindowLabel` from `lib/quota-probe.ts` /
`lib/runtime/quota-headers.ts`, or consolidate on
`formatCompactQuotaWindowLabel` in
`lib/codex-manager/formatters/quota-formatters.ts`. the label rule (`%1440→d`,
`%60→h`, else `m`) must have exactly one source of truth.
- update `parseLeftPercentFromSummary` and its twin in
`lib/codex-manager/login-menu-data.ts` so neither assumes the literal
`"5h"`/`"7d"` tokens when scraping percentages back out of a rendered summary
string.
===============================================================================
Task: 3
implement phase 3: verify downstream consumers and add regression coverage.
confirm nothing else silently assumes secondary == weekly, then lock the fix in
with tests since business/monthly accounts have zero coverage today.
audit step:
- review `lib/forecast.ts` (the `for (const window of [snapshot.primary,
snapshot.secondary])` wait-time loop) and `lib/preemptive-quota-scheduler.ts`
for logic that treats the secondary window as a benign ~7d reset. any "ignore a
healthy weekly secondary" shortcut must key off `windowMinutes`/`resetAtMs`,
never the slot name, since a monthly window in that slot has a much longer reset
horizon.
- explicitly flag and validate the concurrency risk:
`preemptive-quota-scheduler.ts` schedules refresh off reset timestamps — if a
monthly `resetAtMs` is now honored where a weekly one was previously assumed,
confirm we don't schedule wildly distant or immediate wakeups. this is
behavior-affecting, not cosmetic, and must be validated before shipping.
- these files already derive display labels from `windowMinutes`, so expect no
label/string changes here — this audit is about branching logic only.
test step:
- extend `test/auth-menu-quota-bar.test.ts` (currently only covers
`quota5hLeftPercent`/`quota7dLeftPercent` with hardcoded naming, no plan-type
branching) with a case where a window has `windowMinutes: 43200` and assert the
rendered label is `30d`, never `5h`.
- extend `test/quota-headers.test.ts` (currently asserts `300→5h`, `10080→7d`,
`1440→1d`, `60→1h`) with a monthly-scale `windowMinutes` case to lock the label
derivation.
- add a `login-menu-data` test asserting `toExistingAccountInfo` carries
`windowMinutes` through, and that a missing secondary window renders as absent
rather than `100%` — this is the exact "weekly shown as 100%" symptom from the
ticket, currently uncovered for one-window (business) responses.
- note: no fixture currently uses `planType: "business"` or a monthly window, so
these are net-new fixtures, not edits to existing ones.
💡 Iterate on the plan with:
`@coderabbitai` <feedback>
Example Feedback
- `@coderabbitai` You can skip phase 3. Add a simple unit test case for phase 2.
- `@coderabbitai` For design choice 1 go ahead with option 3 and replan.
💬 Have feedback or questions? Drop into our discord!
@ndycode The 7d quota is still showing, despite there being no 7-day quota. It's also shown in hours instead of month. Can both be fixed please?