Repository navigation
Conversation
📝 WalkthroughWalkthroughCodex rate-limit parsing now maps valid backend and RPC individual limits into monthly usage windows. Backend responses can succeed without 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (4)
src/main/rate-limits/codex-fetcher.ts (2)
1111-1145: 🚀 Performance & Scalability | 🔵 TrivialReset-credit reconciliation and business-plan gating look correct, verified against the paired test files (restoring RPC's
rateLimitResetCreditswhen the backend explicitly returnsnull, and skipping the retry entirely for WSL-managed homes).One operational note: this branch triggers a full
fetchViaBackendnetwork round-trip on every poll whenever native RPC returns emptysession/weekly, even for non-Business accounts (the plan check only gates whether the result is used, not whether the fetch happens). For accounts that persistently return empty native windows for reasons unrelated to Business plans, this adds a repeated extra request per poll cycle. Worth keeping an eye on if polling frequency is high.
125-139: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueRemove the unused backend window fields
mapBackendUsageWindowonly readsused_percentandreset_at, soremaining_percentandreset_after_secondsare dead type surface here unless they’re wired in as fallbacks.src/main/rate-limits/codex-fetcher-business-usage.test.ts (2)
288-317: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win"Malformed" sub-case doesn't actually test a malformed backend payload.
The second scenario (
malformedResultPromise) doesn't queue a newfetchmock — it relies on the already-exhausted mock queue falling back tovi.fn()'s defaultundefinedreturn, which incidentally passes only because callers wrapfetchViaBackend/fetchBackendRateLimitResetCreditsintry/catch. This doesn't actually exercise thetypeof payload.plan_type !== 'string'rejection path infetchViaBackendthat "malformed" implies.♻️ Suggested explicit malformed-payload mock
vi.mocked(fetch) .mockRejectedValueOnce(new Error('backend unavailable')) - .mockResolvedValueOnce({ ok: true, json: async () => ({}) } as Response) + .mockResolvedValueOnce({ ok: true, json: async () => ({}) } as Response) + .mockResolvedValueOnce({ ok: true, json: async () => ({ not_a_valid_payload: true }) } as Response) + .mockResolvedValueOnce({ ok: true, json: async () => ({}) } as Response)
105-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTest helper/fixture duplication across three Codex rate-limit test files.
makeRpcChild()and the RPC reset-credit fixtures (rpcResetCreditPayload/expectedRpcResetCredits) are copy-pasted verbatim into the two new test files instead of being imported from a shared module, risking drift if the RPC mock shape or reset-credit normalization changes.
src/main/rate-limits/codex-fetcher-business-usage.test.ts#L105-L117: import a sharedmakeRpcChild()instead of redefining it.src/main/rate-limits/codex-fetcher-backend.test.ts#L21-L34: import the same sharedmakeRpcChild()instead of redefining it.src/main/rate-limits/codex-fetcher-business-usage.test.ts#L35-L55: import sharedrpcResetCreditPayload/expectedRpcResetCreditsfixtures instead of redefining them.src/main/rate-limits/codex-fetcher.test.ts#L41-L63: move these fixtures into a shared test-utils module so both this file andcodex-fetcher-business-usage.test.tsimport from one source.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0f7e3507-07e4-4877-b43c-1390274115f4
📥 Commits
Reviewing files that changed from the base of the PR and between 31f643c and 279de54f484ce6fef9d123ddd62dfb67bc2face8.
📒 Files selected for processing (5)
src/main/rate-limits/codex-business-wham-usage-8664.fixture.jsonsrc/main/rate-limits/codex-fetcher-backend.test.tssrc/main/rate-limits/codex-fetcher-business-usage.test.tssrc/main/rate-limits/codex-fetcher.test.tssrc/main/rate-limits/codex-fetcher.ts
|
Taking a look! |
279de54 to
e5bb6df
Compare
|
Thanks for the clear report and fix! I rebased this onto current |
|
Still broken on Hit it on a second account, different spend-control source than the one in #8664 (amounts redacted): { "plan_type": "business", "rate_limit": null,
"spend_control": { "individual_limit": {
"source": "account_user_spend_controls",
"used_percent": 65, "remaining_percent": 35,
"reset_at": <unix seconds, exactly 00:00 UTC on the 1st> } } }#8664's was Three things from reading the diff. Both gates key off the literal The RPC path may already have this. On codex-cli 0.147.0, Last one is mechanical. Calling the spend control a monthly window rather than a session was right and should stay. I can do the rework as a follow-up crediting you both, or leave it if either of you wants to pick it back up. |
e5bb6df to
57bff8e
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Thanks for the detailed current-main trace and the second payload. I rebuilt this from current The spend control is mapped as a monthly window whenever a usable Standard windows remain additive. Direct RPC monthly data avoids the extra backend usage request; an older successful empty RPC result gets the bounded backend fallback, while WSL backend-first misses aren't retried through the supplement path. Monthly-only snapshots also remain available in inactive-account previews when switching Codex accounts. |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 47309000-89ec-4257-bbec-39ea6fc26ba2
📒 Files selected for processing (6)
src/main/rate-limits/codex-business-wham-usage-8664.fixture.jsonsrc/main/rate-limits/codex-fetcher-backend.test.tssrc/main/rate-limits/codex-fetcher-session-supplement.test.tssrc/main/rate-limits/codex-fetcher.tssrc/main/rate-limits/service-account-target-selection.test.tssrc/main/rate-limits/service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/main/rate-limits/codex-business-wham-usage-8664.fixture.json
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Summary
spend_control.individual_limitresponse to the existing monthly usage window, regardless of whether the source is group-based or account-user controls.individualLimitandplanTypefields directly, preferring preciseused / limitusage and preserving the reset boundary.Closes #8664
Screenshots
No visual change. The existing status bar and usage panels consume the monthly window already supported by Orca.
Testing
AI Review Report
The implementation was reviewed against current
mainacross backend and RPC payload mapping, standard-window classification, fallback eligibility, reset-credit precedence, WSL/native process routing, and inactive-account caching. The review findings were addressed with focused regression coverage for malformed shapes, direct percentage precedence, over-cap values, reset tolerance, no-retry behavior, and monthly-only previews.Security Audit
No authentication or authorization behavior changed. The implementation reuses existing bounded request signals, credential loading, process cleanup, and reset-credit handling. Test credentials are fake literals used only in mocked fixtures.
Notes
This change is scoped to Orca's parsing, precedence, fallback, and cache behavior for the reported payload shapes. The fixtures document compatibility evidence; they do not claim to prove every Codex plan or CLI contract. Rebuilt from current
mainfollowing the second spend-control payload report.ELI5
Codex can report a monthly spending meter in two places. Orca now recognizes both places, keeps the exact reset date, and shows the saved meter when switching between accounts.