Skip to content

land-and-deploy §4a-postfail: remote-branch check assumes origin, misreports fork branches as already cleaned up #2696

Closed

Description

@pierrefuseau

Summary

In land-and-deploy/SKILL.md.tmpl:706-707 (and the generated SKILL.md:1626-1627), the §4a-postfail MERGED-recovery step reconciles the remote branch with:

BRANCH=$(gh pr view --json headRefName -q .headRefName)
git ls-remote --heads origin "$BRANCH"

headRefName is the name of the PR's head branch. For a fork-originated PR that branch lives in the fork, not in origin (the base repo). Querying origin for that name returns exit 0 with empty output — exactly the signature the three-outcome table treats as "branch already deleted":

Exit 0, empty output — the remote branch is already gone ... Tell the user: "The remote branch has already been cleaned up."

So for any fork PR reaching this postfail path, the skill reports the branch as cleaned up regardless of its actual state in the fork. The table has no branch for "this PR's head lives in a different repository".

This is a target error rather than a missing guard: the same block carefully distinguishes the three outcomes, and explicitly warns "never read a failed check as a clean branch". The empty-output case is the one that slips through, because it is indistinguishable from success.

Introduced by e01ee8f (the fix for #2656), so it is present from v1.69.0.0 onward. isCrossRepository does not appear anywhere in the skill (0 occurrences repo-wide), so there is no existing branch on that condition to extend.

Reproduction

  1. Open a PR from a fork (gh pr view --json isCrossRepository returns true).
  2. Drive land-and-deploy Step 4 (gh pr merge --squash --delete-branch) into the postfail path — e.g. from a worktree layout where gh's local cleanup fails after GitHub has already merged, the scenario /land-and-deploy §4a-postfail recovers the merge but never deletes the remote branch, silently dropping the --delete-branch half #2656 describes.
  3. §4a-postfail runs the reconciliation above.

Observed: "The remote branch has already been cleaned up."
Actual: the branch still exists in the fork; origin never carried it.

Suggested fix

Resolve the head repository instead of assuming origin, so the check interrogates the repository that actually holds the branch:

read -r IS_FORK HEAD_URL BRANCH <<<"$(gh pr view \
  --json isCrossRepository,headRepository,headRepositoryOwner,headRefName \
  -q '[.isCrossRepository, (.headRepositoryOwner.login + "/" + .headRepository.name), .headRefName] | @tsv')"

For a same-repo PR (isCrossRepository == false) the existing origin-based three-outcome check is correct as-is. For a fork PR, either query the head repository's URL, or skip the check and say so explicitly rather than reporting a cleanup that did not happen — the important part is that "empty output from the wrong repository" must not keep resolving to "already cleaned up".

Whether the deletion offer should still be made for a fork branch is a separate call: it depends on maintainerCanModify, which the skill does not currently read.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions