Skip to content

Add Codex usage indicator#2484

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

Add Codex usage indicator#2484
lintowe wants to merge 22 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 a97e7c2.


Note

Medium Risk
Adds a new end-to-end Codex usage pipeline (runtime call + adapter caching + ProviderService routing + WebSocket RPC + React Query UI), which could affect provider event handling and increase server/client coupling. Risk is mitigated by being Codex-only and returning null on failures, but correctness depends on normalizing multiple payload shapes and session-less runtime initialization.

Overview
Adds a Codex usage remaining status chip in the web chat toolbar (next to the branch/env controls), controlled by a new client setting codexUsageIndicatorMode (five-hour, both, off, defaulting to five-hour with legacy weekly migrated to both).

Introduces an end-to-end usage fetch path: CodexSessionRuntime gains readAccountRateLimits with lazy one-time initialization, CodexAdapter adds readCodexUsage with caching updated from both account/rateLimits/read and account/rateLimits/updated notifications (including session-less reads via an ephemeral runtime), and a new normalizeCodexUsageSnapshot maps varied payload shapes into a consistent CodexUsageSnapshot contract.

Exposes usage to clients via ProviderService.getCodexUsage and a new server.getCodexUsage WebSocket RPC, consumed in the web app through codexUsageQueryOptions (60s polling) and new CodexUsageIndicator UI/tests; related tests and mocks are updated to include the new optional adapter/service methods.

Reviewed by Cursor Bugbot for commit a97e7c2. 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: 230d1874-216b-4820-9a14-c6145548957c

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