gh-aw icon indicating copy to clipboard operation
gh-aw copied to clipboard

SideRepoOps: create_pull_request bases PR on repo default branch, not the checked-out ref (breaks non-default/release-branch checkouts)

Open yskopets opened this issue 5 months ago β€’ 5 comments

πŸ€– This issue was investigated and filed by Claude Code.

Summary

In a SideRepoOps workflow that checks out a target/side repository at a non-default ref (checkout: [{ repository: …, ref: <release-branch> }]), create_pull_request and push_to_pull_request_branch base the PR on the side repo's default branch, not on the ref that was actually checked out. The agent commits on top of <release-branch>, but the patch's merge-base is computed against the default branch β€” producing a PR with the wrong base (and a diff that drags in the entire release-branch divergence).

This is related to but distinct from the credential/404 failure in #39404. Here the concern is which branch is chosen as the base, even when resolution succeeds.

Where the base branch comes from

For create_pull_request, safe_outputs_handlers.cjs resolves the base branch in this order:

if (prConfig.base_branch) baseBranch = prConfig.base_branch;            // β‘  explicit config
else if (manifestEntry && manifestEntry.default_branch) baseBranch = …; // β‘‘ checkout manifest
else baseBranch = await getBaseBranch(...);                             // β‘’ repos.get() default_branch

Both β‘‘ and β‘’ resolve to the repository default branch:

  • The compiler-emitted "Build checkout manifest for safe-outputs handlers" step computes default_branch via git symbolic-ref --short refs/remotes/origin/HEAD (β†’ the repo's default) or gh api repos/<repo> --jq .default_branch (β†’ the repo's default).
  • get_base_branch.cjs falls back to github.rest.repos.get().default_branch (β†’ the repo's default).

Nothing in the chain consults the ref the workflow checked out. So when a workflow does:

checkout:
  - repository: <owner>/<side-repo>
    ref: <release-branch>      # e.g. a maintenance/release branch, NOT the default
    path: <side-repo>

…the agent works on top of <release-branch>, but the PR ends up based on <default-branch>.

Impact

  • The PR targets the wrong base branch.
  • generate_git_patch computes merge-base(feature, origin/<default-branch>), which lies far behind <release-branch>; the resulting patch/diff includes the whole divergence between the release branch and the default branch, not just the agent's change.
  • Only single-branch repos (where default == the checked-out ref) are unaffected, which masks the bug.

Expected

When a checkout pins a non-default ref, that ref should be the default base for create_pull_request / push_to_pull_request_branch β€” i.e. the base should track the checked-out branch, not the repository's default branch. Concretely, the checkout manifest could record the checked-out ref (e.g. git rev-parse --abbrev-ref HEAD of the checkout) rather than origin/HEAD's default, or the handler could prefer the checkout's upstream branch.

Current workaround

Set base_branch explicitly (path β‘ ) to the checked-out ref:

safe-outputs:
  create-pull-request:
    base-branch: <release-branch>   # must be kept in lockstep with checkout.ref

This works but duplicates the ref and is easy to let drift from checkout.ref. Deriving the base from the checkout would remove that footgun.

Redaction note

Private repository names, branch names, and run URLs are replaced with placeholders (<owner>/<side-repo>, <release-branch>, <default-branch>). Related: #39404.

yskopets avatar Jun 15 '26 16:06 yskopets

External contributor fix for SideRepoOps base-branch resolution.

Fork PR: https://github.com/Tarekchehahde/gh-aw/pull/8 Upstream compare: https://github.com/github/gh-aw/compare/main...Tarekchehahde:gh-aw:fix/39407-create-pr-base-branch

Problem: create_pull_request used the repo default branch from the checkout manifest even when the side repo was checked out at a release branch ref.

Fix: Record checked_out_ref in the manifest and prefer it over default_branch when resolving PR base branches.

Tests: checkout manifest + safe_outputs_handlers tests; Go manifest step test for GH_AW_CHECKOUT_REF_* emission.

Tarekchehahde avatar Jul 11 '26 14:07 Tarekchehahde

Aspire hit a concrete v0.85.4 variant of this in microsoft/aspire run 31507332225, producing the invalid wrong-base draft microsoft/aspire.dev#1460.

The pre-agent resolver and agent-time handler configuration both selected release/13.5, and patch generation used the correct release tip (0bcb9c4eb4bb0b64ae0925646a22dcd3c0af9e95). The agent called create_pull_request without the optional base parameter. Collection canonicalized the item with:

{
  "type": "create_pull_request",
  "base_branch": "release/13.5",
  "base_commit": "0bcb9c4eb4bb0b64ae0925646a22dcd3c0af9e95"
}

but no base field. In the separate apply job, v0.85.4's create-PR path reads pullRequestItem.base for the per-item override rather than the canonical base_branch, so it fell back to the job's static main base and opened #1460 against main.

This shows a second place where SideRepoOps loses the selected checkout ref: even when agent-time configuration resolves the dynamic branch and records it canonically, that value is not carried into apply-time base selection unless the model independently supplies the optional base argument. Aspire is working around it by deriving the apply-job config from the trusted canonical base_branch and by validating the actual created PR base fail-closed; relying on model compliance is not acceptable.

IEvangelist avatar Aug 11 '26 16:08 IEvangelist

Status (2026-10-07; Contributor proposal): A July 11 contributor comment links a fork proposal to prefer the checked-out ref, while the August 11 Aspire report describes a separate apply-job path that fell back to main despite recording release/13.5 as the base. The next step is to review the proposal and test both patch generation and PR creation against a non-default checkout ref; the fork alone does not establish an upstream fix.

pelikhan avatar Oct 07 '26 20:10 pelikhan

Community issue refresher β€” 2026-10-16: Still relevant; the checked-out ref is not automatically the PR base.

Current manifest generation still resolves origin/HEAD or the repository API's default branch. It does not record a checked_out_ref. The handler's priority remains explicit base_branch, then that manifest default, then fallback resolution.

This is also intentional in an existing release-branch regression: without a configured override, it expects the release checkout to be diffed against main, including release-only commits. The fork PR Tarekchehahde/gh-aw#8 remains open, not merged upstream.

Therefore the static checkout.ref / base-branch duplication remains necessary under today's contract. Separately, the Aspire apply-time base_branch versus base mismatch remains pertinent to #41265. Any change needs to distinguish the initial checked-out base from a subsequently created agent feature branch. This is static implementation/test inspection, not a fresh release-branch workflow run.

pelikhan avatar Oct 16 '26 18:10 pelikhan

Rechecked 2026-10-22 against current main (ffdd9c9): still relevant; static checkout.ref does not automatically become the PR base.

The static manifest still resolves origin/HEAD or the API default branch, and the PR handler prioritizes explicit configuration, then that manifest default. The release-checkout regression still expects main and includes the release-only commit.

Tarekchehahde/gh-aw#8 remains open and unmerged; #44476 is closed unmerged. Merged #68593 does not remove the distinction: runtime multi-checkout also records the repository API default, not the selected checkout ref.

Next step: review the intended base-selection contract, then record the initial branch base before the agent can create a feature branch and propagate it through both patch generation and PR application. Cover a release branch diverged from default, detached/tag/SHA checkout handling, an explicit override, and a model request without base. Until then, explicit static base-branch must remain aligned with checkout.ref; that workaround is not automatic resolution. The separate runtime/cross-job acceptance criteria remain tracked in #41265. Static inspection only; no live release-branch workflow was run.

pelikhan avatar Oct 22 '26 21:10 pelikhan