Repository navigation
Keep the last Codex limits, marked stale, when a probe fails - #15249
omarchybot wants to merge 6 commits into
Conversation
A Codex rate-limit probe that times out, gets an error back from the usage backend, or loses its app-server replaced the record's limits with an empty list, so the panel lost limits that were right a refresh ago. The Claude and Grok collectors already keep each account's last limits and mark them stale; Codex now does the same, keyed by home and signed-in ChatGPT account so a home signed in to someone else never inherits them. A sign-out, a missing CLI, or an app-server that exits saying nothing are still reported rather than hidden behind old numbers, and windows that have reset since read as empty. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keying the cache on auth.json's account alone let a keyring or auto-store login, which keeps no account there, share one cache across whoever signs in to the home, and let an access token in the environment fall back on auth.json's account. The cache is now keyed by the token when one is set, by auth.json's account only under the file store, and not kept at all when neither says who is signed in. Naive reset times read as UTC, as in the Claude collector. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
The cache key was read after the probe, so a home signed in to someone else while the app-server answered stored the first login's limits under the second's key. It is now read before and after, and the limits are kept and served only when both agree. The test no longer inherits CODEX_ACCESS_TOKEN from whoever runs it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
An auth.json whose tokens were not an object raised outside the parse's try, and nothing above it caught it any more, so the whole record was lost. Any shape that does not name an account now means the login can't be told apart. The login-change test now also checks the first login's limits survive. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
…ector JSON and the environment can both hand Python a lone surrogate, which strict UTF-8 refuses to encode, so an account id or token carrying one aborted the record while its cache key was hashed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
auth.json's account_id names the ChatGPT workspace, and members of one workspace each have their own limits, so a teammate signing in to the same home could fall back on the last member's numbers. The identity now pairs the workspace with the user from the ID token's claims, read as Codex reads them (chatgpt_user_id, else user_id), and a login that names no user keeps no limits. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
|
| for mode in backend died; do | ||
| kept=$(collect "$mode") | ||
| [[ $(jq -c --argjson at "$fetched_at" '{limitsStale, at: (.limitsFetchedAt == $at), used: [.limits[].percent * 100 | round], status: .usageStatusText, tierLabel}' <<<"$kept") == '{"limitsStale":true,"at":true,"used":[40,0],"status":"","tierLabel":"pro"}' ]] || | ||
| fail "a failed Codex probe ($mode) keeps the last limits, marked stale" "$kept" | ||
| pass "a failed Codex probe ($mode) keeps the last limits, marked stale" |
There was a problem hiding this comment.
Timeout fallback lacks coverage
These tests check saved limits after backend errors and process exits, but not after a timeout. The existing timeout tests check the error message without first saving limits, so a change that blanks saved limits on timeout could pass both suites.
Add a fake server that stays alive without answering account/rateLimits/read. After a successful probe, check that this timeout keeps the old limits and timestamp and marks them stale.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Any failed app-server probe replaced the record's limits with an empty list, so the panel lost limits that were right a refresh ago, and every panel open started another app-server. Each signed-in login now keeps its last good answer in its own codex-limits-<key>.json, keyed by home and by the workspace and user in auth.json, or by CODEX_ACCESS_TOKEN; a keyring login, which can't be told apart, keeps nothing, and neither does a probe a login change ran across. A failed probe serves the kept limits as stale, with elapsed windows at zero, and records and accounts carry limitsStale/limitsFetchedAt and stale/fetchedAt. A probe within 15 seconds is reused unless --force asks again. A stalled app-server, or one that died unable to reach OpenAI, sets retryAdvised. A missing CLI reads as "Codex limits unavailable", the contract's word for it. Builds on #15249 and #14298. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: Omarchybot <[email protected]> Co-authored-by: AnPod <[email protected]>
|
Tested this branch locally on Omarchy with a signed-in Codex account. All 105 checks across four focused suites passed, and a live probe returned both quota windows. Five additional integration tests passed, covering cached limits and timestamp preservation after a timeout, recovery, backend errors, auth errors, login changes, and reset windows. We’re also running the PR collector through our existing widget, where it looks good. This addresses an intermittent failure we’ve been experiencing. We’d appreciate seeing it merged when possible. Thanks! |
|
The classification of this pull request is unsettled, so it carries no class label yet and has not been run on a worker this round. Classified separately by Claude Opus 5.5 and by Codex Medium, from the pull request alone, at #14298 is an older open pull request fixing the same blanking a different way; which of the two should land is for the maintainer. Waiting on the maintainer to settle the classification. |
When a Codex rate-limit probe fails part way — the app-server times out, the usage backend answers with an error, or the app-server exits —
omarchy-agent-usage-codexwrites a record with emptylimits, and the agents panel loses limits that were right one refresh ago. #14049 made those failures rarer and easier to diagnose, but a failed probe still leaves the panel with nothing. The Claude and Grok collectors already keep each account's last limits and mark them stale, and the panel already shows that as "Last updated … ago". Codex was the only one that didn't.The Codex collector now keeps the last limits each home was given and serves them, marked stale, when a later probe fails part way. It emits
limitsStaleandlimitsFetchedAton the record andstaleandfetchedAton each account, the same fields the other collectors emit. A window that has reset since the numbers were taken reads as empty. A sign-out, a missing CLI or an app-server that exits without saying why is still reported, not hidden behind old numbers.Cached numbers are only shown to the login that produced them. The cache is keyed by home and by the signed-in identity, which is the
CODEX_ACCESS_TOKENwhen one is set. Otherwise, under the file store, it is the workspace inauth.jsonpaired with the user in the ID token's claims, read the way Codex reads them, because members of one workspace each have their own limits. A login that can't be told apart (a keyring or auto store, or no user in the token) keeps nothing. The identity is read before and after the probe, and nothing is kept if it changed in between.Reviewed by Claude Opus 5.5 and by Codex Medium as a second opinion over six rounds. Its findings on identity, malformed
auth.jsonand workspace members are fixed here, and its last round found nothing.Fixes #13425