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

[BUG] Auto-disabled sole account is indistinguishable from an operator disable and cannot be validated or re-enabled outside the TUI

Open yentsun opened this issue 1 month ago • 0 comments

Summary

With a single-account pool, the only account was auto-disabled after repeated auth failures, and the plugin then reports that every request fails (All 1 account(s) failed) while Codex-routed requests reportedly keep succeeding. The auto-disable path leaves no accountNote, which the code documents as meaning "operator chose to disable", so the account cannot be distinguished from an intentional disable, cannot be validated (codex-health / codex-refresh skip disabled accounts), and cannot be re-enabled without the interactive TUI menu.

Reproduction

  1. Have a pool with exactly one account (per-project storage) whose refresh token becomes invalid, so the request path accumulates MAX_AUTH_FAILURES_BEFORE_REMOVAL (3) auth failures.
  2. The plugin disables the account (enabled: false, no note) and persists it. The persisted pool file is not modified again.
  3. Restart OpenCode and issue a Codex-routed request.

Expected: a single, unambiguous failure that says the sole account is disabled and needs re-login, and diagnostics that can validate the retained credential. Actual: diagnostics still report the account as [disabled]/blocked and 0 healthy, codex-limits prints an empty list, codex-refresh prints Skipped (disabled), and yet traffic starts working again without any re-login or change to the persisted state.

Expected Behavior

  • A disabled account that is the result of the plugin's own auth-failure handling should carry an explicit reason/note so it is distinguishable from an operator-initiated disable, and codex-status should surface that reason plus the required next step.
  • Diagnostics should be able to validate a retained (disabled) credential instead of skipping it, so a disabled sole account is not a dead end.
  • Re-enabling should be possible outside the TUI (a codex-* tool), not only via /codex-accounts.
  • If a request succeeds, diagnostics should reflect which account/credential/provider actually served it.

Actual Behavior

  • codex-health: Skipped (disabled) — 0 healthy, 0 unhealthy, 1 skipped.
  • codex-status / codex-dashboard: account is [disabled], selection explainability blocked | health=100 | tokens=50.0 | disabled, recommended next step is still "re-login or switch to a healthy account".
  • codex-doctor: errors No healthy account is available for requests, warning 1 account(s) are disabled.
  • codex-metrics: Total upstream requests: 0, Failed responses: 18, Success rate: 0.0%, last error account-failure.
  • codex-limits: prints only the header, no rows.
  • Persisted pool, read directly: enabled: false, no accountNote, lastSwitchReason: "rate-limit", access token expired 2026-10-04T03:33:19Z, and the file mtime predates the successful requests.
  • Meanwhile requests to the same models started completing again with no re-login and no re-enable.

Environment

  • opencode --version: v2.0.23
  • oc-codex-multi-auth --version: 6.26.0 (npm cache: [email protected])
  • OS: Windows 10 Pro (10.0.19045)
  • Node.js: v24.13.1
  • Storage: per-project pool (~/.opencode/projects/<project>/oc-codex-multi-auth-accounts.json)

Diagnostic Outputs

codex-status (email redacted):

Account status
--------------
Total: 1
Running from: installed package v6.26.0
Selection view: gpt-6.1-sol:gpt-6.1-sol

Accounts
- Account 1 (m***@gmail.com, id: 1affd12c...78a4c9, seat:78a4c9) [active] [disabled]
  rate limit: none
  quota: none
  cooldown: none

Routing visibility
Requested model: gpt-6.1-sol
Effective model: gpt-6.1-sol
Selected account: 1
Last error category: account-failure

Selection explainability
- Account 1: blocked | health=100 | tokens=50.0 | disabled

codex-health:

Health check
------------

  ! Account 1 (m***@gmail.com, id: 1affd12c...78a4c9, seat:78a4c9): Skipped (disabled)

Summary: 0 healthy, 0 unhealthy, 1 skipped

codex-doctor:

Findings
- [error] No healthy account is available for requests.
- [warning] 1 account(s) are disabled.
- [warning] Recent error category: account-failure.

codex-metrics (abridged):

Uptime: 1h 31m 47s
Total upstream requests: 0
Successful responses: 0
Failed responses: 18
Success rate: 0.0%
Last error: All 1 account(s) failed (server errors or auth issues). Check account health with `codex-health`.
Last error category: account-failure

Persisted pool record (tokens removed):

{
  "accountId": "1affd12c-cd16-4968-b955-75d17378a4c9",
  "accountIdSource": "token",
  "expiresAt": 1791084799467,
  "enabled": false,
  "addedAt": 1790756967860,
  "lastUsed": 1791196019910,
  "lastSwitchReason": "rate-limit"
}

1791084799467 is 2026-10-04T03:33:19Z. A codex-credential-snapshot-*.json backup exists with the same mtime as the pool file, and the pool file was never rewritten afterward.

Analysis

  • Auto-disable on auth failure writes no note: disableAccountsWithSameRefreshToken() (dist/lib/accounts/recovery.js:252-275) only sets enabled = false and calls markAccountDisabled. It is invoked from the request path at dist/index.js:2536 and dist/index.js:3018 after MAX_AUTH_FAILURES_BEFORE_REMOVAL (dist/lib/constants.js:91, value 3).
  • No-note-disabled is documented as operator intent, so the plugin will not self-heal: dist/lib/accounts/state.js:256-261 treats enabled: false without a re-auth note as "the operator's own choice" and only auto-repairs disables that carry appendReauthNote (the OAuth-scope path at state.js:275-279). An auth-failure disable is therefore permanent until an operator acts, but looks identical to a deliberate disable.
  • Diagnostics skip disabled accounts: dist/lib/tools/refresh-account.js:21-25 returns { status: "skipped" } for account.enabled === false, and codex-health does the same, so the retained refresh token is never validated.
  • Re-enable is TUI-only: setAccountEnabled exists (dist/lib/accounts.js:122, state.js:663) and the menu exposes "Enable account" (dist/lib/ui/auth-menu.js:177), but no codex-* tool wraps it, so headless/scripted users cannot re-enable.
  • Rotation does filter disabled accounts (dist/lib/accounts/rotation.js:32,158,407), so it is not obvious how a request can still be served for this pool. Possibly the traffic is served by a different credential/provider (OpenCode's own openai OAuth entry in auth.json shares the same expiry as this pool account) and the failure is masked, or an in-memory-only re-enable diverges from the persisted enabled: false.

Suggested Fix / Investigation Asks

  1. Confirm what actually serves a Codex model request when every pool account is disabled — a host-auth/OAuth fallback that bypasses the pool enabled flag, or another provider. Surface the effective credential/provider in codex-status/codex-dashboard.
  2. Give auth-failure disables their own note/reason (distinct from the scope re-auth note and from operator intent) and render it in codex-status/codex-doctor with the explicit next step.
  3. Let codex-health / codex-refresh validate retained credentials for disabled accounts (or add an opt-in flag), so a disabled sole account is recoverable without the TUI.
  4. Expose setAccountEnabled as a codex-* tool.

Logs

~/.opencode/logs/codex-plugin/ was never created (ENABLE_PLUGIN_REQUEST_LOGGING not set), so no plugin request logs exist. The OpenCode log records only the surfaced error:

level=ERROR message="Failed to drain Session" cause="AI.Error: All 1 account(s) failed (server errors or auth issues). Check account health with `codex-health`."

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.
  • [x] I reviewed the FAQ and Troubleshooting docs.
  • [x] I removed any secrets/tokens from this report.

yentsun avatar Oct 06 '26 10:10 yentsun