Skip to content

Fix create_pull_request patch using stale origin/<branch> instead of merge-base#28960

Merged
mrjf merged 3 commits intomainfrom
copilot/fix-stale-origin-branch-patch
Apr 28, 2026
Merged

Fix create_pull_request patch using stale origin/<branch> instead of merge-base#28960
mrjf merged 3 commits intomainfrom
copilot/fix-stale-origin-branch-patch

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

In full mode, generate_git_patch.cjs short-circuited to origin/<branchName> whenever that remote-tracking ref existed locally. Since that ref is populated by the startup checkout (fetch: ["*"]) and never refreshed, it points at the pre-run remote tip — not the branch state before the agent's edits. When the agent fast-forwards the local branch to main and then commits (a common pattern for long-running iterative workflows), the resulting patch includes every commit between the stale tip and main, producing phantom files the agent never touched.

Changes

  • actions/setup/js/generate_git_patch.cjs — Remove the origin/<branchName> short-circuit in full mode; always compute merge-base origin/<defaultBranch> <branchName> (this was already the fallback path). Incremental mode is unchanged — its use of origin/<branchName> is correct for push_to_pull_request_branch.
  • actions/setup/js/generate_git_patch.test.cjs — Add regression test that builds a real bare-remote + working repo reproducing the stale-remote-tracking-ref scenario (stale origin/feature-branch + local fast-forward to main + one new commit), and asserts the patch contains only the agent's file. The test explicitly fetches refs/remotes/origin/feature-branch after the initial push so behavior is deterministic across git versions.
  • Generic wording — Removed all repository-specific (tsessebe) and workflow-pattern-specific (autoloop) references from code, tests, changesets, and docs in favor of generic "long-running branch" wording so the messaging applies to all gh-aw users.

Before / After

// Before: full mode
try {
  execGitSync(["show-ref", "--verify", "--quiet", `refs/remotes/origin/${branchName}`], { cwd });
  baseRef = `origin/${branchName}`;   // stale — points wherever the remote was at checkout
} catch {
  baseRef = execGitSync(["merge-base", "--", `origin/${defaultBranch}`, branchName], { cwd }).trim();
}

// After: full mode always uses merge-base
baseRef = execGitSync(["merge-base", "--", `origin/${defaultBranch}`, branchName], { cwd }).trim();

The regression test fails on the pre-fix code (patch contains phantom1.md, phantom2.md, agent-change.txt) and passes after the fix (patch contains only agent-change.txt).

Copilot AI changed the title [WIP] Fix patch generation to use merge-base with default branch Fix create_pull_request patch using stale origin/<branch> instead of merge-base Apr 28, 2026
Copilot finished work on behalf of mrjf April 28, 2026 16:07
Copilot AI requested a review from mrjf April 28, 2026 16:07
@pelikhan pelikhan marked this pull request as ready for review April 28, 2026 19:05
Copilot AI review requested due to automatic review settings April 28, 2026 19:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes generate_git_patch.cjs full-mode base ref selection so create_pull_request patches are computed from merge-base origin/<defaultBranch> <branchName> rather than potentially stale origin/<branchName> remote-tracking refs.

Changes:

  • Remove the full-mode short-circuit that used origin/<branchName> when present; always compute merge-base vs the default branch.
  • Add a regression test that simulates the “stale origin/feature-branch + fast-forward to main + one agent commit” autoloop scenario.
  • Add a changeset documenting the patch fix.
Show a summary per file
File Description
actions/setup/js/generate_git_patch.cjs Ensures full-mode patch base is derived from merge-base with the default branch, avoiding stale remote-tracking refs.
actions/setup/js/generate_git_patch.test.cjs Adds end-to-end regression coverage for the stale origin/<branch> phantom-commit patch issue.
.changeset/patch-fix-stale-origin-branch-merge-base.md Records the user-facing patch-level change in release notes.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment on lines +543 to +575
execSync("git init --bare -b main", { cwd: remoteDir });
execSync(`git remote add origin ${remoteDir}`, { cwd: repoDir });
execSync("git push origin main", { cwd: repoDir });

// Step 1: Create the feature branch at the initial commit and push it.
// This becomes the "old" position of origin/feature-branch.
execSync("git checkout -b feature-branch", { cwd: repoDir });
execSync("git push origin feature-branch", { cwd: repoDir });
const oldBranchSha = execSync("git rev-parse HEAD", { cwd: repoDir }).toString().trim();

// Step 2: main advances with phantom commits the agent will not make
execSync("git checkout main", { cwd: repoDir });
fs.writeFileSync(path.join(repoDir, "phantom1.md"), "# phantom 1\n");
execSync("git add phantom1.md", { cwd: repoDir });
execSync('git commit -m "phantom commit 1"', { cwd: repoDir });
fs.writeFileSync(path.join(repoDir, "phantom2.md"), "# phantom 2\n");
execSync("git add phantom2.md", { cwd: repoDir });
execSync('git commit -m "phantom commit 2"', { cwd: repoDir });
execSync("git push origin main", { cwd: repoDir });

// Step 3: Simulate the agent run — fast-forward the local feature branch to
// main, then make one new commit. Note that origin/feature-branch is still
// pointing at oldBranchSha (we deliberately do NOT push the branch update).
execSync("git checkout feature-branch", { cwd: repoDir });
execSync("git reset --hard main", { cwd: repoDir });
fs.writeFileSync(path.join(repoDir, "agent-change.txt"), "the only real change\n");
execSync("git add agent-change.txt", { cwd: repoDir });
execSync('git commit -m "agent change"', { cwd: repoDir });

// Sanity check: origin/feature-branch is still stale (points to oldBranchSha)
const remoteBranchSha = execSync("git rev-parse origin/feature-branch", { cwd: repoDir }).toString().trim();
expect(remoteBranchSha).toBe(oldBranchSha);

Comment thread actions/setup/js/generate_git_patch.cjs Outdated
Comment on lines +176 to +177
// contains exactly the agent's changes. See issue githubnext/tsessebe autoloop
// failures for context.
@mrjf
Copy link
Copy Markdown
Contributor

mrjf commented Apr 28, 2026

@copilot address comments and fix tests

@mrjf
Copy link
Copy Markdown
Contributor

mrjf commented Apr 28, 2026

@copilot remove all references to tsessebe and autoloop in code -- the code should be generically addressed to all gh-aw users, not specific repos that implement it.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 28, 2026

@copilot address comments and fix tests

Done in dc5c61d. Removed all tsessebe and autoloop references across code, tests, changesets, and docs (replaced with generic "long-running branch" wording). Also addressed the prior review comments: added an explicit git fetch origin feature-branch:refs/remotes/origin/feature-branch in the regression test for determinism, and removed the specific repo reference from the inline comment in generate_git_patch.cjs.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 28, 2026

@copilot remove all references to tsessebe and autoloop in code -- the code should be generically addressed to all gh-aw users, not specific repos that implement it.

Already addressed in dc5c61d — all tsessebe and autoloop references have been removed from code, tests, changesets, and docs. A repo-wide search confirms no remaining matches.

Copilot finished work on behalf of mrjf April 28, 2026 20:59
@mrjf
Copy link
Copy Markdown
Contributor

mrjf commented Apr 28, 2026

@copilot make sure all comments on this PR are addresses, especially the one on actions/setup/js/generate_git_patch.test.cjs

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 28, 2026

@copilot make sure all comments on this PR are addresses, especially the one on [actions/setup/js/generate_git_patch.test.cjs](https://github.com/github/gh-aw/pull/28960/files/773f7c1fe0cf971372209101...

Both prior review comments are already addressed in dc5c61d:

  1. generate_git_patch.test.cjs — line 555 explicitly runs git fetch origin feature-branch:refs/remotes/origin/feature-branch after the initial push to make refs/remotes/origin/feature-branch deterministic across git versions, with a comment explaining why. The test passes (verified locally with npm run test:js -t "stale origin").
  2. generate_git_patch.cjs — the githubnext/tsessebe reference has been removed; the inline comment now uses generic "long-running branch" wording.

Repo-wide grep for tsessebe|autoloop returns zero matches.

Copilot finished work on behalf of mrjf April 28, 2026 21:25
@mrjf mrjf merged commit c439037 into main Apr 28, 2026
61 checks passed
@mrjf mrjf deleted the copilot/fix-stale-origin-branch-patch branch April 28, 2026 21:35
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.

create_pull_request patch uses stale origin/branchName instead of merge-base with default branch

3 participants