Public: anyone can read this; the crew can change it.
Sentinel: shared:01m23vygyffx5hg2f5vm8r74sr:uq7lwkbwgh is past its budget: trevato/forge: "a large malformed numeric array is scanned in linear time" failed on 3 pulls in the last hour — the lan… #15171
Check · Review · Land · Live done — Landed and live in production.
The linear-scan test no longer fails when the check machine is loaded, because it now measures how the scan time grows instead of a fixed 250 ms limit. The changed test passes here, along with tsc and the gate. I didn't run the full suite; the forge runs it on the push.
shipped production is serving it deploy cfe12e4
2 earlier comments
The linear-scan test no longer fails when the check machine is loaded, because it now measures how the scan time grows instead of a fixed 250 ms limit. The changed test passes here, along with tsc and the gate. I didn't run the full suite; the forge runs it on the push.
What changed
- Test:
test/invalid-json-readers.test.tsnow times the malformed array[1,1,…,x]at 100,000 and at 400,000 elements, taking the best of three runs each. It requires the larger run to cost under 10× the smaller one. A scan that ran in linear time would cost about 4×, and a quadratic one about 16×, so a regression still fails. A uniformly slow machine slows both runs alike and doesn't trip it. - Scanner: In
src/http/json_body.ts,firstBadOffsetnow skips whitespace by comparing character codes instead of callingincludeson a string, so it does less work per character. The results are the same.
Not done: I didn't loosen the budget to some larger number, since that would only make the failure rarer.
To try it: run bun test test/invalid-json-readers.test.ts.
Pre-push refused the first push because no commit said how to try the change. I added an empty commit carrying a "Try:" line; that commit is not a code change.
The test "a large malformed numeric array is scanned in linear time" no longer depends on how loaded the check machine is. Before, it failed whenever the box was busy: three pulls went red at 308 ms against a fixed 250 ms limit, with no regression in the code.
- Test (
test/invalid-json-readers.test.ts): it now scans the malformed array[1,1,…,x]at 100,000 and at 400,000 elements, keeps the best of three runs for each, and requires the larger run to take under 10× the smaller one. Four times the input costs about 4× if the scan is linear and about 16× if it is quadratic, so a return of the old quadratic scan still fails. A busy machine slows both runs about equally, so load alone no longer fails it. The test still checks the exact byte offset at both sizes. - Scanner (
src/http/json_body.ts):firstBadOffsetskips whitespace by comparing character codes instead of calling" \t\n\r".includes(...)once per character, so the scan does less work. It returns the same results.
I did not raise the limit to a larger number, because that would only make the failure rarer. The test file, bun x tsc --noEmit and bun scripts/gate.ts --fix pass here; the full suite was not run here.
The new triage note on the issue only confirms the P0 Trust filing and needs no change. The commit starting "Try:" is empty; the pre-push hook asks for one that says how to try the change.
To try it: bun test test/invalid-json-readers.test.ts. Once main's next check is green, shared:01m23vygyffx5hg2f5vm8r74sr:uq7lwkbwgh should leave the degraded list.
🤖 Generated with Claude Code
The test "a large malformed numeric array is scanned in linear time" no longer uses a clock, so a slow check machine can't fail it. It now counts how many bytes the scan copies.
The first version of this pull swapped the 250 ms limit for a ratio of two timings. The flake gate (no raw wall-clock budget in a test (#4429)) refused that too, because it is still a clock bound.
- Test (
test/invalid-json-readers.test.ts): whilefirstBadOffsetscans[1,1,…,x]with 400,000 elements, the test wrapsString.prototype.sliceandsubstringto add up the length of every copy. It checks that total withexpectWork(copied, { max: 0 })and still checks the bad offset is 800,001. The old quadratic bug copied the rest of the body at every number (text.slice(i)), so the copied bytes grew with the square of the input. I put that old reader back temporarily and the test failed with 160,001,200,002 bytes copied; on the current reader it copies nothing. - Scanner (
src/http/json_body.ts, from the earlier commit): the whitespace skip compares character codes instead of callingincludesonce per character. The results are the same.
The test file, test/flake.test.ts, bun x tsc --noEmit and bun scripts/gate.ts --fix pass here. The check's other six failures (pages-budget, page-budget, wallet, repo-pages-timing) fail on main at 68e8710 too, and the check didn't count them against this pull.
To try it: bun test test/invalid-json-readers.test.ts test/flake.test.ts. Once main's next check is green, shared:01m23vygyffx5hg2f5vm8r74sr:uq7lwkbwgh should leave the degraded list.
🤖 Generated with Claude Code
Clean. The clock bound is replaced by counted work (copied bytes via slice/substring wrappers, restored in finally), which fails reliably on the old quadratic reader and never on a loaded machine. The charCode whitespace skip is behaviour-identical. No security surface touched, no new dependency, test file passes here.
The linear-scan test no longer fails when the check machine is loaded, because it now measures how the scan time grows instead of a fixed 250 ms limit. The changed test passes here, along with
tscand the gate. I didn't run the full suite; the forge runs it on the push.What changed
test/invalid-json-readers.test.tsnow times the malformed array[1,1,…,x]at 100,000 and at 400,000 elements, taking the best of three runs each. It requires the larger run to cost under 10× the smaller one. A scan that ran in linear time would cost about 4×, and a quadratic one about 16×, so a regression still fails. A uniformly slow machine slows both runs alike and doesn't trip it.src/http/json_body.ts,firstBadOffsetnow skips whitespace by comparing character codes instead of callingincludeson a string, so it does less work per character. The results are the same.Not done: I didn't loosen the budget to some larger number, since that would only make the failure rarer.
To try it: run
bun test test/invalid-json-readers.test.ts.Pre-push refused the first push because no commit said how to try the change. I added an empty commit carrying a "Try:" line; that commit is not a code change.
Closes #15153