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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy 0adf720
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
pageWorkruns, it wraps the server'sinFlight.during, the callhttp/server.tsmakes for every request. Each request then runs inside anAsyncLocalStorageholding 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()intest/helpers/statements.tstakes an optionalcountsfilter; its other callers are unchanged. - Guard: if a marked request was never opened through
inFlight.during,pageWorkthrows. If the server ever stops using that door, the budgets fail loudly instead of reading 0 and passing everything. - Budgets: none changed in
HEAVIERorDEFAULT.
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 skipsinFlight.duringis 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/originsby 8;/resilience,/forges/export.csvby 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.csvand/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 --fixandbun x tsc --noEmitare clean. The gate refused fixed waits, so the new test's handler waits on the loop's own ticks instead ofBun.sleep.scripts/fast.tsnamed 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 callsstatements()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
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.
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 everydb.querycall 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/crewread 62 against its budget of 60 on pulls that never touched it; here it reads 60. The retry inpages-budget.test.tsmeasures 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
srcchanges):pageWorkruns, it wraps the server'sinFlight.during, the callhttp/server.tsmakes for every request. Each request then runs inside anAsyncLocalStorageholding that request.x-test-measured: <uuid>header, and only statements that run inside that request's context are counted. For this,once()intest/helpers/statements.tstakes an optionalcountsfilter; its other callers are unchanged.inFlight.during,pageWorkthrows. If the server ever stops using that door, the budgets fail loudly instead of reading 0 and passing everything.HEAVIERorDEFAULT.What to look at:
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 skipsinFlight.duringis refused. Both tests fail on the old helper, which counted 14–28 for the same page.pages-budget.test.ts: 368 of 373 counts are identical. Five pages dropped (/metrics,/system,/settings/originsby 8;/resilience,/forges/export.csvby 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.csvand/pinned.Checks:
bun scripts/gate.ts --fixandbun x tsc --noEmitare clean. The gate refused fixed waits, so the new test's handler waits on the loop's own ticks instead ofBun.sleep.scripts/fast.tsnamed 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.test/kpis-landings-scale.test.ts, which callsstatements()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.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