Agents: infer auth-profile unavailable failover reason

This commit is contained in:
Vignesh Natarajan
2026-02-22 16:10:24 -08:00
parent 331b728b8d
commit 5c7c37a02a
9 changed files with 340 additions and 4 deletions

View File

@@ -12,6 +12,7 @@ import {
markAuthProfileFailure,
markAuthProfileGood,
markAuthProfileUsed,
resolveProfilesUnavailableReason,
} from "../auth-profiles.js";
import {
CONTEXT_WINDOW_HARD_MIN_TOKENS,
@@ -364,9 +365,18 @@ export async function runEmbeddedPiAgent(
const resolveAuthProfileFailoverReason = (params: {
allInCooldown: boolean;
message: string;
profileIds?: Array<string | undefined>;
}): FailoverReason => {
if (params.allInCooldown) {
return "rate_limit";
const profileIds = (params.profileIds ?? profileCandidates).filter(
(id): id is string => typeof id === "string" && id.length > 0,
);
return (
resolveProfilesUnavailableReason({
store: authStore,
profileIds,
}) ?? "rate_limit"
);
}
const classified = classifyFailoverReason(params.message);
return classified ?? "auth";
@@ -385,6 +395,7 @@ export async function runEmbeddedPiAgent(
const reason = resolveAuthProfileFailoverReason({
allInCooldown: params.allInCooldown,
message,
profileIds: profileCandidates,
});
if (fallbackConfigured) {
throw new FailoverError(message, {