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

Full suite red: test/boot-beside-peer.test.ts #16126

Merged opened this in answer to

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

Merged

test/boot-beside-peer.test.ts no longer fails when one /healthz probe times out on a loaded machine. I changed only the test. I didn't change the forge, so I don't know what stalled it in the failing run.

Notes

shipped production is serving it deploy 3fede26

opened this

test/boot-beside-peer.test.ts no longer fails when one /healthz probe times out on a loaded machine. I changed only the test. I didn't change the forge, so I don't know what stalled it in the failing run.

What was failing. In the failing run, a single probe took over 1 s. The forge's own log showed its event loop blocked for 223–812 ms while 4 test files ran at once. I read that as machine load, not the forge waiting on the peer's write lock.

What changed. A probe that times out is now retried once, and it counts as slow only if the retry also times out. The peer holds the lock for 1.5 s, which is longer than the 1 s probe timeout. A forge that really waited on the lock would therefore fail both attempts and still be caught.

Checks.

  • bun test ./test/boot-beside-peer.test.ts --rerun-each 3 passed all 3 runs.
  • bun x tsc --noEmit is clean.
  • I didn't run scripts/gate.ts. I didn't check whether the repo has scripts/gate.ts or scripts/fast.ts, so I used the issue's own rerun command instead of scripts/fast.ts.
  • I didn't run the 4-files-at-once load that triggered the failure, so the retry's effect under that load isn't confirmed.

Left alone. I didn't loosen the 1 s requirement or change the forge's startup. If the stalls are a real startup cost, that needs its own look.

Closes #16124

4 earlier comments · 2 events
commented

test/boot-beside-peer.test.ts no longer fails when one /healthz probe times out on a loaded machine. I changed only the test. I didn't change the forge, so I don't know what stalled it in the failing run.

What was failing. In the failing run, a single probe took over 1 s. The forge's own log showed its event loop blocked for 223–812 ms while 4 test files ran at once. I read that as machine load, not the forge waiting on the peer's write lock.

What changed. A probe that times out is now retried once, and it counts as slow only if the retry also times out. The peer holds the lock for 1.5 s, which is longer than the 1 s probe timeout. A forge that really waited on the lock would therefore fail both attempts and still be caught.

Checks.

  • bun test ./test/boot-beside-peer.test.ts --rerun-each 3 passed all 3 runs.
  • bun x tsc --noEmit is clean.
  • I didn't run scripts/gate.ts. I didn't check whether the repo has scripts/gate.ts or scripts/fast.ts, so I used the issue's own rerun command instead of scripts/fast.ts.
  • I didn't run the 4-files-at-once load that triggered the failure, so the retry's effect under that load isn't confirmed.

Left alone. I didn't loosen the 1 s requirement or change the forge's startup. If the stalls are a real startup cost, that needs its own look.

Changes requested — before the latest push

The retry weakens the regression this test guards. Fix first: do not let a second attempt absorb a lock wait.

  1. The comment says a forge waiting on the 1.5 s lock hold fails the retry too. That holds only if the first probe starts at the very start of the hold. Attempt 1 times out at 1.0 s and attempt 2 runs from 1.0 s to 2.0 s. A forge blocked until 1.5 s then answers attempt 2, and the test passes. The bug the test exists to catch (the forge blocking on the peer write lock) can now go unnoticed. Show with a test or a run against a deliberately blocking forge that the new loop still fails. Otherwise bound the two attempts by one deadline, so that a probe counts as slow whenever the total time to an answer exceeds the limit.
  2. The retry is a blanket mask for machine load. Direction says tests never flake, and a flake is better fixed by removing the load dependence than by retrying. Say how the 1 s requirement is still enforced, or add a separate assertion that keeps a held-lock stall visible.
  3. The summary admits the 4-files-at-once load was not reproduced, and scripts/gate.ts and scripts/fast.ts were not run. Run bun scripts/gate.ts --fix and files=$(bun scripts/fast.ts) && bun test $files, and report the results.
  4. A fast non-timeout error such as ECONNREFUSED is also retried silently. Retry only on a timeout.
commented

I took out the retry and changed what the test counts as slow, but it isn't flake-proof. A single stalled probe is now ignored, so a forge that really blocks on the lock is only caught if it times out at least twice. I didn't run a deliberately blocking forge to show that it still fails.

What changed in test/boot-beside-peer.test.ts

  • Retry gone. The second attempt could absorb a lock wait, as you said. Each probe is now one fetch with a 1 s timeout, so a probe that doesn't answer in 1 s is recorded as slow.
  • Timeouts only. Only a TimeoutError or AbortError counts as slow. A refused connection or a non-OK status goes into a separate refused list, and the test requires that list to be empty.
  • Two slow probes fail the test. I don't think a single-probe requirement can be removed from the load dependence. The log showed the forge's own thread blocked for 0.2–0.8 s by load, which can push one probe past 1 s. A forge waiting on the peer's 1.5 s write lock times out on every probe that starts early in a hold, and a run has several holds. So the test fails at two timed-out probes. A unit test (slowByLock) pins that rule: [] and [1001] pass, [1001, 1002] fail. This tolerates one stall, so it is a trade-off and not a full fix for the flake.

Checks

  • bun x tsc --noEmit is clean.
  • bun scripts/gate.ts --fix rewrapped comments in this file, and that is committed.
  • bun test ./test/boot-beside-peer.test.ts --rerun-each 3 passed 6 of 6 (3 runs of 2 tests).
  • scripts/fast.ts named 125 test files for this one-file change, about 10 minutes, over its 5-minute budget. I didn't run them, and the forge's full check will. I also didn't run the 4-files-at-once load.
Changes requested — before the latest push

Test-only change, so the preview has nothing to show and I have no UX findings. It is not yet a flake fix, and the new guard against a lock-blocked forge is not shown to work. Three changes, in this order:

  1. The new test pins slowByLock and not the regression. expect(slowByLock([1001,1002])).toBe(true) only restates length >= 2. It would pass even if the boot test never caught a forge blocked on the lock. Show that a forge that really blocks on the peer write lock still fails the boot test, or drop the tautology.
  2. Exporting a helper from a *.test.ts file is a pattern the repo does not have. Inline the rule or move it into a helper module that the test uses.
  3. The direction is tests that never flake, and this still flakes when two probes stall under load. Either bound the claim honestly in the code or remove the load dependence. For example, take the probes that start inside the hold window and require that none exceed the limit by a margin, or use the forge's own event loop stalled log to tell load from lock.

Smaller: refused.push(0) drops the error, and the log is printed only when slow is non-empty, so a refusal gives no diagnosis. Record the status or error name and print out when refused is non-empty.

commented

test/boot-beside-peer.test.ts now passes or fails on the forge's own log instead of on probe timing, so machine load can no longer turn it red (#16124). The verdict is whether any statement held the forge's thread for 1 s or more. The forge already logs every statement that holds its thread 200 ms or more ([sql] slow statement held the thread ms=N, src/kernel/slow_sql.ts). A forge waiting on the peer's write lock waits inside one of those statements, while a starved machine produces no such line.

  • Load vs lock: the boot test now requires heldThread(boot.out) to be empty. Probe timeouts are printed with the forge log for diagnosis but no longer fail the test. The "two slow probes" rule and its tautological unit test are gone. The event loop stalled assertion is dropped too, because a stall can come from load alone, which is exactly what made the suite red.
  • No helper exported from a test file: the rule lives in test/helpers/held-thread.ts (heldThread, HELD_MS = 1_000), and the test imports it.
  • Proof against a forge that really blocks:
    • A new test opens a real forge handle, times its statements the way src/main.ts does, and writes while the peer script holds the lock for 2 s. The forge's logged line is caught at 1 s or more.
    • By hand (not committed), I made waitForPeer write every 100 ms during the wait, like a forge that starts its own work. The boot test went red and named waits of 1565, 1546 and 1543 ms.
    • One write per 1 s poll was not caught, because it landed after the peer had let go. The test catches a forge that keeps writing beside the peer, not a single stray write.
  • Refusals: a refused probe now records status N or Name: message, and the forge log is printed whenever a probe is refused or times out.
  • Bound, stated in the code: the check only sees statements on the database handles the forge times (src/main.ts's and the worker's). A lock wait on a handle opened anywhere else would go unseen.

The gate, bun x tsc --noEmit and bun test test/boot-beside-peer.test.ts (2 pass) are green. This changes only tests, so the hold on releasing trevato/forge doesn't affect it.

🤖 Generated with Claude Code

commented

The latest comment says the full suite is green again, and the branch is already pushed and matches origin. I made no new changes.

What changed (already on this branch): test/boot-beside-peer.test.ts no longer judges the boot by probe timings, which a loaded machine can stall. The verdict now comes from the forge's own slow-statement log. A test also shows that a forge writing beside the peer is caught.

What I left out: I didn't add retries or raise the 1 s bound. Earlier commits tried retrying a slow probe, and I removed that.

How to try it: bun test test/boot-beside-peer.test.ts. I didn't re-run it here, because the forge's check run on f324950 already reported the full suite green.

commented

The suite now has a lock-holding test that checks against the forge's own log of statements that held the thread, not against probe times. This push gets two tests back under the 2 s per-test budget the check enforces. Neither file goes on the SLOW list.

  • test/boot-beside-peer.test.ts — the "forge's handle that writes while the peer holds its lock" test borrowed the ticking peer and held the lock for 2 s, so it took 2.21 s even when run alone. It now uses a one-shot peer: it takes the write lock with BEGIN IMMEDIATE, prints held, and lets go 1.4 s later (HELD_MS + 400 ms of slack for reading that line late). The forge's write still waits past the 1 s mark and is still logged as holding the thread. On its own the test takes about 1.5 s.
  • test/egress-literals.test.ts — this test also breached the budget (2.13 s in the check, 2.04 s alone). Its first two tests each transpiled every file under src/. It now transpiles only files whose text contains https:// or wss://, since only those can name a host, and caches each file's hosts for the rest of the suite. The test that took 2.04 s now takes 0.73 s. The test proving that a host in a comment doesn't count and one in a string does still passes.

What to look at: the 400 ms of slack is the trade-off. If a loaded machine reads the peer's held line more than 400 ms late, the forge's write waits under 1 s and the lock test fails rather than passing wrongly. No src/ code changed.

To try it: bun test test/boot-beside-peer.test.ts test/egress-literals.test.ts (both pass here). bun scripts/gate.ts --fix and bun x tsc --noEmit are clean.

🤖 Generated with Claude Code

Approved

Approved. The earlier asks, against the diff since 09164629:

  1. A retry must not absorb a lock wait: met. The retry is gone, and the verdict is now the forge's own [sql] slow statement held the thread lines, 1 s or more (test/helpers/held-thread.ts).
  2. Say how the 1 s requirement is still enforced: met. The new test a forge's handle that writes while the peer holds its lock is named as holding the thread shows a real blocking write is caught. It would fail if the check were loosened.
  3. Retry only on a timeout: met. Non-timeout errors and bad statuses go to refused, which must be empty.
  4. gate and fast: reported run in the pull. I did not re-run them.

The change is test-only: no src/ code, no new dependency, and no page or terminal door is touched. The egress-literals speed-up keeps the comment-versus-string behaviour, and it caches per text.

Two things to do next:

  • Non-blocking: the lock test's 400 ms of slack (HOLD_PAST_MS) fails if the held line is read more than 400 ms late on a starved machine. That is the same load dependence the pull removes elsewhere. If it flakes, have the peer print held and then hold for a fixed time measured from the lock, or give the child a head start.
  • Non-blocking: the bound stated in the code (handles opened outside src/main.ts and the worker are unseen) deserves a follow-up issue, so a later handle gets timed too.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs