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

Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:3f0ik8dh7l is past its budget: trevato/forge: "every GET page is within its counted work, warm, naming its slowest phase" failed on 11 pulls in the la… #15956

Merged opened this

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

Merged

The page budget now counts only the measured request's own SQL statements, so the check machine's load no longer changes its verdict. Cause. pageWork (test/helpers/work.ts) counted every db.query call in the whole test process while the measured request was open.

Notes

shipped production is serving it deploy 0adf720

opened this

The page budget now counts only the measured request's own SQL statements, so the check machine's load no longer changes its verdict.

Cause. pageWork (test/helpers/work.ts) counted every db.query call in the whole test process while the measured request was open. The test server shares that process with the background workers (the keep tick, the readers) and with work earlier requests leave running. On a busy check machine those statements landed inside the window and were counted as the page's. That is how /settings/crew read 62 against its budget of 60 on pulls that never touched it; here it reads 60. The retry in pages-budget.test.ts measures again immediately, without waiting for the process to go quiet, so a busy machine pays the same noise each time.

Change (test helpers only; nothing in src changes):

  • Which request a statement belongs to: the first time pageWork runs, it wraps the server's inFlight.during, the call http/server.ts makes for every request. Each request then runs inside an AsyncLocalStorage holding that request.
  • Counting: the measured request carries an x-test-measured: <uuid> header, and only statements that run inside that request's context are counted. For this, once() in test/helpers/statements.ts takes an optional counts filter; its other callers are unchanged.
  • Guard: if a marked request was never opened through inFlight.during, pageWork throws. If the server ever stops using that door, the budgets fail loudly instead of reading 0 and passing everything.
  • Budgets: none changed in HEAVIER or DEFAULT.

What to look at:

  • New test, test/page-work-own.test.ts: a 3-statement handler runs while a loop queries the same database every millisecond. It reads exactly 3, and a server that skips inFlight.during is refused. Both tests fail on the old helper, which counted 14–28 for the same page.
  • Before and after over every walked page in pages-budget.test.ts: 368 of 373 counts are identical. Five pages dropped (/metrics, /system, /settings/origins by 8; /resilience, /forges/export.csv by 1), which is the background noise leaving. Between repeat runs the old counter jumped by 8–9 on random pages; the new one moves by at most 1, on /forges/export.csv and /pinned.
  • Not covered: git process counts still come from the process-wide record. Every failure in the evidence was SQL.

Checks:

  • bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. The gate refused fixed waits, so the new test's handler waits on the loop's own ticks instead of Bun.sleep.
  • scripts/fast.ts named 201 files (about 16 minutes, over its budget), so I ran the 77 test files that import the changed helpers instead: 524 passed, 2 failed.
  • Both failures were in test/kpis-landings-scale.test.ts, which calls statements() without the new filter and so never reaches the changed code. Its "the count matches the per-row NOT EXISTS" test hit its 5 s timeout in this sandbox on main too (12–15 s there), so it is machine load, not this change.
  • The sandbox also refused one outbound connection, to parent.test:443, during that run.

Try it: bun test test/page-work-own.test.ts test/pages-budget.test.ts

🤖 Generated with Claude Code

Closes #15924

commented

The page budget now counts only the measured request's own SQL statements, so the check machine's load no longer changes its verdict.

Cause. pageWork (test/helpers/work.ts) counted every db.query call in the whole test process while the measured request was open. The test server shares that process with the background workers (the keep tick, the readers) and with work earlier requests leave running. On a busy check machine those statements landed inside the window and were counted as the page's. That is how /settings/crew read 62 against its budget of 60 on pulls that never touched it; here it reads 60. The retry in pages-budget.test.ts measures again immediately, without waiting for the process to go quiet, so a busy machine pays the same noise each time.

Change (test helpers only; nothing in src changes):

  • Which request a statement belongs to: the first time pageWork runs, it wraps the server's inFlight.during, the call http/server.ts makes for every request. Each request then runs inside an AsyncLocalStorage holding that request.
  • Counting: the measured request carries an x-test-measured: <uuid> header, and only statements that run inside that request's context are counted. For this, once() in test/helpers/statements.ts takes an optional counts filter; its other callers are unchanged.
  • Guard: if a marked request was never opened through inFlight.during, pageWork throws. If the server ever stops using that door, the budgets fail loudly instead of reading 0 and passing everything.
  • Budgets: none changed in HEAVIER or DEFAULT.

What to look at:

  • New test, test/page-work-own.test.ts: a 3-statement handler runs while a loop queries the same database every millisecond. It reads exactly 3, and a server that skips inFlight.during is refused. Both tests fail on the old helper, which counted 14–28 for the same page.
  • Before and after over every walked page in pages-budget.test.ts: 368 of 373 counts are identical. Five pages dropped (/metrics, /system, /settings/origins by 8; /resilience, /forges/export.csv by 1), which is the background noise leaving. Between repeat runs the old counter jumped by 8–9 on random pages; the new one moves by at most 1, on /forges/export.csv and /pinned.
  • Not covered: git process counts still come from the process-wide record. Every failure in the evidence was SQL.

Checks:

  • bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. The gate refused fixed waits, so the new test's handler waits on the loop's own ticks instead of Bun.sleep.
  • scripts/fast.ts named 201 files (about 16 minutes, over its budget), so I ran the 77 test files that import the changed helpers instead: 524 passed, 2 failed.
  • Both failures were in test/kpis-landings-scale.test.ts, which calls statements() without the new filter and so never reaches the changed code. Its "the count matches the per-row NOT EXISTS" test hit its 5 s timeout in this sandbox on main too (12–15 s there), so it is machine load, not this change.
  • The sandbox also refused one outbound connection, to parent.test:443, during that run.

Try it: bun test test/page-work-own.test.ts test/pages-budget.test.ts

🤖 Generated with Claude Code

Approved

Test-helper-only change, no src or page touched, so the security, terminal and docs items do not apply. It fits the pipeline-first direction: it makes the page budget stop flaking on a loaded check machine. The new test fails on the old helper, and the guard that throws when a request skips inFlight.during is a good fail-loud choice. Two things I would do next: (1) count git spawns per request the same way, since they still come from the process-wide record; (2) wrap inFlight.during once per test process and restore it in an afterAll, so the patch does not outlive the helper, and wrap the long throw line in work.ts so it reads at normal width.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs