Files
fusion/.changeset
Timoteo f082398be1 fix: preserve worktree content during automatic cleanup (#3519)
## Summary

- Centralize fail-closed cleanliness validation in the shared
`removeWorktree` path for every automatic cleanup reason: pool prune,
idle/cap sweeps, self-healing reclaim/conflict/stale-branch cleanup,
merger cleanup, and step-session cleanup.
- Preserve tracked, untracked, ignored, or unverifiable checkout
content; native Git revalidates without `--force` at the deletion
boundary and never falls through to recursive deletion for defensive
callers.
- Keep explicit destructive teardown reasons on their legacy forced
path.
- Replace recursive removal of unregistered worktree directories with
non-recursive `rmdir`.
- Preserve `.env` when cleanup is refused; prune only metadata for
defensive registrations whose path already disappeared.
- Use argv-based `execFileSync` in the real-worktree test fixture and
provide labeled release metadata.

## Why this replaces #3461

#3461 accumulated quarantine, recovery, generated-residue
classification, and race-repair machinery while addressing successive
bot reviews. This replacement keeps one essential invariant in one
shared path:

> Automatic cleanup removes a worktree only when cleanliness can be
proven; otherwise it preserves the checkout.

### Original-review requirements retained

- Real Git regressions exercise dirty, clean, ignored `dist/manual.txt`,
probe-failure, missing-path, and backend-routing paths.
- Every automatic reclaim reason uses the same defensive guard.
- Failed status probes and dangling/unregistered content fail closed.
- Native defensive removal never uses the recursive fallback.
- Worktrunk receives `--force` only from explicit caller intent.
- A refused reclaim does not pre-delete the managed environment file.

### Deliberate simplifications

- No pathname heuristics for `node_modules`, `dist`, or build output.
- No quarantine, recovery directory, pointer stash, or restoration
lifecycle.
- No destructive reclamation of corrupt/dangling metadata when safety
cannot be proven.

These omissions prefer a recoverable disk leak over possible user-data
loss. Add targeted reclamation only if operational evidence shows the
conservative behavior is insufficient.

## Verification

- `worktree-backend.test.ts`: 64 passed
- `worktree-defensive-removal-preservation.real-git.test.ts`: 13 passed
- `self-healing-tempdir-sweep.test.ts`: 26 passed
- `worktree-pool.test.ts`: 60 passed
- `worktree-pool-secrets-env-cleanup.test.ts`: 2 passed
- `worktrunk-worktree-removal.test.ts`: 2 passed
- `worktree-acquisition.test.ts`: 47 passed
- Engine typecheck passed
- ESLint passed
- Changeset status passed
- `git diff --check` passed

## Scope

Worktree cleanup safety only.

Supersedes #3461.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Worktree cleanup now preserves directories containing uncommitted,
ignored, unverifiable, or user-created files.
  * Cleanup fails safely when worktree status cannot be verified.
* Clean worktrees continue to be removed normally, while selected forced
teardown scenarios retain their existing behavior.
* Dangling or orphaned worktree directories are preserved instead of
being deleted unexpectedly.
* **Tests**
* Added coverage for defensive removal, orphan preservation, and clean
worktree pruning.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-23 23:40:34 -07:00
..
2026-08-23 14:49:26 -07:00

Changeset Format Guide

Each changeset file in this directory describes one user-facing change for release notes.

Required body format

---
"@runfusion/fusion": minor
---

summary: Add a Command Center productivity control for LOC backfills.
category: feature
dev: Uses the new `fn_backfill_loc` tool; settings key `commandCenter.locBackfill`.

Fields

Field Required Description
summary Yes One line, user-facing, max 120 chars. Describe what changed for the operator.
category Yes One of: feature, fix, breaking, security, performance, internal.
dev No Developer or migration detail. Preserved in per-package CHANGELOGs but excluded from distilled release notes.

Audience

The summary is the only content that appears in end-user release notes by default. Write for Fusion operators — describe behavior, fixes, and what changed. Avoid internal class names, file paths, and implementation detail.

Bump types

  • patch — bug fixes, internal changes
  • minor — new features, CLI additions, tools
  • major — breaking changes

Validation

Run pnpm check:changesets to validate. The linter runs in the PR-check gate and test:gate. Legacy freeform changesets pass with a warning during the transition period.