Skip to content

FE-883: Cook run worktree/branch GC#231

Closed
kostandinang wants to merge 3 commits into
ka/fe-883-orchestrator-improvementsfrom
ka/fe-883-worktree-gc
Closed

FE-883: Cook run worktree/branch GC#231
kostandinang wants to merge 3 commits into
ka/fe-883-orchestrator-improvementsfrom
ka/fe-883-worktree-gc

Conversation

@kostandinang

@kostandinang kostandinang commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Stacks on #230 (FE-883 slice 1). Replaces the operator-owned git worktree remove / git branch -D cleanup that worktree.ts documented, and retires the dead code slice 1 orphaned.

Worktree/branch GC (slice 2)

gcCookRun reclaims a finished run's transient state: removes every worktree registered under the run dir (run worktree + nested slice/__epic__ worktrees, deepest-first), deletes the intermediate brunch/slice/<runId>/* branches (their work is folded into the run branch), and removes the on-disk run dir — while keeping the brunch/run/<runId> artifact branch the user reviews/merges, and every other run untouched. Best-effort + idempotent; realpath-safe so it matches git's worktree-list paths (macOS /var/private/var).

Wired into cook-cli: auto-GC on a completed + promoted brownfield run, best-effort (never fails a good run). Halted/conflicted runs return earlier and keep their worktrees for inspection (keep-on-failure). No flag — no leaks by default.

Retire dead promoteBrownfieldRun (1d)

Slice 1 replaced the brownfield promotion path with harvestCookRun's merge-tree fold, leaving promoteBrownfieldRun (file-copy commit-tree) used only by its own tests. Deleted it + BrownfieldPromoteOptions + its test block, cleaned the now-unused imports, and rebuilt the landCookBranch test fixture (it had used promoteBrownfieldRun to construct a promoted branch) with a plain commit on brunch/run/r1. mergeSlicesIntoEpicSandbox and promoteGreenfieldRun stay (the greenfield path).

Tests

run-refs.test.ts (GC keeps the run branch; unrelated runs untouched), promote-run.test.ts (rewired fixture). Full orchestrator suite green (677).

Remaining

A multi-slice end-to-end runCook test of the promotion + GC wiring — the merge logic is unit-tested (run-artifact.test.ts) and the 1-slice brownfield-smoke exercises the engine path, so this is the one coverage gap. Tracked in memory/CARDS.md.

@cursor

cursor Bot commented Jun 18, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Runs destructive git worktree/branch and filesystem cleanup on the user repo, though scoped to the run directory, best-effort, and skipped when promotion fails; incorrect path matching could affect unrelated worktrees.

Overview
Adds gcCookRun in run-refs.ts to reclaim a finished run’s transient git state: nested worktrees under the run dir (deepest-first), intermediate brunch/slice/<runId>/* branches, and the on-disk .brunch/cook/runs/<id> tree, while preserving brunch/run/<runId> and other runs. Path matching is realpath-safe for macOS.

cook-cli invokes gcCookRun automatically after a completed, successfully promoted brownfield run (wrapped in try/catch so cleanup never fails the run). Halted or conflicted runs exit earlier and keep worktrees for inspection.

Removes the unused promoteBrownfieldRun path (superseded by harvestCookRun), its types/imports, and the dedicated test block; landCookBranch tests now seed a promoted branch via a throwaway worktree commit. memory/CARDS.md marks FE-883 Slice 2 (worktree/branch GC) as done.

Reviewed by Cursor Bugbot for commit 593032a. Bugbot is set up for automated code reviews on this repo. Configure here.

@kostandinang kostandinang force-pushed the ka/fe-883-orchestrator-improvements branch from b902c7a to 3890b32 Compare June 18, 2026 10:42
@kostandinang kostandinang force-pushed the ka/fe-883-worktree-gc branch from be0eadf to ba2562d Compare June 18, 2026 10:42
@kostandinang kostandinang force-pushed the ka/fe-883-orchestrator-improvements branch from 3890b32 to 6b3aaba Compare June 18, 2026 11:43
@kostandinang kostandinang force-pushed the ka/fe-883-worktree-gc branch 2 times, most recently from 6b7b1ab to 918bd08 Compare June 18, 2026 11:46
@kostandinang kostandinang force-pushed the ka/fe-883-orchestrator-improvements branch from 6b3aaba to 4df8c49 Compare June 18, 2026 11:46
kostandinang and others added 3 commits June 18, 2026 14:15
Replaces the operator-owned `git worktree remove` / `git branch -D` cleanup that
worktree.ts documents. After a run, gcCookRun removes every worktree registered
under the run dir (run worktree + nested slice / __epic__ worktrees, deepest
first), deletes the intermediate brunch/slice/<runId>/* branches (their work is
folded into the run branch), and removes the on-disk run dir — while keeping the
brunch/run/<runId> artifact branch the user reviews/merges, and every other run's
state. Best-effort + idempotent. Canonicalizes runDir via realpathSync so it
matches git's realpath-resolved worktree-list paths (macOS /var → /private/var).

Primitive only; wiring it into cook-cli (auto-GC after a completed promotion,
keep-on-failure) is the remaining slice-2 step.

🍳 Built with brunch

Co-Authored-By: Opus 4.8 <noreply@anthropic.com>
Wire gcCookRun into cook-cli's brownfield promotion success path: once the run
completed and the result is promoted onto brunch/run/<runId> (and optionally
landed), reclaim the run's worktrees + intermediate brunch/slice/<runId>/*
branches. Best-effort — cleanup never fails a promoted run. Halted/conflicted
runs return before this point, so they keep their worktrees for inspection
(keep-on-failure). Auto, no flag: no leaks by default.

🍳 Built with brunch

Co-Authored-By: Opus 4.8 <noreply@anthropic.com>
Slice 1 (1b) replaced the brownfield promotion path with harvestCookRun's
merge-tree fold, leaving promoteBrownfieldRun (file-copy commit-tree of a composed
tree) used only by its own tests. Delete it + BrownfieldPromoteOptions + its test
block, and clean the now-unused imports (mkdtempSync/tmpdir/rmSync/join). The
landCookBranch test built its promoted-branch fixture via promoteBrownfieldRun;
rebuild it with a plain commit on brunch/run/r1 through a throwaway worktree —
the same branch shape landCookBranch merges.

mergeSlicesIntoEpicSandbox and promoteGreenfieldRun stay (the greenfield path).

🍳 Built with brunch

Co-Authored-By: Opus 4.8 <noreply@anthropic.com>
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