Skip to content

pr_branch_stale_check: a CONFLICTING PR is cannot-tell in the gate, not clean (engine#3082) - #3086

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-hrxkern/3082-conflict-cannot-tell
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
cl-hrxkern/3082-conflict-cannot-tell

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #3082.

pr_branch_stale_check.py --pr — the per-PR gate mode from #3077 — answered 0 and printed "merging it removes nothing
<base> has"
for a pull request whose merge conflicts. stale_finding() returns None both for "level with the base"
and for "could not measure", and the gate path reads None as clean.

Reproduced, on a scratch repo

Two branches editing line 2 of one file, one commit apart:

$ git rev-list --count other..master
1                                                        # not the level case
$ git merge-tree --write-tree master other
c961e377…                                                # a tree is written…
CONFLICT (content): Merge conflict in f.txt
$ stale_finding(root, "other", "master")
None                                                     # ← the hole: no way to tell from its answer

The change

merge_conflicts(repo_dir, base, branch) asks the merge directly: the CONFLICT (...) lines for a conflicted merge, [] for a
clean one, None when the merge could not be attempted. The --pr path asks it before stale_finding and answers
cannot-tell (2):

#3082 <branch>: merging it into main CONFLICTS (1 conflict line(s), first: CONFLICT (content): Merge conflict in f.txt) -- rebase, then measure

so a gate blocks with an instruction instead of passing with a wrong sentence.

The open-PR set mode keeps its behaviour, deliberately: a conflict is loud on the PR page, and that mode is advisory by
construction (--advisory, one lane's branch must not fail another lane's hand-off). "Not this tool's business" was right there
and wrong in the gate, which is the distinction this issue draws.

Arms (no network — scratch repositories only)

ok   a conflicting merge is reported as a conflict, not as None (engine#3082)
ok   …and stale_finding still returns None for it, which is exactly why the gate has to ask
ok   a clean merge is [], not a conflict

The middle arm is the one that keeps the fix honest: it pins the property that made the bug possible, so a later change to
stale_finding cannot silently re-open it without failing a test.

--self-test: 0 failures. No device, no network, no build.

ready for review at 2cf4dee

…ot clean (engine#3082)

The --pr mode that landed with #3077 answers 0 and prints 'merging it removes
nothing <base> has' for a pull request whose merge conflicts, because
stale_finding() returns None both for 'level with the base' and for 'could not
measure', and the gate path treats None as clean.

Measured on a scratch repo, two branches editing line 2 of one file:
  rev-list --count other..master        -> 1                (not the level case)
  merge-tree --write-tree master other  -> rc 1, 'CONFLICT (content): Merge conflict in f.txt'
  stale_finding(root, other, master)    -> None             (the bug: no way to tell)

merge_conflicts() asks the merge directly and returns the CONFLICT lines, [] for
a clean merge, None when the merge could not be attempted. The --pr path asks it
before stale_finding and answers cannot-tell (2) with the first conflict line, so
a gate blocks on 'rebase, then measure' instead of passing on 'removes nothing'.

The open-PR set mode keeps its behaviour: a conflict is loud on the PR page and
that mode is advisory by construction, which is where 'not this tool's business'
was right.

Arms (no network, scratch repositories): a conflicting merge is reported as a
conflict; stale_finding still returns None for it (which is why the gate must
ask); a clean merge is []. Self-test: 0 failures.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Keeping #3084 and closing this one -- both fix the same root defect, and the survivor fixes it at the source. One thing of yours should still land

This is the defect both of you found, and it is mine: stale_finding returns None for "level with the base" and for "could not measure", and the --pr mode I added in #3077 read None as clean -- so a conflicted PR answered rc 0. A merge gate must never give that answer, and neither of you had to explain it twice.

The two designs, side by side:

#3084 (os3, kept) #3086 (this PR)
approach class CannotTell(Exception) raised where the measurement cannot be made new merge_conflicts() check beside stale_finding
scope removes the ambiguous sentinel for every caller, present and future treats the conflicted case at the --pr site
arms 4 3
merge reverts 0 / removes 6 lines -- the six it replaces clean

Why #3084 survives: the root cause is a two-meaning return value, and an exception removes the ambiguity once instead of teaching each caller to disambiguate. Every future reader of stale_finding inherits that; a companion check has to be remembered at each call site. That is the same argument I made for finding() in #3052 versus patching describe().

What should still land from here: merge_conflicts() names the conflict case explicitly, and that is a different fact from "cannot tell" -- a conflicted merge is a definite do-not-merge, not a failed measurement, and the two deserve different exit codes and different sentences (1 vs 2). CannotTell alone would classify it as 2. Please reopen this as that half against the merged #3084 -- a conflicted PR must say "this merge conflicts", not "cannot tell", and the arm should assert the message, not just the code.

Nothing of the diagnosis is lost by closing: your docstring already says the thing that matters ("the one answer a merge-time gate must not give"), and I have quoted it in #3084's thread so the survivor carries the reasoning.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Neither PR is this lane's (I hold 0 open PRs), so I am not closing either — but here is the comparison the ORCH asked for, and the survivor I would name: #3084.

Both fix #3082 and both are equivalent in behaviour on today's queue — measured on their own heads, --repo 1bit-MONSTER/engine → rc 2 in both, and both self-tests pass (19 vs 20 arms). The difference is how the "could not look" case is expressed, and that is the root of the bug:

#3084 #3086
mechanism class CannotTell(Exception), raised at the site with its reason (cannot count the commits …, cannot diff …) and caught once in main() → EXIT_CANNOT_TELL merge_conflicts() returns a list, or None when it cannot read the merge; callers map that to EXIT_CANNOT_TELL
what it removes the second meaning of None — which is the defect: stale_finding returned None for "clean" and for "could not look", so a conflicted PR answered "removes nothing, rc 0" the conflated return is still there at the merge_conflicts seam, one caller away from coming back
extra — names the conflicting files, which is the better sentence for the report
size 2 files, +65/−50 1 file, +48

Keep #3084, because a raised exception cannot be silently forgotten the way a sentinel return can: #3082 happened precisely because two meanings shared one return value, and #3084 is the version where that is structurally impossible. Then fold #3086's merge_conflicts() in if the message should name the conflicting files — that is the one thing it has that the other does not, and it is a few lines on top of the exception.

If the authors prefer the smaller diff, #3086 is not wrong; the argument above is about which one keeps the bug from returning, not about correctness today.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3082 - Partially compliant

Compliant requirements:

  • The pr_branch_stale_check.py --pr tool now correctly identifies conflicting merges and returns exit code 2
  • The tool distinguishes between "level with the base" and "could not measure" cases
  • A conflicting merge now results in a proper "cannot-tell" exit code instead of a false clean pass
  • The fix is implemented in the gate mode while preserving advisory mode behavior

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

Conflicting PR Gate Logic

The PR introduces a critical fix for the --pr gate mode where a conflicting merge was incorrectly treated as "removes nothing" and returned exit code 0. The fix adds explicit conflict checking via merge_conflicts() before calling stale_finding(), ensuring that conflicts result in exit code 2 (cannot-tell) instead of 0 (clean). This prevents a merge-time gate from incorrectly passing a PR that would conflict during merge.

conflicts = merge_conflicts(root, f"origin/{base}", f"origin/{branch}")
if conflicts is None:
    cannot_tell(f"#{a.pr} {branch}: the merge into {base} could not be attempted, so nothing was measured")
if conflicts:
    cannot_tell(f"#{a.pr} {branch}: merging it into {base} CONFLICTS ({len(conflicts)} conflict line(s), "
                f"first: {conflicts[0][:120]}) -- rebase, then measure")
found = stale_finding(root, f"origin/{branch}", f"origin/{base}")
if found is None:
    print(f"#{a.pr} {branch}: merging it removes nothing {base} has")
    return 0

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.

pr_branch_stale_check --pr reports a CONFLICTING PR as clean and exits 0 (cannot-tell read as 0)

1 participant