feat: add round-robin rotation and cooldown for auth profiles
Adds usage tracking to auth profiles for automatic rotation: - ProfileUsageStats type with lastUsed, cooldownUntil, errorCount - markAuthProfileUsed(): tracks successful usage, resets errors - markAuthProfileCooldown(): applies exponential backoff (1/5/25/60min) - isProfileInCooldown(): checks if profile should be skipped - orderProfilesByMode(): now sorts by lastUsed (oldest first) On auth/rate-limit failures, profiles are marked for cooldown before rotation. On success, usage is recorded for round-robin ordering. This enables automatic load distribution across multiple accounts (e.g., Antigravity 5-hour rate limit windows).
This commit is contained in:
@@ -24,7 +24,7 @@ import {
|
||||
} from "../process/command-queue.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { resolveClawdbotAgentDir } from "./agent-paths.js";
|
||||
import { markAuthProfileGood } from "./auth-profiles.js";
|
||||
import { markAuthProfileGood, markAuthProfileUsed, markAuthProfileCooldown } from "./auth-profiles.js";
|
||||
import type { BashElevatedDefaults } from "./bash-tools.js";
|
||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js";
|
||||
import {
|
||||
@@ -954,6 +954,10 @@ export async function runEmbeddedPiAgent(params: {
|
||||
const authFailure = isAuthAssistantError(lastAssistant);
|
||||
const rateLimitFailure = isRateLimitAssistantError(lastAssistant);
|
||||
if (!aborted && (authFailure || rateLimitFailure)) {
|
||||
// Mark current profile for cooldown before rotating
|
||||
if (lastProfileId) {
|
||||
markAuthProfileCooldown({ store: authStore, profileId: lastProfileId });
|
||||
}
|
||||
const rotated = await advanceAuthProfile();
|
||||
if (rotated) {
|
||||
continue;
|
||||
@@ -1040,6 +1044,8 @@ export async function runEmbeddedPiAgent(params: {
|
||||
provider,
|
||||
profileId: lastProfileId,
|
||||
});
|
||||
// Track usage for round-robin rotation
|
||||
markAuthProfileUsed({ store: authStore, profileId: lastProfileId });
|
||||
}
|
||||
return {
|
||||
payloads: payloads.length ? payloads : undefined,
|
||||
|
||||
Reference in New Issue
Block a user