Skip to content

feat(mobile): add safe Codex rate-limit resets - #9394

Merged
brennanb2025 merged 11 commits into
stablyai:mainfrom
kazu-42:agent/mobile-codex-reset-credit
Jul 24, 2026
Merged

brennanb2025 merged 11 commits into
stablyai:mainfrom
kazu-42:agent/mobile-codex-reset-credit

Conversation

@kazu-42

@kazu-42 kazu-42 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • expose Codex earned reset-credit consumption from the mobile Accounts screen only when the connected host advertises accounts.codex-reset-credit.v1
  • bind every request to the exact host or WSL target, Orca-managed account ID, account revision, and reset offer revision that the user confirmed
  • persist the mobile attempt UUID before sending and reuse it on the next user-confirmed retry after timeout, reconnect, route remount, or app restart
  • coordinate redemption through the main-process Codex account mutation queue and a durable attempt ledger so ambiguous retries fail closed
  • reuse the same managed-account coordinator for the desktop reset action
  • add accounts.selectCodexForTarget so WSL System default selection fails closed against older hosts instead of silently clearing the host selection

Screenshots

Accounts screen showing an available Codex reset credit

Verified the Accounts screen locally at 390 x 844:

  • reset action is 104 x 44 with no horizontal overflow
  • the confirmation names the account email and exact host or WSL runtime target; the mutation remains bound internally to the managed account ID and revision
  • disconnected state hides the mutation action

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 passed
  • pnpm 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 fix
  • Added or updated high-quality regression tests

Current-head follow-up after maintainer commits and CodeRabbit review through 3abc20054:

  • reviewed the maintainer-added reset durability, removed-account cleanup, older-host decode compatibility, and reconnect-safe capability recovery
  • hardened the capability probe so null, non-array, and mixed-type success payloads fail closed as unsupported without scheduling retries
  • rebuilt mock terminal fixtures per request, preferring the explicit worktree selector and otherwise using the currently active worktree
  • added regressions for malformed payload handling, no-retry behavior, worktree creation, worktree activation, and explicit terminal-list routing
  • root focused suite passed: 11 files, 1,469 tests
  • mobile full suite passed: 322 files; 2,339 tests passed, 2 skipped
  • focused capability-probe suite passed: 10 tests; focused terminal-fixture regression passed
  • root and mobile TypeScript checks passed
  • mobile full lint and format checks passed; changed-file Oxlint/Oxfmt, root changed-file type-aware lint, commit hooks, and git diff --check passed
  • styled-scrollbar, reliability, and max-lines gates passed
  • all four inline CodeRabbit threads are resolved at the current head
  • all three current-head GitHub Actions runs are action_required with zero jobs because this fork PR awaits maintainer workflow approval; this is not a source-level CI failure

Current-head verification after rebasing onto 827cd49f4 and addressing CodeRabbit feedback:

  • root focused suite: 11 files, 1,378 tests passed
  • mobile full suite: 310 files passed; 2,223 tests passed, 2 skipped
  • root TypeScript typecheck passed
  • mobile TypeScript typecheck passed
  • changed-file Oxlint, type-aware switch lint, Oxfmt, and React Doctor commit hooks passed
  • mobile full lint passed
  • styled-scrollbar, reliability, max-lines, and localization-catalog gates passed
  • git diff --check passed

Current-head aggregate checks that are not green:

  • root full suite: 3,154 files passed, 6 failed, 6 skipped; 33,511 tests passed, 4 failed, 54 skipped. The failures are outside this PR: three packaging checks cannot resolve the newly upstreamed windows-native-registry package in this macOS install, and SSH/GitHub-project/WorktreeCard timing tests exceeded their deadlines.
  • root full-project type-aware lint exhausted the 4 GB Node heap; the same configuration passed when scoped to the changed root files.
  • the bundled-skill check reports stale 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:

  • root full suite: 2,983 files passed, 6 skipped; 31,712 tests passed, 52 skipped
  • mobile full suite, repeated: 293 files; 2,098 tests passed, 2 skipped
  • production build components passed for relay binaries, CLI, Electron renderer/main, web verification, macOS universal helper, and notification status

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-renderer is 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

  • the RPC remains behind existing Orca paired-device E2EE authentication and an explicit mobile method allowlist
  • UUID, target, account, revision, offer, and request scopes use strict Zod validation; responses use explicit outcome discrimination plus validated forward-compatible account snapshots
  • the provider call uses the immutable managed account home captured inside the serialized mutation
  • no provider tokens are added to mobile storage, persisted state, logs, or RPC payloads
  • no dependency or shell-command execution surface was added
  • host and WSL targets are validated explicitly; SSH is not accepted by the mutation contract
  • IPC and mobile RPC responses are schema-checked before replacing client state
  • ambiguous provider outcomes remain pending and retry with the same idempotency key rather than issuing a new spend attempt
  • each mobile journal entry has a strict bounded schema, and the main-process ledger is capped at 10,000 entries

Notes

  • this draft supports exact Orca-managed Codex accounts on the host and exact WSL distros; SSH is intentionally excluded
  • the desktop System default path retains its existing non-durable fallback because it has no stable managed-account scope
  • managed accounts added multiple times remain separate Orca idempotency domains; provider state remains the final protection against redeeming an already-used offer
  • account removal or reauthentication after an ambiguous provider outcome may require manual recovery; the implementation fails closed instead of guessing
  • this PR does not automatically consume reset credits, switch accounts, restart sessions, or replay prompts
  • automatic failover should be a separate main-process supervisor design with structured exhaustion signals, opt-in account pools, bounded retries, durable transitions, and version-gated conversation handoff

@kazu-42
kazu-42 force-pushed the agent/mobile-codex-reset-credit branch from 400acde to 4aeb166 Compare July 20, 2026 17:42
@kazu-42
kazu-42 marked this pull request as ready for review July 20, 2026 17:43
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: safe Codex rate-limit resets in mobile.
Description check ✅ Passed All required sections are present and filled with specific summary, screenshots, testing, review, security, and notes details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/ipc/rate-limits.ts (1)

15-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider a brief "why" note on the reset-credit delegation.

rateLimits:consumeCodexResetCredit now delegates to codexAccounts.consumeCurrentRateLimitResetCredit() instead of rateLimits.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 value

Use z.uuid() for both idempotencyKey fields. Zod 4 deprecates z.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.tsx
  • mobile/app/index.tsx
  • mobile/scripts/mock-server-account-rpc.ts
  • mobile/scripts/mock-server-account-state.ts
  • mobile/scripts/mock-server-rpc-handlers.ts
  • mobile/src/accounts-route-reset-credit.test.ts
  • mobile/src/components/AccountUsage.tsx
  • mobile/src/components/CodexResetCreditAction.test.ts
  • mobile/src/components/CodexResetCreditAction.tsx
  • mobile/src/components/account-usage-state.test.ts
  • mobile/src/components/account-usage-state.ts
  • mobile/src/components/accounts-snapshot.test.ts
  • mobile/src/components/accounts-snapshot.ts
  • mobile/src/components/codex-reset-credit-capability.test.ts
  • mobile/src/components/codex-reset-credit-capability.ts
  • mobile/src/components/codex-reset-credit.test.ts
  • mobile/src/components/codex-reset-credit.ts
  • mobile/src/components/use-codex-reset-credit-action.ts
  • mobile/src/mock-server-account-state.test.ts
  • mobile/src/storage/codex-reset-attempt-journal.test.ts
  • mobile/src/storage/codex-reset-attempt-journal.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/service.ts
  • src/main/ipc/rate-limits.test.ts
  • src/main/ipc/rate-limits.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
  • src/main/runtime/mobile-rpc-allowlist.test.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/accounts.test.ts
  • src/main/runtime/rpc/methods/accounts.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/runtime-rpc.ts
  • src/shared/codex-reset-credit-attempt-ledger.test.ts
  • src/shared/codex-reset-credit-attempt-ledger.ts
  • src/shared/codex-reset-credit-scope.test.ts
  • src/shared/codex-reset-credit-scope.ts
  • src/shared/constants.ts
  • src/shared/protocol-version.ts
  • src/shared/types.ts

@AmethystLiang
AmethystLiang requested a review from Jinwoo-H July 20, 2026 18:26
@AmethystLiang AmethystLiang assigned OrcaWin and unassigned Jinwoo-H Jul 20, 2026
@AmethystLiang
AmethystLiang requested review from OrcaWin and removed request for Jinwoo-H July 20, 2026 18:35
@kazu-42
kazu-42 force-pushed the agent/mobile-codex-reset-credit branch from 4aeb166 to 35d1f7a Compare July 21, 2026 13:12
@kazu-42

kazu-42 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
mobile/src/components/codex-reset-credit-capability.test.ts (1)

1-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid 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.tsx
  • mobile/app/index.tsx
  • mobile/scripts/mock-server-account-rpc.ts
  • mobile/scripts/mock-server-account-state.ts
  • mobile/scripts/mock-server-rpc-handlers.ts
  • mobile/scripts/mock-server-terminal-fixtures.ts
  • mobile/src/accounts-route-reset-credit.test.ts
  • mobile/src/components/AccountUsage.tsx
  • mobile/src/components/CodexResetCreditAction.test.ts
  • mobile/src/components/CodexResetCreditAction.tsx
  • mobile/src/components/account-usage-state.test.ts
  • mobile/src/components/account-usage-state.ts
  • mobile/src/components/accounts-snapshot.test.ts
  • mobile/src/components/accounts-snapshot.ts
  • mobile/src/components/codex-reset-credit-capability.test.ts
  • mobile/src/components/codex-reset-credit-capability.ts
  • mobile/src/components/codex-reset-credit.test.ts
  • mobile/src/components/codex-reset-credit.ts
  • mobile/src/components/use-codex-reset-credit-action.ts
  • mobile/src/mock-server-account-state.test.ts
  • mobile/src/storage/codex-reset-attempt-journal.test.ts
  • mobile/src/storage/codex-reset-attempt-journal.ts
  • mobile/src/transport/runtime-capability-probe.test.ts
  • mobile/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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f53a363 and b6fe76c.

📒 Files selected for processing (2)
  • mobile/src/transport/runtime-capability-probe.test.ts
  • mobile/src/transport/runtime-capability-probe.ts

…set-credit

# Conflicts:
#	src/main/codex-accounts/service.ts
#	src/shared/protocol-version.ts
@brennanb2025

Copy link
Copy Markdown
Contributor

Merged latest main to resolve the conflict and refresh against current base. Also folded in two small hardening fixes from review:

  • Older-host compatibility: the accounts snapshot now defaults missing claudeTarget/codexTarget to a host target, so desktops from before runtime targeting render the Accounts screen instead of failing closed. The reset action stays hidden on those hosts (no capability, no credits).
  • Account removal: removing a managed account now purges its reset-attempt ledger entries, so a stale providerPending attempt can't permanently wedge that target's reset.

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!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 lift

Make account removal and reset-ledger cleanup atomic.

discardResetAttemptsForRemovedAccount can 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3abc200 and 5cf76d9.

📒 Files selected for processing (8)
  • src/main/codex-accounts/service.test.ts
  • src/main/codex-accounts/service.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/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

@brennanb2025
brennanb2025 merged commit 4a71a0e into stablyai:main Jul 24, 2026
3 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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]>
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.

4 participants