Skip to content
This repository was archived by the owner on Sep 30, 2026. It is now read-only.

feat(usage): pace-aware multi-account rotation with revoked-account auto-failover - #8

Merged
yjuyjuy merged 1 commit into
masterfrom
pace-aware-account-switching
Aug 11, 2026
Merged

yjuyjuy merged 1 commit into
masterfrom
pace-aware-account-switching

Conversation

@yjuyjuy

@yjuyjuy yjuyjuy commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Problem

When an Anthropic account's OAuth is revoked, every jcode worker pinned to it hits a 401 authentication_error (OAuth token revoked; automatic refresh fails with invalid_grant) and stalls at the "last request failed in a way retrying won't fix, /poke to resume" prompt. It does not auto-fail-over to another healthy account in auth.json. Recovery today is fully manual per pane (Escape, /account claude switch <live-label>, /poke), so a routine credential revocation silently wedges the whole fleet.

This is distinct from the 429 usage-limit fallback: a revocation is an auth error (401 / invalid_grant), not a usage signal, so any pace/usage-based auto-switch never triggers on it.

What this branch delivers

Two complementary halves of the same multi-account rotation:

  1. Pace-aware multi-account balancing and priming (existing commit): proactively consumes the soonest-resetting weekly window first and primes cold accounts, so perishable quota is not wasted. Fires on usage-limit / 429 pressure.

  2. Revoked/invalid-grant auto-failover (new): a revoked account fails during token refresh, so its error carries no bare 401/403 status literal - only an OAuth invalid_grant code or a "token revoked" / "refresh failed" phrase. classify_failover_error_message previously matched only unauthorized / authentication failed / 401 / 403, so a revoked account classified as None and the existing same-account failover never fired. This adds invalid_grant, authentication_error, token-revoked, and refresh-failed needles to the auth/access bucket, so a revoked account fails over exactly like a 429 does: mark it unavailable, retry on the next healthy account, then resend.

Net effect: failover now triggers on both usage-limit (429) and auth/revoked (401 / invalid_grant) errors, to the next healthy account, then resends - instead of dead-ending at the /poke stall.

Tests

  • New classifier_fails_over_on_revoked_oauth_without_status_code over the real revoked-error strings.
  • cargo test -p jcode-provider-core failover green (5 passed).
  • cargo build -p jcode-provider-core -p jcode-base and cargo clippy -p jcode-provider-core clean.

Operational note (not code)

Desired live rotation is claude-2 ([email protected]) as primary, auto-switching to claude-1 ([email protected]) on limit or auth failure. The active-account choice is a runtime credential flip in ~/.jcode/auth.json affecting every running session, deliberately left out of this code change.

…t just 401

A revoked or invalidated Anthropic OAuth account fails during token refresh,
so its error surfaces with no bare 401/403 status literal - only an OAuth
`invalid_grant` code or a "token revoked"/"refresh failed" phrase (e.g.
"Claude OAuth token is expired and refresh failed: invalid_grant"). The
same-provider account failover is gated on classify_failover_error_message,
which previously matched only "unauthorized"/"authentication failed"/401/403.
A revoked account therefore classified as None, the failover never fired, and
the turn dead-ended at the "/poke to resume" stall instead of rotating to a
healthy account.

Add invalid_grant, authentication_error, token-revoked, and refresh-failed
needles to the auth/access bucket so a revoked account fails over the same way
a 429 usage-limit already does: mark it unavailable and retry on the next
healthy account, then resend. Covered by a new classifier test over the real
revoked-error strings.
@yjuyjuy
yjuyjuy force-pushed the pace-aware-account-switching branch from 8b34ea9 to 3577358 Compare August 11, 2026 14:35
@yjuyjuy
yjuyjuy merged commit 4557cb7 into master Aug 11, 2026
5 of 11 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants