Skip to content

fix(wts): scrub reused worktree on setup (po-formulas-software-dev-vbz)#20

Open
ryanholtschneider2 wants to merge 1 commit into
mainfrom
agentic-po-formulas-software-dev-vbz
Open

fix(wts): scrub reused worktree on setup (po-formulas-software-dev-vbz)#20
ryanholtschneider2 wants to merge 1 commit into
mainfrom
agentic-po-formulas-software-dev-vbz

Conversation

@ryanholtschneider2

Copy link
Copy Markdown
Owner

What

setup_worktree reused 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-scope git 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 modifications
  • git clean -fd — remove untracked files/dirs

Neither passes -x, so both honor the per-worktree info/exclude rules. 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=1 opts 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:

  • dirty reuse (modified tracked file + untracked file/dir) is scrubbed clean
  • shared .beads/.planning symlinks survive the scrub
  • PO_WTS_REUSE_DIRTY=1 preserves dirty state

Full wts suite: 101 passed.

Closes po-formulas-software-dev-vbz.

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
ryanholtschneider2 marked this pull request as ready for review June 14, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant