Files
fusion/.changeset/FN-4847-discard-foreign-branch.md
Fusion aa6d1c9851 fix(FN-4847): discard foreign branch and recreate on branch-conflict-unrecoverable
Production failure shape:
  Auto-recovery failed: branch conflict unrecoverable \u2014
  Branch fusion/fn-4847 is already checked out at /.../deft-crane
  (tip a881ccc86660, 24 stranded commits since 0b28388876).
  Run branch recovery and explicitly choose whether to reclaim or
  discard prior work.

The 24 stranded commits are cross-task contamination residue from the
FN-4781/FN-4804/FN-4814 worktree-race era \u2014 they are NOT FN-4847's work.
Previously this paused the task with pausedReason='branch-conflict-
unrecoverable' and the task got stuck forever waiting for human
adjudication.

User intent (FN-4847): 'just create a new branch and keep going and
discard the old one'. Implementation:

1. auto-recovery.ts:actionForMode \u2014 in 'deterministic-only' mode (the
   default), branch-conflict-unrecoverable now returns 'retry' (was
   'pause'). This routes the failure to the handler instead of pausing.

2. auto-recovery-handlers/branch-worktree.ts \u2014 'live-foreign' inspection
   no longer emits irreducible-pause. Instead:
   - Check FN-4811 active-session registry. If the foreign worktree is
     bound to a live executor/merger session, do NOT force-remove it
     (would yank the live agent's filesystem). Just requeue and let
     downstream conflict-recovery handle it.
   - Otherwise: force-delete the foreign worktree (--force) + prune git
     worktree admin entries + force-delete the branch. Errors at each
     step are best-effort and logged.
   - Emit new audit event 'branch-worktree:foreign-branch-discarded'
     with stranded-commit count, live-ownership flag, success flags.
   - Requeue task to 'todo' with preserveProgress, clearing
     branch+baseCommitSha.

3. run-audit.ts \u2014 register new DatabaseMutationType.

4. executor-worktree.test.ts \u2014 update the 'records recovery context'
   test to assert the new retry+requeue contract (was asserting the old
   pause-with-status-failed contract).

Verification:
  - Targeted suite (4 files, 343 tests): pass.
  - pnpm --filter @fusion/engine build: clean.
  - pnpm lint: clean.

Fusion-Task-Id: FN-4847
2026-05-16 23:53:56 -07:00

1.5 KiB

@runfusion/fusion
@runfusion/fusion
patch

fix(FN-4847): discard foreign branch and recreate on branch-conflict-unrecoverable

Branch conflicts where the existing fusion/<task-id> branch has stranded commits NOT attributed to the task (cross-task contamination residue from the FN-4781/FN-4804/FN-4814 worktree-race era) previously paused the task with pausedReason: "branch-conflict-unrecoverable" and the error message Auto-recovery failed: branch conflict unrecoverable — Branch fusion/fn-XXX is already checked out at /.../ (tip ..., N stranded commits since ...). The task got stuck forever waiting for human adjudication.

The user has explicitly opted into discard-and-recreate for this case: those stranded commits aren't this task's work, just delete them and move on.

Changes:

  • auto-recovery.ts:actionForMode — in deterministic-only mode, branch-conflict-unrecoverable now returns "retry" (was "pause"), routing the failure to the handler instead of the pause path.
  • auto-recovery-handlers/branch-worktree.tslive-foreign inspection no longer emits irreducible-pause. Instead: force-delete the foreign branch + worktree (safely respecting the FN-4811 active-session gate to avoid yanking live sessions), then requeue the task. The executor's next pickup creates a fresh fusion/<task-id> worktree with no conflict.
  • New audit event branch-worktree:foreign-branch-discarded records the discard with stranded-commit count and live-ownership status.