Public: anyone can read this; the crew can change it.

Follow-up to #16879: restore the timers-named allow-list entry and add the fs… #16949

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/16907-follow-up-to-16879-restore-the-timers-na → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/16907-follow-up-to-16879-restore-the-timers-na was merged into main as 44f5fc4.

Review

Sign in to review this change.
3 files changed +51 −10
test/helpers/crew-standin.ts +6
@@ -54,6 +54,9 @@ export const STAND_IN_TICK_MS = 50;
5454 /** The file the stand-in's SLOW-REVIEW reviewer adds a line to as it starts. */
5555 const SLOW_REVIEW_STARTED = "slow-review.started";
5656
57 /** How often the watch's file is read again, in case fs.watch missed the event. */
58 const WATCH_RECHECK_MS = 100;
59
5760 /**
5861 * A review clock (`reviewClock`) that spends the budget when the stand-in's slow reviewer has
5962 * started since the run was claimed: a line added to `SLOW_REVIEW_STARTED`, seen by a watch on
@@ -66,9 +69,12 @@ function spentWhenStarted(dataDir: string): (overrun: () => void) => () => void
6669 const seen = lines();
6770 let done = false;
6871 const watcher = watch(dataDir, () => check());
72 // fs.watch can miss an event on a loaded host: look again on an interval.
73 const recheck = setInterval(() => check(), WATCH_RECHECK_MS);
6974 const stop = (): void => {
7075 done = true;
7176 watcher.close();
77 clearInterval(recheck);
7278 };
7379 const check = (): void => {
7480 if (done || lines() <= seen) return;
test/page-budget.test.ts +30 −6
@@ -68,6 +68,15 @@ function calibrate(): { cpu: number; wall: number } {
6868 /** How much slower this moment is than a quiet machine, by the calibration's time; 1 at most fast. */
6969 const slowdown = (took: number): number => Math.max(1, took / CALIBRATION_QUIET_MS);
7070
71 /** A request's time read in quiet-host units: divided by how much slower the calibration ran. */
72 const scaled = (took: number, calibration: number): number => took / slowdown(calibration);
73
74 /** The wall-clock ceiling judged on the scaled walls' median, or undefined when it holds. */
75 function wallFinding(b: PageBudget, walls: readonly number[]): string | undefined {
76 const wall = median([...walls]);
77 return wall > WALL_CEILING_MS ? `${b.pattern}: wall-clock median ${wall.toFixed(0)} ms, ceiling ${WALL_CEILING_MS} ms` : undefined;
78 }
79
7180 let root = "";
7281 let app: App;
7382 let servers: Servers;
@@ -193,8 +202,8 @@ async function time(
193202 const res = await fetch(url(b), init(b));
194203 await res.arrayBuffer();
195204 const used = process.cpuUsage(t);
196 walls.push((performance.now() - w) / slowdown(cal.wall));
197 samples.push((used.user + used.system) / 1000 / slowdown(cal.cpu));
205 walls.push(scaled(performance.now() - w, cal.wall));
206 samples.push(scaled((used.user + used.system) / 1000, cal.cpu));
198207 header = res.headers.get("server-timing") ?? "";
199208 }
200209 return { samples, walls, phases: parsePhases(header) };
@@ -240,10 +249,7 @@ test("each first page answers under its median warm, retried before it is named"
240249 const t = await time(b);
241250 mid = median(t.samples);
242251 found = timeFinding(b, { status: 200, statements: 0, samples: t.samples, phases: t.phases });
243 const wall = median(t.walls);
244 if (!found && wall > WALL_CEILING_MS) {
245 found = `${b.pattern}: wall-clock median ${wall.toFixed(0)} ms, ceiling ${WALL_CEILING_MS} ms`;
246 }
252 found ??= wallFinding(b, t.walls);
247253 if (!found) break;
248254 }
249255 table.push(`${b.pattern}\tmedian ${mid.toFixed(1)} ms`);
@@ -276,3 +282,21 @@ test("the median is the middle sample, or the mean of the middle two", () => {
276282 expect(Number.isNaN(median([]))).toBe(true);
277283 });
278284

Two blank lines here; keep one.

285
286 test("a page that really takes twice its ceiling on a quiet host still fails, scaled or not (#16907)", () => {
287 const b = PAGE_BUDGETS[0]!;
288 // A quiet host: the calibration ran at its quiet time, so nothing is scaled away.
289 const quiet = CALIBRATION_QUIET_MS;
290 expect(slowdown(quiet)).toBe(1);
291 expect(scaled(2 * WALL_CEILING_MS, quiet)).toBe(2 * WALL_CEILING_MS);
292 const walls = Array.from({ length: TIMED }, () => scaled(2 * WALL_CEILING_MS, quiet));
293 expect(wallFinding(b, walls)).toBe(`${b.pattern}: wall-clock median 1000 ms, ceiling ${WALL_CEILING_MS} ms`);
294 // The CPU side: a page 2x its median budget misses on a quiet host too.
295 const cpu = Array.from({ length: TIMED }, () => scaled(2 * b.medianMs, quiet));
296 expect(timeFinding(b, { status: 200, statements: 0, samples: cpu, phases: [] })).toContain("budget");
297 // A faster-than-quiet calibration never scales a time up.
298 expect(scaled(100, 0.1)).toBe(100);
299 // A host that really is 2x slower is forgiven by exactly that factor, not more.
300 expect(scaled(2 * WALL_CEILING_MS, 2 * quiet)).toBeCloseTo(WALL_CEILING_MS, 6);
301 expect(wallFinding(b, [WALL_CEILING_MS * 1.01])).toBeDefined();
302 });
test/timers-named.test.ts +15 −4
@@ -35,6 +35,8 @@ interface Allowed {
3535 readonly call: Call;
3636 /** How the callback begins, whitespace collapsed: it names one occurrence. */
3737 readonly starts: string;
38 /** The callback is exactly `starts`, not merely begins with it: for a bare name. */
39 readonly exact?: true;
3840 readonly why: string;
3941 }
4042
@@ -55,8 +57,8 @@ const DEADLINE = "a one-shot deadline on one call in flight: it settles, aborts
5557 /** A one-shot that signals one child process. */
5658 const KILL = "a kill deadline on one child process: it sends a signal, nothing runs on the loop";
5759
58 const allow = (call: Call, why: string, at: readonly (readonly [string, string])[]): Allowed[] =>
59 at.map(([file, starts]) => ({ file, call, starts, why }));
60 const allow = (call: Call, why: string, at: readonly (readonly [string, string] | readonly [string, string, true])[]): Allowed[] =>
61 at.map(([file, starts, exact]) => ({ file, call, starts, ...(exact ? { exact } : {}), why }));
6062
6163 /**
6264 * Each entry names one timer (an entry listed twice names two alike). The one-shots are
@@ -175,7 +177,7 @@ const ALLOWED: readonly Allowed[] = [
175177 ["src/crew/plan.ts", "() => resolve(undefined)"],
176178 ["src/crew/decide.ts", "() => abort.abort()"],
177179 // The review budget's default clock (`reviewClock`): its callback aborts the run and arms the grace.
178 ["src/crew/runner.ts", "overrun"],
180 ["src/crew/runner.ts", "overrun", true],
179181 ["src/crew/runner.ts", "() => giveUp({ state: \"failed\""],
180182 ["src/crew/claude.ts", "() => { input.log("],
181183 ["src/crew/claude.ts", "() => { why = \"timeout\"; stopChild(); }"],
@@ -336,7 +338,7 @@ function scan(): Timer[] {
336338 }
337339
338340 const matches = (a: Allowed, t: { file: string; call: Call; callback: string }): boolean =>
339 a.file === t.file && a.call === t.call && t.callback.startsWith(a.starts);
341 a.file === t.file && a.call === t.call && (a.exact ? t.callback === a.starts : t.callback.startsWith(a.starts));
340342
341343 describe("background timers run inside during", () => {
342344 test("the scan reads each timer's first argument", () => {
@@ -407,6 +409,15 @@ describe("background timers run inside during", () => {
407409 expect(callbacks("\n\nsetInterval(tick, 5);", "setInterval")[0]?.line).toBe(3);
408410 });
409411
412 test("the bare overrun entry names only the identifier, not any callback that begins with it (#16907)", () => {
413 const entry = ALLOWED.find((a) => a.file === "src/crew/runner.ts" && a.starts === "overrun")!;
414 const at = (callback: string) => ({ file: "src/crew/runner.ts", call: "setTimeout" as const, callback });
415 expect(matches(entry, at("overrun"))).toBe(true);
416 expect(matches(entry, at("overrun2"))).toBe(false);
417 expect(matches(entry, at("() => { overran = true; controller.abort(); }"))).toBe(false);
418 expect(matches(entry, at("overrun(); doWork()"))).toBe(false);
419 });
420
410421 test("each allowed entry names exactly one timer, and says why", () => {
411422 const all = timers();
412423 for (const a of ALLOWED) {

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs