feat: add cross-PR conflict detection to github-code-review skill - #38864
feat: add cross-PR conflict detection to github-code-review skill#38864BingqingLyu wants to merge 1 commit into
Conversation
Add Section 6 (optional) that uses codegraph to detect function-level conflicts across open PRs during code review. When two PRs modify the same function, a conflict comment is posted to help coordinate merge order. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Analysis results — tested on this repo (500 open PRs)Ran
Examples — functions modified by multiple PRs
InterpretationFor example, Cost efficiencyThe entire pipeline (index → detect → report) is purely structural analysis — tree-sitter parsing + graph queries. No LLM calls are involved at any stage. This means cross-PR conflict detection runs at near-zero marginal cost regardless of the number of PRs analyzed, compared to LLM-based review approaches that scale linearly with token consumption. |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the concrete cross-PR-review workflow and the repository-scale validation results.
Problems
skills/github/github-code-review/SKILL.md:512documentscodegraph pr-review update --pr, but the linked upstream guide documents onlyprepareandlabel; its argument tables do not provideupdate,--pr, or--comment-only(upstream guide:134-152). The documented workflow cannot run as written.skills/github/github-code-review/SKILL.md:500-508directly installs a package and modifies the checkout (.codegraph,.gitignore). The upstream guide instead specifies an isolated virtual environment and supports a separate--outputpath (upstream guide:17-23, 85-92).- The section makes an external CLI the primary SKILL.md interaction, which conflicts with
AGENTS.md:902-914.
Suggested changes
- Rework against the currently supported codegraph CLI/Python API, with a read-only analysis path and explicit approval before posting GitHub comments.
- Keep the venv, graph database, and reports outside the target checkout; do not edit
.gitignore. - Put external orchestration in a supporting script or make codegraph an explicit optional MCP prerequisite, then add the required skill test.
Automated hermes-sweeper review.
| ```bash | ||
| # Install codegraph if not present | ||
| if ! command -v codegraph &>/dev/null; then | ||
| pip install codegraph-ai |
There was a problem hiding this comment.
Please do not install this package into the active environment. The linked codegraph guide requires an isolated virtual environment (pr-analysis.md:17-23); this skill should make that prerequisite explicit or delegate the external setup to a supporting script.
| codegraph init --repo . --db .codegraph | ||
| # Re-run periodically (e.g. weekly) to keep the index fresh | ||
| codegraph pr-review prepare --db .codegraph --limit 500 | ||
| echo ".codegraph/" >> .gitignore |
There was a problem hiding this comment.
This mutates the repository under review and leaves a tracked .gitignore diff. Keep graph and report state outside the checkout (the upstream guide supports --output) rather than editing project files during a review.
| fi | ||
|
|
||
| # Ensure this PR is in the index (idempotent — safe to re-run on existing PRs) | ||
| codegraph pr-review update --db .codegraph --pr $PR_NUMBER |
There was a problem hiding this comment.
The linked upstream guide currently documents only codegraph pr-review prepare and label; it has no update subcommand or --pr argument. Please replace this with a supported full-pipeline or Python-API flow.
| codegraph pr-review update --db .codegraph --pr $PR_NUMBER | ||
|
|
||
| # Check for conflicts (dry-run to preview) | ||
| codegraph pr-review label --db .codegraph --pr $PR_NUMBER --comment-only --dry-run |
There was a problem hiding this comment.
Upstream documents label flags only for --db, --repo, and --dry-run (pr-analysis.md:146-152); --pr and --comment-only are not documented. This command must be revised before the workflow can be used.
Summary
github-code-reviewskill — detects when the current PR modifies functions also changed by other open PRspip install codegraph-ai) for function-level conflict detection across open PRsMotivation
Repos with many concurrent PRs often have multiple PRs modifying the same functions. Reviewing them independently wastes effort — merging one invalidates the diffs of the others. This extension gives the reviewer visibility into cross-PR dependencies so they can coordinate merge order.
Related issue: #38054
How it works
codegraph builds a code knowledge graph using tree-sitter to parse source code into function-level nodes and call edges, stored in a NeuG graph database.
For cross-PR conflict detection, the pipeline works in three steps:
Index: Parse each open PR's diff (
gh pr diff) and resolve changed hunks to function-level granularity. For each PR, create aPRnode andCHANGESedges to theFunctionnodes it modifies — verified against the existing code graph to distinguish modified functions from newly added ones.Detect: Query the graph for functions with incoming
CHANGESedges from multiple PRs:Then compute connected components (union-find) to group all transitively conflicting PRs.
Report: For each PR in a conflict group, post a comment listing the shared functions and the other PRs that touch them.
This catches conflicts that git cannot — git only detects merge conflicts between two branches at merge time, and has no awareness of other open PRs. codegraph compares all open PRs simultaneously at the function level, surfacing semantic overlaps before any merge is attempted.
What changed
skills/github/github-code-review/SKILL.md:Verification
Tested the full workflow (
init→prepare→update→label --comment-only) against open PRs in this repo. Confirmed conflict detection, idempotent update, and comment posting all work correctly. Detailed analysis results will be posted as a follow-up comment.