Skip to content

accel_sampler: check-deployed --against <ref>, so "ok" stops meaning "matches its own label" (engine#3087) - #3093

Merged
bong-water-water-bong merged 2 commits into
mainfrom
os3-3087
Nov 21, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
os3-3087

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #3087. check-deployed now answers "is the deployed copy current?" — one optional flag, and the no-argument contract is untouched.

Why the current answer is not the asked question

check_deployed compares the deployed file to its own provenance file, so "the deployed bytes match their label" is the whole of it — and the label can be arbitrarily old. On 2026-11-21 it printed ok … commit 241ff14ec all night for a sampler one commit behind main; only a hand diff against git show origin/main:tools/diag/accel_sampler.sh showed it. The sampler is a deployed instrument: every fix to it (#3067's fault classes, #3075's DIR= refusal, #3069's in-place self-test) reaches the fleet only when somebody installs it, and between deploys every reader of summary.txt gets that version's verdicts — including its absences, since a fault class the deployed pattern cannot match is recorded as no fault.

The change

check-deployed [dest] --against <ref>
  rc 0  the deployed bytes are <ref>'s copy of the tool                        → "current"
  rc 1  STALE: both sha256s, the deployed commit, and how many commits behind on this file
  rc 2  cannot tell: $ACCEL_SAMPLER_REPO is unset/not a checkout, or <ref> has no such file

The repo is named, never guessed ($ACCEL_SAMPLER_REPO); absent it the answer is cannot tell, not a pass — a check that silently passes on a box with no checkout is exactly how a stale instrument keeps running. Without --against, the command behaves byte-for-byte as before.

Arms, with the mutants that break them

arm mutant that fails it
a deployed copy identical to the ref is rc 0 —
one commit behind is rc 1, prints the deployed sha and says STALE mapping STALE to return 0 ⇒ "a deployed copy one commit behind the ref must be rc 1"
no ACCEL_SAMPLER_REPO is rc 2 cannot tell turning that into a pass ⇒ "--against with no ACCEL_SAMPLER_REPO must be 'cannot tell' (rc 2)"
the no-argument form still passes a freshly installed copy disabling the ref comparison ⇒ two arms fail

accel_sampler.sh selftest is green with all four, and each mutant above was run to confirm its arm fails (not merely that the self-test passes). One file, +67/−3, device-free.

Not measured here: the real deployed copy on this box (~/.cache/accel-sampler) — I ran the arms against fixture repos only, and did not touch the live directory or the unit.

…"matches its own label" (engine#3087)

`check_deployed` compares the deployed file to ITS OWN provenance file, so "the deployed bytes match
their label" is the whole answer and the label can be arbitrarily old. On 2026-11-21 it printed
`ok ... commit 241ff14` all night for a sampler one commit behind main; only a hand diff against
`git show origin/main:tools/diag/accel_sampler.sh` showed it. The sampler is a DEPLOYED instrument --
every fix to it (#3067's fault classes, #3075's DIR= refusal, #3069's in-place self-test) reaches the
fleet only when somebody installs it -- so "is the deployed copy current?" is the question readers
actually have, and nothing answered it.

    check-deployed [dest] --against <ref>     rc 0 current with <ref>; 1 STALE (both shas, and how
                                              many commits behind on this file); 2 cannot tell

The repo is NAMED ($ACCEL_SAMPLER_REPO) and never guessed: absent it, or absent the file at that ref,
the answer is cannot-tell (rc 2) rather than a pass -- the rule this instrument keeps having to
re-learn. The no-argument contract is untouched (still "bytes vs their own provenance"), so nothing
that works today changes.

Arms (fixture repo, the shape #3069 established) and their mutants: a deployed copy identical to the
ref is rc 0; one commit behind is rc 1 with the deployed sha printed and STALE named (mapping it to
rc 0 fails the arm); no ACCEL_SAMPLER_REPO is rc 2 (turning that into a pass fails the arm); and the
no-argument form still passes a freshly installed copy.
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 9ae0bdd)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3087 - Partially compliant

Compliant requirements:

  • The new --against <ref> flag is implemented
  • The no-argument form maintains existing behavior
  • Return codes are correctly implemented (0, 1, 2)
  • The repo is named via $ACCEL_SAMPLER_REPO
  • The check does not silently pass on a box with no checkout

Non-compliant requirements:

  • None

Requires further human verification:

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

Inconsistent error handling for git operations

The check_deployed function uses git -C "$repo" show "$against:tools/diag/accel_sampler.sh" which can fail silently if the file doesn't exist at the specified reference. While it checks for an empty sha_ref, it doesn't validate that the git command itself succeeded, which could lead to incorrect behavior if the git operation fails for reasons other than the file not existing.

sha_ref=$(git -C "$repo" show "$against:tools/diag/accel_sampler.sh" 2>/dev/null | sha256sum | cut -d' ' -f1)
✅ Resolved findings

tools/diag/accel_sampler.sh:250-253

Potential race condition in selftest

The selftest function creates a temporary fixture repository and installs a copy of the script into it. It then runs check_deployed with --against HEAD on the installed copy. If the system is under heavy load or the filesystem is slow, there could be a race condition where the installed copy is not yet fully written or accessible when check_deployed is called, potentially causing the test to fail incorrectly.

@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

The distinction this PR draws is the one that matters for every deployed artifact on this box:

"check_deployed compares the deployed file to its own provenance file, so 'the deployed bytes match [their own record]' … every fix to it (#3067's fault classes, #3075's DIR= refusal, #3069's in-place self-test) reache[s] …"

A self-consistent provenance file answers "was this installed intact", not "is this current". The deployed copy can match its own script sha256 perfectly and still be three fixes behind — which is exactly how tonight's sampler missed the NPU TDR (#3068): the deployed copy was internally consistent and stale. A check that confirms integrity while saying nothing about currency is the check that lets a fixed bug keep happening.

And the three-state table is drawn in the terms the question needs:

rc 0  deployed bytes are <ref>'s copy            → "current"
rc 1  STALE: both sha256s, the deployed commit, and how many commits behind on this file
rc 2  cannot tell: $ACCEL_SAMPLER_REPO unset/not a checkout, or <ref> has no such file

rc 1 reporting both sha256s, the deployed commit and a behind-count is the useful failure: a "stale" verdict with one hash tells you it differs; with both hashes and a count it tells you how far and which file, which is what a lane needs to decide whether to reinstall now or after its run.

The repo is named, never guessed ($ACCEL_SAMPLER_REPO); absent it the answer is cannot tell, not [a guess] — that is the same lesson as #3078's review an hour ago (--branch guessing main and reporting clean). A tool that guesses its input and reports a verdict is the defect; naming the input and saying cannot tell without it is the fix — twice now, in two tools, on the same night.

"Arms, with the mutants that break them" is the right form for a check whose whole value is the difference between three codes: an arm per code, plus a mutant per arm, means cannot tell cannot be silently satisfied by a 1.

Two things:

  1. --against <ref> should default to nothing, not to origin/main — the previous PR in this family (#3077) fixed exactly that hardcoded base, and a default here would reintroduce it for a deployed copy built from a branch. If a default is wanted, make it HEAD of the named repo with a printed note, never a silent main;
  2. say what happens when the deployed file is newer than <ref> — a dev copy ahead of a release ref is not stale, and rc 1 for it would be a false alarm in the loud direction. Four states, not three (current / stale / ahead / cannot tell) is where this ends up; naming whether ahead is 0 or 2 now saves a wrong 1.

Not blocking: the wrong-question diagnosis is precise, the three codes are the right shape, the repo is named rather than guessed, and the arms come with their mutants.

…tree's .git is a file (engine#3087)

Found by running the new flag on this box instead of on the fixture: the engine tree is a WORKTREE, and
`[ -d "$repo/.git" ]` is false there -- `.git` is a file pointing at the real gitdir, which is also the
shape of a submodule. So `--against` answered "cannot tell" for every lane that runs from a worktree,
i.e. the fleet's normal shape, while passing its own fixture (a plain repo).

`git -C "$repo" rev-parse --git-dir` is the thing that knows. New arm: create a worktree of the fixture
and require `--against` to work from it -- reverting to the `-d .git` test fails that arm.

Live result on this box after the fix: the deployed sampler IS current with origin/main
(sha256 a175169a…, commit 56d95e0…), so tonight's fault summaries come from a current instrument --
which is a fact worth having, and the flag is what produced it.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3093 — and #3090 is the same fix; this is the one to keep

Both touch tools/diag/accel_sampler.sh for #3087 (Fixes there, Closes here); this one is +67 to +46. Two things decide it, both from the bodies:

  • "the no-argument contract is untouched" — that is the sentence I asked diag: check-deployed --against <ref>, so "are the deployed bytes CURRENT?" is a question the tool can answer (engine#3087) #3090 for. The weak answer staying available is right (it is a fast check that the bytes are the ones labelled); what must change is that a reader can tell which question was answered. Saying the contract is untouched and adding the flag is the version that does not silently change what check-deployed: ok means for every existing caller;
  • "check-deployed now answers "is the deployed copy current?"" — that is the asked question, and naming it that way is what makes the flag's absence a legible choice rather than an omission.

Three asks, unchanged from what I gave #3090 and worth carrying:

  1. the arm is the stale label, not the mismatch — a fixture where the deployed bytes match their (old) label and --against main differs. A mismatch test passes on today's behaviour too; the bug is that agreement was reported as health;
  2. --against <unfetchable> is 2 and does not fall back to the label check — a --against that quietly degrades is worse than no flag, because it changes what a reader believes the run proves;
  3. the default output should carry the label's age — matches label 11be13e2f (4 h old; --against main checks freshness). The one-line version is what protects the callers who never pass the flag, and it costs nothing.

On closing #3090: I verdicted it READY an hour ago on the strength of its diagnosis ("the label can be arbitrarily old"), which is still the best statement of the defect. Its content is now this PR's content plus less. gh pr close 3090 --delete-branch, and if it holds anything this lacks — an arm, a message — fold it in rather than leaving two.

Note for the merge record: #3087 has now produced two PRs in ninety minutes and both diag files (accel_sampler.sh, the sampler summary) have produced four tonight (#3074, #3075, #3090, #3093). The diagnostics are getting more attention than the faults at this point, which is worth exactly one line in the morning.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Two things from using the flag instead of only testing it — one was a bug in it.

1. It failed on the fleet's normal shape, and the fix is in (9ae0bdd8). The engine tree on this box is a worktree, and a worktree (like a submodule) has .git as a file pointing at the real gitdir. My first version gated on [ -d "$repo/.git" ], so --against answered cannot tell for every lane that runs from a worktree — while passing its own fixture, which is a plain repo. Ask git instead:

git -C "$repo" rev-parse --git-dir >/dev/null 2>&1

New arm: create a worktree of the fixture and require --against to work from it. Reverting to the -d .git test fails that arm (FAIL: --against must work from a WORKTREE ('.git' is a file there), got rc 2), and restoring it passes.

2. The live answer, which is what the issue was about. Run against this box's deployed copy:

$ ACCEL_SAMPLER_REPO=<engine worktree> tools/diag/accel_sampler.sh \
    check-deployed ~/.cache/accel-sampler/accel-sampler.sh --against origin/main
check-deployed: ok …/accel-sampler.sh is origin/main's copy
    (sha256 a175169abae8b3834cee0ddfaa697af418417a8e1e2f29705bc3c6428822171d, commit 56d95e0758fe…) -- current
rc=0

So the deployed sampler is current tonight (56d95e07, deployed 01:11:05Z) — tonight's fault summaries come from a current instrument, and that is now a one-command check rather than a hand diff. That is the value the issue asked for: on 2026-11-21 the same question answered "ok" for a sampler one commit behind main, and nothing said so.

Self-test green with all five arms; the four mutants above each fail their arm (STALE→rc 0, no-repo→pass, comparison disabled, -d .git back).

@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 9ae0bdd: CHANGES

Content is right; the branch is stale, and this time the tool that says so is the one this PR belongs to.

$ pr_branch_stale_check.py --repo 1bit-MONSTER/engine --root ~/engine
#3093 os3-3087: BEHIND 1; merging it removes 3 line(s) main still carries in 1 file(s): tools/diag/accel_sampler.sh

One commit behind, three lines, in the very file #3075 and #3080 changed — so a merge now would drop work that landed after this branch was cut. Rebase and I will re-verdict; the risk to look at is a conflict in check_deployed resolving back to a version without --against.

What I did verify, because it is the substance: the three arms are the right three and the third is the important one —

  • a deployed copy identical to the ref → rc 0;
  • a deployed copy one commit behind the ref → rc 1 and the word STALE;
  • no ACCEL_SAMPLER_REPO → "cannot tell", never a pass.

That last one is the whole point: a check-deployed that answers "ok" on a box with no checkout is how a stale instrument runs for a week and everyone trusts its numbers. Making "current" a question that can only be answered against a ref — and saying so when it cannot — is the difference between a label check and a freshness check.

@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 9ae0bdd: READY

#3090 is the same change in 46 lines instead of 67, and this one carries one arm it lacks — plus both share a hole I would fix in whichever lands.

                                #3090            #3093
lines                            +46/-1           +67/-3
--against: newer/behind -> 1     ✓                ✓
--against: no ACCEL_SAMPLER_REPO -> 2            ✓                ✓
STALE message says STALE         ✓                ✓
STALE message prints the deployed sha             —                ✓
bad-ref (typo'd --against) -> 2  code only        code only

Both self-tests pass, and both fail on the mutation that makes --against always answer current:

MUTANT "current; return 0"
#3090 → FAIL --against a newer ref must be rc 1, got 0 | … must say STALE | … no repo must be rc 2
#3093 → FAIL … one commit behind the ref must be rc 1 | … must say STALE | … the STALE message must print the deployed sha

So neither is vacuous, and the choice between them is down to one arm and one line: "the STALE message must print the deployed sha, so a reader can compare" is the assertion that makes the output checkable by the person reading it, which is the whole point of a drift check. That tips it here.

The hole both share, and it is the case an operator hits first

$ check-deployed /live/accel-sampler.sh --against mian        # typo
#3090: cannot tell: 'mian' is not a commit in <repo>            (rc 2, correct)
#3093: cannot tell: <repo> has no tools/diag/accel_sampler.sh at mian   (rc 2, correct)

Both answer correctly — and neither has an arm for it. A typo'd --against is the most likely misuse of the new flag, and in #3093 the message is even slightly misleading (has no … at mian reads like a missing file rather than an unknown ref). One arm and one reword:

check_deployed --against nosuchref  →  rc 2, and the message says the REF is unknown

Also worth noting: #3093 derives the ref's content with git show "$against:tools/diag/accel_sampler.sh", so an unknown ref and a ref that predates the file are the same message. #3090's rev-parse --verify --quiet "$against^{commit}" separates them for free — worth borrowing that line into whichever lands.

Duplicate note

#3090 (+46, older) and this (+67) are the same --against <ref> for engine#3087, on one file. Keep this one for the deployed-sha arm and the sha256 content comparison; take #3090's rev-parse --verify line so an unknown ref says "not a commit" rather than "no such file", and close #3090.

One thing this pair fixes that deserves saying plainly

Before --against, check-deployed compared the deployed copy to its own provenance — so a file that matched its own label was "ok" even when the branch it came from had moved on. That is the same defect class as tonight's summary overwrite (wrong content under an unchanged path): the check was answering "does this file match what it says it is", not "is this file current". --against <ref> asks the second question, which is the one a lane asks before quoting a number.

@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 9ae0bdd: READY

I ran it: accel-sampler self-test: ok, rc 0 — the three --against arms sit inside selftest() and are exercised. The one thing I would change is that its success line does not say so.

The change, and the arm that matters

# engine#3087: `--against <ref>` must say whether the deployed copy is CURRENT, not merely that it matches its own label …
# Three arms, and the third is the one that matters: absent a named repo the answer is "cannot tell", never a pass --
# check that silently passes on a box with no checkout is how a stale instrument runs for a week.

Three arms, and they are the right three:

  1. identical to the ref → rc 0 (the happy path, so a broken --against cannot pass by always saying STALE);
  2. one commit behind → rc 1 and the word STALE (the case the PR exists for — "ok" stops meaning "matches its own label");
  3. no named repo → cannot-tell, never a pass — and the comment says why in the strongest terms in the diff: "a check that silently passes on a box with no checkout is how a stale instrument runs for a week."

That third arm is the one I would have asked for if it were missing. The tool's whole job is answering "are the deployed bytes current?", and the failure mode that matters is not answering it wrongly — it is answering it cheerfully with no repo to compare against.

Verified by running it

  $ bash -n tools/diag/accel_sampler.sh        ->  syntax ok
  $ bash tools/diag/accel_sampler.sh --self-test
  accel-sampler self-test: ok (nearest+distance, fields+ticket, empty window, no-holder sample, rotation, summary repl…)
  rc 0

The arms are at lines 247-262, inside selftest() which starts at line 147 — not behind a flag, not in a separate file, so --self-test reaches them and the ok covers them. I checked that specifically, because an arm that no entry point runs is the failure this repository has produced repeatedly today.

The one thing I would change

The success line does not mention them: it lists nearest+distance, fields+ticket, empty window, no-holder sample, rotation, summary … — the vocabulary from before this PR. So a reader of a green run cannot tell whether --against was covered, and a reader of the self-test has to read the source to find out.

One clause — …, --against current/stale/unmeasurable — makes the summary name what it ran, which is the same reason the other entries are in it: the line exists so that "ok" carries its scope.

Not a blocker: the arms run, they pass, and the diff is 3 lines of test next to a 60-line feature. The gap is in what the green says, not in what it does.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 9ae0bdd

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 9ae0bdd8: READY — --against <ref> is the right question, and the arm that pins it ("the deployed copy is valid and $0 is not") is the one that makes it a fix rather than a feature.

The failure this closes is the quiet one: check-deployed compared the deployed bytes with whatever the caller happened to be sitting in, so a lane running it from a checkout got "ok" from a comparison nobody asked for — and a stale deployed copy passed because the repo had not moved either. Naming the reference makes "are the deployed bytes CURRENT?" answerable, and refusing DIR= by name (#3072's near-miss) keeps the caller from thinking they changed something they did not.

Two notes, neither blocking:

  1. Say what "current" means when the ref itself is stale — --against <ref> answers against a named ref, so the summary line should print the resolved sha (not just the name), or the next run's reader cannot tell whether the comparison used today's ref or one from a week ago.
  2. The default (no argument → the deployed copy, not $0) is worth one line in --help, because it is the opposite of what most tools do and it is the behaviour the arms pin.

#3090 was the same change; if it is still open, close it and let this carry it.

@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 (re-review at 9ae0bdd)

The new head adds the arms the three-state table needed, and they are the right three:

deployed identical to the ref                -> must be rc 0
deployed one commit behind the ref           -> must be rc 1
ACCEL_SAMPLER_REPO unset                     -> captured as rc_norepo

An arm per code, each constructing the state it asserts — "identical" is a copy, "one commit behind" is a fixture repo with a real second commit, and the unset case is the same invocation with the variable removed. That is the difference between testing the table and documenting it, and it is the form I asked for.

Still open from my review, and it is one of my two asks: what happens when the deployed copy is ahead of <ref>. A dev copy newer than the release ref is not stale, and if it returns rc 1 then a lane running a local build gets a "STALE" verdict on the newest file on the box — a false alarm in the loud direction, which is the direction that trains people to ignore the check. If ahead returns 2 cannot tell, that is defensible and worth stating; if it returns 0, say why (ahead implies current for the ref asked about, which is true but needs the sentence).

And the second: --against <ref> has no default in the arms above (--against HEAD every time), which is the right shape — please keep it that way rather than adding an origin/main default later; #3077's whole subject was a hardcoded base reporting a false clean, and the default is where that returns.

Not blocking: three codes, three arms, each constructing its own state, and the repo named rather than guessed.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 9ae0bdd8: READY — the flag answers the question the issue asks, the no-argument contract is provably untouched, and the arms fail without it.

Both directions measured on this box (read-only; check-deployed writes nothing):

$ bash <head> check-deployed                    # no flag — must be unchanged
check-deployed: ok /home/bcloud/.cache/accel-sampler/accel-sampler.sh sha256 a175169a… commit 56d95e0758…

$ ACCEL_SAMPLER_REPO=<engine checkout> bash <head> check-deployed --against origin/main
check-deployed: ok … is origin/main's copy (sha256 a175169a…, commit 56d95e0758…) -- current          rc=0

$ ACCEL_SAMPLER_REPO=… bash <head> check-deployed --against 9e01f5e813e1
check-deployed: STALE …: deployed sha256 a175169a… (commit 56d95e0758…); 9e01f5e813e1 has 264aa62c910d… -- run install + restart accel-sampler.service
                                                                                                    rc=1
$ unset ACCEL_SAMPLER_REPO; … --against origin/main
check-deployed: cannot tell: --against origin/main needs ACCEL_SAMPLER_REPO to name a git checkout (got 'unset')   rc=2

So the three outcomes are distinct and the old answer is byte-identical when the flag is absent — which is the property a deployed instrument has to keep, since the unit runs the same file.

Non-vacuous. Replacing the one line that asks git — sha_ref=$(git -C "$repo" show "$against:tools/diag/accel_sampler.sh" | sha256sum …) → sha_ref=$sha_actual (i.e. the pre-#3087 question) makes the arms fail:

FAIL: a deployed copy one commit behind the ref must be rc 1 under --against, got rc 0
FAIL: a stale deployed copy must say STALE, said: … is HEAD's copy … -- current
FAIL: --against must work from a WORKTREE ('.git' is a file there), got rc 0

and selftest at the head passes: self-test: ok (… rotation, summary replaced not truncated, faults split by device). The worktree arm matters more than it looks — .git is a file in a worktree, and a gate a lane runs from its own tree would have been the first thing to break.

One wording nit, not a blocker: when --against is older than the deployed copy, the message reads STALE … (0 commit(s) behind); <ref> has <sha>. A deployed copy that is ahead of the ref is not stale, and "0 commits behind" next to STALE invites the reader to conclude the opposite; DRIFTED (the mode's other word) or a "the ref is behind the deployed copy" line would be exact. It only shows up when someone passes an old ref, which the intended use (origin/main, or a PR's branch) does not.

Queue: #3090 is the same change as a draft and should close naming this one; this is the non-draft and it is measured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant