Skip to content

Add Codex reset credit controls - #5631

Merged
Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/codex-rate-limit-reset-banking-display-banked-re
Jun 17, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
Jinwoo-H/codex-rate-limit-reset-banking-display-banked-re

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • surface Codex rate-limit reset credits from app-server responses when available, with a ChatGPT backend usage fallback for current Codex builds
  • add a guarded consume path for reset credits through main IPC/preload/store plumbing
  • show reset-credit availability in the status-bar Codex menu and require confirmation before consuming a credit, with a persisted "Don't ask again" option

Closes #5494.

Screenshots

Screenshot proof was captured locally at /tmp/orca-pr-evidence/codex-reset-confirmation.png after launching this worktree via CDP, injecting rateLimitResetCredits.availableCount = 1 in renderer state, opening the Codex status menu, and clicking Reset now. No real reset credit was consumed.

Testing checklist

  • pnpm vitest run --config config/vitest.config.ts src/main/rate-limits/codex-fetcher.test.ts
  • pnpm vitest run --config config/vitest.config.ts src/main/codex-accounts/runtime-home-service.test.ts src/main/codex-accounts/service.test.ts
  • pnpm run typecheck
  • pnpm run verify:localization-catalog
  • targeted pnpm exec oxlint ...
  • Electron proof of the reset confirmation dialog with simulated reset credits

AI Review Report

  • Addressed CodeRabbit actionable comments by using a cross-platform test path, refreshing Codex usage after failed/ambiguous consume attempts, allowing redemption to continue if saving the skip-confirm preference fails, propagating consume failures from the renderer store, and documenting the web no-op reset fallback.
  • Cross-platform check: production path handling uses Node path helpers; the test now mirrors that with join(...).
  • SSH/runtime check: reset consumption stays routed through existing Codex home target resolution and refreshes the selected Codex target.

Security Audit

  • Reads Codex auth only from the resolved Codex home and sends the bearer token only to the ChatGPT backend usage/reset endpoints.
  • Consume calls use a generated idempotency key and keep the operation behind main-process IPC.
  • Web clients do not redeem reset credits because they do not own local Codex auth.

Note: local shell is using Node v26, so pnpm prints the repo's expected Node 24 engine warning, but the checks above passed.

@ghost

ghost commented Jun 17, 2026 •

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Define rate-limit reset types and settings
2 Implement Codex reset credit fetching and consumption
3 Test Codex reset credit fetching logic
4 Wire reset controls through IPC and Store
5 Add reset UI to status bar and tooltips
6 Add localization for reset controls
Open in Stage

Chapters generated by Stage for commit dcd32b8 on Jun 17, 2026 10:31pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 34f7d244-99cc-4a8c-af2d-26c54f931bef

📥 Commits

Reviewing files that changed from the base of the PR and between 801d213 and dcd32b8.

📒 Files selected for processing (10)
  • src/main/rate-limits/codex-fetcher.test.ts
  • src/main/rate-limits/service.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
💤 Files with no reviewable changes (6)
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/components/status-bar/StatusBar.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/preload/index.ts
  • src/preload/api-types.ts
  • src/main/rate-limits/service.ts

📝 Walkthrough

Walkthrough

This PR implements end-to-end support for consuming Codex rate-limit reset credits. New shared types (CodexRateLimitResetOutcome, CodexRateLimitResetResult) and an optional rateLimitResetCredits field are added to ProviderRateLimits. The codex-fetcher gains backend enrichment logic that reads auth.json to call the /backend-api/wham/usage endpoint when reset credits are absent from RPC/PTY responses, plus an exported consumeCodexRateLimitResetCredit function that POSTs to the consume endpoint with idempotency. RateLimitService wraps this with a UUID-keyed method and forces a post-consume refresh. The IPC handler, preload bridge, and renderer store slice wire the operation to the UI. StatusBar.tsx adds a confirmation dialog and dropdown entry for redemption, with a skipCodexRateLimitResetConfirm preference. tooltip.tsx displays the available credit count. Locale strings are added across five languages.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% 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 'Add Codex reset credit controls' clearly and concisely summarizes the main change: adding UI and backend support for displaying and consuming Codex rate-limit reset credits.
Description check ✅ Passed The PR description covers all required template sections: it includes a summary of changes, a note about screenshot evidence, comprehensive testing checklist, AI review report with cross-platform validation, security audit, and platform-specific notes.
Linked Issues check ✅ Passed All three objectives from issue #5494 are satisfied: (1) reset-credit count is surfaced via rateLimitResetCredits field; (2) 'Reset now' button with confirmation is implemented in status-bar UI; (3) per-account support maintained through existing Codex home path resolution.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing Codex reset credit controls: fetching credits, exposing through IPC/preload layers, persisting the skip-confirmation preference, and rendering UI for the status-bar menu.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 and usage tips.

@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: 5


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 03a36686-3505-4e19-befe-b4da9815b2db

📥 Commits

Reviewing files that changed from the base of the PR and between 9e3b3ca and 801d213.

📒 Files selected for processing (20)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/service.test.ts
  • src/main/ipc/rate-limits.ts
  • src/main/rate-limits/codex-fetcher.test.ts
  • src/main/rate-limits/codex-fetcher.ts
  • src/main/rate-limits/service.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/tooltip.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/rate-limits.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/constants.ts
  • src/shared/rate-limit-types.ts
  • src/shared/types.ts

Comment thread src/main/rate-limits/service.ts Resolved
Comment on lines +1318 to +1321
if (skipFutureResetConfirm) {
await updateSettings({ skipCodexRateLimitResetConfirm: true })
}
await handleRedeemReset()

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t let “Don’t ask again” persistence failures block redemption.

On Line 1319, updateSettings is awaited without handling failure. If it rejects, redeem is aborted even though preference persistence is optional.

Proposed fix
   const handleConfirmReset = async (): Promise<void> => {
     if (isRedeemingReset) {
       return
     }
     if (skipFutureResetConfirm) {
-      await updateSettings({ skipCodexRateLimitResetConfirm: true })
+      try {
+        await updateSettings({ skipCodexRateLimitResetConfirm: true })
+      } catch (error) {
+        console.error('Failed to save Codex reset confirmation preference:', error)
+      }
     }
     await handleRedeemReset()
     if (mountedRef.current) {
       setResetConfirmOpen(false)
       setSkipFutureResetConfirm(false)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (skipFutureResetConfirm) {
await updateSettings({ skipCodexRateLimitResetConfirm: true })
}
await handleRedeemReset()
if (skipFutureResetConfirm) {
try {
await updateSettings({ skipCodexRateLimitResetConfirm: true })
} catch (error) {
console.error('Failed to save Codex reset confirmation preference:', error)
}
}
await handleRedeemReset()

Comment on lines +108 to +114
consumeCodexRateLimitResetCredit: async () => {
try {
const result = await window.api.rateLimits.consumeCodexResetCredit()
set({ rateLimits: result.state })
} catch (error) {
console.error('Failed to consume Codex rate-limit reset:', error)
}

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Propagate consume failures instead of resolving silently.

On Line 113, the catch block logs and swallows errors. That makes failed reset-consume attempts look like success to callers and breaks failure-aware UI handling.

Proposed fix
   consumeCodexRateLimitResetCredit: async () => {
     try {
       const result = await window.api.rateLimits.consumeCodexResetCredit()
       set({ rateLimits: result.state })
     } catch (error) {
       console.error('Failed to consume Codex rate-limit reset:', error)
+      throw error
     }
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
consumeCodexRateLimitResetCredit: async () => {
try {
const result = await window.api.rateLimits.consumeCodexResetCredit()
set({ rateLimits: result.state })
} catch (error) {
console.error('Failed to consume Codex rate-limit reset:', error)
}
consumeCodexRateLimitResetCredit: async () => {
try {
const result = await window.api.rateLimits.consumeCodexResetCredit()
set({ rateLimits: result.state })
} catch (error) {
console.error('Failed to consume Codex rate-limit reset:', error)
throw error
}
},

get: () => Promise.resolve(empty),
refresh: () => Promise.resolve(empty),
refreshCodexForTarget: () => Promise.resolve(empty),
consumeCodexResetCredit: () => Promise.resolve({ outcome: 'noCredit', state: empty }),

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a short “Why” comment for the web no-op.

Returning noCredit here is a safe fallback, but the desktop-only reset-credit constraint is non-obvious.

Proposed fix
+    // Why: web clients do not own local Codex auth, so reset-credit
+    // redemption remains desktop-only and reports the safe no-credit outcome.
     consumeCodexResetCredit: () => Promise.resolve({ outcome: 'noCredit', state: empty }),

As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines

…imit-reset-banking-display-banked-re

# Conflicts:
#	src/renderer/src/i18n/locales/ja.json
@Jinwoo-H
Jinwoo-H merged commit 25d2053 into main Jun 17, 2026
1 check passed
@Jinwoo-H
Jinwoo-H deleted the Jinwoo-H/codex-rate-limit-reset-banking-display-banked-re branch June 17, 2026 22:41
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 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.

Codex rate-limit reset banking: display banked resets per account and trigger manual reset

1 participant