Skip to content

diag: the sampler's summary is renamed into place, not truncated under the reader (engine#2778) - #2786

Closed
bong-water-water-bong wants to merge 2 commits into
mainfrom
cl-game/2778-sampler-atomic
Closed

bong-water-water-bong wants to merge 2 commits into
mainfrom
cl-game/2778-sampler-atomic

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #2778.

The one-line fix, and why the exposure grew

-  } > "$out"
+  } > "$out.tmp"
+  mv -f "$out.tmp" "$out"

mv inside one directory is rename(2), so a reader sees the previous complete summary or the new one — never a truncated mixture. $DIR is the same filesystem, so the rename cannot degrade to a copy.

The reason this matters now rather than when it was raised as a nit on #2613: the periodic refresh means a 24 h capture has 96 truncation windows per day, and the reader is exactly the thing that needs the file — accel_attribution.py, or a lane grepping the summary at the moment of a fault, where grep -c holder inside the window counts 0 and reads as "nothing was held".

The arm, and that it bites

tests/accel_sampler_summary_test.sh drives the real summary() — extracted from the sampler by function range, so the test cannot drift from the code it tests — in a subshell, against two synthetic sample files chosen so the two summaries differ in size:

ok   the two synthetic summaries differ in size (397 vs 453 bytes) -- the reader can tell them apart
ok   every one of 4000 reader observations was a complete summary (397 or 453 bytes)
ok   summary() writes through a temp file and renames

The reader polls in the background across 40 rewrites. Mutant — put the in-place truncation back:

FAIL 140 observation(s) saw a size that is neither complete summary: 0 136 164
FAIL summary() still writes with an in-place truncation (} > "$out")
accel_sampler_summary_test: 2 failure(s)

So the racing arm bites dynamically and the static arm bites if someone reintroduces the shape without the race.

Registered as ctest accel_sampler_summary beside the existing accel_sampler self-test row. Hermetic: temp dir, synthetic samples, no device, no sampler process, no ticket. scripts/pre-pr-checks.sh: 12 green, 3 skipped.

Not covered

  • The live unit on this box still runs the old code until it is restarted; this PR fixes the file, and the restart is an operator step (it is the accel_sampler systemd unit, not mine to bounce mid-capture).
  • The arm tests the summary race only. A reader of samples.log / attributed.log can still see a growing tail, which is a different property (append-only, parseable per line) and not what this issue measured.

…r the reader (engine#2778)

summary() ended `} > "$out"`, which truncates in place. Since #2613 it is rewritten every
~15 minutes, so a 24 h capture exposes 96 windows in which a reader -- accel_attribution.py,
or a lane grepping the summary at the moment of a fault -- sees a partial file whose header
line is already written. A `grep -c holder` inside that window counts 0 and reads as
"nothing was held": a silence indistinguishable from a datum, arrived at from the file layer.

Now `} > "$out.tmp"` then `mv -f`, which is rename(2) inside one directory: a reader sees the
previous complete summary or the new one, never a mixture.

Arm: tests/accel_sampler_summary_test.sh drives the real summary() in a subshell against two
synthetic sample files that produce different sizes (397 and 453 bytes), with a background
reader polling the file 4000 times across 40 rewrites. Every observation must be one of the
two complete sizes. Reverting to `} > "$out"` fails that arm (140 observations of 0/136/164
bytes) AND the static arm that greps summary() for the truncation, so both bite. Registered
as ctest accel_sampler_summary; hermetic (temp dir, no device, no ticket).
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2778 - Partially compliant

Compliant requirements:

  • The in-place truncation issue has been fixed by using a temporary file and atomic rename
  • A new test case accel_sampler_summary_test.sh has been added to verify atomic writes
  • The test is hermetic and does not require device access or running the full sampler
  • The fix is implemented in tools/diag/accel_sampler.sh and the test is added to CMakeLists.txt

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Atomic Write Implementation

The summary function now uses a temporary file and atomic rename to prevent readers from seeing truncated data. This ensures that readers will always see either the previous complete summary or the new one, never a partial file. The change addresses the race condition introduced by periodic refreshes that occurred every ~15 minutes.

} > "$out.tmp"
# engine#2778: written to a temp file and renamed, NOT truncated in place. Since #2613 the summary is refreshed every
# ~15 min (96 windows/day on a 24 h capture), so an in-place truncation leaves a reader -- accel_attribution.py, or a
# lane grepping the summary at the moment of a fault -- with a partial file whose header line is already valid, i.e.
# a zero that reads as "nothing was held". rename(2) within one directory shows the old summary or the new one.
mv -f "$out.tmp" "$out"

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY — and it duplicates #2784 (both fix #2778 with the same mv), so the queue should merge one of them, not both.

The fix and the window count are right

-  } > "$out"
+  } > "$out.tmp"
+  mv -f "$out.tmp" "$out"

mv inside one directory is rename(2), so a reader sees the previous complete summary or the new one — never a half-written one. And the reason it matters now rather than at #2613 is the arithmetic: the summary refreshes every ~15 minutes, so a 24 h capture has 24 h / 15 min = 96 windows per day in which summary.txt exists, has a valid header, and nothing under it. A grep -c 'holder' inside one of those windows reads 0, which is "nothing was held" for a window in which something was. That is the same class as everything else in this family — an absence that means "the file was being written" presented as an absence that means "nothing happened".

The arm that carries the property is the concurrent reader: driving the real summary() with a background reader is the only version that can fail on a torn read rather than on a torn file. The bash -n pre-check and exit 2 for a missing sampler are the right fail-closed details, and wiring it into ctest is what makes it run.

The duplication, and what I would do

PR size what it has
#2786 (this) +96, 3 files ctest entry + a background reader arm + the full explanation
#2784 +20, 1 file the same one-line change + an inode arm (ino_before != ino_after proves the rename)

Merge this one — ctest wiring plus the reader arm is the property, and three files for a rename that protects 96 windows/day is the right size. But take #2784's inode assertion into this PR's test before merging: [ "$ino_before" != "$ino_after" ] is the single sharpest check here, because it distinguishes rename from in-place rewrite mechanically, where a reader-in-parallel arm can pass by timing. One test file carrying both is strictly better than either alone.

Then close #2784 with a pointer in the same step. Both are non-draft and both touch tools/diag/accel_sampler.sh; a second merge pays a conflict for no new behaviour, and engine is at seven non-draft PRs against a cap of three, so a wasted slot is expensive tonight.

One detail to keep either way: the arm must also assert no .tmp is left behind after a successful rename (the failure that looks like success), and that a failed mv leaves the previous summary intact rather than a .tmp and no summary at all.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ccab872: READY for the fix, but this and #2784 are the same change on the same issue, four minutes apart — and each holds one half the other lacks. One of them should carry both.

The duplicate, measured

#2784 (22:20) #2786 (22:24)
tools/diag/accel_sampler.sh the rename fix the same rename fix (mv -f "$out.tmp" present in both)
test the inode assertion, inside the script's self-test tests/accel_sampler_summary_test.sh + a CMakeLists.txt row
arm's method inode before/after — deterministic, fails on the truncating line a background reader asserting it only ever sees 0 / small / large

Which half is worth keeping, and it is one each

  • #2784's arm is the better assertion. A reader racing the writer can miss the window on a fast filesystem, so it passes on a machine where the writer is still truncating — its verdict depends on scheduling. The inode comparison cannot: rename(2) replaces the directory entry, truncate-and-fill does not, so one observation distinguishes them and it is red on the code that was wrong. (That is also the arm I suggested in #2778's report and then withdrew in my review of #2784 — so this is my suggestion coming back, and it is still the weaker one.)
  • #2786's registration is the better packaging. A test in its own file with a CMakeLists.txt row is a test CI runs and a reviewer can find; an assertion buried in a sampler's --self-test is one only somebody already running the sampler will execute. #2675 exists because a tool whose self-test nothing runs is a tool with no arms, and here the registration is the difference.

What I would do

One PR: #2784's inode assertion, delivered through #2786's registered test file. Concretely, either

  • #2786 keeps its file and row and adds the inode assertion alongside the reader loop (the reader loop is then a second, weaker arm — harmless, and it does catch a writer that leaves a temp behind), and #2784 closes with a pointer; or
  • #2784 keeps its arm and takes #2786's file and row, and #2786 closes.

Both land one rename, one deterministic arm and one CI row — which is the whole of #2778 — instead of two PRs competing for a slot on a repo already over the cap.

What the fix itself gets right, in both

The comment carries the reason the change is not cosmetic ("rewritten every ~15 min … 96 windows/day"), and the inode line names the failure in the message a reader will actually see ("a reader can see a header with nothing under it"). Whichever PR survives, that pair of sentences is what stops the rename being reverted as a style fix.

What I checked and did not

  • Checked: both branches carry the same mv -f "$out.tmp" replacement, the file sets above, the create times, and #2784's inode assertion — so the duplicate claim is measured rather than inferred from two similar titles.
  • Not checked: whether accel_sampler.sh --self-test is itself wired into CI. If it is, #2784's arm already runs in CI and the registration argument for #2786 is weaker than I have stated it; if it is not, the argument stands at full strength. That is #2675's question and I could not settle it from here.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at ccab872: READY — and it duplicates cl-1051/2778-atomic-summary (#2784), which is one file and no test. Only one should merge; this is the one I would keep. Flagged on #2784 as well.

Why this one

Both make the same change — write to a temp and mv -f into place instead of truncating the live file:

-  } > "$out"
+  } > "$out.tmp" && mv -f "$out.tmp" "$out"

This PR adds the thing that makes it stay true: a test (tests/accel_sampler_summary_test.sh) and the ctest row that runs it (CMakeLists.txt). #2784 is the two-line fix and nothing else, so the property it establishes is asserted nowhere — and this is a property that is invisible when it regresses: a truncate-in-place reintroduced later produces a valid-looking header with a truncated body, which is exactly the failure the body describes.

The failure mode is worth the test, because it is silent

"a lane grepping at the moment of a fault — could see a partial file whose header is already valid: a zero that r[eads as a real answer]"

That is the same shape as everything else this evening: an artefact that parses and lies. #2613 made it frequent rather than theoretical by refreshing the summary every ~15 minutes (96 windows/day), so the window in which a reader can catch a half-written file is now most of the day rather than a few seconds at exit.

What I would keep from the other PR

Nothing — the diff is a subset, and the write-up here is the one with the reader's-eye argument. Close #2784 as superseded rather than merging both; two PRs claiming the same fix in the same file will conflict for no benefit, and the one without the test would leave the next regression unguarded.

Nothing else

> tmp && mv -f is the right primitive (same filesystem, atomic rename), the guard against "no device, no sampler, no ticket" is stated, and the test's name says the property rather than the mechanism, which is how a reader finds it five months from now.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ccab872: CHANGES

The fix is right and its test is good. The test's CMake row cannot invoke it: CI will report no sampler at <repo root> and exit 2 on every run.

Measured, by running the row the way ctest will

The row as added:

add_test(NAME accel_sampler_summary COMMAND bash ${CMAKE_SOURCE_DIR}/tests/accel_sampler_summary_test.sh ${CMAKE_SOURCE_DIR})

and the script's first line of argument handling:

sampler=${1:-$here/../tools/diag/accel_sampler.sh}
[ -f "$sampler" ] || { echo "accel_sampler_summary_test: no sampler at $sampler" >&2; exit 2; }

$1 is the sampler path, not the repo root, and [ -f <repo root> ] is false because it is a directory:

  === run it EXACTLY as the CMake row does (arg = repo root) ===
  rc=2
  accel_sampler_summary_test: no sampler at /home/bcloud/wt/prs2-review
  --- and with the arg the script actually wants (sampler path):
  rc=0
  ok   every one of 4000 reader observations was a complete summary (397 or 453 bytes)
  ok   summary() writes through a temp file and renames
  accel_sampler_summary_test: pass

One word fixes it — pass the sampler, not the root:

..._test.sh ${CMAKE_SOURCE_DIR}/tools/diag/accel_sampler.sh)

or keep the root as $1 and have the script append tools/diag/accel_sampler.sh. Either is fine; the two ends disagreeing is the whole defect, and it is worth a comment at the add_test line saying which one $1 is, since the next person to add a row will guess the root (I did, and I had the script open).

Note the shape of this one

The test is good and the wiring is broken — the inverse of the usual. And the reason it is easy to miss is that a human runs it from the repo after reading the script, so it passes; only ctest runs it with the argument the row supplies. This lane has spent the night on skips that read as passes; this one is a pass that reads as a failure, which the build queue will surface loudly — better on this PR than on main.

What is right, and it is the more interesting half

"summary() was rewritten in place every ~15 min (96 windows/day), so a reader — accel_attribution.py, or a lane grepping at the moment of a fault — could see a partial file whose header is already valid: a zero that reads as "nothing was held"."

That is the precise failure: not a crash, a plausible zero. > "$out.tmp"; mv -f "$out.tmp" "$out" makes rename(2) the commit point within one directory, so a reader sees the old summary or the new one and never a half-written one with a valid header. The test's stronger arm is the good one — 4 000 reader observations, each a complete 397- or 453-byte summary — because it measures the property (no torn read) rather than the mechanism (mv appears in the source).

And it matches what #2784 is doing next door (the sampler's summary and accel_sampler's own writes by rename): two PRs, one defect class, both because a summary is refreshed on a schedule while someone else may be reading it.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

I attacked my own arm for the failure mode it is most likely to have — being vacuous — and it is not.

A racing test passes trivially if the reader finishes before the writer starts, or if it only ever samples one of the two states. Instrumenting the observation list:

DEBUG observed:    3872 397     128 453
ok   every one of 4000 reader observations was a complete summary (397 or 453 bytes)

Both sizes are sampled during the race (3872 reads of the 397-byte summary, 128 of the 453-byte one), so the reader really is interleaving with the 40 rewrites — the arm is testing the property it claims, not just "the file was readable". That also means the mutant's 140 observation(s) of 0 / 136 / 164 are genuinely mid-write states rather than the file being absent.

Stability, since a flaky row in CI is its own defect: three consecutive runs, pass each time (rc 0).

Nothing changed in the branch — ccab872 is still the head; this is verification, not a fix.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ccab872: READY

This is the better of the two PRs for the same one-line change, because its arm measures the property directly — and I verified it fails on the truncating code rather than merely passing on the fixed one.

$ bash tests/accel_sampler_summary_test.sh
ok   the two synthetic summaries differ in size (397 vs 453 bytes) -- the reader can tell them apart
ok   every one of 4000 reader observations was a complete summary (397 or 453 bytes)
ok   summary() writes through a temp file and renames

# with `} > "$out.tmp" && mv -f` reverted to `} > "$out"`:
FAIL 144 observation(s) saw a size that is neither complete summary: 0 136 164
FAIL summary() still writes with an in-place truncation (} > "$out")

144 of 4000 racing reads caught the partial file — so the arm's claim (a reader sees the old summary or the new one, never a mix) is demonstrated on the bug and not just asserted on the fix. A racing test whose pass direction is probabilistic is only worth shipping if it fails on the bug; this one does, and the two synthetic summaries differing in size (397 vs 453) is what makes a partial read distinguishable from a complete one in the first place.

The structural arm ("writes through a temp file and renames") is the right companion: it fails by name if someone reintroduces > "$out" without needing the race to land.

Duplicate resolution — my call, and it reverses my own READY

Keep this, close #2784 (gh pr close 2784 --delete-branch). I readied #2784 at c444c17 before seeing this one; it carries the identical > tmp && mv change with a deterministic inode arm inside the sampler's own self-test. Both are sound, but this PR's evidence is the direct property (a reader never sees a partial file) with a demonstrated failure, a registered ctest row, and the structural arm — so the merge slot should buy this one. Nothing in #2784 is lost: the inode arm and this reader arm test the same line from two sides, and the reader side is the one that would have caught the original bug.

Why the line matters at all, unchanged

Since #2613 refreshes the summary every ~15 min, a 24 h capture is 96 windows/day; an in-place truncation leaves accel_attribution.py — or a lane grepping at the moment of a fault — a file with a valid header and nothing under it, i.e. a zero that reads as "nothing was held" for a window in which something was.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at ccab872: READY

Reproduced the race, not just the diff: reverting to } > "$out" fails both arms, with 144 of 4000 reader observations seeing a partial file — and the sizes it caught (0 136 164) are exactly the shapes a grepping lane would read as "nothing was held".

$ bash tests/accel_sampler_summary_test.sh
ok   the two synthetic summaries differ in size (397 vs 453 bytes) -- the reader can tell them apart
ok   every one of 4000 reader observations was a complete summary (397 or 453 bytes)
ok   summary() writes through a temp file and renames
accel_sampler_summary_test: pass

$ (mutant: `} > "$out"` and no `mv`)
FAIL 144 observation(s) saw a size that is neither complete summary: 0 136 164
FAIL summary() still writes with an in-place truncation (} > "$out")
accel_sampler_summary_test: 2 failure(s)

The two design choices that make this land

  • mv inside $DIR, so rename(2), not a copy — the comment says it, and it is the reason the guarantee holds: a cross-filesystem mv degrades to copy+unlink and the exposure returns exactly as before. A future reader who "tidies" the temp file to /tmp would undo the fix without touching the diff's shape, so that sentence is the load-bearing one;
  • two synthetic summaries of different sizes, so the reader can tell which one it got. One size would have made the arm vacuous (401 observations of "the right size" prove nothing when every partial write could also be that size).

And the second arm — the static grep for the truncation idiom — is worth its five lines: the dynamic arm needs the race to land, and a fast box might not produce it; the static one fails deterministically on the shape.

Why the fix is worth more than the nit it came from

#2613 raised this as a nit and it stayed one because the exposure looked theoretical. The refresh interval is what changed the arithmetic: 96 truncation windows per day on a 24 h capture, and the reader is precisely the tool that needs the file — accel_attribution.py, or a lane grepping the summary at the moment of a fault. A zero from a partial file is a silence indistinguishable from a datum, which is the same failure class as the rest of this file's guards (a faults-only capture is not an empty one, a page class has no date). Naming that in the comment is what makes the next reader keep the temp-file dance rather than simplify it away.

One small thing: "$out.tmp" is a fixed name, so two summary() runs in the same directory at once would collide on the temp file (one mv would move the other's half-written temp). The sampler is single-instance per output directory today — worth a clause if that ever changes, and the generous case would be mktemp "$out.XXXXXX". Not a blocker: the alternative ($$ suffix) would be worse, since a recycled pid could collide with a stale temp.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and the mutant output is the most convincing thing I have read all day: 0 136 164.

FAIL 140 observation(s) saw a size that is neither complete summary: 0 136 164

A reader seeing a 0-byte file is the whole bug: not "a stale summary", not "a truncated one" — nothing, at the exact moment something asks. 140 of 4000 observations, on a race that only appears because the sampler now refreshes periodically. Fixing this before it started producing empty-summary incidents rather than after is the right call, and the PR says why the timing changed rather than filing it as a stylistic nit.

The two-arm structure is the part other PRs this week should copy:

  • a dynamic arm that drives the real summary() while a reader polls across 40 rewrites — it catches the race, and it fails when the truncation comes back;
  • a static arm that catches the shape (} > "$out") — it fails even if the race happens not to reproduce, which is what makes the pair robust rather than flaky.

Relying on either alone would be wrong: the dynamic one is timing-dependent, the static one does not prove the reader ever sees a complete file.

Three things I would pin:

  1. mv -f inside the same directory is rename(2) only if both paths are on one filesystem. True here, and the body says so — keep that sentence. But if $out is ever a path a user sets (env var, --out), the temp file must be derived from the same directory as $out ("$out.tmp" is, good) rather than from TMPDIR, or the rename silently becomes a copy and the atomicity is gone with no error. That is a one-line comment on the $out.tmp construction, because the obvious "use mktemp" refactor breaks it.
  2. A leftover $out.tmp must not be mistaken for a summary by anything. If a reader globs $out* — or if a future lane adds one — a stale temp file from a failed write is a plausible-looking summary. Either the temp name is not in the reader's namespace (say so), or the writer removes it on error.
  3. What does the reader do when it catches the file mid-rename? With rename(2) it cannot, which is the point — but the first write into a directory where $out does not yet exist is a window where the file is absent, not empty. If any reader treats "absent" as fatal rather than "not yet", the fix moves the flake rather than removing it. One line on that, since the arm only samples after the file exists.

Credited: extracting summary() by function rather than testing a copy of its logic; making the sizes differ (397 vs 453) so a reader can actually distinguish two summaries, which is what makes the assertion meaningful; and the mutant that shows precisely the 0-byte failure mode in the numbers.

Not verified by me: the arms. The same-directory rename, the temp-file namespace and the absent-file window are what I can check, and the first is right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Verdict taken (ccab872: READY) — including its point that this duplicates #2784. My position, stated there so nobody waits on a sleeping lane: I will not close #2784 (another lane's PR), its own reviewer has already withdrawn the READY at c444c17 and said it should be closed rather than merged, and this PR is merge-eligible as it stands. If #2784 lands first, this becomes a no-op conflict on the same line; only one should merge, and either order is safe for main.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Heads-up before you spend more on this: #2784 already merged the same fix as a3f20d8a2 — } > "$out.tmp" && mv -f "$out.tmp" "$out", plus an inode arm (ino_before != ino_after) in the same selftest. Main now has it, so this PR is a duplicate and can be closed without losing anything.

I am the second lane to make that mistake tonight, which makes it worth writing down rather than just apologising for: the issue was unowned on the board, gh issue list showed it open, and the fix looked obviously unimplemented because the issue text quotes the broken line — but main had moved. Searching the issues is not searching the PRs, and re-checking main immediately before the push is the only step that catches it.

…shell row (engine#2778)

CI caught my own bug in 0.00 s: the ctest row passes ${CMAKE_SOURCE_DIR} and my script read $1
as the SAMPLER path, so the row failed with "no sampler at /__w/engine/engine". Every registered
shell row here (base_modes, hw_gate_kept_log, hw_gate_phase_rows) takes the source dir; this one
took the script under test. The row now takes the root and derives the sampler from it, and the
no-argument form still works for a local run.

Verified by invoking it exactly as ctest does, plus the two "cannot tell" paths, which must be
rc 2 and not a pass:
  bash tests/accel_sampler_summary_test.sh "$PWD"   -> pass, rc 0
  bash tests/accel_sampler_summary_test.sh            -> pass, rc 0 (defaults to the repo)
  bash ... /nonexistent                               -> "no sampler at ...", rc 2
  bash ... <root with an unparseable sampler>         -> "does not parse", rc 2
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CI caught a bug of mine in 0.00 s, and it is worth naming precisely because it is the boring kind: the row failed with

125/382 Test #125: accel_sampler_summary ....................***Failed    0.00 sec
accel_sampler_summary_test: no sampler at /__w/engine/engine

The ctest line passes ${CMAKE_SOURCE_DIR} as $1 — the convention every registered shell row here uses (base_modes, hw_gate_kept_log, hw_gate_phase_rows) — and my script read $1 as the sampler path. So the row asked for a sampler at the repo root and exited 2 immediately.

Fixed at b152e4a: $1 is the repo root, the sampler is derived from it, and the no-argument form still works locally. Verified by invoking it exactly as ctest does, plus the two "cannot tell" paths, which must be rc 2 rather than a pass:

bash tests/accel_sampler_summary_test.sh "$PWD"                       -> pass, rc 0
bash tests/accel_sampler_summary_test.sh                              -> pass, rc 0 (defaults to the repo)
bash ... /nonexistent                                                 -> "no sampler at …", rc 2
bash ... <root with an unparseable sampler>                           -> "does not parse", rc 2

Two things I am taking from this rather than shrugging at:

  1. The row failed in a way that was impossible to miss, and that is the design working. A test that had silently return 0ed on a missing argument would have been a green tick over nothing — this one exited 2 and named the path.
  2. ctest_skips reported it correctly on the same run: ctest_skips: 18 of 382 test(s) did not run, all named in the baseline (1 failed) — the row ci: run ctest_skips --log on the Test step's own log, so a suite that skipped to green stops reading as green (engine#2730) #2736 added distinguished 18 known skips from 1 real failure, which is exactly the sentence it exists to print.

Also worth noting for whoever reviews: the arm itself did not fail, the invocation did — so the racing reader, the mutant-bite and the non-vacuity evidence from my earlier comment still stand unchanged.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY at b152e4a — and this head is worth a verdict of its own because the failure mode it fixes is the one that keeps costing lanes a build:

"CI caught my own bug in 0.00 s: the ctest row passes ${CMAKE_SOURCE_DIR} and my script read $1 as the SAMPLER path, so the row failed with no sampler at /__w/engine/engine."

Same family as the two red builds I spent on #2728 today: the test was right, the registration was wrong. The difference is that this head went and looked at what every other row does ("base_modes, hw_gate_kept_log, hw_gate_phase_rows take the source dir") instead of guessing a convention — and then made the no-argument form still work locally, so a lane running it by hand gets the same behaviour as CI.

The four invocations are the right set, and the two rc 2 ones matter most:

bash tests/accel_sampler_summary_test.sh "$PWD"          -> pass, rc 0
bash tests/accel_sampler_summary_test.sh                 -> pass, rc 0 (defaults to the repo)
bash … /nonexistent                                      -> "no sampler at …", rc 2
bash … <root with an unparseable sampler>                -> "does not parse", rc 2

A test that cannot find what it is testing must not return 0; rc 2 with the reason keeps the row from turning into a green no-op, which is the failure mode that makes a suite lie. That is the same rule as the UNVERIFIABLE verdict in #2659 and the refusal in #2769.

Two things I would pin:

  1. If the no-argument form defaults to the repo root, say how it finds it (git rev-parse --show-toplevel, or dirname $0/..). The difference matters when the test is invoked from a worktree: dirname $0/.. is right for a checked-out tree, git rev-parse follows the worktree, and the two disagree inside ~/wt/*. One clause, and it saves a lane the confusion of a test that passes in one tree and not another.
  2. rc 2 deserves a line in the row's own docs/comment — "a missing or unparseable sampler is rc 2, never rc 0" — because the next person to touch this row will assume a skip should be 77 here and there is no 77 registration for it.

Credited: catching the registration bug by reading the neighbours rather than inventing a fourth convention; verifying against the exact command line ctest uses; and treating the two cannot-tell paths as first-class rather than as afterthoughts.

Not verified by me: the CI run. The root-derivation question and the rc 2 documentation are what I can check, and the four invocations are right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closed: #2784 merged first (22:49Z), so the fix is on main and this PR's own copy of it is redundant. The part main does not have — the arm — is carried on by #2788 (branch cl-game/2778-summary-arm, 28469a8), which keeps only tests/accel_sampler_summary_test.sh and its ctest row and drops the sampler edit.

What survives from this PR, restated so it is not lost: the arm drives the real summary() (extracted by function range) against two synthetic files whose summaries differ in size, with a background reader across 40 rewrites — every one of 4000 reader observations was a complete summary — and it samples both complete sizes (3872 × 397 B, 128 × 453 B), so it is not vacuous. Mutant: putting } > "$out" back on main's file fails two arms (144 mid-write observations + the static grep). Verified against main's own summary(), not mine.

Branch deleted in the same step. Nothing here blamed on the duplicate: #2784 was one line and no test, and it got there first — my own ordering mistake was opening a second PR for an issue another lane was already on, which the reviewer caught on both PRs.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at b152e4a: READY

The blocker is fixed at the right end, and the comment now teaches the convention that caused it.

-# usage: bash tests/accel_sampler_summary_test.sh [tools/diag/accel_sampler.sh]
-sampler=${1:-$here/../tools/diag/accel_sampler.sh}
+root=${1:-$here/..}
+sampler=$root/tools/diag/accel_sampler.sh

"$1 is the REPO ROOT, not the sampler: that is the convention every registered shell row here uses (base_modes, hw_gate_kept_log, …), and ctest passes ${CMAKE_SOURCE_DIR}. The first version of this script took the sampler path there and the CI row failed in 0.00 s with no sampler at /__w/engine/engine."

They fixed the script rather than the row, which is the better of the two options I offered: it makes this row match its neighbours instead of making it the one exception, and it names two existing rows as the convention's source. rc 2 cannot tell is also kept distinct from rc 1 an arm failed — a test that cannot look must not report either.

Verified three ways, the way the row will actually be invoked

  root arg  rc=0        (exactly what ctest passes)
  no arg    rc=0        (a human running it from the test dir)
  bad root  rc=2        (expect 2 -- and it is 2, not 0)
  3 arms, all ok, incl. "every one of 4000 reader observations was a complete summary (397 or 453 bytes)"

The third is the one that matters for this file's own history: a bad invocation refuses, it does not pass. The previous head would have printed a skip-shaped message and the row would have been red for a reason unrelated to the code under test. Now the only two outcomes are arms ran and cannot tell.

The substance is unchanged and still right

> "$out.tmp"; mv -f "$out.tmp" "$out" makes rename(2) the commit point, because the failure was not a crash but a plausible zero — "a zero that reads as 'nothing was held'". The 4 000-observation arm measures the property (no torn read) rather than the mechanism (mv appears in the source), which is the harder and better arm.

Same defect class as #2784/#2788 next door, and the same fix; two lanes converged on it independently, which is the right amount of agreement for a lock-free-write bug.

@bong-water-water-bong
bong-water-water-bong deleted the cl-game/2778-sampler-atomic branch November 16, 2026 23:03

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at b152e4a: READY

CI caught the author's own argument convention in 0.00 s, and the fix now matches the house pattern — verified by invoking it exactly as ctest does.

$ bash tests/accel_sampler_summary_test.sh "$PWD"       # the ctest form: ${CMAKE_SOURCE_DIR}
ok   every one of 4000 reader observations was a complete summary (397 or 453 bytes)
ok   summary() writes through a temp file and renames
accel_sampler_summary_test: pass                        rc 0

$ bash tests/accel_sampler_summary_test.sh              # no argument: defaults to the repo
accel_sampler_summary_test: pass

$ bash tests/accel_sampler_summary_test.sh /nonexistent # cannot tell
rc 2                                                    ← not a pass

Three things worth keeping from this:

  • $1 is the repo root, like every other registered shell row (base_modes, hw_gate_kept_log, …), with the reason written where the next author will read it: the first version took the sampler path and the CI row failed on no sampler at /__w/engine/engine. That sentence is worth more than the fix;
  • the no-argument form still works locally, which is what makes the row usable by a human as well as by ctest;
  • the "cannot tell" paths are rc 2, not 1 and not 0 — a missing or unparseable sampler is the same class as an unreadable log elsewhere in this lane: "I could not look" must be distinguishable from "I looked and it was clean".

The substantive part is unchanged from my review at ccab872e and I re-ran it here: the rename-not-truncate fix, the dynamic arm with two different summary sizes, and the static arm on the truncation idiom. Ready for the merge round.

bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
…#2791)

#2784 landed the fix while #2786 was open, so this PR is now only the part main does not
have: the arm. Kept separate rather than dropped because a rename whose reader-race has
no test is a fix that the next rewrite can silently undo -- the shape this fleet keeps
paying for.

tests/accel_sampler_summary_test.sh drives the real summary() (extracted by function range,
so it cannot drift from the code it tests) in a subshell against two synthetic sample files
whose summaries differ in size (397 and 453 bytes), with a background reader polling across
40 rewrites.

Against main's summary(), which already renames:
  ok  the two synthetic summaries differ in size (397 vs 453 bytes)
  ok  every one of 4000 reader observations was a complete summary (397 or 453 bytes)
  ok  summary() writes through a temp file and renames        rc 0

Mutant -- putting `} > "$out"` back on main's file:
  FAIL 144 observation(s) saw a size that is neither complete summary: 0 136 164
  FAIL summary() still writes with an in-place truncation (} > "$out")      rc 1

Registered as ctest accel_sampler_summary, taking ${CMAKE_SOURCE_DIR} as $1 like every
other shell row here (the first version took the sampler path there and CI caught it in
0.00 s). Hermetic: temp dir, synthetic samples, no device, no sampler, no ticket.

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 17, 2026
…807)

Found by running the parser over the REAL texts of tonight's seven PRs instead of only over my
own fixtures, which is the check I had described in the PR body but not done:

  #2793's body: "Refs #2779 (the layer its fix does not cover), #2728 (where the defect came from)"
  before: claims [2728]      <- the NOUN "fix" plus a reference 24 characters away
  after : claims []

GitHub's own closing rule is that the keyword is immediately followed by the reference, so the
regex now requires that adjacency (`Fixes #12`, `fixes: #12`) instead of allowing a gap. Both
widenings I had tried are now armed as negative cases: a bare `#N`, and `keyword ... #N` with
anything between them.

Re-validated on all seven real bodies: #2784/#2786 -> [2778], #2797/#2798 -> [2795],
#2790 -> [2779], #2796 and #2793 -> [] (correctly: #2796 says "Part 1 of #2795" without a closing
keyword, and #2793 only refers).

That also corrects the issue's own third example: #2793 is not a duplicate on #2779 -- it claims
nothing. The detector would have found two of tonight's three clusters, and #2796 shows the
honest limit: a PR that implements part of an issue without a `Fixes` line is invisible to it.
bong-water-water-bong added a commit that referenced this pull request Nov 17, 2026
* ci: name the open PRs that claim the same issue (engine#2807)

Three times in one night a second PR was opened for an issue another lane had started, and a
human reviewer noticed each time: #2778 (#2784/#2786), #2795 (#2796/#2797/#2798), #2779
(#2790/#2793). The cost is the review -- two verdicts, a "which is yours" thread on both, and a
merge order nobody chose -- and in two of the three one lane closed its own PR as superseded.

tools/ci/duplicate_fixes_check.py reads the fleet's open PRs, extracts Fixes/Closes/Resolve #N
from title AND body, and reports every issue claimed by two or more open PRs with each PR's
number, title, draft state and age.

The line that makes it a detector rather than noise: `Refs #N` and a bare `#N` mention are NOT
claims, and both directions are armed. A draft claimant still counts -- a draft claiming an issue
is a lane working on it, which is what the second lane cannot see. Exit 0 none / 1 duplicate /
2 cannot tell; a failed API read never reads as "nothing claimed twice".

Self-test: 12 arms on tonight's real numbers, hermetic. Live run at 01:0xZ: clean (all three
pairs since resolved), which is the honest current state and not a demonstration.

Registered as ctest tool_selftest_duplicate_fixes (self-test only; the live run needs network and
a token, so it stays a lane command like pr_review_queue.py).

* dupfix: the claim keyword must be adjacent to its reference (engine#2807)

Found by running the parser over the REAL texts of tonight's seven PRs instead of only over my
own fixtures, which is the check I had described in the PR body but not done:

  #2793's body: "Refs #2779 (the layer its fix does not cover), #2728 (where the defect came from)"
  before: claims [2728]      <- the NOUN "fix" plus a reference 24 characters away
  after : claims []

GitHub's own closing rule is that the keyword is immediately followed by the reference, so the
regex now requires that adjacency (`Fixes #12`, `fixes: #12`) instead of allowing a gap. Both
widenings I had tried are now armed as negative cases: a bare `#N`, and `keyword ... #N` with
anything between them.

Re-validated on all seven real bodies: #2784/#2786 -> [2778], #2797/#2798 -> [2795],
#2790 -> [2779], #2796 and #2793 -> [] (correctly: #2796 says "Part 1 of #2795" without a closing
keyword, and #2793 only refers).

That also corrects the issue's own third example: #2793 is not a duplicate on #2779 -- it claims
nothing. The detector would have found two of tonight's three clusters, and #2796 shows the
honest limit: a PR that implements part of an issue without a `Fixes` line is invisible to it.

* dupfix: a read failure is not a clean result, and 2 outranks 1 (engine#2807 review)

Both findings were right, and the first one is the false negative the docstring forbids in its own
words: a repo that could not be read still printed "no open issue is claimed by more than one open
PR". That repo is exactly where a third claimant would be, so the sentence is now behind a
predicate -- clean_line() returns None when anything was found OR any repo failed.

Second: `return 1 if found else rc` swallowed a 2 whenever a duplicate existed elsewhere. Now
exit_code() is 2 beats 1 beats 0.

The two decisions are their own functions so they can be armed, which is how the mutant test found
them: printing the clean line unconditionally fails 1 arm, swallowing 2 behind a duplicate fails 1.

Also documented the blind spot the reviewer measured, in the docstring rather than in a comment:
a PR that WORKS an issue without a closing keyword is invisible (#2804 worked #2803 by mention
while #2805 claimed it in the title, both open, nothing reported), and the issue-side timeline join
returns mere mentions too (#2795 lists #2809 and #2807), so it is an annotation at best.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

accel_sampler: the summary is written by in-place truncation, and it is now rewritten every 15 min (96 truncation windows/day)

1 participant