[BUG] Scope downgrade on token rotation is not detected, accounts report healthy while sessions fail 401
Summary
After a refresh-token rotation, a ChatGPT Business workspace seat received an OAuth token whose oauthScope had dropped from the previously working set (openid profile email offline_access resource.invoke chatgpt.tokens.use.direct) to openid profile email offline_access. Existing sessions then failed mid-conversation with Integration.Authorization: Request failed: 401 raised from ModelResolver.resolveModel. Any subsequent opencode auth login attempt for the same account is rejected by auth.openai.com with error_code: 3p_delegated_access_policy_denied, so the account cannot be re-added through the normal flow.
The plugin's own scope check does not catch this, because REQUIRED_OAUTH_SCOPES in dist/lib/auth/scopes.js lists only openid, profile, email, offline_access:
export const REQUIRED_OAUTH_SCOPES = [
"openid",
"profile",
"email",
"offline_access",
];
A token missing resource.invoke and chatgpt.tokens.use.direct therefore passes hasRequiredOAuthScopes() and is persisted and used as healthy.
Reproduction
- Sign in a ChatGPT account whose plan type is
self_serve_business_prolite(a seat in a Business workspace, rolestandard-user) usingopencode auth login-> OpenAI -> Codex OAuth. - Confirm the account works and that the stored
oauthScopeincludesresource.invoke chatgpt.tokens.use.direct. - Let the access token expire and trigger rotation with
codex-refresh(or use the account until the plugin rotates it). - Inspect
oauthScopein~/.opencode/oc-codex-multi-auth-accounts.json.
Observed: oauthScope is now openid profile email offline_access, tokenRotatedAt is updated, and the account is still reported healthy by codex-health, codex-status, and codex-doctor. Sessions fail 401 at ModelResolver.resolveModel.
The access token itself is still accepted by the ChatGPT backend — GET https://chatgpt.com/backend-api/me with the rotated token returns 200 for the same chatgpt-account-id — so this is not a dead token, it is a token whose granted scopes no longer cover the Codex/agent endpoints.
Note that 3p_delegated_access_policy_denied on re-login also affects every alternate login method. All four OAuth methods (browser, open URL manually, device code, manual URL paste) use the same CLIENT_ID and AUTHORIZE_URL = https://auth.openai.com/oauth/authorize, so the denial occurs before the redirect and device-code/manual-paste do not offer a workaround.
Expected Behavior
Any of the following would prevent a silently broken account:
- Detect that a rotated token is missing previously granted scopes and surface a warning instead of reporting the account healthy.
- Treat Codex-required scopes (
resource.invoke,chatgpt.tokens.use.directwhen granted at first login) as required, so a downgraded grant fails loudly with a re-auth message rather than surfacing as a mid-session 401. - When a refresh returns a reduced scope set, log the scope delta so operators can tell a server-side grant change from a plugin bug.
Actual Behavior
A scope downgrade on rotation is invisible in codex-status / codex-health / codex-doctor (all report healthy), and the failure only appears as Integration.Authorization: Request failed: 401 from ModelResolver.resolveModel during a session. Re-login cannot repair it because the authorization server denies the client for this account.
Environment
opencode --version: 2.1.4oc-codex-multi-auth --version: 6.28.0- OS: Windows (win32 x64)
- Node.js: v24.13.1 (plugin runtime reports v26.3.0)
Diagnostic Outputs
codex-doctor:
Accounts: 1
Healthy: 1
Blocked: 0
Failure rate: 0%
- [ok] No critical issues detected.
codex-health:
+ Account 1 (...): Healthy
Summary: 1 healthy, 0 unhealthy, 0 skipped
codex-limits:
Weekly limit: 97% left
Plan: Business Premium (5x)
Stored record (redacted):
accountId: 1affd12c-...-78a4c9
planType: self_serve_business_prolite
oauthScope: openid profile email offline_access
tokenRotatedAt: <rotation timestamp>
Logs (Optional)
level=ERROR message="Failed to drain Session"
cause="Integration.Authorization: Request failed: 401 ...
at ModelResolver.resolveModel ...
at SessionRunner.advanceToStep ..."
level=WARN message="failed to load OpenCode provider config"
cause="HttpClientError: StatusCode: non 2xx status code (401 GET https://opencode.ai/console/api/v2/config)"
The console/api/v2/config warning is ambient noise on this machine and predates the failure by days; it is included only because it appears alongside the 401 and should not be conflated with it.
Compliance Confirmation
- [x] I am using this plugin for personal development only, with an active ChatGPT Plus/Pro subscription.
- [x] This report does not request policy bypasses or commercial-use workarounds. The report is that a scope downgrade is silent, not that the workspace policy should be circumvented.
- [x] I reviewed the FAQ and Troubleshooting docs.
- [x] I removed any secrets/tokens from this report.
Closing as not reproducible — the root cause in the original report was wrong.
What changed
The failure resolved itself roughly six hours later. Verified at close time:
oauthScopeis stillopenid profile email offline_access— unchanged since the rotation that coincided with the failure.tokenRotatedAtis unchanged since that same rotation; no new token was issued.codex-statusreports the account active and eligible;lastUsedadvanced, so requests are succeeding.
The same credential that produced Integration.Authorization: Request failed: 401 from ModelResolver.resolveModel is now serving requests normally. That falsifies the report's central claim: the reduced scope set was not the mechanism, since identical scopes both failed and succeeded without any intervening credential change.
What the evidence still supports
Not much that is actionable, honestly. A ~6-hour window where the credential was rejected and then accepted again, with no local change, is consistent with a transient server-side condition — entitlement evaluation, delegated-access enforcement, or a rotation race — rather than a plugin defect. I have no way to reproduce it or to prove which of those it was.
On the original suggestion
The observation that REQUIRED_OAUTH_SCOPES in dist/lib/auth/scopes.js lists only openid, profile, email, offline_access while working tokens had been granted resource.invoke and chatgpt.tokens.use.direct still stands as a possible hardening opportunity — a scope-delta log line on rotation would have made this far easier to reason about. But it did not cause this failure, and I don't have the evidence to argue it should be treated as required scopes. Treat it as an observation, not a finding.
Apologies for the misdiagnosis in the initial report, particularly the confident causal claim about scopes. Thanks for the template and for maintaining the plugin.