Skip to content

fix(usage): distinguish Codex workspaces by account ID - #10876

Closed
kalvenschraut wants to merge 1 commit into
pingdotgg:mainfrom
RTVision:fix/codex-quota-workspace-identity
Closed

kalvenschraut wants to merge 1 commit into
pingdotgg:mainfrom
RTVision:fix/codex-quota-workspace-identity

Conversation

@kalvenschraut

@kalvenschraut kalvenschraut commented Sep 9, 2026 •

Copy link
Copy Markdown

What changed

Codex workspaces sharing an email address are currently merged into one quota bucket, even when they have separate subscriptions. Carry the workspace account ID from native file-backed authentication and CLIProxyAPI into the shared quota collectors, and group by workspace ID plus normalized email. Different Business members can share a workspace ID while owning different quotas and reset credits. The same workspace still merges across environments and native/hub reports, and reset credits stay attached to the matching workspace.

Email remains the fallback for older servers and providers without an ID. An email-only report joins an identified workspace only when the match is unambiguous; otherwise it stays separate rather than guessing.

Fixes #10835.

Related: #10845 distinguishes accounts by email and plan. That leaves two Business workspaces with the same email and plan merged. Workspace ID plus email distinguishes that case without treating a plan change as a new subscription.

UI

Synthetic fixture captures in the web client: two Business workspaces share an email, with 10% and 80% remaining. One workspace is reported on both Laptop and Desktop. Before, both workspaces collapse into 10%; after, they remain separate and pool to 45%.

Before After
Before After

A second synthetic fixture uses two members of the same Business workspace. Before, only the primary member's 29% quota appears. After, the review member's 77% quota and three reset credits remain separate from the primary member's one credit.

Before After
Business members before Business members after

Verification

  • 120 focused tests passed across the shared collectors, CLIProxyAPI adapter, Codex provider, and provider registry. The shared suite was rerun after the member-identity correction: 51 passed, including separate users in one workspace and reports with no email.
  • Coverage includes workspace separation, cross-environment merging, ambiguous legacy reports in both orders, native/hub matching, reset-credit routing, auth-home resolution, and missing or malformed auth files.
  • Server/shared package typechecks and changed-file lint passed. Shared package typecheck and targeted lint were rerun after the member-identity correction.
  • Shared collectors serve web/desktop and mobile; contracts remain backward compatible. No client-specific UI code changed. Browser evidence uses synthetic fixtures, not an OAuth end-to-end test; mobile was not run.
  • Fable approved the original diff and the member-identity correction. A report with no email stays separate because its workspace ID cannot identify which member owns it. Grouping keys are internal maps; persisted UI keys are unchanged.

Implemented with GPT-6 in Codex; reviewed with claude-fable-5-1 through Claude Code.

Summary by CodeRabbit

  • New Features

    • Codex workspace accounts are now identified separately from sign-in email addresses.
    • Provider authentication and usage-limit details can display an account or workspace ID.
    • Codex account information is detected from supported local authentication data.
  • Bug Fixes

    • Usage limits remain correctly separated for multiple workspaces sharing an email.
    • Codex account IDs are trimmed before quota requests.
    • Unavailable or ambiguous account IDs no longer merge unrelated usage records.

@cursor

cursor Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Sep 9, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This cross-package runtime change reads authentication state, alters Codex quota request identity, and changes shared web/mobile aggregation and reset-credit matching for subscription workspaces. Those authentication and entitlement effects extend beyond a small isolated bug fix.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 35455f66-5859-4f68-9dda-b66817184351

📥 Commits

Reviewing files that changed from the base of the PR and between 2b1fdae and bcbb186.

📒 Files selected for processing (2)
  • packages/shared/src/usageLimits.test.ts
  • packages/shared/src/usageLimits.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Codex account IDs are read from file-backed authentication, propagated through provider and API account data, and used to keep distinct workspace subscriptions separate in usage-limit pooling.

Changes

Codex account identity

Layer / File(s) Summary
Codex authentication and provider propagation
apps/server/src/provider/Layers/CodexProvider.ts, apps/server/src/provider/Layers/CodexProvider.test.ts, apps/server/src/provider/Layers/ProviderRegistry.test.ts
The provider resolves its Codex home, reads account_id from auth.json or chatgpt_account_id from an ID token, and includes the result in provider status authentication data.
API account ID normalization
apps/server/src/usage/cliproxyApi.ts, apps/server/src/usage/cliproxyApi.test.ts, packages/contracts/src/server.ts
Codex account IDs are trimmed, exposed in account results, and sent in quota headers only when non-empty. Server provider authentication accepts the optional accountId field.
Account-ID usage pooling
packages/shared/src/usageLimits.ts, packages/shared/src/usageLimits.test.ts, packages/contracts/src/providerUsageLimits.ts
Usage-limit collection keys accounts by provider account ID and falls back to email only when unambiguous. Tests cover separate workspaces, legacy hub reports, and matching account IDs across environments.

Estimated code review effort: 4 (Complex) | ~45 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CodexAuth
  participant CodexProvider
  participant UsageLimits
  CodexAuth->>CodexProvider: read accountId from auth.json
  CodexProvider->>UsageLimits: provide provider auth accountId
  UsageLimits->>UsageLimits: merge native and hub reports by accountId
Loading

Suggested reviewers: juliusmarminge, chrisdeeming

Merge Risk: ⚪ Minimal · up to bcbb1

The change separates Codex subscriptions that share an email while preserving pooling for the same workspace and compatibility with older reports. The supplied validation covers the affected identity and quota paths, so it is merge-ready.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation addresses issue #10835 by carrying Codex workspace account IDs into quota collection, preserving same-workspace merging across environments and native/Hub reports, and keeping ambig…
Out of Scope Changes check ✅ Passed The changes remain focused on Codex workspace identity and usage-limit account merging. Provider, contract, shared collector, and test updates directly support the stated objective; synthetic UI evide…
Title check ✅ Passed The title clearly identifies the primary change: distinguishing Codex workspaces by account ID for usage handling.
Description check ✅ Passed The description clearly explains the problem, implementation, rationale, UI evidence, and verification. It uses alternative headings for some template sections and omits the checklist, but it provides…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@RHeynsZa

Copy link
Copy Markdown

Might just be me, but those percentage bars need to be stacked vertically instead of horizontally. I can't imagine what that would look like on a small screen. Waiting no this fix btw

@juliusmarminge

Copy link
Copy Markdown
Member

Thanks for the PR. We're not taking changes to the orchestration and provider layers right now: that part of the server is being rewritten for V2, and merging into the current code would either conflict with or be thrown away by that work.

Closing for now. If this is still an issue once V2 lands, please reopen (or open a fresh PR against the new code) and we'll take a proper look.

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

Labels

size:L 100-499 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.

Usage → Limits merges two Codex subscriptions that share an email address

3 participants