Skip to content

Recover CLI rate limits from Pro Lite errors#718

Closed
ImLukeF wants to merge 1 commit intosteipete:codex/fix-codex-prolite-handlingfrom
ImLukeF:codex/recover-cli-prolite-rate-limits
Closed

Recover CLI rate limits from Pro Lite errors#718
ImLukeF wants to merge 1 commit intosteipete:codex/fix-codex-prolite-handlingfrom
ImLukeF:codex/recover-cli-prolite-rate-limits

Conversation

@ImLukeF
Copy link
Copy Markdown
Contributor

@ImLukeF ImLukeF commented Apr 14, 2026

Summary

  • recover Codex CLI usage and credits from the JSON body embedded in account/rateLimits/read decode errors
  • keep the existing TTY /status fallback, but avoid depending on it when the RPC error already contains usable Pro Lite usage data
  • add regression coverage for prolite decode mismatch payload recovery

Root Cause

codex app-server can return unknown variant "prolite" for account/rateLimits/read, while embedding the full /wham/usage response 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 check
  • swift test --filter CodexUsageFetcherFallbackTests
  • ./Scripts/compile_and_run.sh --wait

Notes

Full swift test still has an unrelated existing failure in OpenAIDashboardNavigationDelegateTests: commit completes navigation successfully after grace period.

@ImLukeF ImLukeF marked this pull request as ready for review April 14, 2026 23:16
Copilot AI review requested due to automatic review settings April 14, 2026 23:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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={...} from RPCWireError.requestFailed messages to reconstruct UsageSnapshot and CreditsSnapshot.
  • Wrap RPC usage/credits loads to attempt recovery from RPC errors before failing over.
  • Add regression tests covering recovery from a prolite decode 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.

Comment on lines +826 to +836
switch character {
case "\"":
inString = true
case "{":
depth += 1
case "}":
depth -= 1
if depth == 0 {
endIndex = index
break
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +58
"user_id": "user-HjRmNJhdtyqaGzIB98OrOdJw",
"account_id": "user-HjRmNJhdtyqaGzIB98OrOdJw",
"email": "[email protected]",
"plan_type": "prolite",
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +833 to +835
if depth == 0 {
endIndex = index
break
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@ratulsarna
Copy link
Copy Markdown
Collaborator

Thanks a lot @ImLukeF ! Rebased onto the base branch.

@ratulsarna ratulsarna closed this Apr 15, 2026
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.

3 participants