test(sse): update three backoff assertions stale since the #8396 cooldown cap (#8539)

These three cases assert that a transient-error cooldown keeps doubling
to baseCooldownMs * 2^maxLevel — roughly 45.5h at the default constants.
That is precisely the blackout #8396 removed: capScaledCooldownMs
(open-sse/services/accountFallback/cooldownCap.ts) now bounds every
scaled cooldown by profile.maxCooldownMs, falling back to
BACKOFF_CONFIG.max when the profile does not configure one. All three
call checkFallbackError with a null provider, so the fallback ceiling
applies and the observed value is BACKOFF_CONFIG.max.

The backoff-level clamping each case was written to guard is unchanged
and still asserted; only the expected duration moved. The expressions
keep the original formula wrapped in the cap so the relationship stays
readable, and the first case gains a precondition assertion so it cannot
silently become vacuous if the constants change.

Fixes the error-classification (x2) and thundering-herd (x1) failures
that are red on release/v3.8.49 at its own HEAD.
This commit is contained in:
MumuTW
2026-07-25 22:10:44 +08:00
committed by GitHub
parent 278640b438
commit d06d3fb67d
2 changed files with 23 additions and 3 deletions

View File

@@ -98,13 +98,21 @@ test("502 transient: exponential backoff doubles until the configured max backof
assert.equal(result.newBackoffLevel, level + 1);
assert.equal(result.reason, RateLimitReason.SERVER_ERROR);
}
// #8396: the scaled cooldown is now clamped by capScaledCooldownMs
// (open-sse/services/accountFallback/cooldownCap.ts). With no provider the
// ceiling is BACKOFF_CONFIG.max, so the doubling stops there instead of
// running on to transientInitial * 32.
assert.ok(
COOLDOWN_MS.transientInitial * 32 > BACKOFF_CONFIG.max,
"precondition: the 6th step must exceed the cap, or this test proves nothing"
);
assert.deepEqual(cooldowns, [
COOLDOWN_MS.transientInitial,
COOLDOWN_MS.transientInitial * 2,
COOLDOWN_MS.transientInitial * 4,
COOLDOWN_MS.transientInitial * 8,
COOLDOWN_MS.transientInitial * 16,
COOLDOWN_MS.transientInitial * 32,
BACKOFF_CONFIG.max,
]);
});
@@ -237,8 +245,14 @@ test("subscription quota uses long cooldown when upstream retry hints are disabl
test("high transient backoff levels clamp to the configured maxBackoffSteps", () => {
const result = checkFallbackError(502, "", BACKOFF_CONFIG.maxLevel + 5, null, null);
assert.equal(result.newBackoffLevel, BACKOFF_CONFIG.maxLevel);
// #8396: the level still clamps at maxLevel, but the resulting duration is
// additionally capped — unclamped this would be ~45.5h, which is the blackout
// that PR removed.
assert.equal(
result.cooldownMs,
COOLDOWN_MS.transientInitial * Math.pow(2, BACKOFF_CONFIG.maxLevel)
Math.min(
COOLDOWN_MS.transientInitial * Math.pow(2, BACKOFF_CONFIG.maxLevel),
BACKOFF_CONFIG.max
)
);
});

View File

@@ -39,9 +39,15 @@ test("API profile has shorter transient cooldown", () => {
test("Exponential backoff clamps to the configured maxBackoffLevel", () => {
const result = checkFallbackError(502, "", 20, null, null);
assert.equal(result.newBackoffLevel, BACKOFF_CONFIG.maxLevel);
// #8396: the level still clamps at maxLevel, but capScaledCooldownMs also
// bounds the duration — with no provider profile the ceiling is
// BACKOFF_CONFIG.max rather than the unbounded baseCooldownMs * 2^level.
assert.equal(
result.cooldownMs,
COOLDOWN_MS.transientInitial * Math.pow(2, BACKOFF_CONFIG.maxLevel)
Math.min(
COOLDOWN_MS.transientInitial * Math.pow(2, BACKOFF_CONFIG.maxLevel),
BACKOFF_CONFIG.max
)
);
});