fix(bundle): include refs/heads/<branch> in bundle when agent HEAD is on target branch (non-main dispatch)#37929
Merged
Merged
Conversation
…ch during non-main dispatch Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix dispatched worker for safe_outputs bundle application
fix(bundle): include refs/heads/<branch> in bundle when agent HEAD is on target branch (non-main dispatch)
Jun 8, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a failure mode in safe_outputs when applying git bundles produced by workers dispatched from non-main refs, ensuring bundles include the expected branch ref (or can recover prerequisites when they do not).
Changes:
- Update bundle generation Strategy 2 to avoid
git branch -fwhen HEAD is already on the target branch, so the bundle includesrefs/heads/<branch>. - Make
create_pull_request’s HEAD-only bundle fallback usegetExecOutput(ignoreReturnCode: true)and add prerequisite-commit recovery + retry. - Add/adjust tests to cover the non-main dispatch + HEAD-only prerequisite recovery scenarios.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/generate_git_bundle.cjs | Ensures Strategy 2 preserves a named refs/heads/<branch> ref when HEAD is already on the target branch. |
| actions/setup/js/create_pull_request.cjs | Adds prerequisite-recovery logic to the HEAD-only bundle fetch fallback using stderr-aware execution. |
| actions/setup/js/generate_git_bundle.test.cjs | Adds a regression test for non-main dispatch behavior (shallow clone + HEAD on fix branch). |
| actions/setup/js/create_pull_request.test.cjs | Updates HEAD-only fallback expectations and adds a test for prerequisite recovery in the HEAD-only path. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 2
Comment on lines
+181
to
+183
| // Simulate Actions checkout: shallow clone of feature-branch (depth=1) | ||
| execGit(["clone", "--depth=1", "--branch=feature-branch", remoteDir, workDir]); | ||
| execGit(["config", "user.name", "Test User"], { cwd: workDir }); |
Comment on lines
+283
to
+286
| await execApi.exec("git", headPrereqFetchArgs); | ||
| core.info("Fetched HEAD bundle prerequisite commits from origin successfully"); | ||
| await execApi.exec("git", ["fetch", bundleFilePath, `HEAD:${bundleTempRef}`]); | ||
| } else { |
Collaborator
|
@copilot apply pr-finisher skill |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Applied. I ran a PR-finisher pass, addressed the actionable review feedback, and pushed updates in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a worker is dispatched from a non-
mainscanner run,safe_outputsfails to apply the git bundle withcouldn't find remote ref refs/heads/<worker-branch>. The bundle contains only a bareHEADref instead ofrefs/heads/<branchName>, soapplyBundleToBranchcan't locate it.Root cause
In
generate_git_bundle.cjsStrategy 2, the code creates a named local branch so the bundle embedsrefs/heads/<branchName>:This fails with
fatal: cannot force update the branch '<branchName>' used by worktreewhen the agent has already checked outbranchName(the normal worker flow: checkout fix-branch → commit → callcreate_pull_request). Thecatchsilently falls back torangeEnd = "HEAD", producing a HEAD-only bundle.Changes
generate_git_bundle.cjs(Strategy 2): Before attemptinggit branch -f, resolve the current branch viarev-parse --abbrev-ref HEAD. If it already equalsbranchName, use it asrangeEnddirectly — no force-update needed. Thegit branch -fpath is kept for the case where HEAD is on a different branch.create_pull_request.cjs(defensive fallback): In thebranchRefs.length === 0HEAD-only bundle path, switch from a bareexec()togetExecOutput(ignoreReturnCode: true)and apply the same prerequisite-recovery pattern used by the initial fetch. When the bundle's prerequisite is a non-mainbranch tip (not reachable from themain-only shallow safe_outputs checkout), the missing commits are fetched fromoriginand the bundle apply is retried.Tests: New test in
generate_git_bundle.test.cjscovering Strategy 2 with a shallow feature-branch clone whereGITHUB_SHAis the feature-branch tip and HEAD is on the new fix branch. New test increate_pull_request.test.cjscovering HEAD-only bundle prerequisite recovery. Updated existing HEAD-fallback test to reflect that the HEAD fetch is now viagetExecOutput(notexec).