Bug: one Apple ID with multiple workspace subscriptions collapses onto a single quota pool
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-limitsreports 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)
- The OAuth flow requests
id_token_add_organizations=true, so the id_token contains all organizations the user belongs to. resolveAccountSelection()(dist/lib/auth/login-runner.js) buildsvariantsForPersistencefrom every org candidate (selectBestAccountCandidateprefers org candidates over the token account), all sharing the login token.- The Codex backend meters quota by the
chatgpt-account-idheader and ignores organization ids — confirmed by probingGET /backend-api/wham/usage:chatgpt-account-id: org-xxx→ ignored, falls back to token default subscriptionchatgpt-account-id: cc42163f-...(ChatGPT account id) → routes to the Plus poolchatgpt-account-id: 77d6308e-...(other subscription's account id) → routes to the Team pool (different plan, different reset window)
- Since persisted entries carry org ids as
accountId(source"org"), requests sendchatgpt-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)
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 (existingpersistAccountPooldedup handles this).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
- One OpenAI login (Apple ID) with two workspace subscriptions (e.g. Team + Plus).
opencode auth logintwice, once with each workspace active.codex-limits→ both entries report the same plan/quota (the last login's subscription).codex-switchto the other account → still consumes the same quota pool.
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 (🔗 Related PRs
#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!