fix(codex): restore five-hour usage window - #11415
Conversation
📝 WalkthroughWalkthroughCodex rate-limit handling now uses snapshot-based window types and classifies backend primary and secondary windows into session and weekly results. Missing session windows are restored from backend usage after RPC success and PTY fallback. Status-bar meters fall back to weekly usage when session data is unavailable, with tests covering backend classification, restoration, and rendered weekly-only meters. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR restores the five-hour Codex usage window when the RPC or PTY snapshot only surfaces a weekly window. A new
Confidence Score: 5/5Safe to merge — the supplement path is additive and fault-tolerant, and the classification refactor is a pure rename with no behavioral change. The withBackendSessionWindow function guards every exit with early-returns, wraps the backend call in a try/catch that silently falls back, and only mutates the in-memory snapshot. The duration-based classification of backend windows reuses the battle-tested classifyCodexRateLimitWindows helper. The hasCompleteRateLimitResetCredits guard correctly suppresses the redundant credits fetch when the usage response already supplies zero-credit or expiry data. Test coverage is thorough — 629 existing tests plus three focused new scenarios for the supplement, classification, and credits-reuse paths. Files Needing Attention: The extra wham/usage call in the steady-state weekly-only path (noted in a previous thread) lives in codex-fetcher.ts; no other files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/rate-limits/codex-fetcher.ts | Core logic file; adds withBackendSessionWindow, refactors fetchViaBackend to duration-based window classification, and introduces hasCompleteRateLimitResetCredits. The extra wham/usage call in the weekly-only steady state is the one remaining rough edge. |
| src/main/rate-limits/codex-rate-limit-window-classification.ts | Pure rename of exported types with no behavioral change; logic is unchanged. |
| src/renderer/src/components/status-bar/StatusBar.tsx | Minimal change: meterWindow = p.session ?? p.weekly so the footer MiniBar renders for weekly-only accounts in non-compact mode; compact mode behavior is unchanged. |
| src/main/rate-limits/codex-fetcher-session-supplement.test.ts | New test file covering credit-reuse and two-fetch flows for the withBackendSessionWindow supplement path; scenarios are well-targeted. |
| src/main/rate-limits/codex-fetcher-backend.test.ts | Adds a test confirming a sole seven-day backend primary window is classified as weekly rather than session. |
| src/main/rate-limits/codex-fetcher.test.ts | Extends the main integration test with a scenario where the RPC reports weekly-only and the backend supplies the missing 5-hour session window; verifies a single fetch call. |
| src/main/rate-limits/codex-rate-limit-window-classification.test.ts | Type rename propagated to test helper; no behavioral change. |
| src/renderer/src/components/status-bar/UsageRosterPanel.test.tsx | Strengthens the existing dual-window test with explicit assertions for 5h/25%/wk/10% labels. |
| src/renderer/src/components/status-bar/inline-usage-bars.test.tsx | New test verifies the footer MiniBar appears for a weekly-only Codex plan in non-compact mode. |
Reviews (2): Last reviewed commit: "fix(codex): reuse backend reset credit m..." | Re-trigger Greptile
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/rate-limits/codex-fetcher.ts (1)
573-602: 🧹 Nitpick | 🔵 TrivialSession-restore fallback adds a backend call every cycle for accounts genuinely lacking a session window.
withBackendSessionWindowfires an extrafetchViaBackendrequest wheneversessionis missing andweeklyis present. This is the right trade-off for the (confirmed real, currently ongoing) upstream Codex issue where the app-server temporarily omits the 5h window. However, if this affects an account persistently (which is plausible given upstream reports of the five-hour window being hidden across sessions until fixed), every refresh cycle will keep re-issuing this backend request even though it will keep returning no session. Worth keeping an eye on backend load/latency impact if refresh polling is frequent; no action required now since the fix correctly matches the PR's stated intent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b6478a49-fb78-4a2b-a8d9-eb6835742527
📒 Files selected for processing (2)
src/main/rate-limits/codex-fetcher-session-supplement.test.tssrc/main/rate-limits/codex-fetcher.ts
Summary
Context
Codex has restored the 5-hour quota, but Orca can still receive a weekly-only snapshot from an installed CLI/app-server. When that happens, Orca now checks the official backend usage contract and fills the missing session window if the backend reports it.
This extends the duration-based RPC classification from #10136 to backend responses and incorporates the remaining backend work from #10466. It remains compatible with the weekly-only PTY handling from #8643 and the earlier investigation in #8493.
OpenAI's generalized window-label work is documented in openai/codex#22929.
Screenshots
The after image is a controlled dual-window snapshot rendered in this branch's Electron development build. The current live account still returned only the weekly bucket during verification.
Testing
AI Review Report
Security Audit
No new endpoints, credentials, IPC surfaces, or persistence were introduced. The fallback reuses Orca's existing authenticated Codex backend request and only merges rate-limit metadata into the in-memory snapshot.
Notes
No release or dependency changes.