Skip to content

Fix create_pull_request rewrite/push parity for excluded files and base drift - #49474

Merged
pelikhan merged 15 commits into
mainfrom
copilot/create-pull-request-bugfix
Aug 1, 2026
Merged

Fix create_pull_request rewrite/push parity for excluded files and base drift#49474
pelikhan merged 15 commits into
mainfrom
copilot/create-pull-request-bugfix

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

create_pull_request could validate one object and push another. In practice this showed up in two ways: excluded paths could be removed from the .patch but still present in the pushed commit, and the signed-push rewrite path could absorb or revert unrelated base-branch drift from shallow/long-running checkouts.

  • Rewrite against the agent base, then replay onto the current base tip

    • rewriteBundleBranchAsSingleCommit now linearizes against the bundle prerequisite commit, preserving the agent’s actual change set.
    • After synthesizing the single commit, it rebases that commit onto the current origin/<base> tip so the final pushed diff stays relative to the live base branch instead of reintroducing drift.
    const newHead = await linearizeRangeAsCommit(baseRef, commitHeadline, execApi, {
      excludedFiles: options.excludedFiles,
      rebaseOnto: fallbackBaseRef,
    });
  • Extend linearization to support replay onto a newer base

    • linearizeRangeAsCommit now accepts rebaseOnto for the “compute diff from old base, publish on new base” case.
    • If replay fails, the helper aborts any in-progress rebase before restoring the original HEAD.
  • Lock in validation/push parity with regressions

    • Promote the merge-rewrite parity case from expected-fail to required pass.
    • Add a focused regression covering base drift: after rewrite, origin/main..HEAD contains only the agent-authored file set, not unrelated files added on base.
    • Keep the existing excluded-files parity coverage aligned with the pushed commit shape.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 14.8 AIC · ⌖ 5.87 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 20.7 AIC · ⌖ 8.23 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Run: https://github.com/github/gh-aw/actions/runs/30700817659

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11 AIC · ⌖ 6.51 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11.4 AIC · ⌖ 9.37 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.64 AIC · ⌖ 7.34 AIC · ⊞ 8.1K ·
Comment /souschef to run again


Run URL: https://github.com/github/gh-aw/actions/runs/30719603092

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.21 AIC · ⌖ 6.88 AIC · ⊞ 8.1K ·
Comment /souschef to run again

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Evaluation Summary

On-topic: This PR addresses two critical bugs in `create_pull_request's push path that allow files to reach committed changes when they should be excluded. This directly aligns with the project's focus on agentic workflows and file-protection guarantees.

Focused: The PR targets a single, well-defined issue (#48934) with two related root-cause bugs in the push validation and bundle filtering logic.

⚠️ Early-stage work: This is marked [WIP], has no file changes yet (0 additions, 0 deletions), and likely represents an in-progress agent implementation task.

Feedback

Before this PR is ready for review:

  1. Add implementation — The diff is currently empty. Once the fixes are applied:

    • Fix linearization to use the agent's own base commit instead of the moving branch tip (Bug 1)
    • Apply excluded-files filtering to the bundle artifact, not only the patch (Bug 2)
    • Add post-rewrite validation of staged files
  2. Add test coverage — Include tests covering:

    • Shallow checkout + rewrite scenario with base drift
    • excluded-files filtering on bundle artifacts
    • Validation that excluded files never reach the push
  3. Update PR description — Replace the [WIP] marker with a concise summary once implementation is complete.

Generated by ✅ Contribution Check · auto · 46.2 AIC · ⊞ 8.7K ·

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix commit push to exclude disallowed files Fix create_pull_request rewrite/push parity for excluded files and base drift Aug 1, 2026
Copilot AI requested a review from pelikhan August 1, 2026 05:58
@pelikhan
pelikhan marked this pull request as ready for review August 1, 2026 06:27
Copilot AI review requested due to automatic review settings August 1, 2026 06:27
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the implementation label and has 0 new lines of code in business logic directories (threshold: 100).

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

An existing bundle integration test still asserts the pre-rebase working-tree shape and will fail.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

Fixes validation/push parity by rebasing synthesized commits onto the current base tip.

Changes:

  • Adds rebaseOnto support to commit linearization.
  • Replays bundle rewrites onto the live base.
  • Promotes and adds parity regression coverage.
File summaries
File Description
actions/setup/js/git_helpers.cjs Adds replay and rebase cleanup.
actions/setup/js/git_helpers.test.cjs Tests base-drift replay.
actions/setup/js/create_pull_request.cjs Rebases rewritten bundles onto the base tip.
actions/setup/js/create_pull_request_validation_push_parity.test.cjs Enables rewrite parity regression.
Review details

Suppressed comments (1)

actions/setup/js/create_pull_request.cjs:388

  • Replaying onto origin/main changes the resulting working tree to include base drift, but the existing regression in actions/setup/js/create_pull_request_bundle_integration.test.cjs:531-543 still requires base-drift.txt to be absent. This new path therefore makes that integration test fail. Update that regression to assert the rebased shape (base drift present in the tree, absent from origin/main..HEAD, and HEAD^ == origin/main) so it validates the behavior introduced here.
          const { exitCode } = await execApi.getExecOutput("git", ["cat-file", "-e", `${prereqSha}^{commit}`], { ignoreReturnCode: true, silent: true });
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Balanced

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Review: Fix create_pull_request rewrite/push parity

The fix is correct and well-structured.

Correctness: linearizeRangeAsCommit correctly applies git rebase --onto rebaseOnto baseRef HEAD after synthesizing the single commit, replaying only the agent-authored delta onto the live base tip without absorbing base-branch drift. The guard (rebaseOnto.trim() !== baseRef) is a defensive no-op in practice (one is a SHA, the other is origin/<branch>).

Error recovery: The nested rebase --abort before reset --hard is the right sequence — it clears REBASE_HEAD state if the rebase started but failed mid-way, then the hard reset restores the original HEAD cleanly.

Test coverage: The new integration test covers exactly the regression scenario: base drift from a collaborator push, then linearizeRangeAsCommit with rebaseOnto, asserting origin/main..HEAD contains only the agent-authored file.

Parity test promotion: Promoting it.fails to it in the parity test is the right signal the fix is complete.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 24.5 AIC · ⊞ 5.3K

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

🧪 Test Quality Sentinel Report

Test Quality Score: 88/100 — Excellent

Analyzed 4 test(s): 4 design, 0 implementation, 0 violation(s).

📊 Metrics (4 tests)
Metric Value
Analyzed 4 (JavaScript vitest)
✅ Design 4 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 4 (100%)
Duplicate clusters 0
Inflation 2.69:1 (acceptable for integration tests)
🚨 Violations 0
Test File Classification Quality
Sanity: no excluded files create_pull_request_validation_push_parity.test.cjs:170 behavioral_contract High-value design test; verifies baseline parity assumption
Excluded files regression create_pull_request_validation_push_parity.test.cjs:232 behavioral_contract High-value design test; regression for issue #48999
Merge-commit rewrite (NOW PASSING) create_pull_request_validation_push_parity.test.cjs:303 behavioral_contract High-value design test; removed it.fails(), base-drift fix
Base drift linearization git_helpers.test.cjs:1623 behavioral_contract NEW; integration test validates commit replay without reverting collaborator changes
✅ Quality Signals

Excellent Coverage:

  • All 4 tests verify critical design contracts: file-set parity between validation and push
  • Multiple assertions per test (3–5 per test) covering file inclusion, drift preservation, parent commit correctness
  • Real git integration testing with temporary repositories and collaborator simulation
  • Proper cleanup with beforeAll, afterEach hooks using fs.rmSync and vi.clearAllMocks()

Test Infrastructure:

  • No Go mock violations (N/A — JavaScript/vitest)
  • No shell injection risks (git args passed as array)
  • Vitest framework used correctly with async test support
  • Detailed JSDoc comments explaining regression root causes and fix rationale

Design Invariants Enforced:

  1. Patch validation file set == pushed commit file set (guards against excluded-file leaks)
  2. Base-branch drift is preserved during commit rewriting (guards against unintended reversions)
  3. Merge-commit topology is correctly flattened when needed

Verdict

Passed. 0% implementation tests (threshold: 30%). All tests verify critical user-facing design contracts; high-value regression coverage for file-set parity under excluded-file and base-drift edge cases.

🧪 Test quality analysis by Test Quality Sentinel · haiku45 · 21.9 AIC · ⊞ 8.4K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 88/100. 0% implementation tests (threshold: 30%). All tests verify critical user-facing design contracts; high-value regression coverage for file-set parity under excluded-file and base-drift edge cases.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — no blocking issues; three focused comments posted.

📋 Key Themes & Highlights

Key Themes

  • Trim asymmetry (git_helpers.cjs line 783): rebaseOnto is trimmed but baseRef is not, making the skip-same-ref guard asymmetric.
  • Double-restore on rebase failure (git_helpers.cjs line 786): after rebase --abort HEAD is already restored; the subsequent reset --hard is redundant and could confuse future maintainers.
  • Test fixture isolation (git_helpers.test.cjs line 1648): the new integration test checks out a branch on the shared repoDir fixture without a cleanup guard, risking order-dependent test failures.

Positive Highlights

  • ✅ Root cause properly addressed: linearizing against the bundle prerequisite commit and then replaying onto the live base tip is exactly the right two-phase approach.
  • rebase --abort added in the error path — good defensive recovery.
  • it.fails() promoted to it() with matching description update — clean signal that the regression is fully closed.
  • ✅ New integration test exercises the collaborator-drift scenario end-to-end with a real git remote, which is the hardest class of parity bugs to catch with unit mocks.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 34.5 AIC · ⊞ 7K
Comment /matt to run again

Comment thread actions/setup/js/git_helpers.cjs
Comment thread actions/setup/js/git_helpers.cjs
Comment thread actions/setup/js/git_helpers.test.cjs Outdated
@pelikhan

pelikhan commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Verdict: Request changes — the base-drift replay fix has a plausible silent-data-loss gap

Good direction (linearizing against the bundle prerequisite, then replaying onto the current base tip), but the new rebase --onto step lacks a post-rebase verification that the commit actually survived, and conflict/abort handling during that rebase is unverified by tests.

Themes
  • Silent empty-rebase risk: git rebase --onto drops commits that become empty relative to the new base with no error surfaced — this could silently discard the agent's changes in edge cases (e.g. base drift happens to already contain equivalent content), which is exactly the parity bug class this PR is trying to close.
  • Unverified conflict path: the new integration test only covers the clean, non-conflicting replay. The failure/rollback path (rebase --abort swallowing its own failure, then reset --hard) has no coverage for a genuinely conflicting rebase, so the recovery logic added in this PR is unverified.
  • Positive: extending linearizeRangeAsCommit with rebaseOnto and rebasing against fallbackBaseRef after linearizing against the bundle prerequisite is a sound way to preserve the agent's actual diff while still publishing on a fresh tip.

🔎 Code quality review by PR Code Quality Reviewer · auto · 153.6 AIC · ⊞ 7.8K
Comment /review to run again

Comment thread actions/setup/js/git_helpers.cjs
Comment thread actions/setup/js/git_helpers.cjs
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: medium
  • Priority: high
  • Score: 72/100 (Impact40/Urgency20/Quality12)
  • Recommended action: fast_track

Core create_pull_request push/patch parity bug (data-loss risk on excluded files/base drift); 2 approvals.

Generated by 🔧 PR Triage Agent · auto · 73.4 AIC · ⌖ 10.1 AIC · ⊞ 8K ·

@pelikhan

pelikhan commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot add git integration tests

Copilot AI and others added 2 commits August 1, 2026 19:44
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ed files; fix git reset for new excluded files

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan

pelikhan commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot add more integration tests to cover all corner cases

…ner cases

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add more integration tests to cover all corner cases

Added 5 integration tests in commit test: add integration tests for rewriteBundleBranchAsSingleCommit corner cases covering the untested fallback paths and behaviors:

  1. Self-contained bundle (no prereqs) — verifies the prereqs.length === 0 fallback to origin/main; git reports "records a complete history" for such bundles
  2. Multiple prerequisites bundle — uses an independent-branch topology (feature merges a side branch off ROOT, giving 2 prereqs: ROOT + MAIN) to exercise the prereqs.length > 1 fallback
  3. Bundle prereq SHA not in local object store — passes a bundle from an unrelated repo to trigger the cat-file -e failure path, confirming fallback to origin/main produces the correct diff
  4. File deletion — verifies that to-delete.txt appears as D in both the PR diff and the commit diff after rewrite
  5. File modification — verifies that modifications to existing files across multiple commits are squashed to the final state (not just new-file additions)

@pelikhan

pelikhan commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

@copilot add more tests to cover more cases

- Add integration test for excluded modification of existing file (exposes
  and verifies the working-tree restoration fix below)
- Add integration test for excluded files + base drift combined
- Add integration test for no bundleFilePath (no-bundle fallback path)
- Add integration test for file rename preservation
- Add integration test for commit headline from latest commit

Fix: when an excluded file is a modification of an existing base-branch file,
git reset HEAD -- <file> restores the index but leaves the working tree with
the agent's version. This unstaged change caused git rebase --onto to fail.
After the index reset, detect affected files with git diff --name-only and
restore their working tree with git checkout -- <files>.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add more tests to cover more cases

Added 5 more integration tests in commit test: add 5 integration tests and fix excluded-file working-tree bug, covering previously untested corner cases:

  1. Excluded modification of existing file — verifies that excluding a modified base-branch file (not just a new file) leaves the working tree at the base version. This test also exposed a production bug: git reset HEAD -- <file> was restoring the index but leaving the working tree with the agent's version, causing git rebase --onto to fail with "unstaged changes". Fixed by detecting affected files with git diff --name-only after the index reset and restoring the working tree with git checkout -- <files>.

  2. Excluded files + base drift combined — exercises excludedFiles and rebaseOnto together in a single rewrite, verifying only the non-excluded agent file appears in the PR diff with no drift file leaking in.

  3. No bundleFilePath supplied — exercises the if (bundleFilePath) guard path where prerequisite extraction is skipped entirely and origin/main is used directly as the linearization base.

  4. File rename preservation — verifies that a git mv rename survives linearization (old name absent, new name present with correct content, no spurious changes in the PR diff).

  5. Commit headline from latest commit — verifies that when the agent has multiple commits, the linearized commit uses the subject of the HEAD (latest) commit, not the first.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot quick triage for this PR:

  • Recent copilot follow-up says the 5 review threads were addressed on the current head; please resolve any still-open reviewer threads that are now satisfied and summarize the remaining maintainer-facing blockers.
  • Branch refresh: GitHub branch update was requested from this run.
  • Please run the pr-finisher skill before handoff.

Generated by 👨🍳 PR Sous Chef

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.64 AIC · ⌖ 7.34 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot quick triage for this PR:

  • Recent copilot follow-up says the 5 review threads were addressed on the current head; please resolve any still-open reviewer threads that are now satisfied and su...

pr-finisher summary for HEAD 1bfa641:

  • Review threads — all 5 threads are already resolved (marked is_resolved: true)
  • Local validationmake agent-report-progress-no-test passes (268 workflows compiled, lock files in sync, 0 lint errors); make test-unit-all exits 0 (all Go + JS tests pass)
  • ⚠️ CI on current HEAD — shows action_required on the CJS workflow, which requires a maintainer to approve the run (not a test failure — this is the GitHub workflow protection gate for PR workflows triggered by bots). The require-fs-io-try-catch ESLint failures visible in earlier runs are pre-existing in main (introduced in d1adb68, unrelated to this PR).

Remaining maintainer action: approve the pending CI run for 1bfa641 (or close/reopen the PR to trigger a fresh run), then merge.

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot
Please investigate this PR and move it toward merge readiness.
Please refresh the branch if needed, address any unresolved review feedback, and run the pr-finisher skill.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 4.21 AIC · ⌖ 6.88 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Please investigate this PR and move it toward merge readiness.
Please refresh the branch if needed, address any unresolved review feedback, and run the pr-finisher skill....

pr-finisher summary for HEAD d8ee14a:

  • Branch — already refreshed (merge commit d8ee14a from main c81f086)
  • Review threads — all 5 resolved (is_resolved: true)
  • Local validationmake agent-report-progress-no-test passes (268 workflows compiled, lock files in sync, 0 lint errors)
  • ⚠️ CI — CJS workflow shows action_required on d8ee14a — this is the GitHub Actions bot-PR protection gate, not a test failure. Prior successful runs on 1bfa641 and 5b8ba9c show the tests pass when approved.

Remaining maintainer action: approve the CJS run for d8ee14a (run 30719823478), then merge.

@pelikhan
pelikhan merged commit 06583c9 into main Aug 1, 2026
9 checks passed
@pelikhan
pelikhan deleted the copilot/create-pull-request-bugfix branch August 1, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_pull_request: pushed commit can contain files that allowed-files/excluded-files should have kept out

4 participants