Skip to content

[Bug]: Anthropic pool session affinity is lost on restart and on any 429, so one Claude Code session moves between accounts #7813

Closed

Description

@vibewriter-hand

Client or integration

Claude Code CLI 2.1.311 and Codex CLI 0.164.0, both through OpenCodex on 127.0.0.1:10100 (Anthropic OAuth account pool, Messages and Responses).

Area

Account pool / session affinity (Anthropic).

Summary

One Claude Code session should stay on one Anthropic account until that account is truly exhausted or unusable. On 2.92.0 a session moves to another account in three ordinary situations, so prompt caches go cold and one conversation is spread over several accounts.

Measured on our usage ledger over 24 hours (2026-10-26 16:41 to 2026-10-27 16:41 KST): 204 identifiable multi-call Claude conversations, 16 of them used more than one account, 39 transitions in total, and none of the transitions followed a positive quota-exhaustion marker. In the same window 195 GPT conversations through the Codex pool changed account 0 times.

Causes we found in the installed source (src/oauth/anthropic-routing.ts):

  1. The binding lives only in memory (sessionAffinity, a RoutingMap). Every proxy restart, including a machine reboot, drops all bindings, and the next request of a running session is placed by strategy (round-robin in our case) on a different account.
  2. Any 429 clears every binding of that account (clearAnthropicSessionAffinityForAccount(failedAccountId) after the cooldown write, around line 1270), also for a short request-rate 429 where the account still has quota in its 5-hour and weekly windows.
  3. A cooled account fails stillUsable and the binding is deleted (around line 1043), so a short cooldown permanently moves the session instead of pausing it.

Round-robin itself is fine for choosing the first account of a new session; the problem is only that existing bindings do not survive these events.

Reproduction

  1. Enable the Anthropic account pool with two or more accounts, strategy: round-robin.
  2. Start a Claude Code session and make a few requests; note the account label in the usage ledger.
  3. Restart OpenCodex (or trigger one 429 on that account) and send the next request of the same session.
  4. The request is served by another account; the binding is gone.

Version

opencodex 2.92.0 (latest on npm on 2026-10-27).

Operating system

macOS (Apple silicon).

Provider and model

anthropic OAuth pool, claude-opus-5-5 and claude-sonnet-5-5.

Logs or error output

No error; the effect is visible only as changing account labels inside one conversation in the usage ledger.

Proposed fix

  1. Persist the session-to-account map (for example next to the usage ledger, with the existing 24 h idle TTL and 2000-entry cap), and load it at start, so a restart keeps every binding.
  2. On a request-rate 429 where the account still has quota (the rejected window is not the 5-hour or weekly quota window), keep the binding: wait for Retry-After or the cooldown and retry the same account, or serve only that one request elsewhere without rebinding.
  3. Rebind only when the account is positively exhausted for the model, paused, needs re-auth, or removed; log each rebind with its reason so it can be audited.
  4. Optional: a config switch such as anthropicAccountPool.affinityStrict: true for users who need strict one-session-one-account behaviour.

Checks

  • I searched existing issues and documentation.

Activity

  1. added
    bug
    account-pool
    on Oct 27, 2026
  2. lidge-jun commented on Oct 28, 2026

    @lidge-jun
    Owner

    Fixed in #7828, merged to dev as d9ae8e5.

    • Restart: Anthropic pool session bindings now persist per config home and Anthropic instance in a private snapshot holding only a SHA-256 digest of the session key, the opaque account id, the last-use time and a hashed login fence (no raw session id, bearer, email or label). Bindings restore after a restart only while the account still exists, is usable and has the same login; a replacement login retires them, ordinary token refresh does not.
    • 429s: the classification described here was already on dev (fix(anthropic): classify 429s and admit by per-model weekly quota in the Claude account pool #6443): a request-rate 429 pauses the account briefly, a shared 5h/7d rejection cools it and clears its bindings. What remained was a race where a short pause expiring during a detour rebound the session; a detour now keeps the original binding (bounded by a five-minute grace), while measured exhaustion, shared-quota and entitlement refusals still rebind.

    Ships with the next release from dev.

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

    account-poolbug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions