fix(auth): keep timeout expiry per profile

This commit is contained in:
Peter Steinberger
2026-05-31 13:53:16 +01:00
parent ef51d736fe
commit d64e2a4d2f
2 changed files with 21 additions and 1 deletions

View File

@@ -95,6 +95,26 @@ describe("getSoonestCooldownExpiry", () => {
).toBe(now + 30_000);
});
it("uses the earliest matching timeout cooldown for the requested model", () => {
const now = 1_700_000_000_000;
const store = makeStore({
"openai:p1": {
cooldownUntil: now + 10_000,
cooldownReason: "timeout",
cooldownModel: "gpt-5.4",
},
"openai:p2": {
cooldownUntil: now + 30_000,
cooldownReason: "timeout",
cooldownModel: "gpt-5.4",
},
});
expect(
getSoonestCooldownExpiry(store, ["openai:p1", "openai:p2"], { now, forModel: "gpt-5.4" }),
).toBe(now + 10_000);
});
it("still counts profile-wide disables for other models", () => {
const now = 1_700_000_000_000;
const store = makeStore({

View File

@@ -104,7 +104,7 @@ export function getSoonestCooldownExpiry(
}
const matchingModelScopedCooldown =
options?.forModel &&
isModelScopedCooldownReason(stats.cooldownReason) &&
stats.cooldownReason === "rate_limit" &&
stats.cooldownModel === options.forModel &&
!isActiveUnusableWindow(stats.blockedUntil, ts) &&
!isActiveUnusableWindow(stats.disabledUntil, ts);