Skip to content

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

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

fix(usage): distinguish Codex workspaces by account ID#10876
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. 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. A workspace ID 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

Verification

  • 120 focused tests passed across the shared collectors, CLIProxyAPI adapter, Codex provider, and provider registry. The shared suite was rerun after lint cleanup: 49 passed.
  • 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 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 reviewed the diff and approved its scope, behavior, and test coverage.

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

Summary by CodeRabbit

  • New Features

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

    • Usage limits now remain correctly separated for multiple workspaces sharing the same email.
    • Codex account IDs are trimmed before use, preventing invalid quota requests from whitespace-padded values.
    • Unavailable or ambiguous account IDs no longer cause unrelated usage records to merge.

@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: 8e89edaa-3146-40d5-ab2b-b5376d701956

📥 Commits

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

📒 Files selected for processing (9)
  • apps/server/src/provider/Layers/CodexProvider.test.ts
  • apps/server/src/provider/Layers/CodexProvider.ts
  • apps/server/src/provider/Layers/ProviderRegistry.test.ts
  • apps/server/src/usage/cliproxyApi.test.ts
  • apps/server/src/usage/cliproxyApi.ts
  • packages/contracts/src/providerUsageLimits.ts
  • packages/contracts/src/server.ts
  • packages/shared/src/usageLimits.test.ts
  • packages/shared/src/usageLimits.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 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.

Priority: ➖ Normal

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

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 2b1fd

Codex workspaces sharing an email now remain separate when their account IDs differ, while matching workspaces continue to pool usage and reset credits across reports. No material merge-readiness risk remains.

Suggested reviewers: juliusmarminge, t3dotgg

🚥 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
Title check ✅ Passed The title clearly identifies the primary change: distinguishing Codex workspaces by account ID for usage tracking.
Description check ✅ Passed The description explains the change, rationale, UI impact, and verification results. It omits the template checklist and uses slightly different headings, but it is otherwise complete and focused.
Linked Issues check ✅ Passed The changes satisfy issue [#10835] by propagating Codex workspace account IDs, keeping same-workspace reports merged, separating workspaces that share an email, and preserving unambiguous email fallba…
Out of Scope Changes check ✅ Passed The code changes remain within the linked issue scope. Provider identity propagation, contract updates, quota-key logic, and focused tests directly support Codex workspace separation. No unrelated cod…
  • 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.

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

1 participant