Recover CLI rate limits from Pro Lite errors#718
Recover CLI rate limits from Pro Lite errors#718ImLukeF wants to merge 1 commit intosteipete:codex/fix-codex-prolite-handlingfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves CodexBar’s Codex CLI (RPC) usage/credits fetching by recovering rate-limit and credit information from JSON bodies embedded in account/rateLimits/read decode-mismatch errors (e.g., unknown variant "prolite"), reducing reliance on the TTY /status fallback when the RPC error already contains usable data.
Changes:
- Add parsing/recovery of embedded JSON
body={...}fromRPCWireError.requestFailedmessages to reconstructUsageSnapshotandCreditsSnapshot. - Wrap RPC usage/credits loads to attempt recovery from RPC errors before failing over.
- Add regression tests covering recovery from a
prolitedecode mismatch payload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
Sources/CodexBarCore/UsageFetcher.swift |
Adds RPC error-body decoding + JSON object extraction to recover usage/credits when RPC decoding fails. |
Tests/CodexBarTests/CodexUsageFetcherFallbackTests.swift |
Adds tests validating recovery from embedded JSON error payloads and preserves existing TTY fallback tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| switch character { | ||
| case "\"": | ||
| inString = true | ||
| case "{": | ||
| depth += 1 | ||
| case "}": | ||
| depth -= 1 | ||
| if depth == 0 { | ||
| endIndex = index | ||
| break | ||
| } |
There was a problem hiding this comment.
extractJSONObject sets endIndex when depth == 0, but the break here only exits the switch, not the surrounding for loop. That means parsing continues past the end of the JSON object, which can lead to incorrect depth tracking (potentially negative) and unnecessary scanning if there are additional braces later in the message. Use a labeled break/early return once the matching closing brace is found.
| "user_id": "user-HjRmNJhdtyqaGzIB98OrOdJw", | ||
| "account_id": "user-HjRmNJhdtyqaGzIB98OrOdJw", | ||
| "email": "[email protected]", | ||
| "plan_type": "prolite", |
There was a problem hiding this comment.
This test payload includes real-looking personal data (email and user_id/account_id). Even in tests, embedding potentially real PII is risky (logs, crash reports, public repo visibility). Replace these with clearly fake placeholder values (e.g., user-TEST, [email protected]) while keeping the shape of the payload the same.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5bb41951e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if depth == 0 { | ||
| endIndex = index | ||
| break |
There was a problem hiding this comment.
Break out once JSON body closes
In extractJSONObject, the break inside the case "}" branch only exits the switch, not the surrounding for loop, so parsing continues after the first balanced JSON object. If the RPC error message includes additional diagnostic text with braces after body={...} (for example headers={...}), endIndex is overwritten and the returned slice is no longer valid JSON, causing usage/credits recovery to silently fail for that message format.
Useful? React with 👍 / 👎.
|
Thanks a lot @ImLukeF ! Rebased onto the base branch. |
Summary
account/rateLimits/readdecode errors/statusfallback, but avoid depending on it when the RPC error already contains usable Pro Lite usage dataprolitedecode mismatch payload recoveryRoot Cause
codex app-servercan returnunknown variant "prolite"foraccount/rateLimits/read, while embedding the full/wham/usageresponse body in the error. In explicit Codex CLI mode this left CodexBar with no usable usage or credits when the text status fallback also failed.Validation
pnpm checkswift test --filter CodexUsageFetcherFallbackTests./Scripts/compile_and_run.sh --waitNotes
Full
swift teststill has an unrelated existing failure inOpenAIDashboardNavigationDelegateTests:commit completes navigation successfully after grace period.