Skip to content

[Bug]: Anthropic OAuth account is marked needsReauth after Windows reboot and models disappear #209

Closed

Description

@KWON-ui

Summary

On Windows 11, the Anthropic OAuth account remains present after every reboot, but it is marked as needing reauthentication and all Anthropic models disappear from the model list.

The dashboard still shows the Anthropic provider as active and OAuth as logged in, while the account row has a yellow indicator and a Re-login button. Removing the account and adding it again immediately restores the Anthropic models, but the same problem returns after the next Windows reboot.

Expected behavior

The persisted Anthropic refresh token should be used after OpenCodex starts again, and Anthropic models should remain available without removing and re-adding the account.

Actual behavior

  • Provider remains configured and active.
  • OAuth status reports logged in.
  • The active account is present but has needsReauth: true.
  • /api/models returns zero Anthropic models.
  • The provider connectivity test treats Anthropic as not logged in.
  • Deleting and reconnecting the account restores the models until the next reboot.

Reproduction

  1. On Windows 11, start OpenCodex with ocx start.
  2. Open http://localhost:10100/.
  3. Add an Anthropic account through Log in with your Claude account.
  4. Confirm that Anthropic models appear and work.
  5. Reboot Windows.
  6. Run ocx start again and open the dashboard.
  7. Observe:
    • Anthropic provider is still shown as active/OAuth.
    • The account row has a yellow status dot and a Re-login button.
    • Anthropic models are absent from the model list.
  8. Delete the Anthropic account and add it again.
  9. Observe that the models reappear immediately.

This has happened consistently after reboots in this environment.

Logs and diagnostics

Current post-reboot state, collected from the local management API and redacted:

opencodex: 2.7.26
codex-cli: 0.144.5
node: v24.15.0

GET /api/oauth/status?provider=anthropic
  loggedIn: true

GET /api/oauth/accounts?provider=anthropic
  accountCount: 1
  activeAccountIdPresent: true
  active: true
  needsReauth: true

GET /api/models
  anthropicModelCount: 0

POST /api/providers/test?name=anthropic
  ok: false
  latencyMs: 0
  error: "static catalog only — upstream not verified (not logged in)"

Redacted auth-store metadata:
  source: local-cli
  hasAccessToken: true
  hasRefreshToken: true
  accessTokenExpired: true

Dashboard visual state: Anthropic provider is active, the single account row has a yellow status dot, and the Re-login action is shown.

No tokens, account IDs, email addresses, or other personal data are included.

Area

Provider adapter / Anthropic OAuth token persistence and refresh across process or OS restart.

Version

@bitkyc08/opencodex 2.7.26

OS

Microsoft Windows 11 Home, version 10.0.26200, 64-bit

Config shape

{
  "provider": "anthropic",
  "adapter": "anthropic",
  "baseUrl": "https://api.anthropic.com",
  "defaultModel": "claude-sonnet-5",
  "authMode": "oauth",
  "disabled": false
}

Checks

  • I searched existing open and closed issues first.
  • I removed secrets, tokens, account identifiers, email addresses, and personal data.

Activity

  1. Wibias commented on Jul 21, 2026

    @Wibias
    Contributor

    Thanks for the detailed diagnostics - this made tracking down the root cause much easier.

    What's happening

    The needsReauth: true flag was being written to auth.json and reloaded on every process start. After a reboot, Windows often doesn't have network connectivity yet when ocx start runs. The first refresh attempt for the (expired) Anthropic access token then hits a network error, isTerminalRefreshError matches it, the account is marked needsReauth: true on disk, and from that point on every subsequent start skips the refresh entirely - the account is permanently locked until you remove and re-add it (which clears the flag by writing fresh credentials).

    The fix

    PR #221 moves needsReauth to an in-memory-only Set that starts empty on every process start. Within a session it behaves exactly as before - a confirmed terminal failure (revoked/rotated grant) still marks the account and the guardian skips it. But the mark never survives a restart, so a transient boot-time network error can't permanently lock a valid account. On the next ocx start the refresh is retried with the still-valid refresh token and succeeds normally.

    The fix is in src/oauth/store.ts: normalizeAccount no longer copies needsReauth from the JSON file; getAccountSet overlays the in-memory markers when returning accounts; all the credential-save and account-remove paths clear the in-memory key on success.

  2. lidge-jun commented on Jul 21, 2026

    @lidge-jun
    Owner

    v2.7.31에 수정 반영했습니다. Anthropic refresh 오류를 구조화하고 generation-safe refresh 및 durable refresh intent로 재부팅과 stale-lock 경합 시 잘못된 token replay를 막았습니다. 반영 커밋: a626a5b, 0de138a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions