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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16907-follow-up-to-16879-restore-the-timers-na → main 0 commits fork 1 thread · 1 unresolved
3 files
changed +51
−10
test/helpers/crew-standin.ts +6
| @@ -54,6 +54,9 @@ export const STAND_IN_TICK_MS = 50; | ||
| 54 | 54 | /** The file the stand-in's SLOW-REVIEW reviewer adds a line to as it starts. */ |
| 55 | 55 | const SLOW_REVIEW_STARTED = "slow-review.started"; |
| 56 | 56 | |
| 57 | /** How often the watch's file is read again, in case fs.watch missed the event. */ | |
| 58 | const WATCH_RECHECK_MS = 100; | |
| 59 | ||
| 57 | 60 | /** |
| 58 | 61 | * A review clock (`reviewClock`) that spends the budget when the stand-in's slow reviewer has |
| 59 | 62 | * 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 | ||
| 66 | 69 | const seen = lines(); |
| 67 | 70 | let done = false; |
| 68 | 71 | 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); | |
| 69 | 74 | const stop = (): void => { |
| 70 | 75 | done = true; |
| 71 | 76 | watcher.close(); |
| 77 | clearInterval(recheck); | |
| 72 | 78 | }; |
| 73 | 79 | const check = (): void => { |
| 74 | 80 | if (done || lines() <= seen) return; |
test/page-budget.test.ts +30 −6
| @@ -68,6 +68,15 @@ function calibrate(): { cpu: number; wall: number } { | ||
| 68 | 68 | /** How much slower this moment is than a quiet machine, by the calibration's time; 1 at most fast. */ |
| 69 | 69 | const slowdown = (took: number): number => Math.max(1, took / CALIBRATION_QUIET_MS); |
| 70 | 70 | |
| 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 | ||
| 71 | 80 | let root = ""; |
| 72 | 81 | let app: App; |
| 73 | 82 | let servers: Servers; |
| @@ -193,8 +202,8 @@ async function time( | ||
| 193 | 202 | const res = await fetch(url(b), init(b)); |
| 194 | 203 | await res.arrayBuffer(); |
| 195 | 204 | 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)); | |
| 198 | 207 | header = res.headers.get("server-timing") ?? ""; |
| 199 | 208 | } |
| 200 | 209 | return { samples, walls, phases: parsePhases(header) }; |
| @@ -240,10 +249,7 @@ test("each first page answers under its median warm, retried before it is named" | ||
| 240 | 249 | const t = await time(b); |
| 241 | 250 | mid = median(t.samples); |
| 242 | 251 | 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); | |
| 247 | 253 | if (!found) break; |
| 248 | 254 | } |
| 249 | 255 | 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", () => { | ||
| 276 | 282 | expect(Number.isNaN(median([]))).toBe(true); |
| 277 | 283 | }); |
| 278 | 284 | |
| 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 { | ||
| 35 | 35 | readonly call: Call; |
| 36 | 36 | /** How the callback begins, whitespace collapsed: it names one occurrence. */ |
| 37 | 37 | readonly starts: string; |
| 38 | /** The callback is exactly `starts`, not merely begins with it: for a bare name. */ | |
| 39 | readonly exact?: true; | |
| 38 | 40 | readonly why: string; |
| 39 | 41 | } |
| 40 | 42 | |
| @@ -55,8 +57,8 @@ const DEADLINE = "a one-shot deadline on one call in flight: it settles, aborts | ||
| 55 | 57 | /** A one-shot that signals one child process. */ |
| 56 | 58 | const KILL = "a kill deadline on one child process: it sends a signal, nothing runs on the loop"; |
| 57 | 59 | |
| 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 })); | |
| 60 | 62 | |
| 61 | 63 | /** |
| 62 | 64 | * Each entry names one timer (an entry listed twice names two alike). The one-shots are |
| @@ -175,7 +177,7 @@ const ALLOWED: readonly Allowed[] = [ | ||
| 175 | 177 | ["src/crew/plan.ts", "() => resolve(undefined)"], |
| 176 | 178 | ["src/crew/decide.ts", "() => abort.abort()"], |
| 177 | 179 | // 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], | |
| 179 | 181 | ["src/crew/runner.ts", "() => giveUp({ state: \"failed\""], |
| 180 | 182 | ["src/crew/claude.ts", "() => { input.log("], |
| 181 | 183 | ["src/crew/claude.ts", "() => { why = \"timeout\"; stopChild(); }"], |
| @@ -336,7 +338,7 @@ function scan(): Timer[] { | ||
| 336 | 338 | } |
| 337 | 339 | |
| 338 | 340 | 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)); | |
| 340 | 342 | |
| 341 | 343 | describe("background timers run inside during", () => { |
| 342 | 344 | test("the scan reads each timer's first argument", () => { |
| @@ -407,6 +409,15 @@ describe("background timers run inside during", () => { | ||
| 407 | 409 | expect(callbacks("\n\nsetInterval(tick, 5);", "setInterval")[0]?.line).toBe(3); |
| 408 | 410 | }); |
| 409 | 411 | |
| 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 | ||
| 410 | 421 | test("each allowed entry names exactly one timer, and says why", () => { |
| 411 | 422 | const all = timers(); |
| 412 | 423 | for (const a of ALLOWED) { |
new above
offline
Two blank lines here; keep one.