Skip to content
Source
Sign inSign up
pingdotgg/t3code

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

Closedkalvenschraut(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/10876/headopened View on GitHub

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%.

BeforeAfter
BeforeAfter

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.

BeforeAfter
Business members beforeBusiness 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.
    1. 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.

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. 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](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 2b1fdae7534c8af29dc394cda0f9ec0cba1b0786 and bcbb1862297ba2cc758be90aa56bbbfe04a61516.

      📒 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

      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 nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Linked Issues check✅ PassedThe 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✅ PassedThe 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✅ PassedThe title clearly identifies the primary change: distinguishing Codex workspaces by account ID for usage handling.
      Description check✅ PassedThe 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.
    5. 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

    6. 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.

    7. juliusmarminge closed this

Sign in to join this conversation.