Skip to content

Commit 8647800

Browse files
committed
fix(router): dev PPR capture backoff cap, cf-basic ppr warmup + CI budget, snapshot-test flake (#652 item 3)
Four coordinated changes unblocking cloudflare-basic-e2e on cold CI runners (failures on the main run for 2586ea9, the PR #657 runs, and PR #659's own first CI run): 1. Dev backoff cap (runtime). The refused-capture backoff window is exponential per consecutive failure, `min(BASE * 2^(failures-1), ceiling)`; the ceiling was a flat 60s in every mode. On a cold runner each cold re-probe climbs the count, and once the window exceeds ~16s it outlasts warmToHit's 20s poll: every request is skipped as backed-off, an eternal MISS. The ceiling is now mode-dependent: 60s in production (a genuinely ineligible route should be re-probed rarely), ~2s in dev, where the dominant no-shell cause is a cold module graph that warms on the very attempt that failed. Dev signal is `process.env.NODE_ENV !== "production"`, matching handler.ts / server-action.ts / progressive-enhancement.ts. 2. PPR dev warmup (test-side, the sufficient fix). PR #659's first CI run showed the cap alone is not sufficient: one probe cycle is ~12s (5s attempt + 5s in-place retry + 2s capped backoff), so the 20s window fits ~2 cycles and today's cold runners need more because the dev module graph is compiled ON DEMAND during the capture render, repeatedly blowing the 5s budget (physics hole failed 3x at ~20s). Extend tests/cloudflare-basic's existing dev-warmup setup project (which the dev project already depends on) with a ppr warmup: GET every ppr fixture route under an isolated `?probe=warmup` shell key (module-graph warm only, no test-visible entry pre-stored), then poll each capturable fixture to x-rango-shell HIT, proving the full capture pipeline (Flight render, fizz prerender+abort, putShell) is hot before any real test's warm window starts. Cap + warmup together: the warmup makes first attempts succeed; the cap remains the safety net for anything cold the warmup missed. warmToHit windows and runtime constants are otherwise untouched. 3. CI budget (the 600s owner). cloudflare-basic's playwright globalTimeout was `10 * 60 * 1000` on CI; the merged PPR stack grew the sequential dev -> production -> hmr run past 10m, so healthy runs brushed the cap and any flake retry tipped it over — Playwright killed the run mid-flight ("Timed out waiting 600s for the test suite to run"), failing whichever test was executing (the 0ms hmr-warmup skip-cascade, the mid-hmr kill at 10:31:06 while hmr tests were passing). Raised to 14m, and the cloudflare-basic-e2e job's timeout-minutes from 15 to 20 so the workflow cap contains ~3-4m setup + the 14m playwright budget. vite-rsc-demo and rangojs-router keep their 600s globalTimeout: their jobs shard/split, and recent CI runs show per-job playwright time of ~3-5m — nowhere near the cap. 4. shell-snapshot.test.ts 1ms flake (also blocking CI). "serves snapshot values AS FRESH" builds the seeded store and the expected value from two separate snapshotOf() calls, and segData embeds `Date.now() + 60_000` as expiresAt — a millisecond tick between the calls fails the deep-equal (seen on the #659 run). Pin the clock with fake timers (the shell-cache.test.ts pattern). The rest of the file was audited: no other assertion deep-equals across two Date.now() instants. Production backoff ceiling/growth, retry-in-place, the in-flight set, and the e2e warm-window lengths are unchanged. #652 items 1-2 (barrier narrowing, drain unification) remain open.
1 parent 9fc1061 commit 8647800

7 files changed

Lines changed: 365 additions & 46 deletions

File tree

‎.github/workflows/e2e.yml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,12 @@ jobs:
499499
github.event_name == 'workflow_dispatch' ||
500500
github.event_name == 'schedule'
501501
runs-on: ubuntu-latest
502-
timeout-minutes: 15
502+
# 20 (was 15): the suite's playwright globalTimeout was raised to 14m
503+
# (playwright.config.ts — the PPR shell stack grew the sequential
504+
# dev -> production -> hmr run past the old 10m budget), so the job cap
505+
# must contain ~3-4m of setup (install, router build, browser deps) plus
506+
# the full 14m playwright budget.
507+
timeout-minutes: 20
503508

504509
steps:
505510
- uses: actions/checkout@v5

‎packages/rangojs-router/docs/design/ppr-shell-resume.md‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -596,19 +596,34 @@ after the in-place retry ALSO failed (or a genuine error), and within the window
596596
the key is not re-probed.
597597
598598
The window is EXPONENTIAL in the consecutive-failure count —
599-
`min(BASE * 2^(failures-1), MAX)`, so 1 s, 2 s, 4 s, … capped at 60 s
600-
(`REFUSED_CAPTURE_BASE_MS` / `REFUSED_CAPTURE_MAX_MS`). A flat 60 s conflated two
601-
very different failures. A structurally ineligible route fails forever and wants
602-
the long cap. But a cold-but-ELIGIBLE route can also fail the retry under a truly
603-
cold graph (dev module transform, or a cold worker under parallel load), and it
604-
must recover on the next request or two — freezing it for 60 s would re-break the
605-
cold-start DX the retry exists to fix (this is not hypothetical: a flat 60 s
606-
backoff made the cloudflare dev PPR e2e time out, because `warmToHit`'s
607-
multi-request recovery was blocked). Escalating from 1 s lets the eligible route
608-
re-probe almost immediately (warm now → HIT, which clears the entry), while the
609-
doomed route ramps to the 60 s cap within a handful of failures. Either way an
610-
app-wide mount never re-renders a doomed route on every request. A successful
611-
capture clears the entry outright.
599+
`min(BASE * 2^(failures-1), ceiling)`, so 1 s, 2 s, 4 s, … up to the mode's ceiling
600+
(`REFUSED_CAPTURE_BASE_MS`, and the ceiling below). A flat window conflated two
601+
very different failures. A structurally ineligible route fails forever and wants a
602+
long cap. But a cold-but-ELIGIBLE route can also fail the retry under a truly cold
603+
graph (dev module transform, or a cold worker under parallel load), and it must
604+
recover on the next request or two — freezing it would re-break the cold-start DX
605+
the retry exists to fix (this is not hypothetical: a flat 60 s backoff made the
606+
cloudflare dev PPR e2e time out, because `warmToHit`'s multi-request recovery was
607+
blocked). Escalating from 1 s lets the eligible route re-probe almost immediately
608+
(warm now → HIT, which clears the entry), while the doomed route ramps to the cap
609+
within a handful of failures. Either way an app-wide mount never re-renders a
610+
doomed route on every request. A successful capture clears the entry outright.
611+
612+
The ceiling is MODE-DEPENDENT (`refusedCaptureCeilingMs`): 60 s in production
613+
(`REFUSED_CAPTURE_MAX_MS`), but only ~2 s in dev (`REFUSED_CAPTURE_DEV_MAX_MS`).
614+
The reason is that in dev the DOMINANT no-shell cause is a cold module graph that
615+
warms on the very attempt that failed, so a long window is pure harm — and even the
616+
escalating window eventually climbs past ~16 s, which OUTLASTS the e2e warm window.
617+
That was the residual cold-CI failure (#652 item 3): on a slow CI runner the first
618+
capture races an unfinished shell, each re-probe is also cold and climbs the count,
619+
and once the window exceeds `warmToHit`'s 20 s poll every subsequent request is
620+
skipped as backed-off — an eternal MISS even though the modules are warm by then.
621+
Capping the dev window at ~2 s keeps a cold-but-eligible route re-probing roughly
622+
every 2 s across the whole warm window, so one of those warm re-probes always lands
623+
inside it. Production keeps the full 60 s cap because there the no-shell cause is
624+
far more likely to be a genuinely ineligible route, which should be re-probed
625+
rarely. (This is item 3 of #652; items 1–2 — barrier narrowing and drain
626+
unification — remain open.)
612627
613628
### Capture quiesce: task-based, not wall-clock
614629

‎packages/rangojs-router/src/cache/__tests__/shell-snapshot.test.ts‎

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,33 +185,44 @@ describe("SeededShellStore", () => {
185185
}
186186

187187
it("serves snapshot values AS FRESH (shouldRevalidate: false) without touching the real store", async () => {
188-
const inner = new MemorySegmentCacheStore();
189-
// The real store is EMPTY / different — the seed must win and not fall through.
190-
const getItemSpy = vi.spyOn(inner, "getItem");
191-
const getSpy = vi.spyOn(inner, "get");
192-
const seeded = new SeededShellStore(inner, snapshotOf());
193-
194-
const seg = await seeded.get("seg1");
195-
expect(seg).toEqual({
196-
data: (snapshotOf()[0] as any).value,
197-
shouldRevalidate: false,
198-
});
199-
expect(getSpy).not.toHaveBeenCalled(); // pinned key never hits the real store
200-
201-
const item = await seeded.getItem("item1");
202-
expect(item).toMatchObject({
203-
value: "PINNED-ITEM",
204-
handles: "PH",
205-
tags: ["pt"],
206-
shouldRevalidate: false, // MUST NOT kick SWR revalidation for a pinned key
207-
});
208-
expect(getItemSpy).not.toHaveBeenCalled();
209-
210-
const resp = await seeded.getResponse("res1");
211-
expect(resp!.shouldRevalidate).toBe(false);
212-
expect(resp!.response.status).toBe(203);
213-
expect(resp!.response.headers.get("x-h")).toBe("v");
214-
expect(await resp!.response.text()).toBe("PINNED");
188+
// Pin the clock: snapshotOf() -> segData() embeds `Date.now() + 60_000` as
189+
// expiresAt, and this test builds the seed and the expected value from two
190+
// SEPARATE snapshotOf() calls. On real timers a millisecond tick between them
191+
// makes the deep-equal below flake by 1ms (seen on CI). Same pattern as
192+
// src/cache/__tests__/shell-cache.test.ts.
193+
vi.useFakeTimers();
194+
vi.setSystemTime(new Date("2026-01-01T00:00:00Z"));
195+
try {
196+
const inner = new MemorySegmentCacheStore();
197+
// The real store is EMPTY / different — the seed must win and not fall through.
198+
const getItemSpy = vi.spyOn(inner, "getItem");
199+
const getSpy = vi.spyOn(inner, "get");
200+
const seeded = new SeededShellStore(inner, snapshotOf());
201+
202+
const seg = await seeded.get("seg1");
203+
expect(seg).toEqual({
204+
data: (snapshotOf()[0] as any).value,
205+
shouldRevalidate: false,
206+
});
207+
expect(getSpy).not.toHaveBeenCalled(); // pinned key never hits the real store
208+
209+
const item = await seeded.getItem("item1");
210+
expect(item).toMatchObject({
211+
value: "PINNED-ITEM",
212+
handles: "PH",
213+
tags: ["pt"],
214+
shouldRevalidate: false, // MUST NOT kick SWR revalidation for a pinned key
215+
});
216+
expect(getItemSpy).not.toHaveBeenCalled();
217+
218+
const resp = await seeded.getResponse("res1");
219+
expect(resp!.shouldRevalidate).toBe(false);
220+
expect(resp!.response.status).toBe(203);
221+
expect(resp!.response.headers.get("x-h")).toBe("v");
222+
expect(await resp!.response.text()).toBe("PINNED");
223+
} finally {
224+
vi.useRealTimers();
225+
}
215226
});
216227

217228
it("falls through to the real store for non-pinned keys", async () => {

‎packages/rangojs-router/src/rsc/__tests__/shell-capture.test.ts‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {
55
captureAndStoreShell,
66
runShellCapture,
77
scheduleShellCapture,
8+
isCaptureBackedOff,
9+
markCaptureBackoff,
10+
clearCaptureBackoff,
11+
REFUSED_CAPTURE_DEV_MAX_MS,
812
} from "../shell-capture.js";
913
import { createHandleStore } from "../../server/handle-store.js";
1014
import {
@@ -1201,3 +1205,155 @@ describe("runShellCapture", () => {
12011205
expect((reqCtx as any)._shellCaptureRun).toBeUndefined();
12021206
});
12031207
});
1208+
1209+
// Refused-capture backoff policy (#652 item 3). markCaptureBackoff escalates the
1210+
// window exponentially per consecutive failure, clamped to the mode's ceiling: 60s
1211+
// in production (a genuinely ineligible route should be re-probed rarely), but only
1212+
// REFUSED_CAPTURE_DEV_MAX_MS (~2s) in dev, where the dominant no-shell cause is a
1213+
// COLD module graph that WARMS on the very attempt that failed. The dev cap is the
1214+
// fix for the cloudflare-basic-e2e cold-CI failure: the 60s exponential outlasts
1215+
// the e2e warm window, freezing every subsequent request as backed-off (eternal
1216+
// MISS) even though the modules are warm by then. These tests drive the exported
1217+
// backoff functions directly so the exact window arithmetic is pinned.
1218+
//
1219+
// NODE_ENV under the unit vitest config defaults to "test" (dev mode) — so the
1220+
// dev-cap tests need no override; the production-growth test sets it explicitly.
1221+
describe("refused-capture backoff policy", () => {
1222+
it("dev cap: the window never exceeds REFUSED_CAPTURE_DEV_MAX_MS however high the failure count climbs", () => {
1223+
vi.useFakeTimers();
1224+
try {
1225+
const key = "/dev-cap-window:shell";
1226+
clearCaptureBackoff(key);
1227+
const t0 = Date.now();
1228+
// Five consecutive failures at the same instant: the exponential term
1229+
// (1000*2^4 = 16000) would blow past the cap, so the window clamps to the
1230+
// dev ceiling (2000).
1231+
for (let i = 0; i < 5; i++) markCaptureBackoff(key);
1232+
1233+
// Just before the cap elapses: still backed off.
1234+
vi.setSystemTime(t0 + REFUSED_CAPTURE_DEV_MAX_MS - 1);
1235+
expect(isCaptureBackedOff(key)).toBe(true);
1236+
// At the cap: the window has elapsed — a re-probe is allowed. This is the
1237+
// whole point: the dev window is bounded at ~2s, not the 16s the raw
1238+
// exponential (or the 60s prod cap) would give.
1239+
vi.setSystemTime(t0 + REFUSED_CAPTURE_DEV_MAX_MS);
1240+
expect(isCaptureBackedOff(key)).toBe(false);
1241+
} finally {
1242+
clearCaptureBackoff("/dev-cap-window:shell");
1243+
vi.useRealTimers();
1244+
}
1245+
});
1246+
1247+
it("production: exponential growth is intact (window exceeds the dev cap and climbs to 60s)", () => {
1248+
const original = process.env.NODE_ENV;
1249+
process.env.NODE_ENV = "production";
1250+
vi.useFakeTimers();
1251+
try {
1252+
const key = "/prod-grow-window:shell";
1253+
clearCaptureBackoff(key);
1254+
const t0 = Date.now();
1255+
// Five failures → min(1000*2^4, 60000) = 16000ms, far past the 2s dev cap.
1256+
for (let i = 0; i < 5; i++) markCaptureBackoff(key);
1257+
// Still backed off well past where dev would have cleared (2s) — proof the
1258+
// dev cap does NOT leak into production.
1259+
vi.setSystemTime(t0 + REFUSED_CAPTURE_DEV_MAX_MS + 1);
1260+
expect(isCaptureBackedOff(key)).toBe(true);
1261+
vi.setSystemTime(t0 + 15_999);
1262+
expect(isCaptureBackedOff(key)).toBe(true);
1263+
vi.setSystemTime(t0 + 16_000);
1264+
expect(isCaptureBackedOff(key)).toBe(false);
1265+
1266+
// Many more failures ramp to — and clamp at — the 60s production ceiling.
1267+
clearCaptureBackoff(key);
1268+
const t1 = Date.now();
1269+
for (let i = 0; i < 12; i++) markCaptureBackoff(key); // 1000*2^11 >> 60000
1270+
vi.setSystemTime(t1 + 59_999);
1271+
expect(isCaptureBackedOff(key)).toBe(true);
1272+
vi.setSystemTime(t1 + 60_000);
1273+
expect(isCaptureBackedOff(key)).toBe(false);
1274+
} finally {
1275+
clearCaptureBackoff("/prod-grow-window:shell");
1276+
process.env.NODE_ENV = original;
1277+
vi.useRealTimers();
1278+
}
1279+
});
1280+
1281+
it("a stored capture clears the backoff (failure count resets)", () => {
1282+
vi.useFakeTimers();
1283+
try {
1284+
const key = "/stored-clears:shell";
1285+
clearCaptureBackoff(key);
1286+
const t0 = Date.now();
1287+
markCaptureBackoff(key);
1288+
expect(isCaptureBackedOff(key)).toBe(true);
1289+
// A subsequent capture that STORES clears the entry outright — the next
1290+
// request probes immediately, and any later failure starts the exponential
1291+
// over from BASE (not from the escalated count).
1292+
clearCaptureBackoff(key);
1293+
expect(isCaptureBackedOff(key)).toBe(false);
1294+
markCaptureBackoff(key); // failure count reset to 1 → BASE window (1000)
1295+
vi.setSystemTime(t0 + 1_000);
1296+
expect(isCaptureBackedOff(key)).toBe(false);
1297+
} finally {
1298+
clearCaptureBackoff("/stored-clears:shell");
1299+
vi.useRealTimers();
1300+
}
1301+
});
1302+
1303+
// Regression pin for the cold-CI failure (#652 item 3; main run 2586ea9c and the
1304+
// PR #657 runs). Walk the EXACT e2e cadence: a first capture fails at t0, then
1305+
// warmToHit polls once per second for 20s. On a persistently-cold CI runner every
1306+
// probe ALSO fails, climbing the failure count. Under the dev cap the window stays
1307+
// ≤2s, so the LATE part of the 20s window still admits probes — the route is never
1308+
// frozen out. Non-vacuous: without the dev cap (production exponential, asserted in
1309+
// the sibling test below) the window blows past 20s after a handful of failures and
1310+
// the tail of the poll admits ZERO probes — the eternal MISS the test hit.
1311+
function walkColdCiWindow(): { probes: number; tailProbes: number } {
1312+
const key = "/cold-ci-sequence:shell";
1313+
clearCaptureBackoff(key);
1314+
const t0 = Date.now();
1315+
markCaptureBackoff(key); // t0: first capture attempt failed (post-retry)
1316+
let probes = 0;
1317+
let tailProbes = 0; // probes in the last 4s of the 20s window (s = 17..20)
1318+
for (let s = 1; s <= 20; s++) {
1319+
vi.setSystemTime(t0 + s * 1_000);
1320+
if (!isCaptureBackedOff(key)) {
1321+
probes += 1;
1322+
if (s >= 17) tailProbes += 1;
1323+
markCaptureBackoff(key); // this probe was also cold → re-marks (climbs)
1324+
}
1325+
}
1326+
clearCaptureBackoff(key);
1327+
return { probes, tailProbes };
1328+
}
1329+
1330+
it("simulated cold start: the dev cap keeps re-probing across the full 20s warm window", () => {
1331+
vi.useFakeTimers();
1332+
try {
1333+
const { probes, tailProbes } = walkColdCiWindow();
1334+
// ~10 probes across 20s (one roughly every 2s), and crucially the tail of
1335+
// the window is NOT frozen out — the CI test would see a HIT the moment one
1336+
// of these warm re-probes captures.
1337+
expect(probes).toBeGreaterThanOrEqual(8);
1338+
expect(tailProbes).toBeGreaterThanOrEqual(1);
1339+
} finally {
1340+
vi.useRealTimers();
1341+
}
1342+
});
1343+
1344+
it("without the dev cap (production) the same cold sequence freezes the tail of the warm window — the bug being fixed", () => {
1345+
const original = process.env.NODE_ENV;
1346+
process.env.NODE_ENV = "production";
1347+
vi.useFakeTimers();
1348+
try {
1349+
const { tailProbes } = walkColdCiWindow();
1350+
// The 60s exponential escalates past 20s after ~4 failures, so the last 4s
1351+
// of the poll admit no probe — every request is skipped as backed-off. This
1352+
// is exactly the eternal MISS the dev cap removes.
1353+
expect(tailProbes).toBe(0);
1354+
} finally {
1355+
process.env.NODE_ENV = original;
1356+
vi.useRealTimers();
1357+
}
1358+
});
1359+
});

‎packages/rangojs-router/src/rsc/shell-capture.ts‎

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ const inFlightCaptures = new Set<string>();
169169

170170
/**
171171
* Refused-capture backoff bounds. The window is EXPONENTIAL in the consecutive
172-
* failure count: `min(BASE * 2^(failures-1), MAX)` — 1s, 2s, 4s, … capped at 60s.
172+
* failure count: `min(BASE * 2^(failures-1), ceiling)` — 1s, 2s, 4s, … up to the
173+
* mode's ceiling (60s in production, {@link REFUSED_CAPTURE_DEV_MAX_MS} in dev).
173174
*
174175
* Why exponential and not a flat 60s: a flat long window conflates two very
175176
* different failures. A STRUCTURALLY ineligible route (no loading(), a cookie
@@ -179,12 +180,44 @@ const inFlightCaptures = new Set<string>();
179180
* request or two, not be frozen for 60s (that would re-break the very cold-start DX
180181
* the retry fixes; it bit the cloudflare dev e2e). Escalating from 1s means the
181182
* eligible route re-probes almost immediately (warm now → HIT and clear), while the
182-
* doomed route ramps to the 60s cap within a handful of failures. Either way an
183+
* doomed route ramps to the ceiling within a handful of failures. Either way an
183184
* app-wide mount never re-renders a doomed route on EVERY request.
184185
*/
185186
const REFUSED_CAPTURE_BASE_MS = 1_000;
186187
const REFUSED_CAPTURE_MAX_MS = 60_000;
187188

189+
/**
190+
* DEV-only backoff ceiling. In dev the 60s production cap is pure harm: the
191+
* dominant no-shell cause is a COLD module graph (route modules, SSR/Flight
192+
* transforms built lazily), and the very attempt that failed WARMS that graph, so
193+
* the next attempt a beat later usually completes the shell. Capping the dev window
194+
* low keeps a cold-but-eligible route re-probing every ~2s instead of freezing for
195+
* up to 60s once the exponential climbs (1s→2s→4s→…→60s). A 60s freeze outlasts the
196+
* e2e warm windows on cold CI runners: the capture races an unfinished shell,
197+
* escalates the backoff past the poll window, and every subsequent request inside
198+
* that window is skipped as backed-off — an eternal MISS for the test even though
199+
* the modules are warm by then. Production keeps the full 60s cap: there the
200+
* no-shell cause is far more likely to be a genuinely ineligible route (no
201+
* loading()), which SHOULD be re-probed rarely. See #652 (item 3) and
202+
* docs/design/ppr-shell-resume.md ("Refused-capture backoff").
203+
*/
204+
const REFUSED_CAPTURE_DEV_MAX_MS = 2_000;
205+
206+
/**
207+
* Dev signal, matching the rest of the RSC runtime (handler.ts, server-action.ts,
208+
* progressive-enhancement.ts): treat anything but an explicit production build as
209+
* dev. The build folds `process.env.NODE_ENV` to a literal, so this is a compile-
210+
* time constant in the shipped worker — no runtime probe.
211+
*/
212+
function isDevMode(): boolean {
213+
return process.env.NODE_ENV !== "production";
214+
}
215+
216+
/** The active backoff ceiling for the current mode (dev capped low, prod at 60s). */
217+
function refusedCaptureCeilingMs(): number {
218+
return isDevMode() ? REFUSED_CAPTURE_DEV_MAX_MS : REFUSED_CAPTURE_MAX_MS;
219+
}
220+
188221
/**
189222
* Refused-capture backoff: key -> { consecutive failure count, epoch ms until which
190223
* the key is not re-probed }. A key enters backoff only after runShellCapture's
@@ -203,12 +236,19 @@ function isCaptureBackedOff(key: string): boolean {
203236
return Date.now() < entry.until;
204237
}
205238

206-
/** Record a refused/failed capture, escalating the backoff window exponentially. */
239+
/**
240+
* Record a refused/failed capture, escalating the backoff window exponentially up
241+
* to the current mode's ceiling. The failure count keeps climbing across attempts
242+
* (so a genuinely doomed route still ramps toward its cap), but the WINDOW is
243+
* clamped: 60s in production, {@link REFUSED_CAPTURE_DEV_MAX_MS} in dev so a
244+
* cold-but-eligible route re-probes fast instead of freezing out the e2e warm
245+
* window on a cold CI runner (#652 item 3).
246+
*/
207247
function markCaptureBackoff(key: string): void {
208248
const failures = (refusedCaptures.get(key)?.failures ?? 0) + 1;
209249
const window = Math.min(
210250
REFUSED_CAPTURE_BASE_MS * 2 ** (failures - 1),
211-
REFUSED_CAPTURE_MAX_MS,
251+
refusedCaptureCeilingMs(),
212252
);
213253
refusedCaptures.set(key, { failures, until: Date.now() + window });
214254
}
@@ -895,3 +935,17 @@ async function captureAndStoreShell(
895935

896936
// Exported for unit tests that drive the capture core directly.
897937
export { runShellCapture, captureAndStoreShell };
938+
939+
// Exported for unit tests that pin the refused-capture backoff policy directly
940+
// (dev cap vs production exponential growth, stored-clears, cold-start re-probe).
941+
// These are the same module-level functions the schedule path uses; a test that
942+
// drove them through a real capture round-trip could not assert the exact window
943+
// arithmetic without a full cold render.
944+
export {
945+
isCaptureBackedOff,
946+
markCaptureBackoff,
947+
clearCaptureBackoff,
948+
REFUSED_CAPTURE_BASE_MS,
949+
REFUSED_CAPTURE_MAX_MS,
950+
REFUSED_CAPTURE_DEV_MAX_MS,
951+
};

0 commit comments

Comments
 (0)