Skip to content

feat(ci): report colliding open PRs before claiming and confirming - #3275

Merged
schlessera merged 3 commits into
mainfrom
feat/2941-collision-report
Nov 2, 2026
Merged

schlessera merged 3 commits into
mainfrom
feat/2941-collision-report

Conversation

@schlessera

@schlessera schlessera commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Closes #2941

What changed

bun scripts/collisions.ts is a new read-only repository script that reports which open PRs collide. It lists open ready and draft PRs through gh (the listing is an injectable function, so tests never touch the network) and trial-merges each pair of heads with git merge-tree --write-tree. When a merge is clean, it compares the two PRs' affected closures using the CI selection code. Each colliding pair is reported once:

  • textual, with the conflicting paths;
  • closure, with the shared affected workspaces (reverse manifest dependants, from planUnitChecks), the shared paths (changed files plus runnable unit owners from unitImportOwners), and the proof categories both sides select;
  • unknown, when the selection graph cannot be built, a head or base commit cannot be read, or the trial merge errors. An unknown is never reported as disjoint.

--json prints the full report: graph commit and status, PR numbers and head SHAs, and the collisions. --pr <n> keeps only the pairs that involve PR n. --paths <glob...> reports which open PRs touch an area (path) or share its closure (closure) before any branch exists. work-issue now runs --paths on the candidate's cited files before claiming, preferring a non-colliding candidate among those of the same priority. It runs --pr before confirm and records the result in the PR. CONTRIBUTING.md describes the command.

Why this shape

  • Reuse the CI selection code. The script calls the existing CI selection functions (discoverUnitImports, unitImportOwners, planUnitChecks, changedFiles) instead of reimplementing them. planUnitChecks gained an optional prebuilt graph argument, so one import graph (about 4s) serves every PR instead of being rebuilt for each one. Callers that omit it behave exactly as before.
  • Compare against this checkout's graph. The graph is built from this checkout, and the report records its commit. Building it at each PR head would mean a checkout or worktree write per PR.
  • Leave out the universal fallback set. Unit owners of unresolved imports join every selection, so they say nothing about whether two particular PRs overlap.
  • Fetch objects only. Missing PR objects are fetched with --no-write-fetch-head --refmap= --no-auto-maintenance and no destination refspec. That adds objects but writes no ref, no FETCH_HEAD and no remote-tracking update. merge-tree writes only objects.
  • Detection only. No locks, reservations or messages, per Epic: independent changes land on main concurrently, with only overlapping work serialized #2934's constraints.

Proof

bun run check:pr --base origin/main   # passed: lint/leakage, env docs, changeset, 1131 affected fast tests
bun run test tests/collisions.test.ts # 8 pass
bun run test tests/collisions.test.ts tests/ci-plan.test.ts tests/unit-test-consumers.test.ts  # 138 pass
tsc --noEmit                          # clean

The fixture repository puts every PR head only under refs/pull/<n>/head in a bare origin. The clone uses --no-local, so the command has to fetch the heads, and the test asserts they are absent beforehand. It has two textually conflicting branches, one disjoint docs branch, and one branch that changes a different file in the same closure. Refs, HEAD, packed-refs, the index, FETCH_HEAD, the tracked and untracked file listing and the porcelain status are compared before and after.

Before the change, nothing was compared (stub: collisions: []). These named tests fail on their assertions, not on a module load:

  • ONE_TEXTUAL_PAIR: Expected −18 / Received +1
  • SAME_CLOSURE_IS_CLOSURE: −21 / +1
  • UNKNOWN_GRAPH_NEVER_DISJOINT: −8 / +1

Mutations, each restored afterwards (cmp against the original, then 7 pass):

Mutation Named failure
Treat an unknown closure as disjoint UNKNOWN_GRAPH_NEVER_DISJOINT: Expected −5 / Received +0
Treat a conflicted merge (exit 1) as clean ONE_TEXTUAL_PAIR (−1 / +2) and UNKNOWN_GRAPH_NEVER_DISJOINT
Drop --no-write-fetch-head --refmap= from the fetch COLLISIONS_READ_ONLY: fetchHead "absent" became a hash
Report every merge-tree conflict path, not only paths both PRs changed BASE_DRIFT_IS_NOT_TEXTUAL: received a textual pair on packages/ithaca/src/oars.ts
Closure ignores owners and workspaces SAME_CLOSURE_IS_CLOSURE, plus the --pr and --paths tests

The fetch mutation was green at first, because a local git clone copies every object and so the command never fetched. The fixture now clones with --no-local, and the mutation fails as shown above.

Base-drift fix, found by dogfooding. The first --pr 3275 run reported #3056×#3275 as textual on ui-react files this PR never touches. #3056 sits on an older main, so the pair's merge base carried main's own later edits. A pairwise conflict needs a path both PRs changed, so the report now keeps only those paths. BASE_DRIFT_IS_NOT_TEXTUAL covers this case. It fails with the filter removed (restored afterwards; 8 pass).

Live read-only run against this repository: 5 open PRs in 7.7s. A for-each-ref hash taken before and after was identical.

Pre-confirm collision report (bun scripts/collisions.ts --pr 3275, graph at 0e326d93a, head at that time 0e326d93a): no textual and no unknown pairs. There are closure pairs with #3054, #3069 (shared ui workspaces) and with #3056, #3059, #3116 (shared CI tooling tests such as tests/ci-plan.test.ts). These are detection only; e3b81162a only touches scripts/collisions.ts and its test.

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof. (Hosted confirmation is recorded below once it runs.)
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see. (Repository script and skill; no package ships it.)
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved. (Not a brain command; the issue records no contract impact.)
  • Docs under docs/ reflect the change, or nothing documented moved. (CONTRIBUTING.md and the work-issue skill.)
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.

Anything left open

Semantic conflicts beyond closure overlap are out of scope (#2941). Nothing else.

🤖 Generated with Claude Code

@schlessera schlessera added this to the 0.45.0 milestone Nov 2, 2026
@schlessera schlessera added type: chore Tooling, CI, release plumbing, dependencies. area: ci CI workflows, the gates they run, release scripts, packaging. labels Nov 2, 2026
schlessera and others added 3 commits November 2, 2026 09:29
Trial-merges open PR heads pairwise with git merge-tree and compares
their affected closures with the CI selection code, reporting textual,
closure or unknown collisions. planUnitChecks accepts a prebuilt import
graph so one graph serves every PR.

Refs #2941

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ming

Refs #2941

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Heads on different bases conflict wherever main moved underneath the
older one. A pairwise conflict needs a path both PRs changed; report
only those paths.

Refs #2941

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci CI workflows, the gates they run, release scripts, packaging. type: chore Tooling, CI, release plumbing, dependencies.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: report colliding open PRs before claiming and confirming

1 participant