Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

sync records a layer base from a stale local trunk it could not fast-forward, and the next sync replays trunk commits #491

Closed

Description

@zgeoff

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

  1. 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.

  2. 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.

Activity

  1. 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
  2. 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
  3. zgeoff commented on Sep 3, 2026

    @zgeoff
    Author

    might be relevant, might not, don't have time to verify - claude got a little eager and filed the issue on my behalf (sorry)

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