Skip to content

Justfile: fix release-pr's recovery path (F1/F2 from age-plugin-sshagent review) - #3

Merged
unidoc-ahall merged 1 commit into
masterfrom
fix-release-pr-recovery-guard
Sep 2, 2026
Merged

unidoc-ahall merged 1 commit into
masterfrom
fix-release-pr-recovery-guard

Conversation

@unidoc-ahall

Copy link
Copy Markdown
Contributor

Same recipe as age-plugin-sshagent's `release-pr` (byte-identical
modulo main/master) just got this exact fix from unidoc-alip's
review there — porting it here too.

F1 [should-fix]: the remote-branch guard's own "delete it"
recovery advice left a stale local branch behind, so following that
advice and re-running died on a raw `fatal: a branch named ...
already exists` instead of a clear message. Fixed with a
local-branch-exists guard placed before the trap.

F2 [nit]: the `gh pr create` recovery hints weren't runnable as
printed (missing `--title`/`--body`). Added both.

Test plan

  • `go build/vet/gofmt` clean (Justfile-only change; verified locally)
  • Ran all six scratch-harness cases against the fixed Justfile — all correct, including the exact F1 repro (delete remote branch per guard advice, re-run, confirm clean guard message instead of a git fatal error)

…ent review)

Same recipe as age-plugin-sshagent's release-pr (byte-identical
modulo main/master), which just got the identical fix from
unidoc-alip's review there:

F1 [should-fix] — the remote-branch guard's own "delete it: git push
-d origin release/vX.Y.Z" recovery advice left the local branch in
place (the whole point of the wedge fix was that the trap no longer
deletes it). Following that advice and re-running then died on a raw
`fatal: a branch named 'release/vX.Y.Z' already exists` (rc=128) —
not a new wedge (the trap self-heals it on the way out, so a third
run succeeds), but exactly the confusing git-level error the wedge
fix's commit message set out to eliminate. Fixed with a local-branch
guard placed before the trap, so it reports the leftover instead of
the trap silently eating it first.

F2 [nit] — both `gh pr create` recovery hints printed
`--head release/vX.Y.Z` with no `--title`/`--body`, which isn't
copy-pasteable (drops into gh's interactive prompt, or fails outright
non-interactively). Added both.

Reproduced F1 against the actual bug first: bump, gh-fails-after-
push, delete the remote branch per the guard's own advice, re-run —
confirmed the raw git fatal error. Fixed and re-verified all six
cases (no-op bump, gh-fails-after-push, remote-guard re-run,
delete-it-then-re-run, cleanup-then-re-run, happy path) against the
actual fixed Justfile.

go build/vet/gofmt clean (Justfile-only change, no Go source touched).

@unidoc-alip unidoc-alip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: APPROVE — 0 must-fix, 0 should-fix, 3 nits (all non-blocking; take them or leave them)

This PR ports two recovery-path fixes from unidoc/age-plugin-sshagent into
incus-sync's release-pr recipe: a local-branch guard placed before the EXIT trap,
and --title/--body added to both gh pr create recovery hints. Both changes do what
the description says. I reproduced the pre-fix behaviour on origin/master, confirmed the
fix at head, and re-ran a third fixed variant to check an alternative — all against the
real Justfile driven by the real just. Nothing blocking; three nits, one of which is a
framing correction rather than a code change. Findings are keyed F1, F2, … (not #1,
which GitHub would autolink to an unrelated issue).

How this was verified. A verbatim-transplant harness (poc_3_release_pr.sh, in my
scratchpad): the actual Justfile from each of three variants — base (origin/master),
head (2f0a401), fixed (an auto-heal alternative to the new guard) — is copied into a
scratch git repo with a local bare origin, and driven with the real just release-pr 0.2.0. Only gh is stubbed, as a PATH script whose exit status is set by $GH_MODE.
Seven cases per variant; each prints rc | local-branch | remote-branch | current-branch | first-error-line. Caveats: only gh's exit status is modelled, not its output or API
behaviour; the harness has no GPG, no network, and a single-user clone, so it cannot
observe race-y push timing. This repo has no shell-test directory (only *_test.go), so
the harness stayed in scratch — happy to copy it in if you want it kept.

Results (abridged; behaviour differs only on C5/C6):

base   C5 delete-remote-then-rerun  rc=128  local-no  | remote-no  | on-master  | fatal: a branch named 'release/v0.2.0' already exists
base   C6 run3-no-manual-step       rc=0    local-yes | remote-yes | on-release/v0.2.0 | (none)

head   C5 delete-remote-then-rerun  rc=1    local-yes | remote-no  | on-release/v0.2.0 | ✗ local branch release/v0.2.0 left over from a failed run — remove it: git checkout master && git branch -D release/v0.2.0
head   C6 run3-no-manual-step       rc=1    local-yes | remote-no  | on-release/v0.2.0 | ✗ local branch release/v0.2.0 left over from a failed run — ...

On C1 (happy path), C2 (no-op bump), C4 (re-run with the remote branch present) and C7
(manual cleanup, then re-run), base and head agree on rc, branch state and current
branch; the only difference is the F2 message text on C3 and C4, which gain the
--title/--body additions. Behaviour changes on C5/C6 only — the guard introduces no
regression on any path where no leftover local branch exists. The new git show-ref ... && { ...; exit 1; }
does not trip set -e when show-ref fails, because the failing command is not the last in
the && list; confirmed directly (set -euo pipefail; false && { exit 1; }; echo ok prints
ok) and by C1 passing at head.


F1 [nit] Justfile line 90 — the guard removes a self-healing step; the description frames it as a pure win

The PR description says the old path "died on a raw fatal: ..." and that the guard fixes
it. True, but the trade is one-directional in both senses and only one direction is
described. Harness evidence, C5 → C6:

  • base: run 2 fails with fatal: a branch named 'release/v0.2.0' already exists
    (rc=128) — confusing — but the trap is armed by then, so it deletes the leftover local
    branch on the way out and run 3 succeeds unaided (rc=0).
  • head: run 2 fails with the clear, actionable guard message (rc=1) — but it exits
    before the trap is armed, so nothing cleans up and run 3 prints the identical error
    until the user runs git checkout master && git branch -D release/v0.2.0 by hand.

So this swaps a confusing-but-self-healing run for a clear-but-manual one. That is a
defensible trade and I think it is the right one — git branch -D is a force delete, and
having the human confirm it is safer than the recipe silently discarding a branch a person
might have created themselves under that name. But it is a trade, not a strict improvement,
and the description reads as the latter. Worth a sentence in the commit message or the
description so the next reader is not surprised that a re-run does not eventually resolve
itself.

If you would rather trade back for fewer steps, the auto-heal variant I ran as fixed
takes C5 straight to rc=0 (a PR opened) with no manual step and no regression on
C1/C2/C3/C4/C7:

    if git show-ref --verify -q "refs/heads/release/v{{VERSION}}"; then
        echo "ℹ removing leftover local branch release/v{{VERSION}} from a previous failed run"
        git checkout master >/dev/null 2>&1 || true
        git branch -D "release/v{{VERSION}}" >/dev/null
    fi

Its one cost is the force delete above, which is why I am not recommending it over what you
have — I am recording that it was run, so the choice is on the record either way. Its C6
lands on the remote guard (rc=1, "already on origin"), which is correct, not a regression.

Note also that the git checkout master && prefix in the guard message is load-bearing and
correct: at head, C5 leaves you standing on release/v0.2.0 (the trap no longer returns
you to master), where git branch -D on that same branch would refuse. Confirmed in the
harness output above.

F2 [nit] Justfile lines 89 and 101 — the two recovery hints now print a different PR body than the recipe itself would

The --title/--body addition works exactly as intended: I confirmed the escaped quotes
survive just's templating as literal shell quotes, so the printed line is genuinely
copy-pasteable (gh pr create --head release/v0.2.0 --title "Release v0.2.0" --body "Bumps version.txt to 0.2.0." appears verbatim in the harness output at head, and did not at base).

The body in the hints is truncated relative to the recipe's own, which also carries the
follow-up instruction. To be clear about provenance: the truncation came from the snippet in
my own F2 in the sibling review, which the author transcribed faithfully — this is my nit on
my own suggestion, not on the port.

--body "Bumps version.txt to {{VERSION}}. After merge: \`just release {{VERSION}}\` tags master and CI publishes the release."

A PR opened via the recovery hint therefore loses the "After merge: just release X" line
that a normally-opened one has — a small inconsistency on exactly the path where the person
is already off the happy trail and most likely to want the reminder. Either repeat the full
body, or use --fill and let the commit message supply it.

One consequence to weigh before acting on this: the "byte-identical modulo main/master"
property verified below is currently true, and changing the body in this repo alone would
break it. Change both repos or neither.

Minor, in the same hunk: --head release/v{{VERSION}} is redundant in the second hint
(line 101), since a failed gh pr create at that point leaves you standing on that branch.
Harmless, and arguably clearer for being explicit.

F3 [nit] .gitignore line 9 — temp/ is unrelated to the stated change

+temp/ is neither mentioned in the PR title, the description, nor the commit message,
which describe a Justfile-only change ("Justfile-only change, no Go source touched"). It is
almost certainly where the scratch harness from the test plan lived. Not harmful, but it
makes the commit's own claim inaccurate and the entry has no explanation for a future
reader. Either drop it from this PR or add a word to the commit message saying what temp/
is for.


PR description verification

  • "Same recipe as age-plugin-sshagent's release-pr (byte-identical modulo main/master)"
    — confirmed. Extracted both recipes (unidoc/age-plugin-sshagent@main via the
    contents API, and this branch's working tree) and diffed after s/\bmain\b/master/g. The
    only remaining differences are the six main/master occurrences themselves
    (origin/main:version.txt, the no-op-bump message, the guard message, the trap, the
    checkout -b base, and the PR body). No third difference.

  • "just got this exact fix from unidoc-alip's review there — porting it here too"
    — confirmed. unidoc/age-plugin-sshagent#2 carries a COMMENT review whose F1
    ([should-fix], local-branch guard before the trap, with the git checkout main && prefix
    spelled out) and F2 ([nit], --title/--body on both hints) match this PR's F1/F2 both
    in substance and in the severity labels the description reuses. The suggested snippet in
    that review is what landed here, modulo main/master.

  • "go build/vet/gofmt clean (Justfile-only change; verified locally)" — confirmed.
    go build ./... && go vet ./... && gofmt -l . clean at 2f0a401. Also consistent with
    the diff: only .gitignore and Justfile change, no Go source. CI agrees — the test
    job passes on this PR.

  • "Ran all six scratch-harness cases against the fixed Justfile — all correct, including
    the exact F1 repro"
    — confirmed. All six named outcomes reproduce independently on
    my own harness, including the exact F1 repro: base C5 gives rc=128 and the raw
    fatal: a branch named 'release/v0.2.0' already exists, and head C5 gives the clean
    guard message at rc=1.

    Two notes that do not contradict the claim. First, it is not reproducible from the PR —
    the harness is not in the diff and temp/ is gitignored (see F3), so I had to build my
    own rather than run yours. Second, six cases as described stop one run short: adding a
    third run after "delete-it-then-re-run" is what surfaces F1's trade, and none of the six
    would have shown it.

@unidoc-ahall
unidoc-ahall merged commit d041464 into master Sep 2, 2026
1 check passed
@unidoc-ahall
unidoc-ahall deleted the fix-release-pr-recovery-guard branch September 2, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants