Skip to content

Fix Codex quota reading under the app's minimal PATH - #65

Merged
MisterBrookT merged 1 commit into
mainfrom
fix-codex-quota-reading
Sep 14, 2026
Merged

MisterBrookT merged 1 commit into
mainfrom
fix-codex-quota-reading

Conversation

@MisterBrookT

Copy link
Copy Markdown
Owner

Kaji showed Codex at ~4% while ChatGPT reported 9% left (≈91% used), and the 5-hour window showed "no data".

Root causes

  1. The live fetch never ran in the shipped app. A .app launched from Finder inherits PATH=/usr/bin:/bin:/usr/sbin:/sbin, so subprocess(["codex", ...]) raised FileNotFoundError. Every reading silently came from the stale session-file scan. Same bug applied to mmx.
  2. The 5-hour window lives in a per-model group. account/rateLimits/read returns rateLimitsByLimitId: the account-wide codex group (weekly only on this plan) plus e.g. codex_bengalfox (GPT-5.3-Codex-Spark) carrying the live 5-hour window. Only the flat rateLimits object was read.
  3. Stale cache had no age ceiling. With the fetch permanently broken, the last good percentage was served forever, so the breakage was invisible.

Fixes

  • Resolve CLIs through known install prefixes and hand the child a merged PATH.
  • Fold every rate-limit group together, taking the worst reading per window.
  • Cap the stale-cache fallback at 6h; past that the UI shows "no data · check sign-in".

Verification

  • 47 Python tests pass; 19 of the new assertions fail against the old reader.
  • Under a simulated minimal PATH the reader now returns both windows.
  • The running app reports Codex 5h 0% / 7d 92%, matching the ChatGPT usage page.

swift test could not run locally (no Xcode toolchain, only Command Line Tools); CI covers it.

Three defects made Codex report a stale 4% and no 5-hour window:

- A .app launched from Finder inherits PATH=/usr/bin:/bin:/usr/sbin:/sbin, so
  subprocess(["codex", ...]) raised FileNotFoundError and the live app-server
  fetch never ran. Resolve the CLI through the known install prefixes and pass
  a merged PATH to the child so a node-shebang wrapper finds its interpreter.
- codex reports per-limit-id groups; the account group can carry only a weekly
  window while a per-model group holds the live 5-hour one. Fold every group
  together, worst reading per window.
- A failed fetch fell back to the cache with no age ceiling, so a permanently
  broken fetch path served the last good percentage forever. Cap the fallback
  at six hours and let the UI show 'no data'.

Regression tests cover all three (19 of the new assertions fail on the old
reader).
@MisterBrookT
MisterBrookT merged commit 0081d3c into main Sep 14, 2026
2 checks passed
@MisterBrookT
MisterBrookT deleted the fix-codex-quota-reading branch September 14, 2026 08:46
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