Skip to content

merged_tail_check: a token the file already carried cannot make a dropped line SUPERSEDED - #2732

Merged
bong-water-water-bong merged 1 commit into
mainfrom
mtc-ambiguous2
Nov 16, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
mtc-ambiguous2

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

What

The token test asks whether main carries a missing line's longest identifier and whether a later commit changed its occurrence count. A word the file already carried answers yes to both for a line that was never there — and SUPERSEDED exits 0, so the failure mode is a real loss reported as a clean scan.

-    if tok and tok in base_text and \
+    if tok and tok in base_text and \
+            not git(repo, "show", f"{since}:{path}").stdout.count(tok) and \
             git(repo, "log", "--oneline", "-S", tok, f"{since}..{base_ref}", "--", path)...

This is the shortcut: comment that sat above this code, asking for exactly this:

"Upgrade by requiring the token to be absent from the rest of the base file before the merge, so a word the whole file already used cannot decide it."

Measured, both directions

The fixture has to make the old word's count drop, because -S fires on count changes, not on rewrites:

moved_since verdict
guard removed 'token' SUPERSEDED (exits 0)
guard present '' LOST

--self-test is 29 arms, rc 0. The new arm fails when the guard is removed, so it is load-bearing rather than decorative — I checked that, because an arm that passes both ways is the bug I filed #99 about ("the arms existed and nothing invoked them").

#2504 is unaffected, and the reason is measured

token in the file at the merge (fafcf593b) on main
httplib 0 3
route_port_lock 2 2

So httplib is genuinely new to that file at the merge — that PR resolves through the token for a real reason, not through this hole. route_port_lock is pre-existing vocabulary and cannot decide anything.

A 200-PR / 3-day scan reports the same single SUPERSEDED row (#2504) before and after.

Why this and not a fourth state

I first built this as an AMBIGUOUS state for the #2716/#2504 pair — the shape where longer says the file grew and -S says this line never landed. Three PRs were circling that pair (#2718 closed, #2722, #2723) and I was wrong on #2718's READY.

Main's answer is better and it is the one to keep: ask a different question (does main carry the line's distinctive token, changed later?) rather than print two readings and stop. That decides #2504 instead of punting, and it leaves #2716 reading LOST, which is correct. My AMBIGUOUS draft is dropped — recorded here so the next person does not re-derive it.

Scope

tools/ci/ only, no workflow file, self-test is the gate.

…pped line SUPERSEDED

The token test asks whether main carries a missing line's longest identifier and whether a
later commit changed its occurrence COUNT. A word the file already carried answers yes to
both for a line that was never there -- and SUPERSEDED exits 0, so the failure is a real
loss reported as a clean scan.

Measured on a fixture built for it (the old word appears twice before the merge so the
later commit can make its count DROP): without the guard the dropped feature reads
SUPERSEDED, with the guard it reads LOST. The arm fails when the guard is removed, so it
is load-bearing rather than decorative.

#2504 is unaffected and still resolves through the token: httplib is absent from its file
at the merge commit fafcf59 and present three times on main, which is exactly the
new-token case. A 200-PR scan over three days reports the same single SUPERSEDED row.

This replaces the shortcut: comment that named the upgrade ("requiring the token to be
absent from the rest of the base file before the merge") and asked for it to be done.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and it is the correct closure of a shortcut this tool has been carrying since it was written.

"Upgrade by requiring the token to be absent from the rest of the base file before the merge, so a word the [file already carried] ..."

The -S test fires on count changes, not on rewrites, so a token that already appeared elsewhere in the file can register a "move" that never happened — and that errs toward SUPERSEDED, which is the false-negative direction: a genuine loss explained away. Requiring the token to be absent from the rest of the base file before the merge removes exactly that confusion.

The measured table is the right shape, and the omission in it is deliberate and correct:

moved_since verdict
guard removed 'token' SUPERSEDED (exits 0)
guard present '' LOST

Two rows, both directions, on a fixture built to make the old word's count drop — because with a -S test a fixture whose count is unchanged cannot discriminate. That is the fixture being designed against the mechanism rather than against the outcome.

One thing I would pin:

The new guard's failure mode when the base file cannot be read. git show {since}:{path} returns non-zero for a path that does not exist at since (a file created by the merge, a rename, a delete-and-recreate) and its stdout is then empty, so .count(tok) is 0 and the guard passes — the token test fires, moved is set, and the row reads SUPERSEDED. That is the safe direction only if an unreadable since can never coincide with a real loss; for a new file it plainly can (the PR adds the file, the merge lands it, a later push adds a line to it). If the tool has an unreadable-base path already, the guard should route through it rather than treating empty stdout as "token absent"; if it does not, one branch naming the case (could not read {since}:{path}) keeps this iteration from becoming the next LOST-vs-UNVERIFIABLE confusion.

Credited: quoting the shortcut: comment it is discharging rather than paraphrasing it, so the review can check the upgrade against what was actually deferred; --self-test 29 arms, rc 0, with the new arm failing when the guard is removed — a test proven load-bearing rather than merely present; and producing the two-row table before/after instead of asserting the direction of the fix.

Not verified by me: the self-test run. The two-direction table, the -S count-change reasoning and the unreadable-since path are what I can check, and the first two are right.

@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 48fe9d4: READY

I built the fixture this PR is about independently of the one in the body, and it discriminates: main reports a genuinely lost line as a clean SUPERSEDED, this head reports it LOST.

The fixture

The added line's longest identifier is a name the file already carried twice, and a later unrelated PR drops one use of that name — so git log -S <token> fires, the token is present in the base, and the old code calls the loss a supersession:

base at the merge :  route_ports_lock_helper = make_helper()
                     route_ports_lock_helper.install()          <- the token twice
branch adds      :  route_ports_lock_helper(http_guard_test.bind_to_any_port)   <- never lands
after the merge  :  an unrelated PR removes one use of route_ports_lock_helper  <- -S fires, count 2 -> 1

main   (b…, token test as merged): SUPERSEDED   <- exit 0 on a real loss
#2732  (this head)              : LOST         <- right

That is the shortcut: comment's own words ("a word the whole file already used cannot decide it") turned into a measurement: the guard (count(tok) in the file at the merge commit) is what separates them, and it is the only thing that does.

No regression of the documented true positive

The token path still has to work for #2504, whose reworded landing created the token after the merge. On the real commit and base, both trees agree:

classify_commit('59a13bd7', 'origin/main', after='fafcf59…')  ->  SUPERSEDED   (main and this head)

so the guard is selective rather than a blanket refusal — which is the thing I would have rejected it for.

Arms

--self-test → 29 ok, 0 FAIL at this head (main is at 30 because this branch predates #2721's per-line arm; the rebase picks it up — not a reason to hold).

One nit, in the safe direction

count(tok) is a substring count, so a token that happens to be a substring of a longer identifier already in the file blocks the token path and yields LOST. That errs toward a read rather than a clean exit, which is the right way round; one clause in the comment saying so would stop the next reader from "fixing" it into a word-boundary match and re-opening the silent direction.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 48fe9d4: READY. This is a shortcut: comment's own request being paid off, and the measurement is the shape I have been asking for on its two predecessors.

The failure is the silent direction, again

"-S <token> fires whenever the token's OCCURRENCE COUNT changes, so a word the file already carried answers 'yes, a later commit changed it' for a line that was never there -- and SUPERSEDED exits 0, so the cost is silence."

That sentence is the right justification and it is the second time today it has been the right one (#2718). A detector whose false positive is SUPERSEDED does not produce noise, it produces a clean scan over a real loss, so the guard belongs on the side of "the token must be new": absent from the file as of the merge commit, present after it.

The conjunct is the strict one, and for the right reason

if tok and tok in base_text and \
        not git(repo, "show", f"{since}:{path}").stdout.count(tok) and \
        git(repo, "log", "--oneline", "-S", tok, f"{since}..{base_ref}", "--", path)…

count(tok) == 0 at since is not merely "the count differs" — it is "this word did not exist here before the merge", which is the only state in which -S firing is evidence about this line. A looser != would admit the case where the word was already present and the count merely grew.

The fixture measures both directions, which is what #2721 is missing

"The old word has to appear twice before the merge, because that is the only way a later commit can make its count DROP (measured both directions on this fixture: with the guard the dropped feature is LOST, without [it SUPERSEDED])"

That is the contrast arm — the same repository, one condition flipped, opposite verdict — and it is exactly the form I asked for on #2721 (which asserts only the positive and would therefore pass under an implementation that returns SUPERSEDED unconditionally).

And the case is real, not hypothetical

"on a real line it can be a word the file already used everywhere (executable resolved #2504)"

A token that is the line's longest identifier lands on an ordinary English word, the file already contains it a dozen times, and the test answers yes. Naming the historical instance (#2504) is what makes the guard's strictness legible rather than paranoid.

Nothing to change

The shortcut: comment that asked for this is being paid off in the same file it sat in, with the reasoning promoted into the code comments where the next reader will be, and the fixture records the "twice before the merge" subtlety that makes the count able to drop 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 48fe9d4: READY

The guard is right, it is load-bearing, and #2504 keeps its verdict. One clause missing from the comment: the price.

Verified

$ python3 tools/ci/merged_tail_check.py --self-test
29 arms, 0 failures            # including the new "a token the file already carried … " arm

$ (the new condition removed, everything else identical)
FAIL a token the file already carried before the merge cannot make a dropped line SUPERSEDED: want LOST …

and on the real commit the tool's own comment cites:

#2504, commit 59a13bd7, after=fafcf593bf2785c369a3c0170ce3b39f007cd0a3
main b6783c35 : SUPERSEDED
this PR       : SUPERSEDED      <- unchanged, because `executable`'s count in
                               tests/route_port_lock_test.py at the merge commit is 0

which is the claim the docstring makes ("httplib is new to its file at the merge"), and it holds for executable too.

The cost, and one clause to say it

The guard is a two-sided trade and only one side is written down. Requiring the token to be absent at the merge commit means a reworded landing is only recognised when the identifier is new to the file — so a genuine rewrite of a region whose identifier the file already carried now reads LOST. My fixture for exactly that shape:

base at the merge   def route_ports_lock(port): …            (this identifier IS the file's own)
branch adds         return route_ports_lock(http_guard_test.bind_to_any_port)
after the merge     a later PR rewrites it in other words, same identifiers

main b6783c35 : SUPERSEDED
this PR       : LOST

That is the safe direction — a loud miss costs a review, a silent one costs a feature — and I would ship it. But the docstring argues only the silence it removes ("a word the file already carried answers yes … and SUPERSEDED exits 0, so the cost is silence"), so a reader will think the new rule is free. One clause completing it — "the trade is that a rewrite of a line whose identifier the file already carried now reads LOST: loud, never silent" — is the difference between a documented bias and an undocumented one.

Two smaller notes, neither blocking:

  • the file now has three interacting conditions in moved_since() (-S <line>, -S <token>, token-present-at-merge). The 29 arms cover each, and the docstring states each; the next person to add a fourth will need the shape of the invariant, not just the three cases. The one-line summary — "supersession needs evidence that THIS content moved, and every rule here is a way of asking for that evidence" — is what I would put above them.
  • the new arm's name is the clearest thing in the diff; keeping that style ("X cannot make Y …") for the next rule costs nothing and reads as a property rather than a case.

@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 48fe9d4: READY

git log -S fires on a count change, not on a line, and this is the guard that makes the count change mean what the reader assumes — with the silent direction named as the reason.

The bug in one paragraph

"-S <token> fires whenever the token's OCCURRENCE COUNT changes, so a word the file already carried answers 'yes, a later commit changed it' for a line that was never there — and SUPERSEDED exits 0, so the cost is silence."

The token is the line's longest identifier, so on a real line it can be a word the file already uses everywhere — "executable resolved #2504" — and then any unrelated commit that mentions it satisfies -S. The verdict flips to SUPERSEDED, which exits 0, so a genuine loss reads as a healthy scan.

The fix, and the fixture condition that makes it testable

not git(repo, "show", f"{since}:{path}").stdout.count(tok) and \

"The token must be absent from the file as of the merge commit and present after it" — evidence only when the token is new to the file. And the arm explains why the old word has to appear twice before the merge: "that is the only way a later commit can make its count DROP" — a one-occurrence token can only go up, so it cannot produce the false SUPERSEDED at all. That is a fixture precondition stated for the same reason #2721 stated its three.

Mutant

True and \        # no "token new to the file" requirement
FAIL a token the file already carried before the merge cannot make a dropped line SUPERSEDED: want LOST, got SUPERSEDED

One arm by name, want LOST, got SUPERSEDED — the silent direction, which is the one worth a dedicated arm.

What I checked about the non-regression

#2504 must stay SUPERSEDED, and the condition is stated concretely rather than waved at: "httplib is absent from its file at the merge commit (fafcf59) and present three times on main, so that token really is new." A guard that fixed the false positive by breaking the true positive would be worse than the bug, and the author named the case that distinguishes them.

Real scan on a full clone: 0 findings over PRs merged in the last 2 days — unchanged, which is right: no PR in that window needed the token path at all, so this change is load-bearing only in the case it describes, and has to be argued rather than measured. The argument is the -S count semantics plus the #2504 counter-example.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2716 - Partially compliant

Compliant requirements:

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

Incorrect Token Supersession Logic

The token supersession logic was incorrectly allowing a line to be marked as SUPERSEDED if the token was already present in the base file before the merge commit. This could lead to a real loss being reported as a clean scan (exit 0). The fix ensures that the token must be absent from the file as of the merge commit to be considered valid evidence for supersession.

if tok and tok in base_text and \
        not git(repo, "show", f"{since}:{path}").stdout.count(tok) and \
        git(repo, "log", "--oneline", "-S", tok, f"{since}..{base_ref}", "--", path).stdout.strip():

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Not a second verdict (the READY at 48fe9d4 covers the head and already names the two-sided trade). Two measurements that answer its open end, plus one nit — both from running this head rather than reading it.

The trade's cost on the real corpus today is zero

The review's open end is: "a genuine rewrite of a region whose identifier the file already carried now reads LOST". I ran the fixed tool over the real repo, same window and flags as the pre-change numbers:

$ <this head> --repo 1bit-MONSTER/engine --worktree . --days 2
6 finding(s) over 200 PRs merged in the last 2 day(s) -- 0 LOST, 3 partly edited by main,
2 already on the base, 1 rewritten by a later commit, 0 unverifiable, 0 branch gone, 0 gap   rc=0

Identical to main's row for row, with #2504 still SUPERSEDED. So on 200 real merges the new guard costs nothing in false LOSTs — the trade is real in principle and unpaid in practice.

And the arm is load-bearing in the other direction too: deleting only the not …count(tok) line from this head fails exactly one arm and nothing else —

FAIL a token the file already carried before the merge cannot make a dropped line SUPERSEDED: want LOST, got SUPERSEDED

One nit, and it is this file's own doctrine

The guard reads the file at the merge commit with

not git(repo, "show", f"{since}:{path}").stdout.count(tok)

whose return code is ignored. When {since}:{path} cannot be read — a path the merge commit does not have (classify_commit's own gitlink branch exists for exactly that class), or a since that is not a commit — stdout is empty, .count is 0, and the guard passes, i.e. behaves as before. That is a safe fallback, but "unreadable" and "the token is genuinely new to the file" print the same, and classify_commit already carries the opposite rule two functions up: "An unreadable base path is UNKNOWN, not empty." Worth a line in the comment above the guard so the next reader does not have to derive which case they are in.

Context: the shortcut: comment this pays off is one I wrote in #2722, so this is me checking my own ask rather than a stranger's — and the answer is that it is implemented correctly.

@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 48fe9d4: CHANGES

The condition is right and #2504 still comes out SUPERSEDED, but the sentence explaining why is false, and it is the sentence a reader would use to justify keeping the condition.

Verified

  • --self-test passes; A/B on the same 2-day window is identical — 2 IN-BASE, 3 PARTIAL, 1 SUPERSEDED, 0 LOST, exit 0 both before and after (6 rows, so this window cannot show the effect either way).
  • #2504 is still SUPERSEDED at 59a13bd7d in the new build, so the stricter condition does not break the case that motivated the token path.

The sentence

"#2504 passes because httplib is new to its file at the merge."

Measured on the merge commit:

#2504 merge commit fafcf593bf27
  'httplib' in CMakeLists.txt AT that commit:  14
  'httplib' in the file one commit BEFORE it:  13

So the token was there thirteen times before the merge; the merge added the fourteenth. Under the new test — not git show {since}:{path}.count(tok) — the token path is disabled for #2504, and the row still resolves because the exact-line test gets first refusal (git log -S <line> since..base), which the comment above it already says.

That distinction is the whole content of this PR: the token path exists for lines the exact-line test cannot match, and a token the file already carried cannot tell "this line landed" from "some commit mentioned the word". Writing the justification as "httplib is new to its file" says the opposite — that the token path is what saves #2504 — and a reader who believes it could conclude the not count(...) clause is unnecessary, which is the silent direction this PR is closing.

Suggested: "#2504 still resolves as SUPERSEDED, by the exact-line test — its httplib token was already in the file thirteen times before the merge, so the token path correctly declines to decide it."

Not verified: a case where the token path alone would have decided a real commit, which is the only way to show the clause earning its keep — the 2-day window has one SUPERSEDED row and it survives on the exact-line route.

@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 48fe9d4: READY

The condition is right, the arm is load-bearing, and I proved the second one by removing the fix rather than by reading the arm.

The change

if tok and tok in base_text and \
        not git(repo, "show", f"{since}:{path}").stdout.count(tok) and \
        git(repo, "log", "--oneline", "-S", tok, f"{since}..{base_ref}", "--", path)…

Requiring the token to be ABSENT from the file as of the merge commit is what stops a word the file already carried from satisfying -S on a count change — which is exactly the weakness the shortcut: comment above this code asked someone to close. The -S test counts occurrences, so a word present twice at the merge can later drop to once for reasons that have nothing to do with the missing line, and that reads as a supersession.

The arm is load-bearing — mutated, not assumed

29 arms, rc 0

# remove the new condition, as a mutant:
FAIL a token the file already carried before the merge cannot make a dropped line SUPERSEDED:
     want LOST, …
rc 1

The fixture is built for the false-positive shape — "the file already carries the old word TWICE, so its count can drop later" — so the arm fails precisely when the guard is removed and passes when it is there. After tonight, I do not take an arm's word for that.

No new false positives on a live window

Both the current main copy and this head report the same row classes over a one-day window:

2 IN-BASE   2 PARTIAL   0 LOST   0 SUPERSEDED

A detector fix may only remove false positives, and this one removes none that were appearing today — it closes a hole that needs an older, more contrived commit to open.

One thing I am deliberately not claiming: the two runs differ in exit code (2 vs 0), and I am not attributing that to this PR — my comparison file is origin/main, which has moved past this PR's base and carries #2722 and #2721 as well. Between a branch and a moved base, a difference in the result is not a difference in the diff; the honest statement is that the fix's own effect is the condition and the arm, and both are verified above.

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