fix(combo): propagate selected connection ID to fallback error responses for correct model lockout (#4809)

Integrated into release/v3.8.36
This commit is contained in:
Chewji
2026-06-24 08:56:14 +07:00
committed by GitHub
parent 604654cc3a
commit e99e2887bf
4 changed files with 156 additions and 11 deletions

View File

@@ -30,11 +30,7 @@ function toInteger(
const min = options.min ?? 0;
const max = options.max ?? Number.MAX_SAFE_INTEGER;
const parsed =
typeof value === "number"
? value
: typeof value === "string"
? Number(value)
: fallback;
typeof value === "number" ? value : typeof value === "string" ? Number(value) : fallback;
return Number.isFinite(parsed) ? Math.max(min, Math.min(max, Math.trunc(parsed))) : fallback;
}
@@ -65,10 +61,14 @@ export function resolveModelLockoutSettings(
process.execArgv.includes("--test") ||
process.argv.some((arg) => typeof arg === "string" && arg.includes("test"));
const baseCooldownMs = toInteger(raw.baseCooldownMs, DEFAULT_MODEL_LOCKOUT_SETTINGS.baseCooldownMs, {
min: isTest ? 0 : 5_000,
max: 600_000,
});
const baseCooldownMs = toInteger(
raw.baseCooldownMs,
DEFAULT_MODEL_LOCKOUT_SETTINGS.baseCooldownMs,
{
min: isTest ? 0 : 5_000,
max: 600_000,
}
);
const maxCooldownMs = Math.max(
toInteger(raw.maxCooldownMs, DEFAULT_MODEL_LOCKOUT_SETTINGS.maxCooldownMs, {
min: isTest ? 0 : 5_000,

View File

@@ -1055,7 +1055,7 @@ async function handleSingleModelChat(
breaker._onFailure();
}
return handleNoCredentials(
const noCredsRes = handleNoCredentials(
credentials,
excludedConnectionIds.size > 0 ? Array.from(excludedConnectionIds)[0] : null,
provider,
@@ -1063,6 +1063,11 @@ async function handleSingleModelChat(
lastError,
lastStatus
);
const lastFailedConnectionId =
excludedConnectionIds.size > 0
? Array.from(excludedConnectionIds)[excludedConnectionIds.size - 1]
: null;
return withSelectedConnectionHeader(noCredsRes, lastFailedConnectionId);
}
const accountId = credentials.connectionId.slice(0, 8);