Skip to content

Add Codex usage indicator#2484

Open
lintowe wants to merge 28 commits intopingdotgg:mainfrom
lintowe:feat/provider-usage-indicator
Open

Add Codex usage indicator#2484
lintowe wants to merge 28 commits intopingdotgg:mainfrom
lintowe:feat/provider-usage-indicator

Conversation

@lintowe
Copy link
Copy Markdown

@lintowe lintowe commented May 4, 2026

Summary

  • Adds a Codex usage remaining indicator for the selected composer provider

What Changed

  • Added a Codex usage remaining setting with 5h window, 5h + weekly, and Off
  • Added a composer status chip beside the checkout row for Codex providers
  • Reads Codex app-server account/rateLimits/read and account/rateLimits/updated
  • Maps Codex primary usage to 5h and secondary usage to Weekly
  • Formats reset times like Codex does, using local time/date instead of relative “now”

Screenshots

  • Before
image
  • After
image

Testing

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test -- src/settings.test.ts
  • bun run test -- src/provider/codexUsage.test.ts src/provider/Layers/CodexAdapter.test.ts src/provider/Layers/ProviderService.test.ts
  • bun run test:browser -- src/components/chat/CodexUsageIndicator.browser.tsx

Note

Add Codex usage indicator showing rate limit windows in the chat toolbar

  • Adds a CodexUsageIndicator component to BranchToolbar that displays five-hour and/or weekly Codex rate limit usage with a tooltip and amber styling when a limit is reached; controlled by a new codexUsageIndicatorMode setting (default: five-hour).
  • Introduces normalizeCodexUsageSnapshot on the server to convert heterogeneous Codex rate limit payload shapes into a typed CodexUsageSnapshot with clamped percents, ISO reset times, and a resolved rateLimitReachedType.
  • Adds readCodexUsage to the Codex adapter, which reads account rate limits from the active session runtime or a short-lived temporary runtime, normalizing and caching results; cached snapshots are returned when subsequent reads yield no displayable windows.
  • Exposes getCodexUsage(instanceId) on ProviderService and wires a new server.getCodexUsage WebSocket RPC, polled every 60 seconds from the client via codexUsageQueryOptions.
  • Adds CodexUsageIndicatorMode to client settings with a legacy migration: the old "weekly" value decodes to "both"; the new default is "five-hour".

Macroscope summarized 6b8a1a4.


Note

Medium Risk
Adds a new Codex usage read path (including a new WS RPC) and caching/normalization logic around rate-limit payloads, which could affect provider session runtime behavior and UI polling. Changes are contained to Codex-specific paths but touch server adapter/runtime initialization and client settings persistence.

Overview
Adds an end-to-end Codex usage remaining feature: a new client setting codexUsageIndicatorMode (default five-hour, with legacy weekly migrated to both) and a toolbar CodexUsageIndicator chip that polls and displays remaining 5h/weekly limits with tooltip/reset-time formatting.

On the server, introduces a typed CodexUsageSnapshot contract plus normalization utilities, and extends the Codex provider stack to read account/rateLimits/read (via the active session runtime or a short-lived runtime when no session exists), cache the last usable snapshot, and update the cache from account/rateLimits/updated notifications.

Exposes this through ProviderService.getCodexUsage and a new WS RPC server.getCodexUsage, wires it through the web localApi + react-query helper (codexUsageQueryOptions, 60s polling), and updates tests/mocks to include the new APIs and settings persistence.

Reviewed by Cursor Bugbot for commit 6b8a1a4. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bf6f667e-b11b-4c25-ad2a-6bc099e6e18f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels May 4, 2026
@lintowe lintowe mentioned this pull request May 4, 2026
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts
@lintowe lintowe force-pushed the feat/provider-usage-indicator branch from 4e9f527 to d28c0ed Compare May 4, 2026 00:47
@lintowe lintowe marked this pull request as ready for review May 4, 2026 00:49
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts Outdated
@lintowe lintowe force-pushed the feat/provider-usage-indicator branch from d28c0ed to 8075d94 Compare May 4, 2026 00:54
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 4, 2026

Approvability

Verdict: Needs human review

New feature introducing a Codex usage indicator with new UI components, settings, RPC endpoints, and provider integration. The scope of new functionality—including user-facing UI, new data flows, and external API integration—warrants careful review.

You can customize Macroscope's approvability policy. Learn more.

Comment thread apps/server/src/provider/Layers/CodexAdapter.ts Outdated
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts
Comment thread apps/server/src/provider/codexUsage.ts
Comment thread apps/server/src/provider/codexUsage.ts
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts
Comment thread apps/server/src/provider/codexUsage.ts Outdated
Comment thread apps/server/src/provider/codexUsage.ts
Comment thread apps/server/src/provider/codexUsage.ts
Comment thread apps/server/src/provider/Layers/CodexAdapter.ts Outdated
Comment thread packages/shared/src/codexUsage.ts
Comment thread apps/web/src/components/BranchToolbar.tsx Outdated
Comment thread apps/web/src/providerInstances.ts
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6b8a1a4. Configure here.

if (byKind) return byKind.instanceId;

const anyEnabled = input.entries.find((entry) => entry.enabled);
return anyEnabled?.instanceId ?? input.entries[0]?.instanceId ?? ProviderInstanceId.make("codex");
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.

Refactored fallback drops thread/project model selection IDs

Low Severity

The extracted resolveSelectedProviderInstanceId final fallback returns anyEnabled?.instanceId ?? entries[0]?.instanceId ?? ProviderInstanceId.make("codex"), but the original inline code in ChatComposer additionally tried activeThreadModelSelection?.instanceId ?? activeProjectDefaultModelSelection?.instanceId before the hardcoded "codex" default. When no entries exist at all, the old code could return a meaningful persisted instance ID while the new code always returns the hardcoded "codex" fallback.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6b8a1a4. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant