Appendix D - 4. The worktree-lifecycle stack
Concept
Every agent works in its own isolated checkout, and every checkout has a birth, a life, and a clean death. The stack is the set of records and gates that keep dozens of concurrent worktrees from trampling each other and from leaking half-finished state into the trunk. Skip the close records and the isolation still starts correctly — but it never ends cleanly, and stale worktrees accumulate until a reclaim guesses wrong and destroys live work.
Mandatory members
- Appendix A - 13. Agent registry (append-only log + marker cache) — an append-only log of who is in flight, with a marker-file cache. It is the authoritative answer to "is this worktree still alive?" A reclaim that trusts anything else eventually races a running agent.
- Appendix A - 19. Tombstone commits (lifecycle close records) — the lifecycle close record: a commit that marks a worktree finished and safe to reclaim. Without it, cleanup cannot tell a done worktree from an abandoned one, so it either leaks disk or deletes work.
- Appendix A - 6. Pre-commit hook (3-stanza, tree-sha markers) — the gate every commit passes on its way out of a worktree. It is what keeps an isolated agent from landing a broken tree; the isolation is only safe because the exit is guarded.
Complementary members
- Appendix A - 7. Sentinel first-commit early-abort — an early-abort first commit that fails fast when a worktree is mis-configured, before real work accumulates on top of the mistake. Saves wasted effort; the lifecycle is still correct if the mistake surfaces later at the pre-commit gate instead.
- Appendix A - 5. Merge-train MIS batching — batch non-conflicting worktrees so the trunk absorbs many at once. A throughput optimization layered on the lifecycle; each worktree can also land one at a time.
- Appendix A - 10. Build-serializer (M=8 semaphore) — ration shared heavy compute across the concurrent worktrees. Protects the host; the lifecycle of any single worktree is correct without it.
‹ PreviousAppendix D - 3. The semantic-lint stackContentsNext ›Appendix D - 5. The canonical-seam stack
© James C. Davis, 2026–present