fix: exclude merged upstream commits from diffSize in push_to_pull_request_branch incremental mode#34139
Conversation
…incremental mode When push_to_pull_request_branch targets an existing PR and the agent has merged the default branch (e.g. origin/main) into the PR branch to resolve conflicts, the incremental diffSize was inflated to include all of the default branch's new commits. This caused max_patch_size validation to fail even when the agent's actual contribution was tiny. Root cause: the diffSize was computed as git diff <old-PR-head>..<local-branch>, which includes all commits reachable from the local branch but not from the old PR head — including the hundreds of upstream commits brought in by the merge. Fix: before computing diffSize in incremental mode, check if the merge-base between origin/<defaultBranch> and the local branch is already an ancestor of the PR's current head (baseCommitSha). If it is NOT (meaning the agent merged default-branch commits that are ahead of the PR head), use the merge-base as the effective diff base. This excludes the merged upstream commits from the size measurement, leaving only the agent's actual contribution. The fix preserves existing behavior when the agent does not merge the default branch (the merge-base will be an ancestor of the PR head, so baseCommitSha remains the diff base). Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…fSize test Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes how diffSize is computed in generateGitPatch(..., { mode: "incremental" }) so that merging the base branch into a stale PR branch (e.g., git merge origin/<baseBranch>) does not cause diffSize to balloon by counting already-upstream commits. This is used for size enforcement (e.g., max_patch_size) without changing the transport patch content.
Changes:
- Adjust incremental
diffSizemeasurement to optionally usemerge-base(origin/<baseBranch>, <localBranch>)as the diff base when upstream commits were merged into the PR branch. - Add incremental-mode regression tests covering merge and no-merge scenarios to ensure
diffSizeremains small while the transport patch may remain large.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/generate_git_patch.cjs | Adds merge-base-based diff base selection for incremental diffSize sizing. |
| actions/setup/js/generate_git_patch.test.cjs | Adds tests ensuring incremental diffSize excludes merged upstream commits and doesn’t regress the no-merge case. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
| if (!mbIsAncestorOfBase) { | ||
| debugLog(`Strategy 1 (incremental): agent merged ${defaultBranch} ahead of PR head; using merge-base ${mb} as diff base instead of PR head ${baseCommitSha}`); | ||
| diffBaseForSize = mb; | ||
| } |
|
🧪 Test Quality Sentinel completed test quality analysis. |
|
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. No ADR enforcement needed: PR #34139 does not have the 'implementation' label and has 0 new lines of code in default business logic directories (threshold is 100). |
|
🧠 Matt Pocock Skills Reviewer failed during the skills-based review. |
🧪 Test Quality Sentinel Report
📊 Metrics & Test Classification (2 tests analyzed)
Test Classification Details
Language SupportTests analyzed:
|
|
@copilot review all pull review request comments and resolve them |
…ry rewrites Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed in commit The merge-base adjustment now only applies when |
|
@copilot add more tests covering corner cases |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
`` Please address the unresolved review feedback and push the follow-up fix.
|
|
``
|
When an agent merges
origin/<baseBranch>into a stale PR branch (e.g., to resolve conflicts),diffSizewas computed asgit diff <old-PR-head>..<local-branch>— pulling in all upstream commits reachable from the merge but not from the old PR head. A 2-commit agent change (+6/-4 lines) could produce a 9282 KB "incremental diff" containing 480 upstream commits, failingmax_patch_sizeeven though the agent's actual contribution was tiny.Changes
generate_git_patch.cjs— smarter diff base in incremental modeBefore calling
computeIncrementalDiffSize, compute the merge-base betweenorigin/<defaultBranch>and the local branch:baseCommitSha(agent didn't merge ahead of the PR head): keepbaseCommitShaas the diff base — no behavior change.baseCommitSha(agent merged default-branch commits beyond the PR head): use the merge-base as the effective diff base, cutting out the merged upstream commits.The transport patch (
format-patch) is unchanged — it still carries the full commit range forgit am/bundle apply; only the size enforcement measurement is corrected.generate_git_patch.test.cjs— two new incremental mode testsdiffSize < 1 KBwhen agent merges 50+ KB of upstream changes (transport patch remains > 1 KB).diffSizestays correct when the agent adds commits without merging the default branch (regression guard).pr-sous-chef: update branch requested
run: https://github.com/github/gh-aw/actions/runs/26320547848