refactor: dedupe auth-profile failure marking and rotation test setup

This commit is contained in:
Peter Steinberger
2026-02-22 15:43:57 +01:00
parent 44dfbd23df
commit d0b59270a7
2 changed files with 54 additions and 52 deletions

View File

@@ -500,6 +500,22 @@ export async function runEmbeddedPiAgent(
let lastRunPromptUsage: ReturnType<typeof normalizeUsage> | undefined;
let autoCompactionCount = 0;
let runLoopIterations = 0;
const maybeMarkAuthProfileFailure = async (params: {
profileId?: string;
reason?: Parameters<typeof markAuthProfileFailure>[0]["reason"] | null;
}) => {
const { profileId, reason } = params;
if (!profileId || !reason || reason === "timeout") {
return;
}
await markAuthProfileFailure({
store: authStore,
profileId,
reason,
cfg: params.config,
agentDir: params.agentDir,
});
};
try {
while (true) {
if (runLoopIterations >= MAX_RUN_LOOP_ITERATIONS) {
@@ -869,15 +885,10 @@ export async function runEmbeddedPiAgent(
};
}
const promptFailoverReason = classifyFailoverReason(errorText);
if (promptFailoverReason && promptFailoverReason !== "timeout" && lastProfileId) {
await markAuthProfileFailure({
store: authStore,
profileId: lastProfileId,
reason: promptFailoverReason,
cfg: params.config,
agentDir: params.agentDir,
});
}
await maybeMarkAuthProfileFailure({
profileId: lastProfileId,
reason: promptFailoverReason,
});
if (
isFailoverErrorMessage(errorText) &&
promptFailoverReason !== "timeout" &&
@@ -963,15 +974,10 @@ export async function runEmbeddedPiAgent(
// Skip cooldown for timeouts: a timeout is model/network-specific,
// not an auth issue. Marking the profile would poison fallback models
// on the same provider (e.g. gpt-5.3 timeout blocks gpt-5.2).
if (reason !== "timeout") {
await markAuthProfileFailure({
store: authStore,
profileId: lastProfileId,
reason,
cfg: params.config,
agentDir: params.agentDir,
});
}
await maybeMarkAuthProfileFailure({
profileId: lastProfileId,
reason,
});
if (timedOut && !isProbeSession) {
log.warn(`Profile ${lastProfileId} timed out. Trying next account...`);
}