Skip to content

Claude pool: skip accounts whose seven-day window is spent, also on a fresh instance - #39

Merged
vadymhimself merged 4 commits into
release/2.65.0-vadymhimself.15from
gauge/pool-skip-spent-weekly
Nov 17, 2026
Merged

vadymhimself merged 4 commits into
release/2.65.0-vadymhimself.15from
gauge/pool-skip-spent-weekly

Conversation

@vadymhimself

Copy link
Copy Markdown
Collaborator

Claude account pool: never pick an account whose seven-day window is already spent, even on a fresh instance.

Problem: cooldowns live in a per-process map. A gateway that runs as many short-lived instances starts each one empty, so it keeps routing (by hash, affinity or active account) onto accounts that hit their weekly limit, takes a 429, then fails over, sometimes onto another spent account.

Change:

  • One gate (isCooled) now also skips an account whose cached weekly reading is at least 100% with its reset still ahead (weeklyExhaustedUntil). It covers hash, affinity, active, promote and the failover pickers. A 100% reading with no reset fails open.
  • Lazy reading: when the picked account has no weekly reading, the two async callers read that one account once (existing per-account usage probe and its 10-minute cache, 1500 ms cap, de-duplicated, fail open) and re-pick if it is spent. Never a roster-wide probe on cold start.
  • A rejected seven-day 429 also records the account as 100% until its reset in the quota cache, so every later pick sees it.
  • Failover returns null once only spent or cooled accounts remain, so the original 429 surfaces; Retry-After includes the earliest weekly reset.
  • Weekly window ranking: an unknown reading now ranks before a known 100%.
  • No version bump here: this ships in the next release-line tag with the other open release-line PRs.

Eval added/updated: tests/adapters/anthropic/anthropic-account-pool.test.ts, new describe "spent seven-day window": fresh instance never picks a spent account (40 session keys); one de-duplicated probe re-routes away from a spent account; probe error or timeout fails open; failover with only spent accounts returns null with the weekly-reset Retry-After. Two existing tests updated (ranking of known 100% vs unknown; failover null when the remaining account is spent), each with a comment.

Not run locally (no bun on the authoring box); CI runs the suite.

🤖 Generated with Claude Code

Reopened from #37 on a gauge/ branch at the same head 9aaef91 (the side sweep only merges <seat>/... branches). Same commit, so ci and independent-qa at this sha carry over.

@github-actions github-actions Bot added the chore label Nov 17, 2026
@github-actions

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@vadymhimself

Copy link
Copy Markdown
Collaborator Author

Mars security review: GREEN at 9aaef91 (Claude pool skips accounts with a spent seven-day window)

  • Quota inputs come from upstream only. They are the upstream 7d-status and 7d-reset response headers and the existing usage probe, never client headers or body.
  • Per account. The cache is keyed per account, so one tenant's usage is never counted to another.
  • Strict gate. "Spent" needs 100% and a future reset, and it expires on its own. NaN, zero and past resets are rejected.
  • Fail-open is limited. An unknown reading, or a probe error or timeout (1.5 s cap), fails open by design and is tested. This only means an account is not skipped; the upstream still enforces its own limit.
  • Nothing else. No new secret, host or route. OCX_DISABLE_POOL_WEEKLY_PROBE is a test toggle, the 429 log prints only rate-limit headers, and there is no price or model-to-account change.

Notes, not blocking:

  1. A far-future upstream reset has no upper bound and would bench that account until then (src/oauth/anthropic-routing.ts:915-917). Capping it at 8 days would be safer.
  2. The first pick per account can add up to 1.5 s.

CI has no failures at this head.

@vadymhimself
vadymhimself merged commit c49bb29 into release/2.65.0-vadymhimself.15 Nov 17, 2026
107 of 111 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant