fix(wts): scrub reused worktree on setup (po-formulas-software-dev-vbz)#20
Open
ryanholtschneider2 wants to merge 1 commit into
Open
fix(wts): scrub reused worktree on setup (po-formulas-software-dev-vbz)#20ryanholtschneider2 wants to merge 1 commit into
ryanholtschneider2 wants to merge 1 commit into
Conversation
setup_worktree reused an existing per-bead worktree without resetting it, so leftover working-tree modifications from a prior killed/failed run carried into resumed runs (po-formulas-software-dev-vbz). On reuse, run git reset --hard <branch> + git clean -fd (both honor the per-worktree exclude rules, so the shared .beads/.planning symlinks survive and are re-wired). PO_WTS_REUSE_DIRTY=1 opts out to preserve dirty state. Adds unit tests: dirty reuse is scrubbed, shared dirs survive the scrub, and the env opt-out preserves state.
ryanholtschneider2
marked this pull request as ready for review
June 14, 2026 18:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
setup_worktreereused an existing per-bead worktree at<rig>/.worktrees/wts-<id>/without resetting it. Leftover working-tree modifications from a prior killed/failed run carried into the resumed run (the reported symptom: cross-epic file contamination, out-of-scopegit checkout --cleanups, spurious pre-PR-review findings).Fix
On reuse, scrub the worktree back to its branch tip before re-wiring shared dirs:
git reset --hard <branch>— discard tracked-file modificationsgit clean -fd— remove untracked files/dirsNeither passes
-x, so both honor the per-worktreeinfo/excluderules. The shared.beads//.planning/symlinks (and the.worktrees/nest) are excluded there, so they survive the scrub and are re-wired immediately after.PO_WTS_REUSE_DIRTY=1opts out (preserves dirty state on reuse) for the rare intentional case — this path is only hit from epic-wts flows, never user-driven git ops.Tests
Three new unit tests in
tests/test_worktree.py:.beads/.planningsymlinks survive the scrubPO_WTS_REUSE_DIRTY=1preserves dirty stateFull wts suite: 101 passed.
Closes po-formulas-software-dev-vbz.