Fix bundle apply in safe_outputs: skip unshallow and emit matching fetch-refs step for cross-repo checkouts#35460
Merged
Merged
Conversation
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement algorithm to apply bundle for PR without deep clone
Avoid full-history fetch when applying git bundles in create/push PR flows
May 28, 2026
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes bundle apply failures in the safe_outputs job for large monorepos. The previous flow tried to unshallow before applying a git bundle (expensive and unreliable on big repos) and never fetched secondary fetch: refs declared in checkout: frontmatter, so bundle prerequisite commits weren't reachable. This PR drops the unshallow and emits an agent-job-equivalent fetch-refs step in safe_outputs, relying on the existing per-SHA prerequisite recovery as the fallback path.
Changes:
- Make
ensureFullHistoryForBundlea probe-only function: no moregit fetch --unshallow origin; rely on prerequisite-recovery increate_pull_request.cjs/push_to_pull_request_branch.cjs. - Add
CheckoutManager.GetCheckoutForRepositoryand havebuildSharedPRCheckoutStepsemit a conditional "Fetch additional refs for<repo>" step (mirroring the agent-job fetch step) when the cross-repo target has a matchingcheckout:config withfetch:refs. - Update tests (Go + JS) and rewrite the safe-outputs PR docs section.
Show a summary per file
| File | Description |
|---|---|
actions/setup/js/git_helpers.cjs |
Strip the unshallow call from ensureFullHistoryForBundle; updated comments and warning text. |
actions/setup/js/create_pull_request.cjs |
Comment cleanup referencing the new no-unshallow behavior. |
actions/setup/js/push_to_pull_request_branch.cjs |
Comment cleanup referencing the new no-unshallow behavior. |
actions/setup/js/git_helpers.test.cjs |
Assert no unshallow call and align warning text expectations. |
actions/setup/js/create_pull_request.test.cjs |
Assert bundle apply does not trigger --unshallow. |
actions/setup/js/push_to_pull_request_branch.test.cjs |
Assert bundle apply does not trigger --unshallow. |
pkg/workflow/checkout_manager.go |
Add GetCheckoutForRepository lookup. |
pkg/workflow/compiler_safe_outputs_steps.go |
Emit conditional "Fetch additional refs" step for cross-repo target when checkout fetch: declared. |
pkg/workflow/compiler_safe_outputs_steps_test.go |
Add 4 cases covering fetch-step emission and the negative paths. |
docs/src/content/docs/reference/safe-outputs-pull-requests.md |
Rewrite the PR-creation section to describe bundle apply + fetch refs + single cross-repo target. |
.github/workflows/jsweep.lock.yml |
Lockfile body hash refresh. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 11/11 changed files
- Comments generated: 0
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.
Problem
When the
safe_outputsjob applies a git bundle from the agent, it can fail with "Repository lacks these prerequisite commits" in two related ways:Expensive unshallow:
ensureFullHistoryForBundlewas callinggit fetch --unshallow origin, which pulls full history of large monorepos — slow, heavy, and unreliable.Missing secondary-ref commits: When
checkout:frontmatter declaresfetch:refs (e.g.dsyme/ci-perf/*), the agent job fetches those refs so their tip commits are locally available. Butsafe_outputsonly did a baredepth=1checkout of the base branch — those secondary-ref commits were never fetched, so prerequisite recovery (git fetch origin <sha>) would also fail because the commits aren't reachable from any locally-known ref.Changes
JS: Remove unshallow from bundle application (
git_helpers.cjs,create_pull_request.cjs,push_to_pull_request_branch.cjs)ensureFullHistoryForBundlenow skips thegit fetch --unshallowcall in shallow repos. It probes for shallowness and logs that it will rely on prerequisite recovery.git fetch origin <sha>...→ retry. This handles the common case where the base branch advanced between agent and safe_outputs (the old commit is still reachable from origin).Go: Emit matching "Fetch additional refs" step in
safe_outputsjob (compiler_safe_outputs_steps.go,checkout_manager.go)GetCheckoutForRepository(repoSlug)toCheckoutManagerto look up theresolvedCheckoutentry for a given cross-repo target.buildSharedPRCheckoutStepsnow checks whether the cross-repotargetRepoSlughas a matchingcheckout:config withfetch:refs declared. If so, it emits a "Fetch additional refs for <repo>" step — identical in structure to whatgenerateFetchStepLinesemits for the agent job, but:if:condition as the shared checkout stepcompiler_safe_outputs_steps_test.gocovering: match with fetch refs, match without fetch refs, no match, and push-to-pull-request-branch variant.Result
For
ci-perfworkflows targetinggithub/githubwithfetch: [master, dsyme/ci-perf/*]:safe_outputsnow emits a "Fetch additional refs for github/github" step after the git-credentials step, making those branch tips locally available beforeapplyBundleToBranchruns.git fetch origin <sha>works).Fixes #35459