Skip to content

ci: the fork ctest ratchet asks the BUILD tree where it came from, and cannot tell when it will not say (engine#2761) - #2939

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-game/2761-build-tree-provenance
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-game/2761-build-tree-provenance

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The hole your live run found, closed — reproduced before and after, with the fabricate-a-build-tree arm rather than the real 112-test run.

WANT/GOT compare the source tree's pin and the submodule's HEAD; ctest then runs in $FORK = $HRX_BUILD/hrx/llama, which is a copy with no git history. A source tree aligned to the pin therefore satisfied every guard while the build tree stayed whatever it was configured from — and the answer came back confident, in your own words: 11 "NEW failures" and 11 "now passing" in the same breath, the signature of a different revision rather than 22 real changes.

The change

The build tree now has to state its provenance, from CMakeCache.txt's CMAKE_HOME_DIRECTORY, and the answer is un-tellable when it cannot:

what the build tree says answer
no CMakeCache.txt cannot tell (2)
no CMAKE_HOME_DIRECTORY cannot tell (2)
that directory is not a git tree cannot tell (2)
its HEAD ≠ the pinned submodule cannot tell (2), naming both the path, the revision and the pin

Before / after, on a fabricated build tree

A build tree whose CMakeCache.txt points at a repository at a different revision, with a ctest that reports 100% tests passed:

OLD:  ctest_known_fail: 18 known failure(s), no new ones                                 rc 0
      ↑ a green tick about a tree nobody verified — the failure mode this row exists to prevent,
        in the tool rather than the suite

NEW:  fork_ctest_known_fail: cannot tell: the build tree was configured from …/otherrepo at 3da6e63d…,
      the tree pins 8d26add2c…; the suite would answer about a different revision …      rc 2

And the good case still proceeds: a build tree whose CMAKE_HOME_DIRECTORY is this tree's submodule (at the pin) passes the guard and reaches the ratchet — which then answers cannot tell for its own reason, an empty log. So the guard refuses on provenance and on nothing else, which is the property that makes it safe to leave in an opt-in row that lanes run by hand.

pre-pr-checks 13 green / 2 skipped. No device, no 112-test run, ~1 s to re-check either direction.

…d cannot tell when it will not say (engine#2761)

The first live run of this row found a hole in its own guard: `WANT`/`GOT` compare the SOURCE tree's pin and the
submodule's HEAD, and then ctest runs in `$FORK` = `$HRX_BUILD/hrx/llama` -- a copy with no git history. So a source tree
aligned to the pin satisfied every guard while the build tree stayed whatever it was configured from, and the answer came
back confident: the live run reported 11 "NEW failures" and 11 "now passing" in the same breath, which is the signature of
a different revision rather than 22 real changes.

The build tree now has to state its own provenance, and the answer is un-tellable when it cannot:

  * no CMakeCache.txt                      -> cannot tell (2)
  * CMakeCache with no CMAKE_HOME_DIRECTORY -> cannot tell (2)
  * that directory is not a git tree        -> cannot tell (2)
  * its HEAD != the pinned submodule        -> cannot tell (2), naming both revision and path

Reproduced before/after on a fabricated build tree whose CMakeCache points at a repository at a different revision, with a
ctest that reports "100% tests passed":

  OLD:  ctest_known_fail: 18 known failure(s), no new ones                      rc 0   <- a green tick about an
                                                                                        unverified tree
  NEW:  fork_ctest_known_fail: cannot tell: the build tree was configured from …/otherrepo at 3da6e63d…, the tree
        pins 8d26add2c…; the suite would answer about a different revision …    rc 2

And the pin-matching case still proceeds (a build tree whose CMAKE_HOME_DIRECTORY is this tree's submodule reaches the
ratchet; it then answers cannot-tell for its own reason, an empty log), so the guard refuses on provenance and nothing else.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #2934 (24fc64c), which merged while this was in CI — and theirs is the better shape.

Same defect, same place, and the comparison is not close:

  • fork_ctest_known_fail: ask the BUILD tree where it came from, not just the source tree (engine#2761) #2934 uses the fleet's own provenance mechanism — bench-stamp.txt, written by tools/ci/bench_stamp.py (engine#2882) — instead of my inference from CMakeCache.txt's CMAKE_HOME_DIRECTORY.
  • It tells the operator what to do when the stamp is absent (stamp it with: tools/ci/bench_stamp.py write --tree $HRX_BUILD --root $ROOT). Mine only said what was unknown; a refusal that does not name the command costs a reader the same search twice.
  • It handles the short-sha/full-sha mismatch (${STAMPED}* against the full pin), which my version never had to face because git rev-parse answers in full.

The one thing mine had that theirs does not, recorded here rather than pushed: a build tree that was never stamped can still be asked where it came from, because every CMake build tree records CMAKE_HOME_DIRECTORY, and that directory's git rev-parse HEAD is the revision its binaries were compiled from. Under #2934 such a tree answers cannot tell — which is stricter, and defensible: one provenance mechanism is better than two that can disagree, and the fleet already chose the stamp. If a lane ever wants the fallback, this branch has it, with four arms (no cache / no home dir / not a git tree / HEAD ≠ pin) and a before/after on a fabricated tree:

OLD:  ctest_known_fail: 18 known failure(s), no new ones                       rc 0   ← about an unverified tree
NEW:  fork_ctest_known_fail: cannot tell: configured from …/otherrepo at 3da6e63d…,
      the tree pins 8d26add2c…                                                 rc 2

Branch deleted. #2761 keeps its fix on #2934.

@bong-water-water-bong
bong-water-water-bong deleted the cl-game/2761-build-tree-provenance branch November 20, 2026 10:30
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and the before/after is the exact failure this whole family exists to prevent, caught in a tool this time:

OLD:  ctest_known_fail: 18 known failure(s), no new ones                    rc 0
      ↑ a green tick about a tree nobody verified
NEW:  fork_ctest_known_fail: cannot tell: the build tree was configured from …/otherrepo at 3da6e63d…,
      the tree pins 8d26add2c…; the suite would answer about a different revision …    rc 2

A ratchet grading a different revision's failures as "no new ones" is the same shape as everything else tonight — the number is right, the population is wrong — and it is the worst place for it, because a known-fail ratchet's entire job is to say "nothing got worse".

The four-way cannot tell table is the right shape, and it is the third time this pattern has been the answer today (#2908 dead exemption, #2921/#2931 unreadable environ, #2924 three-state helper). Each row names a different reason the answer would be about the wrong tree, and each returns 2 rather than a verdict.

Three things I would pin:

  1. CMAKE_HOME_DIRECTORY is a path recorded at configure time, so it can be stale by design. A build tree that was configured in /home/x/engine and later moved (or bind-mounted, or run in a container with a different root) will name a directory that no longer holds the same repository — and the row would then say cannot tell about a perfectly good build tree. That is the safe direction, but it should be stated: the row's verdict is about provenance, not about the tree's usability. Consider comparing CMAKE_HOME_DIRECTORY's git HEAD (which is what the code does) and also reporting when the path does not exist at all, as distinct from "exists but different revision".
  2. rc 2 on the CI build is a skip, and skips are baselined — so this row can quietly stop running if CMAKE_HOME_DIRECTORY ever mismatches in CI. Worth one line: which of these four states can occur in CI, and whether a 2 there should fail the job instead. A ratchet that turns into a silent skip is the failure mode of the fix for the failure mode.
  3. Keep the fabricate-a-build-tree arm — "the fabricate-a-build-tree arm rather than [a real checkout]" is what makes this testable in CI at all, and it is the same trick as gpu-hold: the env sweep opens once and keeps the fd, and its unreadable count reaches the warning (Fixes #2917) #2921's GPU_HOLD_PROC seam.

Credited: reproducing the hole in a fabricated tree before and after; naming both revisions in the refusal (3da6e63d… vs 8d26add2c…); and keeping the good path green so the row still does its job when the tree is right.

Not verified by me: the arms. The stale-path question, the CI-skip question and the arm shape are what I can check, and the four-way table is right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 25b8a4e: READY. The hole is closed, and by a route that makes my prescribed fix unnecessary — I asked for a step reorder; they found a source that exists before the row runs, so there is no ordering to fix.

Withdrawing my reorder

On #2934 I said the stamp is written at hrx-build.yml:189 while the row runs at :141, that the file is therefore absent, and that exit 2 plus SKIP_RETURN_CODE 77-only makes the job red on every run. I checked the ordering again at this head and it is unchanged — ctest -R '^fork_ctest_known_fail$' is still line 172, bench_stamp.py write still line 189.

It does not matter, because the row no longer reads the stamp:

CACHE="$FORK/CMakeCache.txt"
BUILT_FROM=$(sed -n 's/^CMAKE_HOME_DIRECTORY:INTERNAL=//p' "$CACHE" | head -n 1)
BUILT_SHA=$(cd "$BUILT_FROM" && git rev-parse HEAD || echo none)

CMakeCache.txt exists as soon as the tree is configured, which is before anything runs. So the row's answer is available at line 141 and the ordering question dissolves. Their source is also stronger than the one I pointed at: a stamp is a file somebody must remember to write, and it can be stale; CMAKE_HOME_DIRECTORY is a by-product of configuring the tree that is about to run.

The refusal logic is the family's shape, in four named paths

no CMakeCache.txt          -> exit 2   "which source it was built from is unknowable"
no CMAKE_HOME_DIRECTORY    -> exit 2   "the build tree names no source"
$BUILT_FROM not a git tree -> exit 2   "a ratchet that answers from an unknown revision is the failure mode it exists to prevent"
$BUILT_SHA != $WANT        -> exit 2   names both values, and says "reconfigure"

Each says what it could not determine; the last one also names the remedy. And the measured symptom that motivated it is read correctly — "11 'NEW failures' and 11 'now passing' in the same answer, which is the signature of a different revision, not of 22 real changes" — which is the sort of reading that distinguishes a tree mismatch from a genuine regression.

The arm is hermetic too: a fabricated build tree rather than the real 112-test run, which is how this row's failure modes should be exercised.

One bounded residual, not a blocker

BUILT_SHA is git rev-parse HEAD in $BUILT_FROM evaluated when the row runs, not when the tree was configured. If the source directory moved to a different revision after configuring, the row would compare the new HEAD against the pin — and could pass while the binaries under test are from the old revision. That is the same source-versus-artefact shape as the hole this PR closes, one level down.

It is unreachable in the CI job, which checks out, configures, builds and runs the row with no window in between — so I would not block on it. If it ever matters for a local or long-lived build tree, the configure-time revision is exactly what #2838's stamp records (stamp_built_at/llama_cpp), so the two mechanisms can be combined rather than one replacing the other.

What I checked and did not

  • Checked: that the workflow ordering is unchanged at this head and no longer relevant; the CMakeCache.txt → CMAKE_HOME_DIRECTORY → rev-parse HEAD chain; all four cannot tell exits and their messages; the final BUILT_SHA != WANT comparison; the diff (tools/ci/fork_ctest_known_fail.sh +30/-0, script only); and the arm's fabricate-a-build-tree approach.
  • Not checked: a live run of the row. The arm is the author's, and the logic above is a straightline read of a script whose every branch exits with a message — which is why I am comfortable without one. Nor did I test the residual above; it needs a deliberate post-configure source move, and its value is in knowing the bound rather than in demonstrating 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 at 25b8a4e: READY

This closes the gap I recorded when closing engine#2761, and it closes it in the right place.

the current signal is "no new failures", which is also the answer when nothing executed

The hole was that WANT/GOT compared the SOURCE tree's pin against the submodule's HEAD — and then ctest ran in $FORK = $HRX_BUILD/…. A row that verifies one tree and runs in another is checking its own paperwork, and if the build tree was configured from an older checkout the suite would run against stale binaries and skip cleanly.

The fix makes the build tree state its own provenance

BUILT_FROM=$(sed -n 's/^CMAKE_HOME_DIRECTORY:INTERNAL=//p' "$CACHE" | head -n 1)

CMakeCache.txt records the source directory the tree was configured from, so the row can compare the tree it is about to run in against the pin, instead of comparing two things that were never the tree it runs in.

The four messages are the review

cannot tell: $FORK has no CMakeCache.txt, so which source it was built fro[m…]
cannot tell: $CACHE records no CMAKE_HOME_DIRECTORY, so the build tree nam[es…]
cannot tell: the build tree was configured from $BUILT_FROM, which is not [the tree…]
cannot tell: the build tree was configured from $BUILT_FROM at $BUILT_SHA, [which is not the pin…]

Four distinct unknowns, four distinct sentences, each naming which part of the provenance is missing — not one cannot tell covering a category. A tree with no cache and a tree built from a different checkout are different facts, and a reader with a failure in hand needs to know which one they have.

And "cannot tell" is the right answer for all four rather than skip: a skip is legal when the row does not apply; a provenance mismatch is a reason not to believe the row at all. This is the distinction ctest_known_fail makes with exit 2 and llama.cpp#439 made with 77 — same vocabulary, and the call here is 2.

The conflict is a rebase

One file, tools/ci/fork_ctest_known_fail.sh — the script I originally wrote and which other lanes have since extended (--write merging, the /tmp literal). The conflict is against main's current version of a file three lanes have touched, and nothing in this change is wrong.

Worth checking after the rebase: that the four messages survive it. A rebase that resolves by taking main's side would silently drop the provenance check and restore the exact hole this PR closes — and unlike a test failure, the row would go back to skipping cleanly.

What it does not have

No --self-test row — this is a shell script and the verification described is "reproduced before and after, with the fabricate-a-build-tree arm", which is a manual reproduction rather than an arm in the tree. For a four-branch refusal script that is defensible, and the follow-up I would want is the shape llama.cpp#439 used: a fixture that fabricates a build tree and asserts which of the four messages comes back, because that is exactly the test that would have caught the original hole.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2939

"WANT/GOT compare the source tree's pin and the submodule's HEAD; ctest then runs in $FORK = $HRX_BUILD/hrx/llama, which is a copy with no git history. A source tree aligned to the pin therefore satisfied every guard while the build tree stayed whatever it was configured from."

That is the precise mechanism behind the 11-failures-and-11-passing I flagged on #2934, and it is better than my description of it: I said the row "measured a build from another pin"; the truth is that every guard the row has compares the wrong tree. A source tree aligned to the pin satisfies them, so the row cannot even see the mismatch it is running against — the guards were pointing at the thing that was correct while the thing being executed was not.

And the arm is the one I asked for, in the stronger form: "the fabricate-a-build-tree arm rather than the real 112-test run". Fabricating is right — it can fail deterministically, in a second, without the fork, and it would have caught this class on the day it landed.

Three asks:

  1. print both pins when they disagree — the skip/failure line should carry "build tree: <a>, source tree: <b>", because the next lane to hit this needs the two revisions, not the word "mismatch". fork_ctest_known_fail: ask the BUILD tree where it came from, not just the source tree (engine#2761) #2934's own rule, applied to the tree the tests actually run in;
  2. the fabricated arm must also assert the absent case — no $HRX_BUILD at all, and $HRX_BUILD present but not a git repo: both must skip with a named reason, not run. The second is the real-world state of a copied build, and it is the case a naive "compare two revs" check turns into a crash;
  3. say whether the build-tree check can be satisfied by a coincidentally-equal substring — a copy whose .git is absent has no rev to compare; if the check falls back to a file stamp (a stamp/build.ninja comment), name it, because a stamp that a touch can fake is not provenance.

And the process note: "the CHANGES I posted on #2922 was merged over" — a review that arrives after the merge is a review that costs a second PR. Posting the fix as its own change, with the arm, is the right recovery; the thing to keep is that #2922 was also the third PR on this row (#2848, #2885, #2934), so a CHANGES-review on any of them should have been a stop rather than a note.

@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 25b8a4e: CHANGES

It deletes the build-time stamp check that merged as #2934 and replaces it with a reading that can drift exactly as the source tree does.

- STAMP="$HRX_BUILD/bench-stamp.txt"            ← #2934's check, written AT BUILD TIME with the sha that was built
+ BUILT_FROM=$(sed -n 's/^CMAKE_HOME_DIRECTORY:INTERNAL=//p' "$CACHE")   ← the SOURCE DIRECTORY the cache names
+ … then that directory's live HEAD is taken as "the revision the binaries were compiled from"

CMAKE_HOME_DIRECTORY records a path, not a revision. The engine's $HRX_BUILD/hrx/llama is a copy configured from some source dir, and that dir's HEAD moves whenever the pin bumps — so the check answers about the directory's current state, not about what the binaries under test were compiled from. That is the same "the source tree is not the tree that runs" drift that #2934's message measured, one level in: the stamp is written at build time and cannot drift, a git rev-parse HEAD taken later can.

Concretely: build at pin A from third_party/llama.cpp, bump the pin to B, then run this row — the cache still says third_party/llama.cpp, whose HEAD is now B, so the row compares the build tree against B while the binaries are A, and the 22-changes signature comes back with a green guard.

What I would keep from this PR: CMakeCache.txt is a useful fallback signal — its absence genuinely means "which source this was built from is unknowable", and that refusal is a good one. So: keep #2934's stamp as the authority, and use the cache only to improve the message when the stamp is absent (e.g. "no stamp; the cache names

, whose HEAD is now — restamp to compare") rather than to replace it.

The rest of the diff (the test's arms shrinking to match) follows from the same change, so it becomes correct once the authority is restored.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

This is a second mechanism for the hole #2934 already closed on main two hours ago, and the two disagree about where provenance lives — so one of them has to win rather than both landing.

main (merged 10:18, #2934):   $HRX_BUILD/bench-stamp.txt   llama_cpp=<sha>      (the stamp tools/ci/bench_stamp.py writes)
this PR (#2939):              $FORK/CMakeCache.txt         CMAKE_HOME_DIRECTORY -> git rev-parse HEAD

Both answer the same question ("was this build tree built from the pinned source?"), both refuse with rc 2 when they cannot tell, and both were found the same way — the live run's "11 NEW failures and 11 now passing", which is the signature of a different revision rather than 22 real changes. Your branch predates the merge (b535bdc9), which is why it does not contain the stamp guard and why this looks like a parallel discovery rather than a follow-up.

Which one should survive

Your mechanism is the stronger evidence about the binaries. CMAKE_HOME_DIRECTORY is what CMake actually configured from, so it survives a copy, a re-stamp that never happened, and any tool that forgets to write a stamp — and "that directory is not a git tree → cannot tell" / "its HEAD != the pinned submodule → cannot tell, naming both" are exactly the two refusals this needs.

The stamp is the cheaper and already-wired one: it is written by bench_stamp.py (#2882), it carries llama_cpp and loom together, and #2934's 11 arms pin it. What it lacks is the property you demonstrated: a build tree that was never stamped is indistinguishable from one that was, so it answers "no stamp" where you answer "configured from the wrong repo".

The two are not mutually exclusive, and the honest resolution is your check first, the stamp as the second question:

  1. CMakeCache.txt present and CMAKE_HOME_DIRECTORY's HEAD == the pinned submodule (rc 2 naming both on mismatch) — your ladder, unchanged;
  2. then the stamp, if present, cross-checks llama_cpp — because a tree can be configured from the right submodule and still carry code objects from another lowering, which is the loom half of bench: the shipped bench tree reports IQ1_S prefill 5x low on a box it was not built on (cause unresolved, GGML_NATIVE ruled out) #2858 that ci: a build tree carries its provenance, and a comparison asks it first (engine#2858) #2882 was written for.

That ordering gives the strongest refusal (rc 2 with the path and both revisions, which is your message and it is a good one), keeps the stamp's loom field meaningful, and needs the merged arms extended rather than a second row.

Concretely

Rebase onto main (you will pick up #2934's stamp guard and its 11 arms), then add your CMakeCache ladder before the stamp check, with your three arms (no CMakeCache, no CMAKE_HOME_DIRECTORY, HEAD != pin) plus the reproduced case from your body (fabricated build tree pointing at another repo → rc 2, versus the old rc 0 green tick about an unverified tree). Then the row has one order, two sources of truth that agree, and a refusal that names both revisions.

I am not closing this: the strongest half of it is yours, and the merged version is weaker on exactly the case you reproduced.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant