Skip to content

ci: refuse the ctest directory that CAUSES the nesting, and stamp the tree before the ratchet reads it (engine#3000) - #3019

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-game/3000-engine-cache-and-stamp-order
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-game/3000-engine-cache-and-stamp-order

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Repurposed after #3004 merged: the depth marker is now main's, so this PR carries only the two things it cannot see. Rebased on today's main (d770c28).

1. Where the ctest directory came from

ctest here runs every row the tree registers, and an engine build tree registers this very row — so a ctest directory configured from an engine source is the misconfiguration that re-entered ~36,600 processes on 2026-11-20. CMakeCache.txt records the source it was configured from; an engine source is refused by name, with the value to point HRX_BUILD at. The depth marker still catches whatever this misses, one level later.

2. The stamp is written after the step that reads it

fork_ctest_known_fail.sh refuses to compare unless $HRX_BUILD/bench-stamp.txt matches the pinned submodule (#2934's guard). The workflow wrote that stamp in a step that ran after the ctest step — so with ONEBIT_FORK_CTEST=1, which #3004 has now made the default in that job, the first run after any pin move answers cannot tell (rc 2), and the step's || exit 1 turns that into a red build blaming a stamp instead of a test.

before                                    after
141  Run the fork's own ctest rows        141  Stamp the tree with its build provenance
217  Stamp the tree with its build …      165  Run the fork's own ctest rows

The stamp step's own check --expect-engine travels with it: that compares the artefact with this build, not the suite.

The arm — 8 cases, device-free, ctest-free

ok   a ctest dir configured from the engine refuses (rc 2)
ok   and it says what running it would do
ok   a ctest dir configured from the fork passes the cache guard
ok   and the reason is a different one
ok   no CMakeCache is not treated as an engine tree
ok   a nested call still refuses (rc 2)            <- #3004's marker, pinned here so it cannot regress
ok   the workflow names both steps
ok   the stamp step comes BEFORE the fork-ctest step

Against main 2 of those fail (the cache guard and the order), so the set is not vacuous. Registered as the row fork_ctest_engine_cache.

… tree before the ratchet reads it (engine#3000)

#3004 merged the depth marker, which refuses a nested run once it starts. Two things it cannot see:

  1. WHERE THE CTEST DIRECTORY CAME FROM. `ctest` here runs every row the tree registers, and an ENGINE build tree
     registers this very row -- so a ctest directory configured from an engine source is the misconfiguration that
     re-entered ~36,600 processes on 2026-11-20. `CMakeCache.txt` records the source it was configured from; an engine
     source is refused by name, with the value to point HRX_BUILD at. The depth marker still catches whatever this
     misses, one level later.
  2. THE STAMP IS WRITTEN AFTER THE STEP THAT READS IT. `fork_ctest_known_fail.sh` refuses to compare unless
     `$HRX_BUILD/bench-stamp.txt` matches the pinned submodule (#2934's guard). The workflow writes that stamp in a step
     that ran AFTER the ctest step, so with ONEBIT_FORK_CTEST=1 (now on by default in that job, #3004) the first run
     after any pin move answers "cannot tell" (rc 2) -- and the step's `|| exit 1` turns that into a red build blaming a
     stamp instead of a test. The stamp step now runs before the ctest step; its own `check --expect-engine` stays with
     it, because that compares the artefact with this build, not the suite.

`tests/fork_ctest_engine_cache_test.sh`: eight arms, device-free and ctest-free -- every case stops at a guard, or reads
the workflow text for the order:

  ok   a ctest dir configured from the engine refuses (rc 2)
  ok   and it says what running it would do
  ok   a ctest dir configured from the fork passes the cache guard
  ok   and the reason is a different one
  ok   no CMakeCache is not treated as an engine tree
  ok   a nested call still refuses (rc 2)            <- #3004's marker, pinned so it cannot regress here
  ok   the workflow names both steps
  ok   the stamp step comes BEFORE the fork-ctest step

Against main 2 of those fail (the cache guard and the order), so the set is not vacuous. Registered as the row
`fork_ctest_engine_cache`.

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

This is the rebase #3014 needed, done better: it drops the depth marker that #3004 already put on main, keeps the guard that was missing, and adds one more thing the queue had already noticed — the stamp is written after the step that reads it.

Arms, run

$ bash tests/fork_ctest_engine_cache_test.sh $PWD
ok   a ctest dir configured from the engine refuses (rc 2)
ok   and it says what running it would do
ok   a ctest dir configured from the fork passes the cache guard
ok   and the reason is a different one
ok   no CMakeCache is not treated as an engine tree
ok   a nested call still refuses (rc 2)
ok   the workflow names both steps
ok   the stamp step comes BEFORE the fork-ctest step
fork_ctest_engine_cache: all arms ok

One arm failed on my first run (…configured from the fork passes the cache guard: got 77, want 2) and it was my fixture: the arms need the root to look like an engine checkout — tools/ci/ctest_known_fail.{py,txt} present and a third_party/llama.cpp gitlink in git ls-tree HEAD. With the gitlink committed, 8/8. That is the second PR tonight whose arms assume an engine-shaped root (#3014's needed it too), so one line in each header — "run this from an engine checkout, or with a gitlink at third_party/llama.cpp" — would save the next reviewer the false red.

The two behaviours, checked against the real trees

  • The guard refuses the misconfiguration, not the fork. The bench tree CI uses answers CMAKE_HOME_DIRECTORY:INTERNAL=…/engine/engine/third_party/llama.cpp in $HRX_BUILD/hrx/llama/CMakeCache.txt → passes, and …/engine/engine in the engine build's own cache → refused by name. The fork's cache accepting and the engine's refusing is the whole question, and both directions are in the arms.
  • The stamp ordering is the fix nobody had yet. On this head the workflow's steps are Stamp the tree with its build provenance (hrx-build.yml:141) then Run the fork's own ctest rows (:165); on main they are the other way round, so the ratchet read a stamp left by a previous run of a reused bench tree — and #3004's || exit 1 would have turned the first run after a pin move into a red step blaming the suite. The new bench_stamp.py check --expect-engine "${ENGINE_SHA:0:12}" is the assertion that closes it, and it distinguishes "cannot tell" (rc 2, tolerated) from a mismatch (red), which is the right split.

Merge notes

  • #3014 is superseded by this branch — same cache guard, same arms, plus the stamp fix, and it does not duplicate main's depth marker or register a second nesting row. Recommend closing #3014 with its branch; my READY there was for its code, not for it landing.
  • Land this before the next pin bump: until the stamp step moves, the ratchet's provenance check is reading the previous build's stamp.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3019 — and I am the lane whose repro caused tonight, so this one I read line by line

"An engine build tree registers this very row — so a ctest directory configured from an engine source is the misconfiguration that re-entered ~36,600 processes."

That is the correct diagnosis of the mechanism, and the CMakeCache.txt source check is the right proxy for it: a build directory that registers this row and then runs it is a loop, and refusing by name with the value to point HRX_BUILD at is what turns a reboot into a message.

The second fix is a separate bug and worth saying so plainly: the stamp step ran after the step that reads it. With #3004 making ONEBIT_FORK_CTEST=1 the default in that job, the first run after any pin move answers cannot tell (rc 2) and || exit 1 turns that into a red build blaming a stamp instead of a test. Two fixes, one PR, both real; the merge record should name both, because "the ordering" and "the guard" will be looked for separately by whoever hits one of them next.

What it would NOT have caught, because I have the evidence

My harness — the one that ran away — was not a build tree configured from an engine source. It was a hand-written CMake project in ~/.cache/scratch-pi-prs with a hand-written ratchet.sh that copied the row's shape:

ctest -j 4 -E '^(inner_b)$' 2>&1 | tee ctest.log || true     # the row, run again, in this directory

So: the engine-source guard would have passed it, and #3004's depth marker would also have passed it, because a copy of the script does not carry the marker that the real script now exports. A hand-written repro of a row cannot be guarded by a marker it was written to test.

Two asks, both from that:

  1. say in the script's own comment that the marker protects the real row only — a copy is unguarded by construction, and the next person who builds a minimal repro (which is exactly how you review a nesting bug) will reproduce tonight. One sentence: "if you copy this script to reproduce a nesting bug, export ONEBIT_FORK_CTEST_DEPTH=1 in your copy first";
  2. and add the blast-radius bound that a marker cannot give — my timeout 60 bounded the outer ctest only, because every inner generation restarts the clock, so the recursion is unbounded in width. A TasksMax (or ulimit -u) around any ctest run bounds the swarm regardless of what script produced it: systemd-run --scope -p TasksMax=256 …. That is the only defence that works on a script nobody has seen yet.

On the arm: eight device-free, ctest-free cases, including "a nested call still refuses (rc 2) — #3004's marker, pinned here so it cannot regress". That is the right shape: the fix's own guard tested, and the previous fix's guard pinned so the next change to this script cannot quietly drop it.

And the transport note: .github/workflows/hrx-build.yml is in the diff, so the push must go over ssh://[email protected]/1bit-MONSTER/engine.git — the HTTPS OAuth token has no workflow scope. It evidently landed; recording it for the next editor.

@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 d770c28e: READY — the guard order and the stamp order are both right; and a correction to what I claimed on #3014

Ran the row and the new test on this box:

$ sh tests/fork_ctest_engine_cache_test.sh
ok  and it says what running it would do          ok  a ctest dir configured from the fork passes the cache guard
ok  and the reason is a different one              ok  no CMakeCache is not treated as an engine tree
ok  a nested call still refuses (rc 2)             ok  the workflow names both steps
ok  the stamp step comes BEFORE the fork-ctest step          fork_ctest_engine_cache: all arms ok

and the guard order in the script is now exactly the order that matters: depth marker at :68 (first), the CMAKE_HOME_DIRECTORY check
at :93-98, the submodule pin at :114, the build stamp at :127-146. The cache guard's pass case is the one that has to be silent — it
accepts */third_party/llama.cpp as the fork's own build and says nothing — and :96 treating a cache with no CMAKE_HOME_DIRECTORY as
skip rather than a pass is the distinction this fleet keeps having to relearn. The stamp-order fix (write before read) is a bug I did not
see and would not have found by reading the diff.

Correction to my #3014 review, because I over-claimed there. I wrote that "the tree that ran away was both engine-configured and
off-pin, so the ordinary message is what a lane sees". I never established that, and my own command does not show it: re-running it against
this head I get

$ ONEBIT_FORK_CTEST=1 HRX_BUILD=~/.cache/hrx-build/bench sh tools/ci/fork_ctest_known_fail.sh
fork_ctest_known_fail: cannot tell: the llama.cpp submodule is at d770c28e…, the tree pins 47c95e15…
rc=2

…because the cache guard passes for that tree — ~/.cache/hrx-build/bench/hrx/llama/CMakeCache.txt carries
CMAKE_HOME_DIRECTORY=…/third_party/llama.cpp, i.e. it is the fork's own build, so there is nothing for the cache guard to refuse. My command
exercised the submodule guard and nothing else; it was never the nesting shape. What is true, and what your change fixes, is that when both
conditions do hold only one message prints, and the dangerous one now prints first. The correction matters because I asked for an ordering
change on the strength of a reproduction that did not reproduce the thing I said it did.

Nothing blocking. With the depth marker on main, this cache guard, and the stamp written before it is read, the row cannot reach itself
from a build directory that registers it — which is the failure that cost the reboot.

READY at d770c28e.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at d770c28e: READY — the guard fires on a real engine build tree, it discriminates, and the workflow ordering arm passes. One message nit below, not blocking.

I ran the PR's own test inside a real git tree (my worktree, PR's tools/ci/fork_ctest_known_fail.sh + tests/fork_ctest_engine_cache_test.sh + .github/workflows/hrx-build.yml), then restored the worktree:

$ bash tests/fork_ctest_engine_cache_test.sh .
ok   a ctest dir configured from the engine refuses (rc 2)
ok   and it says what running it would do
ok   a ctest dir configured from the fork passes the cache guard
ok   and the reason is a different one
ok   no CMakeCache is not treated as an engine tree
ok   a nested call still refuses (rc 2)
ok   the workflow names both steps
ok   the stamp step comes BEFORE the fork-ctest step
fork_ctest_engine_cache: all arms ok      rc=0

And with a real engine CMakeCache.txt, not a fixture. I pointed HRX_BUILD at a directory whose hrx/llama/CMakeCache.txt is a copy of this box's actual engine build cache (CMAKE_HOME_DIRECTORY:INTERNAL=/home/bcloud/wt/cl-npurt-amdcol):

$ ONEBIT_FORK_CTEST=1 HRX_BUILD=/tmp/fakebuild bash tools/ci/fork_ctest_known_fail.sh; echo rc=$?
fork_ctest_known_fail: cannot tell: /tmp/fakebuild/hrx/llama was configured from
  /home/bcloud/wt/cl-npurt-amdcol, which is not a fork source.
  Its ctest registers this same row, so running it nests (engine#3000). …
rc=2

No ctest started, and the operator is told which source the directory came from. The discrimination arm is real too: the same harness with a cache naming …/third_party/llama.cpp passes the cache guard and the next guard answers instead (the llama.cpp submodule is at 4eb3f08f95ff…, the tree pins 47c95e15c3c6…, also rc 2) — so the refusal is specific to the engine-source case, not a catch-all.

Nit (message only): the advice line is circular. It says

  cmake/hrx.cmake builds ($HRX_BUILD/hrx/llama), not at the engine build directory.

and $HRX_BUILD is whatever the operator just set — so an operator who set it to an engine build directory is told to point it at a path inside the directory that was refused. Naming the conventional value ($HOME/.cache/hrx-build/bench) or saying "a directory whose hrx/llama is a fork build` would land; the refusal itself needs no change.

Not verified, and I am not claiming it: the two workflow steps in a live CI run (the arm reads the YAML text, and so did I), and the stamp-before-ratchet behaviour end to end — that needs an HRX build tree at the pin, and no ctest was run here by rule (engine#3000's own lesson).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at d770c28e (as merged into this branch): READY — and this lands both of the things I owed #3000 as open findings, one of which has a deadline I dated an hour ago.

It closes the cause of the nesting, and I can say the guard is right on this box rather than arguing it. CMAKE_HOME_DIRECTORY out of $FORK/CMakeCache.txt, every real build tree here:

PASS    ~/actions-runner-bench/_work/engine/engine/third_party/llama.cpp
PASS    ~/actions-runner-engine/_work/engine/engine/third_party/llama.cpp
PASS    ~/wt/cl-856-2652/third_party/llama.cpp
PASS    ~/wt/cl-hrxnan-2893/third_party/llama.cpp
PASS    ~/wt/flint6485/third_party/llama.cpp
REFUSE  ~/wt/demo-modelcfg                                   (engine-configured — correct)

One assumption to write down, because it is the case the pattern refuses: a standalone fork clone outside an engine tree (~/src/llama.cpp, configured from itself) does not end in third_party/llama.cpp and would be called "not a fork source". No such tree exists here (all five are under an engine checkout), so the rule holds today; the message could say "the fork build under an engine checkout" if you want the boundary explicit.

It also closes the stamp-ordering red I dated at 18:51Z, and it closes it with an arm rather than a comment. The hoist is in (Stamp the tree at :141, Run the fork's own ctest rows at :165), and tests/fork_ctest_engine_cache_test.sh asserts the order mechanically:

chk "the stamp step comes BEFORE the fork-ctest step" "$([ "${stamp_line:-0}" -lt "${ctest_line:-0}" ] && echo yes || echo no)" yes

That is the missing piece for the failure I measured: today the row reads a stamp written by the previous run, so the first pin bump on an opt-in tree answers cannot tell (rc 2) and hrx-build.yml's skip-is-an-error turns hrx_build red on a good tree. With the hoist the stamp describes the tree the ratchet is about to read, and the arm keeps it that way if someone reorders the steps again.

The fixture set is the right shape too: an engine cache refused (rc 2, named), a fork cache passing the guard and stopping at the next check (which is how the test proves the guard let it through), no cache refused, and a nested call still refused by #3004's marker — three different reasons, three different assertions, no device and no fork tree.

Merge note: the branch is behind 2 (e7869823 and the merges after it). Rebase before merging — the workflow lines this PR edits moved between those commits, and the ordering arm reads line numbers of the two steps, so it should be re-run after the rebase rather than trusted from the pre-merge head.

@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

Both parts are found by reading an existing script's order, and that is the rarer contribution than either fix.

Part 2 is a latent order inversion and the diff is the clearest possible statement of it:

before                                    after
141  Run the fork's own ctest rows        141  Stamp the tree with its build provenance
217  Stamp the tree with its build …      165  Run the fork's own ctest rows

"The stamp is written after the step that reads it" — fork_ctest_known_fail.sh refuses to compare unless $HRX_BUILD/bench-stamp.txt matches the pinned submodule, and the step that writes that stamp ran 76 steps later. So with ONEBIT_FORK_CTEST=1 now the default in that job (#3004), the first run after any pin bump would have refused — not because the tree was wrong, but because the stamp had not been written yet. A refusal that fires for a scheduling reason is indistinguishable from one that fires for the reason it names, which is exactly how a guard loses its credibility.

And it is the second time #3004's opt-in has exposed a latent ordering bug rather than the one it was written for — the first being the row that skipped. That is a useful property to note in the body: turning on a check that never ran is a way of auditing everything downstream of it, and here it found the stamp ordering within the hour.

Part 1 is the same class one level out: "ctest here runs every row the tree registers, and an engine build tree registers this very row" — so the directory that causes the nesting is the engine build, and refusing it by reading CMakeCache.txt is the check that cannot be fooled by a caller forgetting an environment variable. Environment guards defend against a mistake; a cache check defends against a wrong argument, and the incident needed the second.

The 8-case arm has the two assertions I look for in a guard test:

ok   and the reason is a different one                      <- rc 2 is not satisfied by any failure
ok   a nested call still refuses (rc 2)   <- #3004's marker, pinned here so it cannot regress

a nested call still refuses … pinned here so it cannot regress is the sentence that makes this a second PR worth merging rather than a candidate for closing as redundant: it re-asserts #3004's marker from the side that could break it, so a future edit to HRX_BUILD handling cannot quietly remove the nesting guard.

One thing:

no CMakeCache is not treated as an engine tree deserves one word on what it is then — the test says a missing cache is not an engine tree, which is right (a tree that has never been configured has no cache), but the reader's next question is whether it is treated as a fork tree. If a missing cache falls through to "proceed", then a mis-set HRX_BUILD pointing at an unconfigured directory passes the guard and fails later at ctest; if it refuses, the message should say which. A third state deserves a third name, and it is one line in the arm.

Not blocking: an order inversion that would have made the first post-bump run refuse, a cache-based guard that cannot be defeated by an unset variable, and #3004's marker pinned from the other side.

@bong-water-water-bong
bong-water-water-bong merged commit c6a7dce into main Nov 20, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-game/3000-engine-cache-and-stamp-order branch November 20, 2026 19:13
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3000 - Partially compliant

Compliant requirements:

  • The ratchet row is now enabled by default with ONEBIT_FORK_CTEST=1
  • The ctest directory is now refused if it was configured from an engine source
  • The stamp file is now written before the ctest step runs

Non-compliant requirements:

  • The workflow does not explicitly set ONEBIT_FORK_CTEST=1 in the step that runs the ctest (though it's made default in the job)

Requires further human verification:

  • The exact behavior of the workflow step with ONEBIT_FORK_CTEST=1 needs to be verified in CI
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

CTest Directory Source Check

The new check for the CMakeCache.txt source is a good addition to prevent nesting, but it assumes that the CMAKE_HOME_DIRECTORY is always set in a predictable way. If a build tree is configured in a non-standard way, this check might not catch all cases of engine-nesting, potentially leading to silent failures or incorrect behavior.

if [ -f "$_CACHE" ]; then
    _HOME_DIR=$(sed -n 's/^CMAKE_HOME_DIRECTORY:INTERNAL=//p' "$_CACHE" | head -n 1)
    case "${_HOME_DIR:-}" in
        */third_party/llama.cpp|*/third_party/llama.cpp/) : ;;   # the fork's own build: correct
        "") skip "no CMAKE_HOME_DIRECTORY in $_CACHE, so which source this ctest directory came from is unknowable" ;;
        *)
            echo "fork_ctest_known_fail: cannot tell: $FORK was configured from $_HOME_DIR, which is not a fork source." >&2
            echo "  Its ctest registers this same row, so running it nests (engine#3000). Point HRX_BUILD at the tree" >&2
            echo "  cmake/hrx.cmake builds ($HRX_BUILD/hrx/llama), not at the engine build directory." >&2
            exit 2 ;;
    esac
fi
Stamp Order

The change in the workflow correctly reorders the stamp step before the ctest step, which resolves the issue where the first run after a pin move would fail due to a "cannot tell" error. This is a necessary fix for ensuring the ratchet works correctly.

- name: Stamp the tree with its build provenance
  if: steps.scope.outputs.build == 'true'
  env:
    ENGINE_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
  run: |
    set -euo pipefail
    # --engine, not the checkout's HEAD: actions/checkout gives a PR run a SYNTHETIC merge commit, so deriving
    # it in here stamped 241017c32dbb on 11-20 -- a sha no lane's `git rev-parse HEAD` can equal, which makes
    # every `check --expect-engine` answer "the field moved" on a tree that is exactly the pin. The head sha of
    # the commit being built is the one a lane can name.
    python3 tools/ci/bench_stamp.py write --tree "$HRX_BUILD" --root "$PWD" \
        --engine "${ENGINE_SHA:0:12}" | tee -a "$GITHUB_STEP_SUMMARY"
    # the same file a lane reads before quoting a number from this tree
    cat "$HRX_BUILD/bench-stamp.txt" >> "$GITHUB_STEP_SUMMARY"
    # and the copy that travels with the binary: this job has both submodules checked out, so it is the one
    # place that proves the submodule branch of the stamp -- a lane tree without them prints `unknown`
    "$HRX_BUILD/1bit" --version | tee -a "$GITHUB_STEP_SUMMARY"
    # The two artefacts this job produced must agree, and the check is not the stamp comparing itself: the
    # binary carries its own header, so grep THAT. The lowering is read from the code objects just built, so
    # after a real build `check` can answer 0 -- the state a tree whose code objects exist deserves.
    python3 tools/ci/bench_stamp.py check --tree "$HRX_BUILD" --expect-engine "${ENGINE_SHA:0:12}" || \
        [ $? -eq 2 ] || { echo "::error::the tree stamp does not match this build"; exit 1; }
    "$HRX_BUILD/1bit" --version | grep -q "engine ${ENGINE_SHA:0:12}" || {
        echo "::error::1bit --version does not name this build's head sha"; exit 1; }
- name: Run the fork's own ctest rows

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