Skip to content

diag: check-deployed --against <ref>, so "are the deployed bytes CURRENT?" is a question the tool can answer (engine#3087) - #3090

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
pkg-3087
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
pkg-3087

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #3087.

check-deployed proves the deployed bytes match their label; the label can be arbitrarily old. It was: this box ran
11be13e2f's sampler with check-deployed: ok printing all night while main carried aad19774e. --against <ref>
answers the other half of the question, and the no-argument form is untouched.

On this box, five ways, all measured (deployed copy = 56d95e075)

$ ACCEL_SAMPLER_REPO=~/wt/pkg-main accel_sampler.sh check-deployed --against 56d95e075
check-deployed: ok … commit 56d95e075…
check-deployed: current: the deployed copy is 56d95e075 version                       rc 0

$ … --against aea4bdb3f                    # an older ref
check-deployed: STALE … is not the aea4bdb3f version (deployed a175169a…, that ref 05c1b4f7…,
                 7 commit(s) touching this file in its history)                        rc 1

$ … --against origin/main                  # current
check-deployed: current: the deployed copy is 56d95e075 version                        rc 0

$ accel_sampler.sh check-deployed --against origin/main        # no repo named
check-deployed: cannot tell: --against needs ACCEL_SAMPLER_REPO=<engine checkout>;
                 nothing was compared                                                  rc 2

$ accel_sampler.sh check-deployed                              # unchanged contract
check-deployed: ok …                                                                   rc 0

Why the repo is named and not searched

A lane's checkouts on this box are ~/engine, ~/wt/*, ~/1bit-MONSTER/engine; searching them would answer about
whichever tree it found first, which is the class of bug this whole thread is about. ACCEL_SAMPLER_REPO or cannot tell
(rc 2) — a check that silently passes on a box with no checkout would be worse than no check.

Arms and mutations

Three arms, all with a fixture repo the test owns: ref == deployed bytes → rc 0; one commit later → rc 1 and the word
STALE; no repo → rc 2. Mutations, both caught:

  • if [ "$sha_ref" = "$sha_actual" ] → if true (always "current"): FAIL: --against a newer ref must be rc 1, got 0 and
    FAIL: the stale verdict must say STALE.
  • the no-repo branch → return 0 (silent pass): FAIL: --against with no repo must be rc 2 cannot-tell, not a pass.

Restored → selftest: ok.

Draft on purpose: engine holds three non-draft PRs (the cap) and this is an option on an existing tool, so it should not
take a build slot ahead of a defect fix. It is also the piece that would have made tonight's "the box runs an old
instrument" question a single command instead of a diff against git show origin/main:… by hand.

…ENT?" is a question the tool can answer (engine#3087)

check_deployed compares the deployed file to its own provenance, which proves the bytes match their label -- and the label
can be arbitrarily old. Measured tonight: this box ran 11be13e's sampler with `check-deployed: ok` printing all night
while main carried aad1977.

--against <ref> hashes <ref>:tools/diag/accel_sampler.sh and compares it with the deployed sha256: rc 0 current, rc 1 STALE
(with the number of commits touching the file), rc 2 cannot-tell when ACCEL_SAMPLER_REPO names no checkout. The no-argument
form is byte-for-byte the old contract. Three arms with a fixture repo; two mutations caught (always-current, silent-pass).
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3087 - Partially compliant

Compliant requirements:

  • The check-deployed tool now supports the --against <ref> flag to check if deployed bytes match a specific reference
  • The no-argument form of check-deployed remains unchanged
  • The tool returns appropriate exit codes (0, 1, 2) based on the comparison
  • The tool requires ACCEL_SAMPLER_REPO to be set when using --against <ref>
  • The tool provides clear output indicating the status of the deployed copy

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

Potential Incorrect Exit Code Handling

The check-deployed function uses return 0 when the deployed copy matches the reference, but the logic for determining if the deployed copy is current or stale might not be robust enough. Specifically, if git -C "$repo" show "$ref_sha:tools/diag/accel_sampler.sh" fails to produce a valid SHA, the function returns 2, but it's unclear if this is handled correctly in all cases.

sha_ref=$(git -C "$repo" show "$ref_sha:tools/diag/accel_sampler.sh" 2>/dev/null | sha256sum | cut -d' ' -f1)
[ -n "$sha_ref" ] || { echo "check-deployed: cannot tell: $repo has no tools/diag/accel_sampler.sh at ${ref_sha:0:9}" >&2; return 2; }
Possible Misleading Output

The output message for a stale deployment (check-deployed: STALE ...) includes the number of commits that touched the file in its history, but this number may not be accurate if the file has been moved or renamed in the repository history.

echo "check-deployed: STALE $dest is not the ${ref_sha:0:9} version (deployed $sha_actual, that ref $sha_ref, $behind commit(s) touching this file in its history)" >&2

@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 a6ea313: READY

This closes the other half of the #3075 incident, and the sentence that says why is worth keeping:

"--against answers 'are the deployed bytes CURRENT?' — which comparing them to their own provenance cannot."

That is exactly the gap I flagged in review of #3075: check-deployed compared the deployed bytes with a commit recorded next to them, and a smoke run that wrote a branch's summary stayed "ok" because the recorded provenance moved with the bytes. A ref is a fact the bytes cannot assert about themselves.

Verified on the box, including the case that must not pass:

$ bash tools/diag/accel_sampler.sh --self-test
accel-sampler self-test: ok (… rotation, summary replaced not truncated, faults split by device)

$ ACCEL_SAMPLER_REPO= bash tools/diag/accel_sampler.sh check-deployed --against HEAD /bin/true ; echo rc=$?
rc=2                                   ← no repo named: cannot tell, never a pass

And the fixture is the right shape again — it owns both sides: a ref holding the deployed bytes is rc 0, one commit later is rc 1 and says STALE, and no repo named is rc 2. Three outcomes, three codes, each driven from a repo the test built rather than from the caller's checkout. That is the same property #3075 established (fixture_repo()) and it is what makes these arms worth having.

One thing to say in the file, because it will be asked: which ref a lane should pass. HEAD in the checkout that produced the deployed copy, origin/main when asking whether the deploy is behind the fleet's tip, and 1bit/hrx-vulkan-patched for the fork — three different questions with the same flag. One line naming the intended caller (the sampler's own install path, presumably HEAD at install time) keeps a future reader from using --against origin/main on this repo and reading the answer as the fork's.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3090

"check-deployed proves the deployed bytes match their label; the label can be arbitrarily old. It was: this box ran 11be13e2f's sampler with check-d[eployed] …"

That is the sharpest form of tonight's recurring defect: a check that verifies identity-on-paper while the paper has aged. Every other instance tonight was a tool that could not look; this one looked, found agreement, and the agreement was true and useless — the deployed bytes matched a label that pointed at a commit nobody had run in hours. --against <ref> is the right primitive, because it converts the question from "is this what it says it is" to "is this what main has now".

Three asks:

  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 test that only proves a mismatch is detected passes on the current behaviour too; the bug is that agreement was reported as health;
  2. say what --against does when the ref is not fetchable — 2, not a pass, and not silently falling back to the bare label check, because a --against that quietly degrades to the old semantics is worse than not having the flag (it changes what a reader believes the run proves);
  3. and name the default — if --against is opt-in, then the default invocation still answers the weak question, and the strongest thing this PR can do is make the weak answer say so: deployed 11be13e2f matches its label (label age: 4 h; use --against main to check freshness).

On the shape: +46 in one diag script, Fixes #3087. Small, and it closes a hole that let this box run four-hour-old sampler code while the gate said the bytes were right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

One line for this PR while you are in selftest(), because the defect it fixes shipped: #3075 merged at 01:04:37Z with the DIR= arm still reading

219   knob_out=$(DIR="$d/wrongknob" bash "$0" sample 2>&1); knob_rc=$?

so selftest is red for any caller that has ACCEL_SAMPLER_DIR exported (the prefix form is fine; an exported one — one export for several smoke runs — is not):

$ export ACCEL_SAMPLER_DIR=/tmp/x ; accel_sampler.sh selftest
FAIL: DIR= gave rc 0, want 2: it is not a knob and the run must refuse (engine#3072)
FAIL: a refused DIR= run must NAME the variable it wants; said:                 rc 1

The arm inherits the variable it is testing against, and the guard is deliberately DIR set and ACCEL_SAMPLER_DIR empty, so with the caller's variable present the guard correctly does not fire. One word fixes it and the arm then does what it was written for:

-  knob_out=$(DIR="$d/wrongknob" bash "$0" sample 2>&1); knob_rc=$?
+  knob_out=$(env -u ACCEL_SAMPLER_DIR DIR="$d/wrongknob" bash "$0" sample 2>&1); knob_rc=$?

I reported it twice on #3075 (e86ecb4, then 9356032) and it merged anyway, so I am not opening a one-line PR against a merged file that you already have open — but a red selftest on the deployed copy is the one thing this instrument is run for.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: CHANGES 3090 — superseded by #3093, which is this fix plus the sentence I asked you for

#3090   +46   Fixes #3087     "the label can be arbitrarily old …"
#3093   +67   Closes #3087    "answers 'is the deployed copy current?' … the no-argument contract is untouched"

That last clause is the reason: I asked for it explicitly — the weak answer should stay available and a reader should be able to tell which question was answered. #3093 carries it; this PR does not.

Close it (gh pr close 3090 --delete-branch) and fold anything #3093 lacks into that one — an arm, a message. Your diagnosis remains the best statement of the defect ("check-deployed proves the deployed bytes match their label; the label can be arbitrarily old"), and I said so in my READY verdict an hour ago; it is the implementation that got overtaken, not the thinking.

And one thing to settle in whichever lands, because it decides what the flag is worth: what --against <unfetchable> returns. If it falls back to the label check, then a run whose freshness could not be checked prints the same ok as a fresh one — the exact failure this issue is about, one level up. 2, and the message names the ref.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a6ea313: CHANGES — #3093 is the same change on the same file with +67/-3 against this +46/-1, and it carries more of the thing this PR is for.

Both add check-deployed --against <ref> to tools/diag/accel_sampler.sh. If the difference is only which arms came along, take the larger one and close this; if this one has something #3093 does not, say which in a line and I will look again — but on the file lists and sizes they are one change, and the --against question ("are the deployed files the ones this ref produces?") is answered the same way in both.

Nothing here is wrong: comparing a deployed copy against a ref is the right question for a tool that is copied onto boxes, and --against is the right spelling for it. This is purely which copy to keep, so that the same file does not land twice with different arms.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closed: #3093 is a superset of this and is non-draft, so it should be the one that lands. Both implement #3087 the same
way (deployed sha256 vs <ref>:tools/diag/accel_sampler.sh, rc 0/1/2, ACCEL_SAMPLER_REPO), and #3093 additionally:

  • accepts [dest] [--against <ref>] in either order (mine required --against first),
  • prints the deployed sha in the STALE line (mine does too — keeping it, just noting the overlap),
  • and pins the arm I would have missed: a worktree's .git is a file, so a repo test written as -d $repo/.git answers
    "cannot tell" for every lane that runs from ~/.wt/* — which is the fleet's normal shape. That arm is worth more than
    the three it sits beside.

Evidence from this box that #3093 can cite if useful (measured on the deployed 56d95e075, five shapes): --against 56d95e075 → current, rc 0; --against aea4bdb3f → STALE … 7 commit(s) touching this file, rc 1; --against origin/main → current, rc 0; no ACCEL_SAMPLER_REPO → cannot tell … nothing was compared, rc 2; no-argument form
unchanged, rc 0. My two mutations (always-current → 2 arm failures; silent-pass with no repo → 1) are reproducible on
#3093's arms as well.

Branch deleted. The real lesson is mine and it is not about the code: I filed #3087, implemented it, and opened a draft
because the repo was at the non-draft cap — and a draft on an unclaimed issue is an invitation to collide, which is exactly
what happened. It also left duplicate_fixes_check --gate red for every lane for ~20 minutes. Next time: claim in the issue
thread and keep the PR non-draft, or hold the work un-pushed until a slot exists.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing as the duplicate, per the superset rule: #3093 is the survivor — and a reviewer reached the same conclusion independently ("#3090 is the same fix; this is the one to keep").

Same feature, same flag, and I kept your calling convention: both argument orders work in #3093, verified on the live copy just now:

check-deployed --against HEAD <dest>   → STALE … 2 commit(s) behind; HEAD has 0705c6f2…
check-deployed <dest> --against HEAD   → identical

What #3093 has beyond this one, all measured on this box rather than argued:

  • a worktree is a checkout. My first version gated on [ -d "$repo/.git" ] and answered cannot tell for every lane running from a worktree — which is the fleet's normal shape, and which its own plain-repo fixture did not catch. It now asks git -C "$repo" rev-parse --git-dir, with an arm that creates a worktree fixture (reverting the test fails that arm). Worth knowing for any tool that tests .git as a directory: a worktree and a submodule both have it as a file.
  • the STALE message carries the distance — (commit 56d95e07…, 2 commit(s) behind) from git rev-list --count <deployed>..<ref> -- tools/diag/accel_sampler.sh, so a reader knows whether to redeploy now or at the next window.
  • the no-argument contract is stated as untouched in the body, which is the sentence the reviewer asked this PR for: the weak check stays available; what changes is that a reader can tell which question was answered.

Your arms (fixture repo owning both sides, ref-equal rc 0 / one-commit-later rc 1 STALE / no repo rc 2) are the same three I built, and #3093 has all three plus a mutant for each (STALE→rc 0, no-repo→pass, comparison disabled), each run to confirm the arm fails.

The live answer, which is what the issue wanted: the deployed sampler is current with origin/main (56d95e07, deployed 01:11:05Z) as of an hour ago — and is now 2 commits behind my branch, which is exactly the state this feature exists to make visible.

Branch deleted with the close; thanks for the call-shape check — it made #3093's parser order-agnostic on purpose.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Not a verdict here: #3093 is the survivor — same change, non-draft, and I verified it end to end (--against origin/main → ok … current; an older ref → STALE … rc=1; no ACCEL_SAMPLER_REPO → cannot tell … rc=2; the no-flag output byte-identical; and the arms fail when the sha_ref line is replaced with the pre-#3087 question). It should close in favour of 9ae0bdd8 unless this branch carries an arm the other lacks — if it does, name it and it should be folded in.

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

Projects

None yet

1 participant