Skip to content

scripts/pr_overlap.py: list the open pull requests that change the same files and lines - #8476

Closed
Jun2028 wants to merge 1 commit into
ProjectLeonida:mainfrom
Jun2028:pr-overlap-tool
Closed

Jun2028 wants to merge 1 commit into
ProjectLeonida:mainfrom
Jun2028:pr-overlap-tool

Conversation

@Jun2028

@Jun2028 Jun2028 commented Nov 23, 2026

Copy link
Copy Markdown

Claim: #8344 (comment) (new BUILD item, not on the list)

Why

AGENTS.md asks every contributor to check the open pull requests before starting. GitHub's search reads titles and descriptions, not diffs, so a pull request that makes the same change in other words is not found by searching for yours. That is how my #8170 missed #6432: the same one-line CSS change, four hours earlier, under a title that shares no keyword with mine. @LaugeM's one-off comparison in the coordination issue found 36 such groups among the open pull requests.

What

scripts/pr_overlap.py, a read-only check to run before a claim or a pull request:

python -I scripts/pr_overlap.py PATH [PATH ...]     # the open pull requests that change these files (or folders)
python -I scripts/pr_overlap.py --branch [REF]      # ... the files REF (default HEAD) changes against --main
python -I scripts/pr_overlap.py --pr N              # ... the files pull request N changes

With --branch or --pr there is a diff to compare, so each pull request sharing a file is marked same lines (a hunk within --slack lines of one of yours, default 3) or same file, with the number of identical changed lines the two diffs share. On #8170, from the 3,643 pull requests open at the time:

viewer/studio.html  (yours: lines 94)
  #6432  same lines, 1 identical        lines 94, 645, 647       Racurs156: Studio: show one full-width tab and preserve ...
  #5017  same file                      lines 742-743            Misha0009: viewer: reset Studio camera to the selected ...

How it works:

  • The open pull requests and their files come from gh api graphql, 100 per request (about two seconds each; 3,643 took 1 min 53 s). A file list longer than 100 is paged to its end rather than cut, since a cut list would hide an overlap.
  • --cache FILE keeps that list and reuses it (--refresh reads again), so several checks cost one read and a saved file works offline. The second run above took 20 s, all of it the 25 diffs.
  • Only --max-diffs diffs are fetched (default 25, the pull requests sharing the most files first); the rest are listed as same file, lines not compared. A diff GitHub refuses (too_large, hit on the first live run) is listed the same way instead of ending the run.
  • Line numbers are each diff's own base, so same lines means "look at this one", not proof; the docstring says so.
  • Exit 0 when nobody else changes the files, 1 when someone does, 2 on a usage, gh or git error (one line on stderr). --json for scripts.

It does not overlap scripts/merge_check.py (is a pull request already on main, would merging it again duplicate text) or #8319 (security scan). Two new files, no existing file touched, so it conflicts with nothing open.

Tests

  • python -I tests/test_pr_overlap.py: 18 tests, 0.7 s, no network. gh is replaced by a stand-in that answers the two GraphQL queries and gh pr diff from a table of made-up pull requests; the --branch case runs the real git diff on a throwaway repository. Covered: the diff parser (replaced, inserted and removed lines, two runs in one hunk, new, deleted, renamed, binary and quoted-path files, the no-newline marker), paging of pull requests and of a 231-file list, the saved list (LF, reused without a request, refreshed, refused when unusable or for another repo), paths and folders, --slack, --max-diffs, --skip-author, a refused diff, the text and JSON reports, usage errors and gh/git failures.
  • Live, against this repository: --pr 8170, --pr 8093, --branch, three paths (one with a backslash), a folder and a path nobody changes, with and without --cache.
  • python -I tests/test_ci_registration.py: OK (the new test file is selected by CI). tests/test_tool_stdout_encoding.py and tests/test_text_write_line_endings.py fail on main for other files and do not name these two. python -m compileall -q and python -I scripts/check_no_game_data.py on both files: clean.

Windows 11, Python 3.13.17, gh 2.x, git for Windows. CPU only; no game files, no GPU involved. Not run: the translator suite, runtime/CMake and GPU tests (nothing here is read by them), and Linux or macOS.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

… and lines

GitHub's search reads titles and descriptions, not diffs, so a pull request
that makes the same change in other words is not found by searching. This
read-only check lists the open pull requests that change given paths, a
branch's files or a pull request's files, and marks the ones whose hunks are
on the same lines, with the number of identical changed lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@matheusfermiano-source

Copy link
Copy Markdown

Independent CLI check on 74d14c275084c3823fe55bf24f5a5bd48b6bb8da. python -I tests/test_pr_overlap.py passed all 18 tests. I exercised --branch --main main --cache <snapshot> --max-diffs 0 --json in a disposable Git repository. These cases used actual git diff output and an offline snapshot with one matching PR.

  1. Pure renames disappear. A commit with only git mv old.py new.py has similarity index 100% and rename from / rename to lines, without a ---/+++ pair. changed_lines() drops the file because SAME_NAME only supplies a fallback when the names are equal. The CLI exits 2 with HEAD against main changes no file, even with new.py in the snapshot. The existing rename test includes a content change, so it exercises a different header. A metadata-only rename should record its destination, with the same-file verdict and no hunk ranges.

  2. diff.noprefix=true causes false negatives. With a normal edit to old.py, the default Git config returned exit 1 and a match for old.py. Setting only git config diff.noprefix true caused exit 0, paths: {}, and unchanged: ["d.py"]. The branch command inherits the Git preference and the parser then strips the first two characters. Passing --src-prefix=a/ --dst-prefix=b/ on the local diff would make this independent of user config.

  3. A Unicode separator inside a line shifts the old line number. I put U+2028 inside an unchanged context line and replaced old line 4. Git still emitted one context line there, but changed_lines() reported [(5, 5)]. Replacing that character with - in the same diff yielded [(4, 4)]. Splitting the patch on LF would keep U+2028 inside the context line and preserve the coordinates.

No live snapshot scan was needed. Synthetic inputs only. AI-assisted (Codex).

@morodirule

Copy link
Copy Markdown

Tested 74d14c2 on Arch Linux, Python 3.14.10, CPU only: pass, first Linux check. New tests/test_pr_overlap.py 18/18 OK via documented python -I runner. Negative control: tool removed so tests fail at import, restored green. Note: under pytest the usage-error test fails on prog name rendering, runner-specific, not the PR. No game files. AI-assisted.

@Grimkaaah Grimkaaah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review (74d14c27)

What changed: new scripts/pr_overlap.py lists open PRs that touch the same files/lines (coordination helper), with unit tests around the overlap logic.

Checked:

  • New script + tests only.
  • python3 -I tests/test_pr_overlap.py → 18 OK.

Looks correct; no game files.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 74d14c27 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_pr_overlap.py -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@rideinstead

Copy link
Copy Markdown

TEST validation — Approve

Validated on CPU (no GPU, no game files). Pure Python read-only tool.

What changed: Two new files:

  • scripts/pr_overlap.py — CLI tool using gh api graphql to list open PRs and flag those sharing files/hunk ranges with checked paths/branch/PR
  • tests/test_pr_overlap.py — 18 unit tests (~0.7s, mocked gh, no network)

Tests added: diff parser (replaced/inserted/removed lines, hunks, new/deleted/renamed/binary/quoted-path files), paging of PRs and 231-file list, saved cache (LF, reuse, refresh, refusal), paths/folders, --slack, --max-diffs, --skip-author, refused diff, text/JSON reports, usage errors, gh/git failures.

Verification:

  • matheusfermiano-source: 18/18 tests pass; exercised --branch --main main --cache <snapshot> --max-diffs 0 --json in disposable git repo
  • morodirule (Arch Linux, Python 3.14.10, CPU only): pass, 18/18 OK
  • Atomic258 (Windows Server 2022, CPython 3.13.12): pass; git diff --check clean; compileall exit 0
  • Grimkeh (reviewer, Linux): python3 -I tests/test_pr_overlap.py → 18 OK; "Looks correct; no game files"

Note: AI-assisted (Codex). CI checks show 0 (no CI run yet). gh dependency required for live runs (cached/offline path works without it). GraphQL rate limits mitigated by caching.

Recommendation: Approve / merge. Fully CPU-validatable, 18/18 tests pass across Windows/Linux, independent positive review, touches no existing files.

@VibeClauding

Copy link
Copy Markdown

Closed my #8509 in favour of this. It added a gh pr list --json files --jq one-liner under "Claim before you start" in AGENTS.md, which is weaker than this script (100 files per pull request, no line matching; see the review there).

One suggestion: AGENTS.md is where agents look before claiming, so a line there pointing at this script would make it get used. Something like this, after "Check its tables and the open pull requests first...":

A title search misses most of them: two pull requests for the same fix rarely share words, but they change the same file. Before claiming, list the open pull requests that change your files: python -I scripts/pr_overlap.py PATH ..., or --branch once you have commits.

Note that tests/test_docs_cli_flags.py checks every flag in a fenced command against the script's source. --branch is in pr_overlap.py, so that one passes.

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.

8 participants