Skip to content

Add Codex usage indicator#2484

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

Add Codex usage indicator#2484
lintowe wants to merge 21 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 the branch toolbar that displays 5-hour and/or weekly Codex rate limit usage, controlled by a new codexUsageIndicatorMode setting ('five-hour', 'both', 'off') in General Settings.
  • Introduces normalizeCodexUsageSnapshot in codexUsage.ts to normalize various Codex rate-limit payload shapes into a consistent CodexUsageSnapshot with clamped percents, window kinds, and resetsAt timestamps.
  • Extends CodexSessionRuntime with readAccountRateLimits, which lazily initializes the client so usage can be fetched without an active session.
  • Adds readCodexUsage to the Codex adapter, using the active session runtime or a short-lived ephemeral runtime, with a cache updated by both reads and provider notifications.
  • Exposes ProviderService.getCodexUsage and a server.getCodexUsage WebSocket RPC endpoint, wired through to the web client via React Query (codexUsageQueryOptions) with a 60-second refetch interval.
  • Behavioral Change: ClientSettings gains codexUsageIndicatorMode defaulting to 'five-hour'; the legacy value 'weekly' decodes to 'both'.

Macroscope summarized d62e76a.


Note

Medium Risk
Adds a new Codex-specific usage read path (including a new WS RPC) and introduces caching/normalization around provider rate-limit payloads, which could affect provider session/runtime behavior if edge cases are missed.

Overview
Adds an end-to-end Codex usage remaining indicator: a new client setting codexUsageIndicatorMode (default five-hour, supports both/off with legacy weeklyboth migration) and a toolbar chip (CodexUsageIndicator) that polls usage via React Query.

On the server, introduces a normalized CodexUsageSnapshot contract and normalizeCodexUsageSnapshot to convert multiple Codex account/rateLimits/* payload shapes into displayable 5h/weekly windows, caches snapshots from notifications/reads, and exposes them through CodexAdapter.readCodexUsageProviderService.getCodexUsage → new websocket RPC server.getCodexUsage (wired through localApi/RPC client). Also refactors provider-instance selection by centralizing the logic in resolveSelectedProviderInstanceId and updates tests/mocks accordingly.

Reviewed by Cursor Bugbot for commit d62e76a. 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: 5ca5565b-ff4d-4cdd-b2d7-c87d2d685b6d

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

This PR introduces a new user-facing feature (Codex usage indicator) with new UI components, settings, API endpoints, and schemas across multiple packages. New features introducing user-facing behavior warrant human 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
Comment thread apps/web/src/providerInstances.ts Outdated
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels May 8, 2026
@lintowe lintowe force-pushed the feat/provider-usage-indicator branch from 3cae74f to 072624f Compare May 8, 2026 14:22
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:XXL 1,000+ changed lines (additions + deletions). labels May 8, 2026
Comment thread apps/web/src/providerInstances.ts
Comment thread apps/web/src/components/settings/SettingsPanels.tsx
@lintowe lintowe force-pushed the feat/provider-usage-indicator branch 2 times, most recently from a7796fc to 7246156 Compare May 8, 2026 14:49
@lintowe lintowe force-pushed the feat/provider-usage-indicator branch from 7246156 to 5af6aa1 Compare May 8, 2026 19:35
Comment thread apps/web/src/components/ChatView.tsx
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 3d4194f. Configure here.

Comment thread apps/web/src/components/ChatView.tsx Outdated
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