/context-restore can load the wrong worktree checkpoint (shared origin-derived slug + newest-across-all-branches restore)
Summary
With multiple git worktrees of the same repo, /context-restore in one worktree
can load a checkpoint saved by a different worktree. Two design choices combine.
Root cause
bin/gstack-slugderives the slug fromgit remote get-url origin. All worktrees of a repo share one origin → same slug → same~/.gstack/projects/<slug>/checkpoints/dir. (The per-cwd slug cache just stores that same shared value under each worktree's path key.)/context-restoreby default "loads the most recent saved context across ALL branches" and explicitly "does NOT filter the candidate set by current branch" (percontext-restoreSKILL.md — intentional, for Conductor handoff).
Together: each worktree's /context-save writes into the same shared dir, and
/context-restore picks the newest file across all branches — which may be
another worktree's.
Repro
- Repo with
originset;git worktree add ../repo-b feature-b. - Worktree B:
/context-save(checkpoint B). - Worktree A (older/no checkpoint for its branch):
/context-restore. - A restores B's checkpoint.
Impact
Cross-worktree context contamination — the agent resumes from the wrong worktree's state. Most visible in concurrent multi-session/multi-worktree usage.
Proposed fix (options)
- Default
/context-restoreto branch-scoped selection (filter candidates by frontmatterbranch:== current branch), with an explicit--all-branchesopt-in to keep the cross-branch handoff use case. Checkpoints already recordbranch:in frontmatter. - And/or make the slug worktree-aware so each worktree gets its own checkpoints dir.
- A
--branch <name>/ explicit-path selector for deterministic pinning.
Related
#1125 (slug derivation), #1191 (concurrent same-repo state), #1161 (repo-local artifacts)
Environment: gstack 1.48.0.0
Opened #2054 for this. It orders restore candidates current-branch-first (read from each checkpoint's branch: frontmatter) so a sibling worktree's newer save can't shadow the current branch's own checkpoint, while keeping the full cross-branch set as a fallback — so Conductor handoff (restore when the current branch has no checkpoint) is unchanged. Implements the first proposed option without flipping the default to a hard branch filter. +5 regression tests against the Step-1 pipeline.
+1 — the same root cause hits /qa and /qa-only too, just for a different artifact. Both select the test-plan with:
ls -t ~/.gstack/projects/$SLUG/*-test-plan-*.md 2>/dev/null | head -1
(qa/SKILL.md:1115, qa-only/SKILL.md:883) — newest-by-mtime, slug-scoped, no branch filter. With two worktrees on different branches each running /autoplan, whichever writes the newer *-test-plan-*.md wins, so /qa in the other worktree picks up its sibling's plan.
The good news is #2054's approach generalizes cleanly: the branch is already in the test-plan filename (<user>-<branch>-eng-review-test-plan-<ts>.md), so the same current-branch-first preference (with a cross-branch fallback) would resolve it without any new metadata. Might be worth extending #2054's fix to the test-plan lookup as well, or tracking it as a sibling. Thanks for the clear write-up here.
@16francej — recommend closing this issue only after a revised #2054 passes real two-worktree selection and large sibling-checkpoint burst checks. The current selector can still choose another branch’s checkpoint when worktrees share a repository identifier. Keep current-branch preference, explicit cross-branch fallback, and the shared-origin contamination case as acceptance criteria.