refactor(agents): share failover HTTP status classification (#36615)

* fix(agents): classify transient failover statuses consistently

* fix(agents): preserve legacy failover status mapping
This commit is contained in:
Altay
2026-03-05 23:50:36 +03:00
committed by GitHub
parent 8ac7ce73b3
commit f014e255df
4 changed files with 49 additions and 29 deletions

View File

@@ -251,6 +251,43 @@ export function isTransientHttpError(raw: string): boolean {
return TRANSIENT_HTTP_ERROR_CODES.has(status.code);
}
export function classifyFailoverReasonFromHttpStatus(
status: number | undefined,
message?: string,
): FailoverReason | null {
if (typeof status !== "number" || !Number.isFinite(status)) {
return null;
}
if (status === 402) {
return "billing";
}
if (status === 429) {
return "rate_limit";
}
if (status === 401 || status === 403) {
if (message && isAuthPermanentErrorMessage(message)) {
return "auth_permanent";
}
return "auth";
}
if (status === 408) {
return "timeout";
}
// Keep the status-only path conservative and behavior-preserving.
// Message-path HTTP heuristics are broader and should not leak in here.
if (status === 502 || status === 503 || status === 504) {
return "timeout";
}
if (status === 529) {
return "rate_limit";
}
if (status === 400) {
return "format";
}
return null;
}
function stripFinalTagsFromText(text: string): string {
if (!text) {
return text;