Repository navigation
feat(mobile): add safe Codex rate-limit resets - #9394
Conversation
400acde to
4aeb166
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change adds Zod validation for account snapshots and fail-closed handling for malformed host data. It introduces Codex reset-credit scope construction, durable idempotency journals, backend consumption coordination, provider-scoped rate-limit refreshes, runtime and RPC endpoints, capability advertisement, and mobile allowlist updates. The mobile account screen supports WSL-targeted selection, reset-credit summaries, confirmation and busy states, and reset result handling. Mock server support and extensive unit, integration, persistence, and UI tests cover these flows. 🚥 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
🧹 Nitpick comments (2)
src/main/ipc/rate-limits.ts (1)
15-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider a brief "why" note on the reset-credit delegation.
rateLimits:consumeCodexResetCreditnow delegates tocodexAccounts.consumeCurrentRateLimitResetCredit()instead ofrateLimits.consumeCodexRateLimitResetCredit(...)(still used internally by the coordinator). A one-line comment noting that this routes through the managed-account mutation queue/durable ledger (so the desktop and mobile reset paths share the same coordinator) would help future readers avoid reverting to the direct rate-limit call.Source: Coding guidelines
src/shared/codex-reset-credit-attempt-ledger.ts (1)
22-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
z.uuid()for bothidempotencyKeyfields. Zod 4 deprecatesz.string().uuid(), so switching avoids deprecation churn.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 46700946-35e6-4194-9be4-1ceb260f2683
📥 Commits
Reviewing files that changed from the base of the PR and between d9d939a and 4aeb1668668c408b4c4b63ff176b3a0131906373.
📒 Files selected for processing (45)
mobile/app/h/[hostId]/accounts.tsxmobile/app/index.tsxmobile/scripts/mock-server-account-rpc.tsmobile/scripts/mock-server-account-state.tsmobile/scripts/mock-server-rpc-handlers.tsmobile/src/accounts-route-reset-credit.test.tsmobile/src/components/AccountUsage.tsxmobile/src/components/CodexResetCreditAction.test.tsmobile/src/components/CodexResetCreditAction.tsxmobile/src/components/account-usage-state.test.tsmobile/src/components/account-usage-state.tsmobile/src/components/accounts-snapshot.test.tsmobile/src/components/accounts-snapshot.tsmobile/src/components/codex-reset-credit-capability.test.tsmobile/src/components/codex-reset-credit-capability.tsmobile/src/components/codex-reset-credit.test.tsmobile/src/components/codex-reset-credit.tsmobile/src/components/use-codex-reset-credit-action.tsmobile/src/mock-server-account-state.test.tsmobile/src/storage/codex-reset-attempt-journal.test.tsmobile/src/storage/codex-reset-attempt-journal.tssrc/main/codex-accounts/service.test.tssrc/main/codex-accounts/service.tssrc/main/ipc/rate-limits.test.tssrc/main/ipc/rate-limits.tssrc/main/ipc/register-core-handlers.test.tssrc/main/ipc/register-core-handlers.tssrc/main/persistence.test.tssrc/main/persistence.tssrc/main/rate-limits/service.test.tssrc/main/rate-limits/service.tssrc/main/runtime/mobile-rpc-allowlist.test.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/main/runtime/rpc/methods/accounts.test.tssrc/main/runtime/rpc/methods/accounts.tssrc/main/runtime/runtime-rpc.test.tssrc/main/runtime/runtime-rpc.tssrc/shared/codex-reset-credit-attempt-ledger.test.tssrc/shared/codex-reset-credit-attempt-ledger.tssrc/shared/codex-reset-credit-scope.test.tssrc/shared/codex-reset-credit-scope.tssrc/shared/constants.tssrc/shared/protocol-version.tssrc/shared/types.ts
4aeb166 to
35d1f7a
Compare
…ant, rebase test mocks
…set-credit # Conflicts: # mobile/app/h/[hostId]/accounts.tsx # src/main/runtime/mobile-rpc-allowlist.test.ts # src/shared/protocol-version.ts
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
mobile/src/components/codex-reset-credit-capability.test.ts (1)
1-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid adding new tests with deprecated
react-test-renderer.React 19.2 deprecates this package; prefer supported React Testing Library rendering/hook utilities for new tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 60a05f15-74ee-40af-9eb3-e047aac8f8ca
📥 Commits
Reviewing files that changed from the base of the PR and between 4aeb1668668c408b4c4b63ff176b3a0131906373 and f53a363.
📒 Files selected for processing (24)
mobile/app/h/[hostId]/accounts.tsxmobile/app/index.tsxmobile/scripts/mock-server-account-rpc.tsmobile/scripts/mock-server-account-state.tsmobile/scripts/mock-server-rpc-handlers.tsmobile/scripts/mock-server-terminal-fixtures.tsmobile/src/accounts-route-reset-credit.test.tsmobile/src/components/AccountUsage.tsxmobile/src/components/CodexResetCreditAction.test.tsmobile/src/components/CodexResetCreditAction.tsxmobile/src/components/account-usage-state.test.tsmobile/src/components/account-usage-state.tsmobile/src/components/accounts-snapshot.test.tsmobile/src/components/accounts-snapshot.tsmobile/src/components/codex-reset-credit-capability.test.tsmobile/src/components/codex-reset-credit-capability.tsmobile/src/components/codex-reset-credit.test.tsmobile/src/components/codex-reset-credit.tsmobile/src/components/use-codex-reset-credit-action.tsmobile/src/mock-server-account-state.test.tsmobile/src/storage/codex-reset-attempt-journal.test.tsmobile/src/storage/codex-reset-attempt-journal.tsmobile/src/transport/runtime-capability-probe.test.tsmobile/src/transport/runtime-capability-probe.ts
🚧 Files skipped from review as they are similar to previous changes (19)
- mobile/src/components/AccountUsage.tsx
- mobile/src/components/CodexResetCreditAction.test.ts
- mobile/src/mock-server-account-state.test.ts
- mobile/src/components/codex-reset-credit-capability.ts
- mobile/src/components/CodexResetCreditAction.tsx
- mobile/src/components/use-codex-reset-credit-action.ts
- mobile/src/components/account-usage-state.test.ts
- mobile/src/components/account-usage-state.ts
- mobile/scripts/mock-server-account-rpc.ts
- mobile/src/storage/codex-reset-attempt-journal.test.ts
- mobile/app/index.tsx
- mobile/src/accounts-route-reset-credit.test.ts
- mobile/src/components/accounts-snapshot.test.ts
- mobile/src/components/codex-reset-credit.test.ts
- mobile/scripts/mock-server-account-state.ts
- mobile/app/h/[hostId]/accounts.tsx
- mobile/src/components/codex-reset-credit.ts
- mobile/src/components/accounts-snapshot.ts
- mobile/src/storage/codex-reset-attempt-journal.ts
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: 84b432f3-a3f2-4a67-a60c-4b9af6a87a19
📒 Files selected for processing (2)
mobile/src/transport/runtime-capability-probe.test.tsmobile/src/transport/runtime-capability-probe.ts
…set-credit # Conflicts: # src/main/codex-accounts/service.ts # src/shared/protocol-version.ts
|
Merged latest
Conflict resolution kept the durable ledger purge and adopted main's non-blocking quota refresh. Typecheck + the reset/account suites are green locally. Thanks @kazu-42! |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/codex-accounts/service.ts (1)
829-833: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftMake account removal and reset-ledger cleanup atomic.
discardResetAttemptsForRemovedAccountcan fail at its durability barrier after the account settings and managed home have already been removed. The operation then rejects with stale reset attempts still present, potentially leaving the target permanently fail-closed with no account ID available for retry. Commit the account removal and ledger purge atomically, or retain the account until ledger cleanup succeeds.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4a76cb04-2926-4eb8-94fb-8f17be8d7e73
📒 Files selected for processing (8)
src/main/codex-accounts/service.test.tssrc/main/codex-accounts/service.tssrc/main/persistence.test.tssrc/main/persistence.tssrc/main/rate-limits/service.test.tssrc/main/rate-limits/service.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.ts
🚧 Files skipped from review as they are similar to previous changes (7)
- src/main/rate-limits/service.test.ts
- src/main/runtime/orca-runtime.test.ts
- src/main/runtime/orca-runtime.ts
- src/main/persistence.ts
- src/main/rate-limits/service.ts
- src/main/persistence.test.ts
- src/main/codex-accounts/service.test.ts
* feat(mobile): add safe Codex rate-limit resets * fix(mobile): address reset credit review feedback * review: purge removed-account reset attempts, shared capability constant, rebase test mocks * review: preserve host compatibility and reset durability * fix(mobile): recover reset capability after cutover * fix(mobile): validate runtime capability payloads * fix(mobile): enforce capability payload contract * fix(mobile): route mock terminals to selected worktree * test(mobile): pin malformed probe retry behavior --------- Co-authored-by: Brennan Benson <[email protected]>
Summary
accounts.codex-reset-credit.v1accounts.selectCodexForTargetso WSL System default selection fails closed against older hosts instead of silently clearing the host selectionScreenshots
Verified the Accounts screen locally at 390 x 844:
The screenshot uses synthetic mock account data.
Testing
pnpm lint— source-wide Oxlint and mobile full lint passed; changed-file type-aware lint and the relevant repo gates passed. The aggregate root command remains unchecked because its full-project type-aware phase exhausted the 4 GB Node heap, and later upstream-only artifact/localization gates are also stale.pnpm typecheck— root and mobile TypeScript checks passedpnpm test— current-head root focused and mobile full suites passed. A later broad root rerun was terminated externally with SIGTERM 143 before completion; earlier unrelated packaging/timing failures remain documented below.pnpm build— production build components passed, but the monolithic command was not rerun after the final backend-only race fixCurrent-head follow-up after maintainer commits and CodeRabbit review through
3abc20054:git diff --checkpassedaction_requiredwith zero jobs because this fork PR awaits maintainer workflow approval; this is not a source-level CI failureCurrent-head verification after rebasing onto
827cd49f4and addressing CodeRabbit feedback:git diff --checkpassedCurrent-head aggregate checks that are not green:
windows-native-registrypackage in this macOS install, and SSH/GitHub-project/WorktreeCard timing tests exceeded their deadlines.resources/skills/release-mapping.json, and localization coverage reports three strings in AI Vault files; none of those files are changed by this PR.Broader pre-final-delta verification:
The final focused suite includes regressions for account switching before and during redemption, concurrent retries, response loss and restart recovery, host versus WSL isolation, stale account and offer revisions, older-host capability gating, desktop retry behavior, and older refresh generations attempting to overwrite post-reset state.
AI Review Report
Independent review initially identified gaps around account-queue serialization, request scope, mobile lifecycle persistence, timeout budget, WSL attribution, mixed-version capability gating, response schema validation, mock fidelity, durable provider lifecycle, desktop bypasses, target changes during refresh, and older refresh generations.
Those findings were addressed with regression tests. A final independent review approved the scoped refresh and distinct targeted-selection paths, including the generation guard that prevents an older full refresh from overwriting post-reset state.
CodeRabbit later requested the exact-WSL reset explanation, managed-account coordinator documentation, Zod 4 UUID schemas, defensive capability decoding, live mock-terminal routing, and no-retry assertions for malformed success payloads. The actionable findings were applied and all inline threads are resolved. Its review-body suggestion to replace
react-test-rendereris intentionally deferred: the mobile package currently has no React Testing Library dependency and its existing hook-test suite uses the pinned renderer, so a one-off migration would add a second harness without removing the deprecated surface.Cross-platform review explicitly covered macOS, Linux, and Windows, including shortcuts, labels, paths, shell behavior, WSL, SSH, and Electron IPC. This change adds no keyboard shortcut, shell command, dependency, or generic path construction. Native hosts retain the host target, Windows can bind to one exact WSL distro, and SSH is excluded. The desktop Electron action now uses the same managed-account coordinator while its existing System default fallback remains unchanged.
Security Audit
Notes