Repository navigation
Description
Gap
PR #12214 moved each pm-dispatch launch into its own detached worktree under ~/git/fleet/dispatch-<repo>-<task>, fixing interference with the primary clone. It explicitly leaves cleanup as a follow-up. The dispatch worktree creator (pm-stack/dispatch/src/worktree.ts::createDispatchWorktree) creates the tree and returns its path, but the launch lifecycle has no corresponding cleanup after session completion. The generic infra/worktree-reaper cannot retire these trees: worktree_reaper.py::evaluate_tree rejects detached worktrees with reason detached-v1, and test_worktree_reaper.py asserts that detached trees are retained.
This means each dispatched run can leave another checkout and its ignored build output under the fleet worktree root. Repeated runs can accumulate disk use and stale directories. A scan during this review found no current ~/git/fleet/dispatch-* directories; this is a verified lifecycle gap, not a claim that accumulation has already caused an incident.
Expected behavior
Add a dispatch-specific lifecycle for retiring a task worktree once its session is known to have ended, without weakening the generic reaper's conservative detached-worktree policy.
Acceptance criteria:
- Associate the created worktree with the dispatched task/session so cleanup targets only the exact tree created for that launch.
- Clean up after confirmed session termination, including failure/early-exit paths where a session was created; do not remove a worktree while its session may still be running or resumable.
- Fail closed and preserve the tree when session state is ambiguous, the tree is occupied, or it contains uncommitted/untracked work or commits not safely preserved. Do not silently discard user work.
- Make cleanup idempotent and report cleanup failures without masking the original dispatch/session result.
- Add tests for successful cleanup, active/ambiguous session retention, dirty/unpublished work retention, and cleanup failure behavior.
Related: merged PR #12214 (worktree isolation; explicitly defers cleanup), closed issue #12213 (primary-clone interference).
Activity
developing-today commentedon Nov 21, 2026
CODE-4444
dezren39 commentedon Nov 21, 2026
agent-note:v1
task: 20903
lane: oc-code-06
state: picked_up
by: repo-worker-code (OpenChamber scheduled lane)
verified: issue #12217 OPEN, no hard-stop labels; PR #12214 is MERGED with cleanup explicitly deferred; related #12213 is CLOSED by the isolated-worktree change.
action: triaging the remaining cleanup lifecycle gap against current dispatch and reaper behavior; implementation remains out of scope for this triage task.
next: record verified findings and route a scoped implementation follow-up if the gap remains actionable.
dezren39 commentedon Nov 21, 2026
Triage — confirmed and routed (2026-11-21, task 20903, lane oc-code-06)
pm-stack/dispatch/src/worktree.tsdeterministically names and creates one detached tree per task, but has no cleanup helper.pm-stack/dispatch/src/server.tscreates the tree before session creation and registers no cleanup after normal launch/session completion.pm-stack/dispatch/src/opencode.tscan read session state and distinguish 404 from upstream errors, but there is no completion lifecycle callback. The generic reaper intentionally retains detached-v1 trees (infra/worktree-reaper/bin/worktree_reaper.py); that policy must remain unchanged.repo-health:v1:fix:developing-today/code:issue:12217) for implementation and lifecycle tests. No code changes were made in this triage task.repo-queue validatepassed for the follow-up packet; issue/PR state and current-main source were checked fresh.9 remaining items
dezren39 commentedon Nov 21, 2026
agent-note:v1
state: parked
task: 20904
lane: oc-code-01
stage: reproduced
Parked for 30 minutes with the task branch/worktree preserved at
queue/20904-12217-dispatch-cleanup//home/user/git/fleet/20904-12217-dispatch-cleanup. Reproduced the gap: dispatch creates the detached worktree but does not persist its exact association with the returned session ID;getSessiononly distinguishes an extant session from HTTP 404 and no terminal-state contract is documented in this service. We must not treat idle, missing/ambiguous, or transport failure as confirmed termination. Resume by finding an authoritative terminal signal and durable exact worktree↔session mapping, then implement idempotent fail-closed cleanup and lifecycle tests. #12217 remains OPEN; no hard-stop labels.dezren39 commentedon Nov 22, 2026
Picked up to shepherd PR #12219. Revalidating review findings and refreshing the branch against current main before deciding whether it is merge-ready.
dezren39 commentedon Nov 22, 2026
agent-note:v1\nstate: done\ntask: 21063\nlane: code-f\nresult: PR #12219 merged as 7848651 after refreshing against current main; GitHub closed #12217 via the PR closing keyword. Review findings were verified/fixed and documented on the PR. Verification on the final branch:
bun test --timeout 10000(259 passed) andbunx tsc --noEmitpassed. The only reported check was CodeRabbit skipping; no required checks were pending.