Skip to content

fix(codex): restore five-hour usage window - #11415

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/the-user-request-is
Jul 29, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/the-user-request-is

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

  • restore Codex's 5-hour usage window when the app-server RPC or PTY snapshot still reports only weekly usage
  • classify backend primary and secondary windows by duration so weekly-only accounts remain correctly labeled
  • preserve the compact usage meter for weekly-only plans
  • cover the Usage roster's dual 5h + weekly rendering

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

Before: weekly only After: restored 5h + weekly
Codex weekly-only usage Codex 5-hour and weekly usage

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

  • Electron development build launched successfully
  • Electron Usage roster visually verified with controlled 5h + weekly data
  • 63 rate-limit/status-bar test files, 629 tests
  • focused Usage roster test
  • typecheck
  • changed-file Oxlint and Oxfmt
  • max-lines ratchet
  • git diff check

AI Review Report

  • Cross-platform: uses existing fetch/auth/path abstractions with no platform-specific UI behavior
  • WSL: backend windows now use duration classification instead of positional assumptions
  • SSH and folder workspaces: no workspace-type assumptions were added
  • UI: reuses existing status-bar components, tokens, labels, and percentage display behavior
  • Performance: the additional backend read runs only when a weekly window exists and the session window is missing

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.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Codex 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately captures the main change: restoring Codex's five-hour usage window.
Description check ✅ Passed All required sections are present and the content is mostly complete; the AI Review Report could be more explicit about macOS/Linux/Windows coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/main/rate-limits/codex-fetcher.ts
@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR restores the five-hour Codex usage window when the RPC or PTY snapshot only surfaces a weekly window. A new withBackendSessionWindow step supplements the in-memory limits by calling wham/usage and merging the backend's session window (and optionally its credits data) before the existing credits-hydration step runs.

  • codex-fetcher.ts: Adds withBackendSessionWindow to supplement a weekly-only RPC/PTY result with a backend session window; refactors fetchViaBackend to use duration-based classification for both primary and secondary backend windows via the shared classifyCodexRateLimitWindows helper; replaces the old availableCount/nextExpiresAt null-check with hasCompleteRateLimitResetCredits to suppress redundant credits fetches when the usage response already contains complete credit metadata.
  • codex-rate-limit-window-classification.ts: Renames CodexRpcRateWindow/CodexRpcRateLimits to CodexRateWindowSnapshot/CodexRateLimitWindowsSnapshot to reflect their new wider use (RPC and backend).
  • StatusBar.tsx: Extends the footer usage meter to also render for weekly-only accounts (p.session ?? p.weekly) in non-compact mode.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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

@brennanb2025
brennanb2025 merged commit b21f978 into main Jul 29, 2026
25 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/rate-limits/codex-fetcher.ts (1)

573-602: 🧹 Nitpick | 🔵 Trivial

Session-restore fallback adds a backend call every cycle for accounts genuinely lacking a session window.

withBackendSessionWindow fires an extra fetchViaBackend request whenever session is missing and weekly is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dca7c7 and 0c4f51f.

📒 Files selected for processing (2)
  • src/main/rate-limits/codex-fetcher-session-supplement.test.ts
  • src/main/rate-limits/codex-fetcher.ts

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