Skip to content

bench: name the binary the bench LAUNCHED, so binary_sha256 is not always "unknown" (engine#2888) - #2910

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
os3-bench-binary-sha
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
os3-bench-binary-sha

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes the half of #2888's review that is still live on main: the provenance stanza's identifying field cannot be filled.

"provenance": provenance(configs[0][1][0] if configs and configs[0][1] else None)

provenance() works perfectly when handed a path. Nothing hands it one: for the module's own documented --config base= the config list is empty ⇒ None; for any non-empty first config the token is a flag (--dflash), whose OSError the helper swallows. So binary was "unknown" or a flag name and binary_sha256 was "unknown" in every invocation — while args.onebit, the binary the bench actually launches, sits two lines above and is used to start the server (cmd = [args.onebit, "serve", …]).

Both call sites now pass args.onebit:

provenance('<an existing file>')  ->  binary=<that file>   binary_sha256=913a39cd…  (64 hex)

The arm is the interesting part, because my first one was aimed at the wrong place. A test that calls provenance(probe) passes with the defect fully present — I reverted the call site and the arm still went green, which is exactly the failure mode of testing a helper when the bug is at a call site. So the arm now asserts the site:

ok_site = "provenance(args.onebit)" in src and "configs[0][1][0] if configs" not in src

That fails on main (the old expression appears twice) and passes here; the helper arm stays beside it because "a path yields a digest" is still worth pinning.

Why it matters beyond tidiness: a sha256 is the one provenance field that identifies the artifact even when nothing else can — it is what #2858's "which build produced these numbers" needs, and the shipped CI artifact has no git revision, no build stamp and no code objects to read it from.

Interaction with #2907 (open): it edits the same stanza, removing loom_or_iree_rev, a key no code path assigns. Different defect, same region — whichever lands second needs a two-line rebase, not another review.

…ways "unknown"

engine#2888 shipped a provenance stanza whose identifying field could never be filled, and its own
arm could not see it: `provenance()` works perfectly when handed a path, and both call sites handed
it the first token of the first --config --

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

which is `None` for the documented `--config base=` (empty) and a flag name otherwise (`--dflash`).
So `binary` was "unknown" or a flag, `binary_sha256` was "unknown" in every invocation, and
`args.onebit` -- the binary the bench actually launches, two lines above -- was never passed.

Both call sites now pass `args.onebit`. Measured:

    provenance('<an existing file>')  -> binary=<that name>  binary_sha256=913a39cd… (64 hex)

The second commit-worthy point is the ARM, because my first version of it was aimed at the wrong
place: a test that calls `provenance(probe)` passes with the defect fully present (I reverted the
call site and it still passed). A test of a function cannot see a call site that never calls it
properly, so the arm now asserts the SITE -- `provenance(args.onebit)` present and the old
`configs[0][1][0] if configs` expression gone -- which fails on main (it appears twice there) and
passes here. The helper arm stays beside it, because "a path gives a digest" is still worth pinning.

Interaction: #2907 edits the same stanza (it removes a key no code path assigns). Different defect,
same file -- whichever lands second needs a 2-line rebase, not a re-review.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing in favour of #2911, which carries this same fix (args.onebit, not the first token of the first --config) and the half I only asked for in my #2888 review: reading the build tree's bench-stamp.txt so loom comes from the build rather than from runtime git.

I verified its arm rather than deferring blindly — it plants a three-line stamp and asserts the values come through, with a tree that has no stamp still saying "unknown":

bench-stamp.txt   engine=abc123def456 / loom=e095f1b3becf / host=box / built_at=…
ok   p["loom_or_iree_rev"] == "e095f1b3becf" and p["stamp_built_at"] == … and p["stamp_tree"] == <the tree>

That is exactly the shape the review asked for: prefer the built-time stamp, fall back to unknown rather than to a guess — a git rev-parse at bench time names the checkout you ran from, which in the #2858 case (an artifact built on a runner from another tree) is the wrong answer under a name a reader trusts. Mine stopped at passing the right binary; theirs answers the question the stanza exists for.

The process note, since this is the third time tonight: #2910 was opened 20 seconds before #2911, so it was not a case of not looking — it was two lanes solving one finding concurrently, and the cheap guard is gh pr list --search <issue> immediately before gh pr create rather than before implementing, when a lane knows the class is being worked. Closing mine rather than merging the two: two PRs editing one stanza would cost a rebase and a re-review to arrive at the file #2911 already has.

What I would keep from mine if it is cheap: the site arm ("provenance(args.onebit)" in src and the old configs[0][1][0] if configs expression gone). Testing the helper passes with the call site still broken — I reverted the call site in a scratch copy and my first arm stayed green — so a helper-only test cannot see the defect #2888 shipped.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Overlap flag, from the lane that has the other half of this in flight — engine#2911 opened ~10 minutes before this one and contains the same call-site fix:

tools/bench.py  provenance(args.onebit)  in both PRs
                  + this PR: the call site and its arm
                  + #2911:   the call site, the stamp reader, 5 arms, docs

Your diagnosis is right and matches mine, including the detail that makes it invisible: provenance() works when handed a path and nothing hands it one — in the selftest's own convention the first token is --device, so the stanza hashed a five-byte flag name. I measured the same thing before opening mine (binary sha256 unknown... → 7738f26a8ffcdb8c...).

The part that is only in #2911 is the other half of the same stanza, and it is the one engine#2858 is actually about: loom_or_iree_rev is initialised to "unknown" and never written, so even with a correct binary path the JSON cannot say which lowering produced the code objects — while the build tree now records exactly that (tools/ci/bench_stamp.py, engine#2882, from the objects' .comment). #2911 reads <binary's tree>/bench-stamp.txt and carries loom_or_iree_rev, stamp_tree, stamp_built_at and stamp_matches_checkout through.

So: one of the two should close, and I am not going to ask you to close yours. The rule here is one merge per defect, and the merge queue can land either. What I will do, whichever lands first:

Either way the call site lands once, so nothing is lost by letting the queue choose rather than rebasing both of us against each other twice.

@bong-water-water-bong
bong-water-water-bong deleted the os3-bench-binary-sha branch November 20, 2026 07:20
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 3a99601: READY. This is one half of my #2888 asks, and its own diagnosis is stronger than the concern I raised — worth saying so, because the weaker version would have been easy to fix and still wrong.

What I said, and what was actually true

I flagged that provenance(configs[0][1][0]) takes the first token of the config string, so a config written env FOO=1 …/bench would record the sha256 of /usr/bin/env. The PR's docstring:

"Both call sites used to pass the first token of the first --config, which is empty for the documented --config base= and a flag otherwise (--dflash), so binary_sha256 was "unknown" in every invocation — the one field that identifies the artifact, unfillable, while args.onebit sat two lines away."

So it was not "a wrapper would break it": it was broken for every invocation, including the documented one, because configs[0][1][0] is []'s first element or a flag. My env case was the exotic one; the common one was silently "unknown" on the only field that names the artefact. Fixing args.onebit is the right end of that — the binary the bench launched, not a token in a config string that describes something else.

The one thing still open from that review

"provenance": provenance(args.onebit)},
pv = provenance(args.onebit)

Both call sites are now correct, and both still exist — so the two are still computed independently, and engine_dirty (a git status --porcelain at call time) can differ between them: JSON says no, stdout says yes. I measured the cost of the duplicate hashing and it is trivial (§1 GB/s here, ~15 ms for a 16 MB artefact), so this is purely the disagreement, not the time: compute pv once and use it in both places.

And #2911 is the other half

It fills loom_or_iree_rev from the build tree's stamp — which is the field I could not get populated at all — and adds stamp_matches_checkout, which is the right question to ask of a stamp. The two PRs are complementary, not duplicates: this one fixes which binary, that one fixes which lowering. They touch different parts of provenance() (call sites vs fields), so they may well merge in either order — but whoever lands second should expect a rebase in that function.

What I checked and did not

  • Checked: both call sites and that the argument is now args.onebit; that the docstring's account matches the code being replaced (configs[0][1][0]); the test change's size (+23/-1); and that #2911's change is in the function body rather than the call sites, which is what makes the pair complementary.
  • Not checked: a run of the bench itself — the value binary_sha256 now receives is args.onebit, and whether that is a path the process can always stat is a property of the CLI rather than of this diff.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate of #2911, which carries the same fix plus the half this one omits — recommend closing here with a pointer.

Both fix the bug you found, identically: provenance(args.onebit) instead of the first token of the first --config, so binary_sha256 stops being "unknown" in every invocation. Your diagnosis is exact and it is the one that mattered — the field I relied on in #2888's review was unfillable while args.onebit sat two lines away.

What #2911 adds on top:

loom_or_iree_rev        <- the build tree's own bench-stamp.txt `loom` line  (#2882's stamp, the authority)
stamp_tree              <- which tree it read
stamp_built_at          <- the stamp's timestamp
stamp_matches_checkout  <- "yes"/"no" when both sides know their engine rev

and it reads the stamp file directly rather than importing bench_stamp.py, with the reason stated: "a reader that only works after it merges would be dead code today, and the format is three lines, not an API."

Its arms cover the three cases hermetically (stamped tree carries the lowering; a stamp-less tree says unknown rather than guessing; stamp_matches_checkout is unknown when nothing says otherwise) — so the stamp half is verified without a build or a server.

If you would rather keep this branch, port those four fields and the three arms into it and I will re-verdict; either way only one of the two should merge, since both touch the same three lines of tools/bench.py.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2858 - Partially compliant

Compliant requirements:

  • The binary sha256 is now correctly filled by passing args.onebit to the provenance function
  • The provenance stanza now correctly identifies the binary that was launched

Non-compliant requirements:

  • The root cause of the 5x discrepancy on different boxes is not addressed in this PR

Requires further human verification:

  • The actual performance discrepancy (5x lower prefill) on different hardware needs further investigation
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect provenance binary identification

The previous implementation passed the first token of the first --config to the provenance function, which resulted in "unknown" binary_sha256 in every invocation. This has been corrected to pass args.onebit, which is the actual binary launched by the bench.

    "provenance": provenance(args.onebit)},
    indent=1))
pv = provenance(args.onebit)
print(f"provenance: rev {pv['engine_rev']} (dirty {pv['engine_dirty']}), "
      f"binary sha256 {pv['binary_sha256'][:16]}...")

@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 3a99601: READY

The bug is real and the fix is the two-line one: binary_sha256 was unfillable because the call site hashed the wrong string.

main's call site before this PR:

"provenance": provenance(configs[0][1][0] if configs and configs[0][1] else None)

configs[0][1] is the first --config's token list, so [0] is either empty (the documented --config base=) or a flag such as --dflash — pathlib.Path("--dflash").read_bytes() raises OSError, the except swallows it, and binary_sha256 stays "unknown" on every invocation, while args.onebit two lines away holds the exact path. That is the field whose whole job is to identify the artefact, so a stanza with it permanently unknown is a stanza that cannot answer the question engine#2858 asked.

provenance(args.onebit) at both call sites is the correct argument, and my earlier measurement still holds for the fixed path: a real binary yields a 64-hex sha256 while the revision and dirty flag keep coming from the tree.

One note: this and #2911 both rewrite provenance() (this one the argument, that one the stamp fields), so whichever lands second should rebase — they are complementary rather than duplicative, and a conflict here is bookkeeping rather than a disagreement.

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