oc-codex-multi-auth icon indicating copy to clipboard operation
oc-codex-multi-auth copied to clipboard

Bug: one Apple ID with multiple workspace subscriptions collapses onto a single quota pool

Open JackTheCoconut opened this issue 3 months ago • 1 comments

Bug: one Apple ID with multiple workspace subscriptions collapses onto a single quota pool

Summary

When a single ChatGPT account (one Apple ID / email) has two workspace subscriptions (e.g. Team + Plus), every opencode auth login persists one account entry per organization, but all entries share the same OAuth token. As a result:

  • All account entries always draw from the last logged-in workspace's quota pool — the other subscription's quota is never used.
  • codex-limits reports identical plan/quota for every entry.
  • Re-logging in with the other workspace overwrites every entry's token, so you can never hold both subscriptions simultaneously.

Root cause (verified empirically)

  1. The OAuth flow requests id_token_add_organizations=true, so the id_token contains all organizations the user belongs to.
  2. resolveAccountSelection() (dist/lib/auth/login-runner.js) builds variantsForPersistence from every org candidate (selectBestAccountCandidate prefers org candidates over the token account), all sharing the login token.
  3. The Codex backend meters quota by the chatgpt-account-id header and ignores organization ids — confirmed by probing GET /backend-api/wham/usage:
    • chatgpt-account-id: org-xxx → ignored, falls back to token default subscription
    • chatgpt-account-id: cc42163f-... (ChatGPT account id) → routes to the Plus pool
    • chatgpt-account-id: 77d6308e-... (other subscription's account id) → routes to the Team pool (different plan, different reset window)
  4. Since persisted entries carry org ids as accountId (source "org"), requests send chatgpt-account-id: org-..., which the backend ignores → every entry burns the token's default subscription.

Each workspace subscription is a distinct ChatGPT account (distinct chatgpt_account_id JWT claim), so per-entry tokens WOULD give per-entry quotas.

Proposed fix (local patch verified working)

  1. dist/lib/auth/login-runner.js — resolveAccountSelection(): persist ONLY the token-scoped account (chatgpt_account_id, source "token") instead of every org candidate. A re-login with a different workspace then appends a separate account with its own token/quota; re-login with the same subscription updates in place (existing persistAccountPool dedup handles this).
  2. dist/lib/auth/token-utils.js — resolveRequestAccountId(): for legacy org-sourced entries, return the token's ChatGPT account id instead of the org id, so routing actually reaches the intended subscription.

After patching: login once per workspace (opencode auth login → fresh, then add). Verified result — two entries, one team plan (98%, resets 18:30) and one plus plan (95%, resets 20:14), each drawing from its own pool.

Repro

  1. One OpenAI login (Apple ID) with two workspace subscriptions (e.g. Team + Plus).
  2. opencode auth login twice, once with each workspace active.
  3. codex-limits → both entries report the same plan/quota (the last login's subscription).
  4. codex-switch to the other account → still consumes the same quota pool.

JackTheCoconut avatar Aug 10 '26 03:08 JackTheCoconut

🔗 Related PRs

ndycode/oc-codex-multi-auth#41 - fix(identity): preserve distinct workspace accounts and strict orgId sourcing [closed] ndycode/oc-codex-multi-auth#64 - fix: preserve multi-org accounts and prevent cascading auth-removal [closed] ndycode/oc-codex-multi-auth#85 - fix: gracefully handle deactivated_workspace — remove only the dead workspace, preserve siblings [merged] ndycode/oc-codex-multi-auth#161 - fix: preserve workspace-specific usage quotas + harden test isolation [closed] ndycode/oc-codex-multi-auth#180 - fix(storage): token-source duplicate must not disable the real org account on merge (#171) [closed]


📝 Issue Planner

Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

  • [ ] Create Plan

🧪 Issue enrichment is currently in open beta.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

💬 Have feedback or questions? Drop into our discord!

coderabbitai[bot] avatar Aug 10 '26 03:08 coderabbitai[bot]