AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-276
  5. plan
  6. plan.md
plan.md(1.9 KB)· Apr 3, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks

Plan: Fix worktree reuse path destroying committed agent work#

Summary#

Remove git reset --hard origin/master from the worktree reuse path in WorktreeService.createWorktree(). The reset silently destroys agent commits made during prior phases (e.g., execute → address_review). The reuse path should only run git fetch origin to update remote refs, preserving the branch's existing HEAD.

Files#

FileActionDescription
src/worktree/worktree.service.tsmodifyRemove reset --hard origin/master from the worktreeReused block (lines 103-106); keep only git fetch origin
src/worktree/worktree.service.spec.tsmodifyUpdate test at line 145 to assert reset --hard is NOT called on reuse; remove the assertion that expects the reset call

Steps#

  1. In src/worktree/worktree.service.ts, remove the git reset --hard origin/master exec call from the if (worktreeReused) block (lines 103-106). Keep the git fetch origin call (line 103) and the surrounding log/comment. Remove or update the now-incorrect invariant comment (lines 98-102).
  2. In src/worktree/worktree.service.spec.ts, update the test 'reuses an existing valid worktree without removal, runs fetch+reset' (line 145): rename to reflect fetch-only behavior, assert that NO reset call is made (expect(resetCall).toBeUndefined()), and retain the assertion that fetch is called in the worktree directory.
  3. Run npm run test and npm run lint to verify all tests pass and no lint errors are introduced.

Verification#

  • Unit test explicitly asserts reset --hard is NOT called when a valid worktree is reused.
  • All existing worktree tests continue to pass (fresh create, invalid removal, branch attach paths unaffected).
  • npm run lint passes with zero warnings.

Risks#

  • None significant — the change is a 3-line deletion with a corresponding test update. The fresh-create and branch-attach paths are untouched.
ContextPrd