CB-544: shutdown drain preserves worker worktrees — no data loss on daemon restart #24

Closed
agent wants to merge 0 commits from worker/cb-544-drain-preserves-worktree-925fad-3 into main
Member

Fixes confirmed data-loss defect CB-544: SessionManager.drainAll() (shutdown drain) fused two concerns in release() — stopping the worker pane and removing its worktree. A daemon restart while a worker was mid-turn deleted that worker's worktree (the sole copy of any uncommitted work) after a 5s default drain timeout.

What changed:

  • release() now takes an explicit ReleaseCause (COMPLETED vs SHUTDOWN). A COMPLETED release (explicit bridge_stop / REST stop / reaper / context-cap / recycle) still stops the pane AND removes the worktree — unchanged. A SHUTDOWN release (drainAll on close) stops the pane but PRESERVES the worktree.
  • drainAll() releases with SHUTDOWN. A session still BUSY when the drain timeout expires is abandoned mid-turn and logged loudly (WARN) with the preserved worktree path so an operator can find and reclaim it. Idle sessions get an INFO line noting the preserved path.
  • Orphaned worktrees are acceptable and strictly preferable to destroyed work; no automatic cleanup is added (reclamation left to boot reconciliation).

Tests (added to WorktreeSessionManagerTest against the existing FakeWorktrees seam):

  • drainAll preserves the worktree of an idle session while still stopping its pane
  • drainAll preserves the worktree of a session still BUSY at timeout while still stopping its pane
  • Existing completed-teardown (releaseRemovesWorktreeButDoesNotDeleteBranch), reaper, and drain tests pass unchanged.

Verified: mvn clean install — Tests run: 542, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS (based on origin/main 91c9f98).

Fixes confirmed data-loss defect CB-544: SessionManager.drainAll() (shutdown drain) fused two concerns in release() — stopping the worker pane and removing its worktree. A daemon restart while a worker was mid-turn deleted that worker's worktree (the sole copy of any uncommitted work) after a 5s default drain timeout. What changed: - release() now takes an explicit ReleaseCause (COMPLETED vs SHUTDOWN). A COMPLETED release (explicit bridge_stop / REST stop / reaper / context-cap / recycle) still stops the pane AND removes the worktree — unchanged. A SHUTDOWN release (drainAll on close) stops the pane but PRESERVES the worktree. - drainAll() releases with SHUTDOWN. A session still BUSY when the drain timeout expires is abandoned mid-turn and logged loudly (WARN) with the preserved worktree path so an operator can find and reclaim it. Idle sessions get an INFO line noting the preserved path. - Orphaned worktrees are acceptable and strictly preferable to destroyed work; no automatic cleanup is added (reclamation left to boot reconciliation). Tests (added to WorktreeSessionManagerTest against the existing FakeWorktrees seam): - drainAll preserves the worktree of an idle session while still stopping its pane - drainAll preserves the worktree of a session still BUSY at timeout while still stopping its pane - Existing completed-teardown (releaseRemovesWorktreeButDoesNotDeleteBranch), reaper, and drain tests pass unchanged. Verified: mvn clean install — Tests run: 542, Failures: 0, Errors: 0, Skipped: 0 — BUILD SUCCESS (based on origin/main 91c9f98).
agent added 1 commit 2026-08-13 20:37:52 +02:00
CB-544: shutdown drain preserves worker worktrees (no data loss)
CI / contract (pull_request) Successful in 41s
CI / build (pull_request) Successful in 1m29s
04e21c9243
Owner

Closing as landed. Verified with git cherry main <branch>: every commit's content is present in main. The branch tip is not an ancestor only because the commit was rebased before merge, so the SHA differs while the patch is identical. No code is lost. Verified 2026-08-15.

Closing as **landed**. Verified with `git cherry main <branch>`: every commit's content is present in `main`. The branch tip is not an ancestor only because the commit was rebased before merge, so the SHA differs while the patch is identical. No code is lost. Verified 2026-08-15.
ltms closed this pull request 2026-08-15 07:10:56 +02:00
Some checks are pending
CI / contract (pull_request) Successful in 41s
CI / build (pull_request) Successful in 1m29s

Pull request closed

Sign in to join this conversation.