From d06d3fb67d8e2194559ece9a868c48ce9006b0d7 Mon Sep 17 00:00:00 2001 From: MumuTW <42820974+MumuTW@users.noreply.github.com> Date: Sat, 25 Jul 2026 22:10:44 +0800 Subject: [PATCH] test(sse): update three backoff assertions stale since the #8396 cooldown cap (#8539) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/unit/error-classification.test.ts | 18 ++++++++++++++++-- tests/unit/thundering-herd.test.ts | 8 +++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/unit/error-classification.test.ts b/tests/unit/error-classification.test.ts index bc267a4050..90d18f7c4d 100644 --- a/tests/unit/error-classification.test.ts +++ b/tests/unit/error-classification.test.ts @@ -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 + ) ); }); diff --git a/tests/unit/thundering-herd.test.ts b/tests/unit/thundering-herd.test.ts index e3af4f81f1..140efa04a6 100644 --- a/tests/unit/thundering-herd.test.ts +++ b/tests/unit/thundering-herd.test.ts @@ -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 + ) ); });