Repository navigation
fix(git): reject stale pull request merge bases - #2229
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2229 +/- ##
========================================
Coverage 85.48% 85.49%
========================================
Files 353 353
Lines 31315 31315
Branches 31315 31315
========================================
+ Hits 26771 26774 +3
+ Misses 4171 4168 -3
Partials 373 373 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Pull request overview
Prevents maintainer merge attempts from reaching signing/push when GitHub’s synthetic refs/pull/<n>/merge is based on an outdated target branch tip, and documents the recovery.
Changes:
- Add a stale-merge-base check in the vendored GitHub merge tool and fail early with a recovery message.
- Extend the deterministic git fixture to publish GitHub-like two-parent merge refs and add a regression test for stale-base rejection.
- Document the GH013 symptom and the “rebase/push/wait/retry” recovery steps in the merge workflow skill doc.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| contrib/dev-tools/git/tests/test-github-merge-symlinks.py | Extends test fixture to publish a synthetic PR merge ref and adds a stale-base regression test. |
| contrib/dev-tools/git/github-merge.py | Adds early detection of stale GitHub merge refs before doing local merge/sign/push steps. |
| .github/skills/dev/git-workflow/merge-pull-request/SKILL.md | Documents the stale merge-ref condition and the GH013-related recovery workflow. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at 6456efb975ed25b8e2948689c82365014732bf73. Recomputed from the bytes at this head.
Three files, +46/−3 (git diff efebacfb 6456efb9 --stat). The guard is six lines placed where the information it needs has just arrived, the new test is proven to depend on it, and every gate I ran is green. Approving, with three non-blocking suggestions and two nits.
What the change does, read from the bytes
main() already force-fetches both sides in one command (+refs/pull/<n>/*:refs/heads/pull/<n>/* and +refs/heads/<branch>:refs/heads/pull/<n>/base). The new block runs immediately after the existing "Cannot find merge of pull request" check and before git checkout -q pull/<n>/base, so it compares two refs that were just written by that fetch:
github_merge_base=git rev-parse pull/<n>/merge^1— the base-side parent of GitHub's test merge.current_base=git rev-parse pull/<n>/base— the target tip as just fetched, not a local branch. The+in the refspec forces it, so a stale local copy cannot survive into the comparison.
That is the right pair: pull/<n>/base is also the ref the tool checks out one line later and merges the head into, so the guard's invariant is exactly the base the local merge would be built on.
Verification
^1really is GitHub's base-side parent. Verified against this pull request rather than from documentation:gh api repos/torrust/torrust-tracker/pulls/2229 --jq .merge_commit_shagives7e38543f2876de1e3e947b28f0f8549a3fddae57, andgh api repos/torrust/torrust-tracker/commits/7e38543f… --jq '.parents[].sha'givesfa084e3a…(the currentdeveloptip) then6456efb9…(this head), in that order. First parent is the base, second is the head.- Exit code.
4is already this tool's refusal code: the symbolic-link refusal exits4,README-github-merge.mddocuments it as such, and the fixture'sEXIT_REFUSED = 4is the constant the new assertion uses. The new path reuses the existing meaning rather than inventing a code, which is the right call. (4is also the "cannot be merged cleanly" / "creating merge failed" code at four later sites, so the exit code alone does not identify the refusal — the new test correctly pins the message text as well.) - Refusal ordering. The check precedes
git checkout -q -b pull/<n>/local-mergeand thegit mergethat builds the local commit, so nothing local is constructed before the refusal. The skill's new paragraph describes the behaviour accurately on both counts: it compares against the fetched tip, and it refuses before any local merge commit exists. - The fixture change costs no existing coverage. Whole suite at the base
efebacfb:Ran 40 tests … OKin 15.05 s. Whole suite at this head:Ran 41 tests … OKin 16.02 s. Sorted test-name diff between the two runs is exactly one line, the new case. So the two-parent merge ref the fixture now publishes changes no pre-existing outcome. It is also necessary: the old fixture published the head commit itself as the merge ref, whose first parent is the previous pull-request commit, so a multi-commit head would have tripped the new check spuriously. - The new test depends on the fix.
git apply -Rof the six-line hunk in a server worktree, then the case alone:FAILED (failures=1),AssertionError: 1 != 4, the captured output showing the run walked on to the maintainer prompt. Restored withgit checkout --,git status --porcelainempty. With the guard in place the same case isOKin 0.35 s. - Stated validation, re-run here.
python3 contrib/dev-tools/git/tests/test-github-merge-symlinks.py→ rc 0, 41 tests, 16 s.bash contrib/dev-tools/git/tests/test-merge-pull-request.sh→ rc 0, 1 s, "All merge workflow wrapper tests passed."TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-commit.sh --format=json→"status": "pass", all 7 steps pass, 64 s. - CI at this head. 13 checks green, including Docs Lint, Documented Clippy Allows, Unit (nightly), Unit (stable), all six Build matrix jobs, Generate Coverage Report and both codecov contexts. Docker E2E skipped.
Test (Docker) (release)was still running when I closed the window — not green yet, worth a glance before merging. - This pull request against its own guard. The head sits on
efebacfbwhiledevelopisfa084e3a, but GitHub has already recomputed the test merge ontofa084e3a(parents above), andgit merge-tree --write-tree fa084e3a 6456efb9returns 0. So the tool would accept this pull request as it stands; no rebase is needed unlessdevelopmoves again first.
Suggestions (non-blocking)
1. The recovery message prescribes a rebase where waiting is often the whole fix. The stale window this guards against is a recomputation race, and GitHub recomputes the test merge when the base moves, with no push to the head branch: this pull request is the demonstration — its head is still on efebacfb, yet refs/pull/2229/merge^1 is already fa084e3a. When the head is already current and only the recomputation is late, "Rebase the pull request branch onto develop, push it" is an instruction the maintainer cannot carry out, because the rebase produces nothing to push. Making the wait the primary action and the rebase conditional on the branch actually being behind would match what the guard detects. Small related point: the message renders the fetched remote tip as "develop is at <sha>", while the skill's wording, "the fetched develop tip", is the precise one — a maintainer whose local develop differs will read the message as being about their own branch.
2. The two new rev-parse calls are the only unguarded git invocations in that block. Each of the four checks above them wraps its git call and exits 3 with a diagnostic naming what could not be found; subprocess.check_output here raises straight out of main() instead. This is the same defect class README-github-merge.md already records under "Known Upstream Issues" — "the maintainer sees a Python error report instead of the diagnostic". A merge ref that has just been fetched always has a first parent, so this is unlikely rather than impossible, but the block would read as one shape if it followed its neighbours.
3. README-github-merge.md is now slightly behind the tool. Its "Deterministic Coverage Boundary" section enumerates what the Python suite covers and names only the symbolic-link check, and exit 4 appears in the rules list with the symbolic-link refusal as its only meaning. One sentence in each place keeps the tool's own reference document complete, since the skill covers the maintainer's workflow rather than the tool's contract.
Nits
1. The new assertions hard-code values the fixture already carries as constants. "GitHub's merge for torrust/torrust-tracker#2175 is based on" and 'Rebase the pull request branch onto develop' restate FIXTURE_REPOSITORY, PULL_REQUEST and TARGET_BRANCH; an f-string over those constants keeps the case honest if one of them changes. Nothing new is hard-coded in the tool itself — the message derives both values from pull_reference and branch.
2. The case sits in a file scoped to something else. test-github-merge-symlinks.py opens with "Deterministic tests for the merge tool's symbolic-link declaration handling", and StalePullRequestBaseTest inherits SymlinkDeclarationTestCase, so the run passes --symlinks .symlinks.json even though the refusal happens before the declaration is ever read. The fixture is genuinely the right one to reuse; widening the module docstring, or renaming the base case, would stop the file's stated scope from contradicting its contents.
|
ACK 6456efb — guard compares the fetched target tip with GitHub's merge base before any local merge commit exists; base 40 tests, head 41, and the new case fails when the six-line hunk is reverted. |
|
ACK e5eef75 |
da2ce7
left a comment
There was a problem hiding this comment.
Reviewed at e5eef75ee2a8f66ba0cef8761b92e5e17ad7be9c. Recomputed from the bytes at this head.
Commit 1 is byte-identical to the one I reviewed in #2229 (review) — git range-diff efebacfb..6456efb9 efebacfb..e5eef75e prints 1: 6456efb9 = 1: 6456efb9 plus two added commits — so that review's argument stands unchanged and is not repeated here. This round reads the two new commits. Approving.
Commit 2 — fix(review): refine stale merge base guard
Both changes answer Copilot's threads rather than my round-1 review; none of my three suggestions and neither nit is taken up. Stated only so the record is unambiguous — they were non-blocking then and they remain so, and they are carried forward below without restating.
EXIT_STALE_MERGE_BASE = 4. The constant is used at the single guard site and nowhere else; reverting the whole tool delta (constant and guard together, 7 lines) makes the new case fail, so the named form carries the same behaviour the unnamed one did.
The fixture's merge tree. git merge-tree --write-tree <base> <head> replaces reuse of the head's tree. I checked what it returns for the shape the fixture actually builds: every default-path caller goes through close_pull_request, and no test advances the target branch after the pull request branches — the one that does, the stale-base case, passes its own merge commit and never reaches this code. For a head that descends from the base, merge-tree --write-tree returns exactly the head's tree (probed: fb8f377d…, equal to rev-parse <head>^{tree}). So today the new call is tree-for-tree identical to what it replaced and can change no outcome — confirmed by the suite, 41 tests OK with a test-name list identical to the previous head's. What it buys is a fixture that stays honest the day a scenario does diverge, which is worth having.
Commit 3 — docs(review): document PR #2229 copilot suggestions audit
I checked the table against the live threads rather than against the file's own claims: gh api graphql over reviewThreads returns exactly three threads, all isResolved: true, with IDs PRRT_kwDOGp2yqc6ikpCV, …ikpC9, …ikpDZ, original comments r4016997524, r4016997587, r4016997629, replies r4017119256, r4017132039, r4017136641, and paths matching. Every row's thread ID, URL, reply URL, decision, status and thread state is accurate, and the two action rows name the commit that carries the change. Nothing in the table misstates a thread.
The declined suggestion is declined correctly. pull/<n>/base is written by the tool's own fetch refspec +refs/heads/<branch>:refs/heads/pull/<n>/base, so it and <branch> are the same commit by construction — Copilot's "if branch isn't the same string as base_branch" is a false positive on identity, and naming the temporary ref would point the reader at something they cannot rebase onto. It does answer the ref-naming half of my round-1 suggestion 1; the other half of that suggestion, that the guard fires on a recomputation race where waiting rather than rebasing is the fix, is untouched by it and still stands.
Verification at this head
python3 contrib/dev-tools/git/tests/test-github-merge-symlinks.py→ rc 0,Ran 41 tests … OK, 14.7 s; test-name list identical to the previous head's.bash contrib/dev-tools/git/tests/test-merge-pull-request.sh→ rc 0, 1 s.- The stale-base case alone →
OKin 0.29 s; with the tool delta reverted bygit apply -R→FAILED (failures=1),AssertionError: 1 != 4. Restored,git status --porcelainempty. toml,clippy,rustfmt,shellchecklinters, the Containerfile check,cargo test --doc --workspaceand the dictionary formatter all pass at this head.linter markdownandlinter cspellcould not run on my machine — the node-based linters are currently broken there, reproducibly on unmodifieddevelopas well, so it is not this branch — and CI's Docs Lint, which is exactlylinter lychee,linter markdownandlinter cspell, is green at this sha.- CI: 11 checks green including Docs Lint, Documented Clippy Allows, Layer Boundary Bans, all six Build matrix jobs and Generate Coverage Report; Docker E2E skipped;
Unit (nightly),Unit (stable)andTest (Docker) (release)were still running when I closed the window. No red checks. Worth a glance at those three before merging.
Carried forward from round 1 (non-blocking)
The three suggestions and two nits in #2229 (review) all still apply as written: the rebase-versus-wait wording in the recovery message, the two unguarded rev-parse calls, the README-github-merge.md coverage-boundary and exit-code sentences, and the two test-side nits. None of them blocks this merge; they are equally fine as follow-ups or as nothing at all.
Nits on the new commits (non-blocking)
1. The constant's placement and its promise. EXIT_STALE_MERGE_BASE sits between COMMIT_FORMAT and the if os.name == 'posix': block, under the comment # OS specific configuration for terminal attributes, which now heads a group containing one exit code — and it separates COMMIT_FORMAT from the branch that overrides it. Its own group, or a position next to the GIT/SHELL block, would keep the header true. Related: the name reads as a code dedicated to this condition, while 4 is still returned by five other sys.exit(4) sites (lines 653, 657, 666, 673, 722) and by the symbolic-link refusal, and the fixture still calls the same value EXIT_REFUSED. Naming one of six shared uses is a smaller gain than it looks; naming them all, or a comment saying 4 is the tool's general refusal status, would close it.
2. A conflicting fixture scenario would surface as an opaque error. git merge-tree --write-tree exits 1 on conflicts (probed: rc 1, tree oid still on stdout), and MergeFixture.git runs with check=True, so the CalledProcessError that a future divergent-and-conflicting scenario would raise carries no stdout or stderr in its message. No current scenario reaches it. A check=False plus an explicit assertion, or a comment recording that the helper assumes a conflict-free pair, would keep the next author out of it.
3. The tracker file is a trimmed copy of the template. docs/templates/COPILOT-SUGGESTIONS-TEMPLATE.md carries a <!-- skill-link: process-copilot-suggestions --> marker, a status legend, a ## Workflow section and a ## Notes section, and the three most recent trackers — pr-2224, pr-2225, pr-2227 — all carry all four. This one has none of them. The table itself is complete and correct, so nothing is lost for a reader of this pull request; it is the uniformity across roughly thirty audit files that the omissions cost. In the same spirit, the recent trackers close their Processing Log with the step-5 verification, as in "list-unresolved-threads.sh returned no threads after refresh" — I confirmed independently that no unresolved threads remain, so only the note is missing.
|
ACK e5eef75 — commit 1 unchanged by range-diff, the two new commits verified against the live threads and re-run gates, and the stale-base case still fails when the tool delta is reverted. |
…uest rebases and reconciling rulesets 0bb0d37 docs(pr-reviews): [#2507] record the PR #2508 round 2 review (Jose Celano) 7883393 docs(skills): [#2507] gate manual commits on the pre-commit script's exit status (Jose Celano) 8a4aef7 docs(skills): [#2507] scope the commit-id citation rule to durable references (Jose Celano) 0d8469f docs(adrs): [#2507] drop the alignment padding from the ADR index row (Jose Celano) 41c80ee docs(pr-reviews): [#2507] name the reviewed PR #2508 head by subject after the rebase (Jose Celano) 676e080 docs(pr-reviews): [#2507] fix a spelling failure in the PR #2508 review audit (Jose Celano) 669a815 docs(pr-reviews): [#2507] add the PR #2508 review audit (Jose Celano) c599bda docs(skills): [#2507] recommend pull-request rebases instead of requiring them (Jose Celano) d650390 docs(adrs): [#2507] cite the implementing issue by number in the ADR frontmatter (Jose Celano) 976c9d4 docs(issues): [#2507] link the specification pull request (Jose Celano) d0033d3 docs(issues): add issue specification and ADR for #2507 (Jose Celano) Pull request description: Related to #2507 ## Summary Specification PR. It adds the issue specification for #2507, issue-local baseline evidence, and a root ADR that drops the long-standing, never-documented requirement to rebase every pull request onto the latest `develop` before merging. Rebasing stays **recommended** (when opening a PR, when `develop` is known to have changed, and whenever it is cheap) because it detects integration problems early; it stops being **mandatory** only to reduce CPU consumption and runner costs. The ADR is proposed as accepted with this PR so the recommendation applies immediately. To avoid conflicting instructions (Copilot review finding F1), this PR also updates the `open-pull-request` and `merge-pull-request` skills and `AGENTS.md` to the new rule. The remaining implementation (merge-tool refresh, rulesets, measurements) follows in a separate PR, so #2507 stays open. ## Key findings (details and reproduction commands in `baseline-evidence.md`) - No ADR, issue, or commit body records why rebasing is required; it lives only in the `open-pull-request` and `merge-pull-request` skills and in the stale-merge-base guard added by PR #2229. `AGENTS.md` contradicts it. - Merged PRs grew from 20 (April 2026) to 170 (September 2026); the median open-PR queue reached 8 in October; force-pushes per merged PR rose from 0.39 (June) to 1.58 (October); about two dozen commits since September only repaired rebase fallout in review records and evidence. - `github-merge.py` needs GitHub's `refs/pull/<n>/merge` to be based on the current `develop` tip, and GitHub did not recompute it for at least 48 minutes after `develop` advanced. That is why a head push is needed today; the spec plans a non-rewriting refresh (GitHub "Update branch" is an accepted fallback). - Ruleset 94237 (force-push ban + 16 strict required checks) was disabled around every merge and has been effectively off since 2026-05-05; no merge was ever pushed while it was active. Six required check names no longer exist and documentation-only PRs report only `Docs Lint`, so it cannot be satisfied. Disabling it also removed the force-push ban. - Ruleset 19245352 (Copilot review) was created and disabled by GitHub's `ghost` actor; maintainer PRs still get Copilot reviews through personal settings. ## Files - `docs/issues/open/2507-stop-requiring-pull-request-rebases/ISSUE.md` - `docs/issues/open/2507-stop-requiring-pull-request-rebases/baseline-evidence.md` - `docs/adrs/20261013161419_stop_requiring_pull_request_rebases.md` - `docs/adrs/index.md` - `.github/skills/dev/git-workflow/open-pull-request/SKILL.md` - `.github/skills/dev/git-workflow/merge-pull-request/SKILL.md` - `AGENTS.md` - `docs/pr-reviews/pr-2508-review/PR-REVIEW.md` (review audit) ## Validation - `TORRUST_GIT_HOOKS_LOG_DIR=.tmp ./contrib/dev-tools/git/hooks/pre-commit.sh --format=json`: pass (includes `linter all`, frontmatter validation, documentation tests) ## Review requests - @da2ce7: please review the policy in the ADR and the ruleset target state (section "Ruleset Target State" in the spec), especially the choice between an always-reporting gate check and verifying required checks in the merge tool. ACKs for top commit: josecelano: ACK 0bb0d37 Tree-SHA512: fae5810fa5f961de8cca843085de4ec354d020ed5febb41b7082c2edabe9077f7d5102d1508e6ac452e58ef848ebee3d3d9df0c62d69a7b339d15f44f9c99bf8
Prevent maintainer merge attempts from reaching the signing and push steps when GitHub's synthetic pull-request merge ref is based on an older develop revision.
The vendored merge tool now compares that merge ref's first parent with the fetched target tip and gives an explicit rebase, push, and recomputation recovery message.
The deterministic fixture now publishes GitHub-like two-parent merge refs and covers the stale-base rejection. The canonical merge workflow skill documents the GH013 symptom and recovery.
Validation: