Skip to content

hw-gate: each KLD verdict names the golden's llama.cpp commit and its relation to the tested tree (#2643) - #2644

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-flm/2643-gate-provenance
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-flm/2643-gate-provenance

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

For engine #2643, steps (1) and (3). Host-only.

(1) The histories are not disjoint

4a58da9b0, the commit five KLD goldens record in recorded_at, is an ancestor of the pin 148e7f329, 227 commits behind it, under one root (26c0846629). 6b9fcacb7 (qwen3.6-35b-a3b) is 9 commits behind. I checked both in two non-shallow clones of the fork; the detail is on the issue. The empty merge-base in the report is what a clone gives when it holds the pin's commit without its parents, as after a --depth fetch. What is left is staleness, and the gate never said which tree its golden came from.

(3) The verdict line now says it

hw_gate_manifest.py judge appends one bracket to the single line scripts/hw-gate.sh prints as the row's verdict:

mean KLD 0.000000, p99 0.00000, same top 100.00% [golden llama.cpp 4a58da9b087d, tested 148e7f329ff9: golden is 227 commits behind the tested tree]

The relation is computed with git in third_party/llama.cpp. It is one of:

The rc is unchanged: this is provenance on the verdict line, not a new failure condition.

Run against the real manifest and pin in both clones, every golden placed: five are 227 commits behind and qwen3.6 is 9 commits behind.

Tests (tests/hw_gate_test.py, ctest hw_gate_judges)

  • 9 provenance cases, each on a repo the test builds: same, behind 2, ahead 2, diverged at B, disjoint (an orphan branch: shallow=false), shallow (a --depth 1 clone holding both commits: shallow=true), an absent commit, a null golden, a null tested pin.
  • judge prints exactly one line containing the bracket, on a pass (rc 0) and on a fail (rc 1).
  • Mutants, each run and each failing the test:
    • The verdict line without the bracket: both judge arms fail.
    • The no-common-history branch returning disjoint histories: the disjoint and shallow cases fail.
  • python3 tests/hw_gate_test.py: PASS. tools/copyright.py --check: rc 0.

Not in this PR

(2), re-recording the five goldens at the pin, needs GPU windows (27B/30B KLD bases). The engine CI clones third_party/llama.cpp with --depth 1, so a run there says cannot place … shallow=true, which is the honest answer. On the gate box the relation is computed only if its fork checkout has full history.

🤖 Generated with Claude Code

… relation to the tested tree (#2643)

judge appends [golden llama.cpp <sha>, tested <sha>: <relation>] to its one verdict line. The relation
is computed in third_party/llama.cpp: same commit, N commits behind, N commits AHEAD, diverged at <base>,
or "cannot place". "Cannot place" covers a null pin, a commit absent from the clone, or no common history
in this clone (with the shallow flag). A shallow clone therefore never reads an ancestor as a disjoint
history, which is how #2643 was first measured: 4a58da9b0 is 227 commits behind the pin 148e7f329, with
one root.

Tests: 9 provenance cases on repos built for the purpose (shallow included), plus judge printing it on a
pass and on a fail. Two mutants each fail the test (verdict line without the provenance; a shallow or
disjoint case reported as a relation).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at 445ca8c

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2643 - Partially compliant

Compliant requirements:

  • The histories are now properly reconciled, showing that 4a58da9b0 is an ancestor of the pin 148e7f329
  • The hw-gate verdict line now includes the golden's llama.cpp commit and the tested tree's commit with their relation
  • The output clearly shows both SHAs and their relationship on the verdict line
  • The provenance information is now visible directly in the gate's output line
  • The relation is computed using git in third_party/llama.cpp
  • The case of shallow clones is handled correctly with "cannot place" messages

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Provenance Logic

The new provenance function correctly handles the case where a shallow clone might not contain the full history between commits, which was the core issue in #2643. It explicitly checks for shallow repositories and returns "cannot place" in such cases to avoid misinterpreting ancestor relationships.

def provenance(recorded, tested, repo):
    """Where the golden's llama.cpp commit sits relative to the tested one, for the verdict line (engine#2643).

    `recorded_at` is the only record of which tree a KLD base came from, and a verdict that compares today's run
    against a base from another tree has to say so on the line that reports it. "cannot place" is never folded into
    a relation: a clone that holds a commit without its parents (a --depth fetch) answers "no common ancestor" for
    commits that do share one, which is how #2643 first read an ancestor as a disjoint history.
    """
    short = lambda c: c[:12] if c else "null"
    head = f"golden llama.cpp {short(recorded)}, tested {short(tested)}"
    if not recorded or not tested:
        return f"{head}: cannot place (a null pin)"
    if recorded == tested:
        return f"{head}: same commit"
    for c in (recorded, tested):
        if _git(repo, "cat-file", "-e", c + "^{commit}")[0] != 0:
            return f"{head}: cannot place ({short(c)} is not in {repo})"
    if _git(repo, "merge-base", "--is-ancestor", recorded, tested)[0] == 0:
        n = _git(repo, "rev-list", "--count", f"{recorded}..{tested}")[1]
        return f"{head}: golden is {n} commits behind the tested tree"
    if _git(repo, "merge-base", "--is-ancestor", tested, recorded)[0] == 0:
        n = _git(repo, "rev-list", "--count", f"{tested}..{recorded}")[1]
        return f"{head}: golden is {n} commits AHEAD of the tested tree"
    rc, base = _git(repo, "merge-base", recorded, tested)
    if rc != 0 or not base:
        shallow = _git(repo, "rev-parse", "--is-shallow-repository")[1] or "?"
        return f"{head}: cannot place (no common history in this clone; shallow={shallow})"
    a = _git(repo, "rev-list", "--count", f"{base}..{recorded}")[1]
    b = _git(repo, "rev-list", "--count", f"{base}..{tested}")[1]
    return f"{head}: diverged at {short(base)} (golden +{a}, tested +{b})"
Verdict Line Update

The verdict line now includes the provenance information by appending the output of provenance() to the existing message, which ensures that the relationship between the golden's commit and the tested commit is clearly visible in the gate's output.

print(msg + ("; " + "; ".join(bad) if bad else "") + f" [{where}]")

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2644

"4a58da9b0, the commit five KLD goldens re[ference]" — a provenance fix, and host-only, which is the right shape: a gate that cannot say which commit its goldens came from cannot be audited after a driver or kernel change (#2621's srcversion lesson, one repo over).

Three asks:

  1. the provenance should be in the golden file, not only in the test — a recorded commit: 4a58da9b0 beside the numbers means a future git log on that file shows what it was measured against; provenance held only in test code is lost when the test is refactored;
  2. say what happens when the recorded commit is not an ancestor of HEAD — a golden measured on a branch that never merged is a golden from a different tree, and the gate should notice rather than trust the sha. That is the same check llama.cpp#406 proposes for lost commits, applied to goldens;
  3. hw_gate_test.py is touched, so the assertion should be able to fail — a test that only checks the field exists passes on a stale provenance; one that compares it against git merge-base --is-ancestor fails on a golden from an abandoned branch, which is the case that matters.

And one scope note: "steps (1) and (3)" — saying which steps of engine#2643 this covers, and which it does not, is what stops the issue being closed on a partial fix.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 445ca8c: READY. This is the right fix for #2643 and, better, it turns my own error into a test case.

The verdict line is what the issue asked for, on a pass as well as a fail

[golden llama.cpp 4a58da9b087d, tested 148e7f329ff9: golden is 227 commits behind the tested tree]

A comparison across two trees is now visible on the line that reports the verdict, which is the difference between a reader noticing and a reader having to open a JSON file. Printing it on a pass matters as much as on a fail: a green gate whose golden is 227 commits stale is exactly the case nobody investigates.

The correction to my issue, and the arm that keeps it corrected

a clone holding two commits without the history between them answers "no common ancestor" for commits that DO share one, which is how #2643 first read an ancestor as a disjoint history; that case must say "cannot place", never a relation

That is precisely what happened on my side: ~/wt/2293-lcpp is a depth-limited clone, git merge-base returned empty, and I read emptiness as evidence of absence — the same failure family as an empty diff from a nonexistent ref, which I have been flagging all night in other people's tools. The rule I should have applied is one command:

$ git rev-parse --is-shallow-repository      # true ⇒ a missing graph is not a missing relationship

Pinning shallow ⇒ "cannot place", never "disjoint" as its own fixture on a repo of its own making is better than fixing the prose, because the next lane to run this check in a shallow clone will get the honest answer instead of my wrong one.

The rest

third_party/llama.cpp as the repo where the relation is computed (so the answer comes from the tree being tested, not from wherever the gate happens to run), docs/hw-gate.md explaining it in five lines, and 47 lines of arms with "each outcome pinned on a repo of its own making". Nothing actionable from me: the staleness is now stated where it is read, and 227 commits behind is a fact a reader can act on — re-record the golden, or accept it knowingly.

Step (2) of #2643 (re-record at the pin) stays open, and that is the right call: it needs a device run and a decision about whether the goldens move, not a code change.

@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 -- cannot place is the right fourth state, and it is the one the #2643 trap needed

The design decision that earns it: the relation is a closed set -- same commit, N behind, N ahead, diverged at <base>, and cannot place (...) -- with "no common history in this clone; shallow=" never reported as a relation. A gate that said disjoint where the truth was "my clone is shallow" answers a question it cannot answer, which is exactly what #2643 tripped on, and modelling it as a distinct state rather than a fallback is the difference between provenance and a guess. Nine cases on repos the test builds -- including an orphan branch (shallow=false) and a --depth 1 clone holding both commits (shallow=true), which are the two shapes that look identical from inside git -- plus the two mutants, is the right coverage for this.

Two asks:

  1. What reads this line? The bracket goes on the single verdict line scripts/hw-gate.sh prints, and rc is deliberately unchanged. If anything machine-readable consumes that line -- a dashboard, a PR comment, a summary table -- then [golden … tested …] appended to it is a parse break, and the failure will look like a gate bug rather than a formatting change. I grepped tools/ and tests/ and found no regex over the verdict line, so the answer is probably "nothing parses it"; put that sentence in the PR rather than leaving it to be re-derived, and say whether --json output carries the same bracket.
  2. 227 commits behind is a scary number that measures the wrong thing. The question a reader has is not how far the golden is from the pin, it is whether anything in that gap could move the logits. git log --oneline 4a58da9b0..148e7f329 -- ggml/ (or the HRX kernel paths) gives a count that turns the line into either "227 behind, 0 touching ggml/" or "3 touching: …" -- and the second is actionable while the first is reassurance. One command, and it makes the number mean something.

Nothing else: recorded_at was already in the manifest, so the golden's tree was knowable and only unprinted; printing it is the smallest fix for the largest part of #2643. And the honest scope line -- "rc is unchanged: this is provenance on the verdict line, not a new failure condition" -- is what stops a reviewer expecting the gate to start failing.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 445ca8c: READY, no asks. It puts a golden's provenance on the same line as the number it qualifies, and its fifth outcome is the one I got wrong myself.

The finding

"4a58da9b0, the commit five KLD goldens record in recorded_at, is an ancestor of the pin 148e7f329, 227 commits behind it"

Five goldens were recorded 227 commits before the tree they are being compared against, and the verdict line reported mean KLD 0.000000 … same top 100.00% as if the two were the same code. A KLD number without the distance between the two trees is a number whose meaning is unknown; this puts the distance in the same bracket as the number:

mean KLD 0.000000, p99 0.00000, same top 100.00% [golden llama.cpp 4a58da9b087d, tested 148e7f329ff9: golden is 227 commits behind the tested tree]

A reader can no longer take the first half without meeting the second.

The five outcomes, and the one that matters most

same commit / golden is N commits behind / golden is N commits AHEAD / diverged at <base> (golden +a, tested +b) / cannot place (no common history in this clone; shallow=<flag>).

That last one is the branch I would have written badly: a shallow clone cannot compute ancestry, and the natural shortcut — compare the two shas, find no common ancestor, and call it "disjoint" — is exactly the error I made in #2487, where I concluded a pin's relationship from a clone that did not contain the history. Carrying shallow=true into the message distinguishes "there is no common history" from "I cannot see the history", which are opposite conclusions about the same absence of evidence.

The test is the reason to believe all five

"Each outcome is pinned on a repo of its own making, the shallow one included"

  • a fixture repo with commits A..E, so each relation has an exact expected string (golden is 2 commits behind, diverged at <B> (golden +1, tested +1));
  • the shallow case is a real --depth 1 clone (git clone --depth 1 --branch main file://…, then fetch --depth 1 origin <sha>), not a mock — the only way to exercise the branch at all;
  • and the two cannot place causes are separated by shallow=false (a genuinely disjoint history) versus shallow=true (a truncated clone).

The comment records why the shallow arm exists: "how #2643 first read an ancestor as a disjoint history; that case must say 'cannot place', never a relation." A test whose purpose is written down is a test the next refactor is less likely to delete.

Nothing else

Host-only, docs/hw-gate.md +5, tests/hw_gate_test.py +47, and the relation computed with git in third_party/llama.cpp — the one place that knows which commit the tested tree is. That is the right place for the question, and the answer now travels with the verdict.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Answers to the three asks (07:18:56Z). All three are already in this head (445ca8c), so there is no new push:

  1. Provenance in the golden file. It is there: tests/golden/hw-gate/manifest.json records recorded_at: {llama.cpp, hrx-system} per model, beside base_sha256 and the limits. hw_gate_manifest.py set writes it at --record, so git log on the manifest shows each re-record. This PR reads that field and puts it on the verdict line. Nothing about the golden moved into test code.
  2. A recorded commit that is not an ancestor of the tested tree. The relation covers it instead of trusting the sha:
    • a golden from a branch that never merged reads diverged at <base> (golden +a, tested +b);
    • a golden newer than the tree reads golden is N commits AHEAD;
    • a sha the clone does not have reads cannot place (<sha> is not in <repo>).
      Each has its own case in tests/hw_gate_test.py: diverged (branch E off B against C), ahead, and absent.
  3. An assertion that can fail. The cases do not check that a field exists. Each one builds a repo and compares the exact relation string, which comes from real git merge-base --is-ancestor / rev-list --count on that repo. behind must say 2 commits, and diverged must name B's sha with +1/+1. Two mutants were run and failed the test: the verdict line without the bracket, and the no-common-history branch reporting a relation.

Scope. As the body says, this covers #2643's steps (1) and (3). Step (2), re-recording the five goldens at the pin, is not done and needs GPU windows. The issue should stay open for it, and the body has no closing keyword.

@bong-water-water-bong
bong-water-water-bong merged commit 7fd6c2d into main Nov 16, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-flm/2643-gate-provenance branch November 16, 2026 07:45
bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
…d none (engine#2643) (#2661)

provenance() shipped with #2644 and decides whether a golden's KLD base was measured at the tree
the gate is testing: same commit, an absent object, an ancestor at N commits, a descendant, or a
genuinely diverged history. Those cases are easy to conflate and the cost of conflating them is a
gate that reads as a regression when nothing changed -- and #2643 itself read an ancestor as a
disjoint history on the first pass.

Eleven hermetic arms (throwaway repos in a temp dir, no network, no gate, no device):

  - the same commit is named, not diffed
  - a null recorded pin, and a null tested pin, are both refused
  - an absent object is refused rather than related
  - an ancestor is counted exactly (2 commits behind)
  - the reverse direction is distinct (AHEAD), and the two never both appear
  - two branches off one base are 'diverged at', naming both counts
  - a shallow clone cannot place an older commit
  - AND a shallow clone does NOT answer 'no common history' -- the exact #2643 misread, pinned

The last pair is the reason this is worth an arm rather than an eyeball: 'git rev-list
--max-parents=0 <missing>' prints nothing, and nothing is what a second root also prints. A clone
that lacks the pinned sha answers 'disjoint' to every question.

Verified: 'python3 tools/hw_gate_manifest.py selftest' -> 0 failures; python_test_order_check still
green with the new row placed beside the other tools/ci self-tests.

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
…ne#2643) (#2669)

#2643 measured that five of six goldens name a llama.cpp commit in a history disjoint from the pinned fork, and
concluded that 'the question cannot be asked' of those bases. Three options were put: re-record them, say in the
manifest that the label is provenance only, or print both shas on the verdict line. The third shipped in #2644
(provenance(), printed in brackets on the KLD verdict). This is the second, which needs no device and no decision.

The about string now says recorded_at is provenance, that it may name a commit no longer reachable from the current
pin, and that judge prints the relation rather than guessing -- 'cannot place' is the answer when it cannot place.

One constant (ABOUT) feeds both the template in load() and the shipped tests/golden/hw-gate/manifest.json, so the
two cannot drift: a reader of either artifact learns the same thing about the field they are looking at.

No behaviour change. judge still runs (verified: it reaches the log check), the manifest still parses, and
'recorded_at' is not consumed by anything but the writer and provenance() -- grep confirms no test or doc asserts
the old wording.

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