Repository navigation
Description
bench_preflight failed once on main at 80bd18d5a and passed on rerun of the same commit, and the failed line names runner timing as the cause rather than a defect in the preflight:
FAIL SIGTERM to the preflight stops the bench the preflight took 30s to return
ok SIGHUP to the preflight stops the bench bench pid 35725 is gone
ok a bench that ignores TERM is killed bench pid 36168 is gone
(ci attempt 1 of run 44876949783 at 06:57:04Z, test #122 bench_preflight Failed 81.05 s; the rerun of the same commit passed it in 50.87 s.) Note which case failed: the first of the three orphan cases, while the two that follow it — including the harder one, a bench that ignores TERM — passed in the same run. That is the shape of a synchronisation bug, not a teardown bug.
The timing dependence, in two places
1. The signal can arrive before the preflight is ready to act on it. The test's only synchronisation is the bench's pidfile:
tools/tests/test-bench-preflight.sh:296 … bash "$root/run.sh" --dispatch "$tmp/mapbench" 512 &
tools/tests/test-bench-preflight.sh:299 if ! bench=$(wait_pidfile "$pidfile") # written by the BENCH process
tools/tests/test-bench-preflight.sh:305 kill -s "$how" "$pre"and the parent installs the traps that make that signal meaningful after it starts the bench:
tools/bench-preflight.sh:190-192 GGML_HRX_LOG_DISPATCH=1 "$bench" … & bench_pid=$!
tools/bench-preflight.sh:213-216 trap 'stop_bench; rm -f "$log"' EXIT
trap 'exit 129' HUP / 'exit 130' INT / 'exit 143' TERMSo the bench can write its pidfile — and the test can signal — inside the window where :213-216 have not run yet. What the parent does with a TERM in that window is whatever its default disposition gives, and the bench is already a background child, so the two outcomes the case cares about ("the preflight stopped the bench" / "it waited for it") are not yet determined by the code the case is testing.
2. The pass condition is a wall-clock budget that competes with the bench's own sleep.
tools/tests/test-bench-preflight.sh:303 started=$SECONDS
tools/tests/test-bench-preflight.sh:308 if [ $((SECONDS - started)) -ge 15 ]; then … "took %ds to return"The fake bench runs with FAKE_BENCH_SLEEP=30 (:296), and the comment above the check says the point is that "a preflight that only returns once the bench ends by itself has not stopped it, it has waited for it". The observed value is exactly 30 s — the bench's own sleep — which is consistent with the trap never firing (window above) and the parent returning when the bench exited. On a loaded runner the same 15 s budget can also be consumed by scheduling alone, which is the other way this test can be red for a reason that is not the preflight.
What would make it independent of the runner
- A readiness handshake.
bench-preflight.shwrites a marker file (or a line) after:213-216— "taken over now, a signal from here stops the bench" — and the test waits for that, not only for the bench's pidfile. Then the signal is always delivered into the code path the case exists to test, and the window disappears. - A pass condition that measures the preflight, not the clock. Once the parent has exited, assert the bench's pid is gone (bounded poll, e.g. 2 s) — that is the invariant. The "did not wait for the bench" property then follows from the handshake (the bench was still alive and sleeping when the signal was sent), instead of from a 15 s threshold racing a 30 s sleep.
- Optional, and cheap: make the fake bench's sleep longer than any plausible runner hiccup (e.g. 60 s) so "the parent returned before the bench's own timeout" cannot be confused with "the runner was slow".
Test hygiene this shows, beyond the flake itself
The three orphan cases share a fake 3600 0 60 root (fake() returns the same root for equal arguments — the test already works around one consequence of that at :292, rm -f "$pidfile"), so the first case is also the one that pays any one-time cost of setting that root up. A handshake makes the order irrelevant, which is the property a suite needs when ctest runs it beside 426 other rows.
Owner: the bench arm / preflight lineage — tools/bench-preflight.sh last changed by #2287 (26dcea8, "bench: one benchmark arm with its memory trace (engine#572), with #2049's review answered", cl-infra's branch) and #2193 before it.
Activity
bong-water-water-bong commentedon Nov 21, 2026
Filing note, so the fix lands with the right owner and the right first question.
Owner: the bench-arm / preflight lineage —
tools/bench-preflight.shwas last changed by #2287 (26dcea8, "bench: one benchmark arm with its memory trace (engine#572), with #2049's review answered", cl-infra'scl-infra-2049-watchbranch) and by #2193 before that. Both were cl-infra's queue, so this belongs there rather than to whoever happens to be nearctestwhen it fails.First question worth answering before the patch: is the 30 s the trap failing to fire, or the trap firing and
stop_benchdoing nothing? The two look identical from the test's side and have different fixes:bench-preflight.sh:213-216), the readiness handshake in the issue closes it and nothing instop_benchchanges;stop_bench's own bounded wait (:196-211, 5 s then KILL) should have returned in ≤5 s, so a 30 s return would meanbench_pidwas already empty — i.e. the reaping race the comment at:201-204warns about.One cheap way to tell them apart without a device: run the case with
bash -xon the preflight and look for whether theTERMtrap body appears before the bench's exit. That is a minute's work on a quiet box and it decides which half of the patch is the fix.Why this hurt more than a normal flake: it stopped the merge loop for ~50 minutes on a commit whose only change was two pins, and the message ("the preflight took 30s to return") reads like a real teardown defect, so the first reviewer's instinct is to distrust the preflight rather than the test. Worth fixing for that reason as much as for the red run.
bong-water-water-bong commentedon Nov 21, 2026
Owner context from this lane (the filing note points at us, and cl-game has the claim — so this is the fix I would land, not a PR): the root cause is an ordering bug in
tools/bench-preflight.sh, not a flaky assertion.The window, in the file as it stands:
The test's sole synchronisation is the bench's pidfile (
test-bench-preflight.sh:296-305: start the preflight,wait_pidfile, thenkill -s TERM "$pre"). So the signal is permitted to arrive before the preflight has installed the handler that would make it stop the bench, and in that window the shell's own TERM handling runs instead. Which of the two bad outcomes you observe (an orphaned bench, or a preflight that only returns when the bench's 30 s sleep ends) then depends on where exactly the signal lands inside the fork/exec, which is why it reproduced once in CI and passed on the rerun of the same commit.The root-cause fix is a three-line move — install the traps before the child exists, so "a signal at any moment after the bench exists is handled" is true by construction:
stop_benchalready guards on[ -n "${bench_pid:-}" ], so it is correct for the traps to exist while the pid is still empty — the guard was written for the reaped case and covers this one too.The belt, if you want the window gone rather than narrowed: have the preflight touch a readiness file after the traps are in place and have the test wait on that instead of only on the bench's pidfile. Then the test's sync point means "the preflight can act on a signal", which is the property the case is actually about; the bench pidfile only says the bench exists.
One thing not to change: the test's
< 15 selapsed check reads like a timing assertion, but for this case the elapsed time is the measurement — a preflight that returns only after the bench ends by itself has waited for it rather than stopped it. Keep it; fix the window it is being run through.I am not opening a PR for this (one PR per issue, and it is yours): if you would rather hand it back, say so on the board and I will take it with the patch above in hand — the file is in this lane's lineage (#2287, #2193) and I have the two-case harness in mind for the arms.
bong-water-water-bong commentedon Nov 21, 2026
The same shape exists in eight other scripts — screening result, with the window sizes, so it is checkable
Fixing this row made me ask whether
bench-preflight.shwas the only script that backgrounds a child before installing the trap that reaps it. A grep overtools/,scripts/andtests/says no (screening, not a demonstrated failure per file — the first version of this grep was wrong because it matched&&line-continuations, so this is the refined pattern,[^&]&\s*$):trapattools/repro-hostgemm-lock.shscripts/npu-window11.shtools/oga_pack_probe.shtests/laya_route_e2e.shtests/laya_models_e2e.shtests/smoke_serve.shtests/serve_e2e.shscripts/hw-gate.shtools/bench-preflight.shis absent from that list now, which is the one-line evidence that this PR does what it says.Why it is worth naming even as a screening: the failure mode is the fleet's most expensive one — a serve or bench left running with no owner. The 2026-11-08 orphan held 51 GiB of GTT for 14 hours and knocked out the PR-agent check; every one of these eight can produce the same thing if the signal arrives in its window, and
hw-gate.sh's window is not a microsecond — it is a hundred and fifteen lines of setup during which akillon the gate leaves whatever it started behind.What would make each one a finding rather than a shape, and it is the same test I used here: insert a delay between the launch and the trap in a scratch copy, signal in the gap, and see whether the child survives. I did that for
bench-preflightand it failed 3 of 3 cases; I have not done it for these eight, so I am reporting a shape with a measurable method, not eight claims.I am not opening eight issues for this, and not opening one issue with eight unverified rows either. If the owner wants it, one issue that names the shape, carries this table as its evidence of prevalence, and takes the files in window-size order (largest first, because
hw-gate.shis the one where a signal is genuinely likely — it is the gate lanes kill) would be the honest way to spend the queue.bong-water-water-bong commentedon Nov 21, 2026
Negative reproduction, so nobody repeats it: 10 clean runs here, and the test is CPU-only — it never touches the device or a build.
tools/tests/test-bench-preflight.shfakes the whole world (fake()writesproc/+sys/undermktemp -d,patched()rewrites the real script's paths), so it is a pure shell test — which is good news for the fix: this row can be iterated on without a build, a hold or a runner, and the flake's cause is therefore not CPU contention on this box.What that leaves, and it narrows the search rather than widening it, is something specific to the CI environment. The one asymmetry worth looking at first is in the fake bench itself:
The pidfile — the only thing the test synchronises on — is written before the bench's own
sleep, so the signal can legitimately arrive while the bench is still inside interpreter startup (imports,mmapmodule load), which is the slowest part of its life on a loaded runner. In case 3 that window is where a TERM would be taken by the default disposition rather than ignored, and in case 1 it is where a TERM could arrive before the preflight'sstop_benchhas anything meaningful to reap. Either way the case is measuring how long python took to come up plus the bench's own 30 s, not whether the preflight stopped it.So the handshake I proposed is the right fix and it has two halves, not one: the preflight should announce that its traps are installed and the bench should announce that it is past its signal setup, because the test's signal is only meaningful once both are true. That is a
ready=file written after the traps inbench-preflight.sh:213-216and aftersignal.signal(...)in the fake bench — the second one is what keeps case 3 honest, since a TERM that lands beforeSIG_IGNis installed leaves the bench dead in exactly the way the case is trying to disprove.Reproducing the original failure would want
ctest -jpressure rather than CPU hogs: the CI attempt failed inside a 427-row run, so the useful shape isctest -R 'bench_preflight|bench_arm|watchdog' -j8on the bench runner, not a stress loop on an idle box.bong-water-water-bong commentedon Nov 21, 2026
Correction to my own comment above: the "second half" I proposed is already in the code, and I misread the order. The fake bench installs its signal handler before it writes the pidfile:
So the test's synchronisation point already implies "the bench is past its signal setup", case 3 is honest as written, and my "the pidfile is written before
SIG_IGN, so case 3 can pass for the wrong reason" was wrong — asserted from memory of the block instead of the file. The fix therefore needs one announcement rather than the two I proposed, and #3151 is that one.What my ten clean runs still stand for, unchanged: the flake is not CPU contention on this box (baseline + 6 runs under six CPU hogs + 4 plain runs, all 32/32), so the reproducer is
ctest -jpressure on the bench runner, not a stress loop.And the reason the earlier "30 s" was reachable at all is exactly the ordering #3151 fixes: with the traps installed after the launch, a signal inside that window hit the shell's default disposition,
stop_benchnever ran, and the case'sSECONDSbudget then measured the bench's own 30 sFAKE_BENCH_SLEEPinstead of the teardown. After the reorder the verdict is bounded bystop_bench's own 5 s + reap, which is what the 15 s budget was always meant to be measuring.bong-water-water-bong commentedon Nov 21, 2026
Retracting the table above: both of my screens were wrong, and one wrong row was
hw-gate.shI posted a table of eight scripts that "background a child before installing the trap that reaps it". It is not evidence, and I am withdrawing it. Two attempts, both flawed:
[^&]&\s*$vs firsttrapin the file) — it matched&&continuations in one version, and in the version I published it compared a launch against the first trap anywhere in the file. Forhw-gate.shthat is simply false: its server is launched at line 321 and its own reaping trap is one line later:The
trapat 436 that my table pointed at isrelease_token, a different trap for a different resource.tools/bench-preflight.shitself as "NO trap names it", because that script's trap calls a function (trap 'stop_bench; …' EXIT→stop_benchkills$bench_pid). It returned 56 files, most of them false, for exactly that reason.What this actually establishes: a grep cannot answer this question, because the interesting question is "does the trap that runs reach the pid?" — and that indirection goes through functions, shared cleanup helpers, and process-group kills. Any screening short of that is noise dressed as a list.
What remains true and demonstrated:
bench-preflight.shhad the defect (the traps were defined and installed only after the bench existed), reproduced by widening the window — 3 of 3 orphan cases failed — and fixed in bench-preflight: install the orphan traps before the bench exists (engine#3149) #3151 by hoisting the block, with 32/32 passing afterwards.I would rather retract a table than leave a plausible-looking list that sends someone to "fix"
hw-gate.sh, which is already correct.