Repository navigation
Preempt to a higher-priority account when one is available - #29
Merged
Merged
Conversation
The `priority` field (added in #28) was only consulted when a switch was forced (current account exhausted/throttled). A healthy lower-priority current account was never preempted, so a recovered preferred account wouldn't be resumed until the in-use one ran low. getActiveAccount now switches to a strictly higher-priority (lower value) available account even from a healthy current one, while staying sticky within the same priority tier. The common case — all accounts at the default priority 0 — is unchanged and never thrashes, since no account is strictly higher than another. Exhaustion-switching and the soonest-weekly-reset heuristic are intact. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up refinement to the
priorityfeature from #28.Problem
prioritywas only consulted inside_selectNext, which runs only when a switch is forced (current account exhausted/throttled, or on requalify/session-reset).getActiveAccountreturns the current account as long as it's available — without checking priority. So if rotation landed on a lower-priority account and your preferred (higher-priority) account recovered, the proxy wouldn't resume it until the current one ran low.Change
getActiveAccountnow preempts a healthy current account when a strictly higher-priority (lower value) account is available, while staying sticky within the same priority tier:Why this is safe
0, no account is strictly higher than another, sobetterExistsis always false and behavior is identical to today — no extra switching, no thrash._isAvailable(session/weekly threshold) is still checked first, and_selectNextstill applies the soonest-weekly-reset tiebreaker within a tier.Tests
test/rotation-priority.test.jsextended: preemption to a higher tier, stickiness within a tier, and the all-equal-priority no-op. 8/8 passing.🤖 Generated with Claude Code