You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sync records a layer base from a stale local trunk it could not fast-forward, and the next sync replays trunk commits #491
Version: observed with gh-stack v0.1.0; the code quoted below is from the v0.1.1 tree, where the same paths are present. Git worktree layout: the trunk (main) checked out in the primary working tree, the stack branches in a linked worktree.
Setup
A stack main <- layer-1 <- layer-2 <- layer-3, submitted, PRs open.
The primary working tree has main checked out and behind origin/main.
Squash-merge layer-1's PR on GitHub, so origin/main advances.
Steps and observed output
From the stack worktree, run gh stack sync.
The trunk fast-forward fails: UpdateBranchRef (internal/git/gitops.go) runs git branch -f main <sha>, which git refuses while main is checked out in the primary tree:
⚠ Could not update local main: failed to run git: fatal: cannot force update the branch 'main' checked out at '<primary tree>'
Rebasing the stack onto origin/main instead; local main is unchanged.
The cascade rebase onto origin/main succeeds. This first sync works because resolveRebaseOldBase still accepts the merged layer's old tip as the rebase boundary.
Afterwards updateBaseSHAs (cmd/utils.go) records layer-2's base by resolving the trunk branch name, which is the stale local main SHA. canUpdateBase accepts it because that SHA is an ancestor of the rebased layer.
Commit on layer-2, then run gh stack sync again.
Actual
✗ Conflict detected rebasing layer-2 onto origin/main
All branches restored to their original state.
gh stack rebase then stops on conflicts in the files the trunk changed since the stale SHA (changelogs and every workspace manifest in our repo), and git log -1 REBASE_HEAD shows a trunk commit (a release commit), not a stack commit.
Cause of the second failure: after step 1's rebase the merged layer's old tip is no longer an ancestor of layer-2, so resolveRebaseOldBase falls through to the recorded base and the cascade runs git rebase --onto origin/main <stale local main> layer-2, replaying every commit the trunk gained since that SHA (18 in our case).
Expected
Either record the base as the SHA the layer was actually rebased onto (the trunk target's SHA, already carried in trunkTarget on the fallback path), or have resolveRebaseOldBase reject a recorded base that is also an ancestor of newBase, since such a boundary can only replay trunk commits.
Workaround
Fast-forward the local trunk before syncing, so sync prints Trunk main fast-forwarded instead of the fallback line. After the stale base is already recorded: gh stack rebase --abort, then a manual git rebase --onto <new parent tip> <old parent tip> <branch> per layer and a lease push; the stack linkage on GitHub survives.
Related
#169 and #485 look like the same symptom class after a squash merge. This report isolates the worktree-pinned-trunk path that writes the stale base.
changed the title [-]sync records a layer base from a stale local trunk it could not fast-forward, and the next sync replays trunk commits[/-][+]~[/+]on Sep 3, 2026
changed the title [-]~[/-][+]sync records a layer base from a stale local trunk it could not fast-forward, and the next sync replays trunk commits[/+]on Sep 3, 2026
Activity
[-]sync records a layer base from a stale local trunk it could not fast-forward, and the next sync replays trunk commits[/-][+]~[/+][-]~[/-][+]sync records a layer base from a stale local trunk it could not fast-forward, and the next sync replays trunk commits[/+]zgeoff commentedon Sep 3, 2026
might be relevant, might not, don't have time to verify - claude got a little eager and filed the issue on my behalf (sorry)