fix(3542): prohibit git stash in executor agents — shared stash storage violates worktree isolation

Closes #3542

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-05-15 08:16:26 -04:00
parent a7f0af2ce9
commit 85d7a8b4b1
4 changed files with 204 additions and 1 deletions

View File

@@ -551,6 +551,30 @@ back, those deletions appear on the main branch, destroying prior-wave work (#20
`<worktree_branch_check>` and per-commit `<pre_commit_head_assertion>` are the
correct prevention; if either fails, the workflow MUST stop, not self-heal.
- `git push --force` / `git push -f` to any branch you did not create.
- `git stash`, `git stash push`, `git stash pop`, `git stash apply`, `git stash drop`
(and any other `git stash` subcommand). **The stash list is shared across the
main checkout and every linked worktree** — git stores stashes at `refs/stash`
inside the parent `.git/` directory, not inside the per-worktree
`.git/worktrees/<name>/` subdirectory. From inside your worktree, `git stash list`
shows the global stack with no indication that entries originated elsewhere, and
`git stash pop` pops the top of that global stack regardless of which worktree
pushed it. Running `git stash pop` after a `git stash` that printed "No local
changes to save" will silently apply WIP from a sibling worktree's prior
session — typically producing UU/UD merge-conflict states, phantom untracked
files, and a contaminated working tree that violates the `isolation="worktree"`
invariant of your execution (#3542).
**Sanctioned alternatives** when you need to set aside or inspect work without
touching `refs/stash`:
- **Move WIP off the working tree:** commit it to a throwaway branch you own
(e.g. `git checkout -b scratch-/<task>-wip && git add -A && git commit -m "wip"`),
then `git checkout <your-worktree-branch>` to return to your task. The
throwaway branch lives in the per-worktree branch namespace and never
collides with sibling worktrees.
- **Read-only inspection of another ref:** use `git show <ref>:<path>` to
print a file at any ref, or `git diff <ref> -- <path>` to compare. Neither
mutates `refs/stash` nor leaks state across worktrees.
If you need to discard changes to a specific file you modified during this task, use:
```bash