From 8e35d29ad0be735e6dcd4c0944d5c1ffdc2c809b Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 25 Apr 2026 13:19:41 -0500 Subject: [PATCH] fix(push-script): fetch PR HEAD sha before \`git worktree add\` (closes #966) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Empirical hit on PR #950 run 24927483127: rebuild-stale-arm64 failed immediately with "fatal: invalid reference: " after correctly resolving STARTUP_SHA_FULL via .pull_request.head.sha. Root cause: actions/checkout@v4 with default settings on a pull_request event fetches refs/pull//merge as a shallow clone. The PR head sha is a known remote ref but is NOT in the local object store, so \`git worktree add --detach \` fails before it can build. Fix: gate \`git worktree add\` on \`git cat-file -e\` and fetch the missing commit if needed. Falls through full-history fetch when shallow fetch is rejected. Dev-machine path unchanged — cat-file -e always succeeds on local HEAD. Why amd64 didn't trip the bug on the same run: rebuild-stale-amd64 was SKIPPED because amd64 already matched HEAD (a prior native push aligned the revision label). The bug was latent for amd64 — would have fired on any push where amd64 actually drifted and CI had to rebuild. Closes #966. Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/push-current-arch.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/push-current-arch.sh b/scripts/push-current-arch.sh index e2ca7c434..814ea4a5f 100755 --- a/scripts/push-current-arch.sh +++ b/scripts/push-current-arch.sh @@ -207,6 +207,21 @@ if [ -e "$WORKTREE_DIR" ]; then git -C "$REPO_ROOT" worktree prune 2>/dev/null || true fi +# Ensure the SHA is a local commit object before `git worktree add`. +# In CI, actions/checkout@v4 with default settings on a pull_request event +# fetches refs/pull//merge as a shallow clone. STARTUP_SHA_FULL +# (resolved above from .pull_request.head.sha) names the PR HEAD commit, +# which exists as a remote ref but NOT as a local object — so +# `git worktree add` fails with "fatal: invalid reference: ". +# Empirical hit on PR #950 / issue #966 in rebuild-stale-arm64. Dev- +# machine path is unaffected: cat-file -e always succeeds on local HEAD. +if ! git -C "$REPO_ROOT" cat-file -e "$STARTUP_SHA_FULL^{commit}" 2>/dev/null; then + echo "→ SHA $STARTUP_SHA_FULL not present as a local object — fetching from origin" + git -C "$REPO_ROOT" fetch --depth 1 origin "$STARTUP_SHA_FULL" 2>/dev/null \ + || git -C "$REPO_ROOT" fetch origin "$STARTUP_SHA_FULL" 2>/dev/null \ + || { echo "ERROR: cannot fetch sha $STARTUP_SHA_FULL from origin (not a real commit, or network/auth issue)" >&2; exit 1; } +fi + echo "→ Creating frozen worktree at $WORKTREE_DIR (pinned at $STARTUP_SHA_FULL)" git -C "$REPO_ROOT" worktree add --detach "$WORKTREE_DIR" "$STARTUP_SHA_FULL" >/dev/null