Repository navigation
Conversation
|
@coderabbitai review |
✅ Action performedReview finished.
|
📝 WalkthroughWalkthroughThe RPC rate-limit response now requires a 🚥 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 18c1e24b-f4d8-4e16-a73d-f1d77c502654
📒 Files selected for processing (2)
src/main/rate-limits/codex-fetcher.test.tssrc/main/rate-limits/codex-fetcher.ts
Greptile SummaryThis PR adds validation of the
Confidence Score: 5/5Safe to merge — the change is a well-scoped guard that adds an explicit validation step before consuming the RPC response, with no changes to the happy-path data flow or persistence format. The type guard correctly rejects all malformed shapes (missing key, null top-level, array, invalid nested windows) while preserving the documented explicit-null case. The fallback wiring through the existing allowPtyFallback / isCodexAuthError checks is untouched. Tests cover all new branches including the disabled-fallback path, and the fake-timer leak is fixed in afterEach. No data is lost or misinterpreted on either the valid or invalid response paths. Files Needing Attention: No files require special attention.
|
| Filename | Overview |
|---|---|
| src/main/rate-limits/codex-fetcher.ts | Adds isRpcRateLimitsResponse type guard and wires it into the RPC response handling path; logic is correct and the error path correctly falls through to PTY fallback or returns an error when fallback is disabled. |
| src/main/rate-limits/codex-fetcher-rpc-test-harness.ts | New shared harness; upgrades makePtyTerm to use Sets so multiple subscriptions coexist correctly, and gives makeDisposable a real cleanup callback so disposal actually removes handlers. |
| src/main/rate-limits/codex-fetcher.test.ts | Migrates helpers to the shared harness, adds five regression tests covering invalid RPC shapes, explicit-null compatibility, and allowPtyFallback: false paths; fixes timer leak by adding vi.useRealTimers() to afterEach. |
| src/main/rate-limits/codex-fetcher-rpc-test-harness.test.ts | Adds a focused unit test verifying that disposing a PTY event subscription stops event delivery; correctly exercises the new Set-based handler management. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[fetchCodexRateLimits] --> B[fetchViaRpc]
B --> C[RPC: account/rateLimits/read]
C --> D{msg.error?}
D -- yes --> E[settle error + kill]
D -- no --> F{isRpcRateLimitsResponse?}
F -- no --> G[settle Invalid RPC rate-limit response + kill]
F -- yes --> H{rateLimits === null?}
H -- yes --> I[settle ok: session=null, weekly=null]
H -- no --> J[classifyCodexRateLimitWindows]
J --> K[settle ok with session/weekly]
G --> L{rpcResult.status === ok/unavailable?}
E --> L
K --> L
I --> L
L -- yes --> M[withBackendSessionWindow / withBackendRateLimitResetCredits]
M --> N[Return result]
L -- no --> O{isCodexAuthError?}
O -- yes --> P[Return auth error]
O -- no --> Q{allowPtyFallback === false?}
Q -- yes --> R[Return RPC error]
Q -- no --> S[fetchViaPty PTY fallback]
S --> T[Parse PTY output]
T --> N
Reviews (3): Last reviewed commit: "test(codex): dispose RPC PTY harness lis..." | Re-trigger Greptile
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: e5c389e7-a662-48b5-81d8-d387290338ac
📒 Files selected for processing (3)
src/main/rate-limits/codex-fetcher-rpc-test-harness.tssrc/main/rate-limits/codex-fetcher.test.tssrc/main/rate-limits/codex-fetcher.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/rate-limits/codex-fetcher.test.ts
- src/main/rate-limits/codex-fetcher.ts
|
Thanks @kazu-42 for the malformed Codex rate-limit fallback fix. We consolidated this with #11766 and #11760 in canonical issue #17518, covering provider RPC, PTY, and local-log fallback behavior. We will reimplement the matrix on current main; no contributor follow-up is requested. Closing this superseded branch while preserving your credit. |
Summary
account/rateLimits/readenvelope before treating an app-server response as usable.rateLimitsdata, including malformed nestedprimary/secondarywindows, so the existing/statusPTY fallback can recover usage instead of showing an incorrect empty state.rateLimits: null, and preserveallowPtyFallback: falsefor background managed-account previews.Protocol evidence
The current Codex app-server documentation shows
account/rateLimits/readreturning a result wrapper withrateLimits, optionalrateLimitsByLimitId, and optionalrateLimitResetCredits.The locally installed
codex-cli 0.146.0generated schema (codex app-server generate-json-schema) declaresrateLimitsas the required backward-compatible single-bucket view andrateLimitsByLimitIdas optional. ArateLimitsByLimitId-only success is therefore treated as invalid rather than silently mapped to empty usage.Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm test— ran 8 focused files / 72 tests covering RPC, backend supplementation, PTY settlement, test-harness disposal, auth errors, window classification, and target selectionpnpm build— no packaging, renderer, dependency, or asset changesFocused verification on the exact rebased head:
The primary regression test failed on the old implementation because
{ rateLimitsByLimitId: null }was accepted asstatus: "ok"with null windows and PTY never started. It now reaches PTY and returns the parsed 5-hour and weekly usage. Separate tests lock explicit-null compatibility, malformed top-level rejection, and both fallback-enabled and fallback-disabled behavior for malformed nested windows.AI Review Report
Five independent final review axes covered correctness, reliability, security/data integrity, cross-version/platform compatibility, and maintainability/test quality.
The review checked:
settle(..., { kill: true })path, including effective test-double subscription disposal;allowPtyFallback: falsebehavior for managed-account background previews;All five final axes reported no remaining P0-P3 findings.
Security Audit
CODEX_HOME/ WSL execution target is unchanged.Notes
This is intentionally separate from fix(codex): make account removal crash-safe #11655: account-removal durability and rate-limit protocol parsing have independent failure modes, tests, and rollback paths.
Unknown or future response shapes fail over to the existing PTY reader instead of being accepted as empty usage.
Rollback is a one-commit revert with no migration.
Contributor X: @DevKazu42