Skip to content

fix(bin): close a task whose copy has a broken git link without touching it - #22

Merged
demy00 merged 3 commits into
mainfrom
feature/fm-teardown-missing-copy
Nov 9, 2026
Merged

demy00 merged 3 commits into
mainfrom
feature/fm-teardown-missing-copy

Conversation

@demy00

@demy00 demy00 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Intent

Cleanup cannot close a task whose local copy is gone or has a broken worktree link. 2026-10-30: bin/fm-teardown.sh --force refused fm-skills-adopt-k4 ("missing, empty, or ambiguous worktree identity" - its worktree is gone) and failed fm-limit-aware-e3 (treehouse return: not a git repository, broken .git/worktrees/firstmate3 link). Both task records stay stranded in flight with no supported path to close them, even though the captain approved discarding both copies and their content is preserved. Captain 2026-11-09: "5 yup" (start the held firstmate fixes).

What Changed

  • bin/fm-teardown.sh adds teardown_copy_link_broken. It detects a task copy whose .git link names a worktree admin directory that is gone, or one that git has bound to a different copy. Such a copy is never handed to git, Treehouse, or Orca. That means no no-mistakes run conclusion, no pipeline spend record, no branch detach or delete, and no Treehouse return or Orca worktree removal.
  • Without --force, a ship task with a broken copy is refused before anything changes, with a hint to run git worktree repair or get the captain's OK to discard. With --force, or for a scout copy, teardown still closes the task record, endpoint and backlog item and drops the task's slot claim, but leaves every file in the copy where it is:
    • A broken copy left in a Treehouse pool is reported as a lost slot (exit 4), with a treehouse destroy preview to clear it.
    • An Orca copy stays listed in Orca, with a note to remove it there.
    • Because git is never run inside a copy linked to another copy, that other task's branch and HEAD are no longer changed.
  • Adds teardown tests for a forced close with a gone admin dir (pool slot, exit 4), a forced close of a copy linked to another copy (the other branch is kept), and the refusal without --force. Also adds a CHANGELOG entry.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The fix round adds a narrow Orca branch that skips orca worktree rm and git mutation for broken-link copies exactly as the user instructed, with a behavioral test asserting no removal call and the other task's branch intact; the earlier broken-link handling is unchanged and bounded by the --force/scout gate.

Testing

I ran the 5 new teardown tests and 2 neighbouring tests, and all pass on the change. Four of the five new tests fail on the base script, so they prove the fix. The deleted-copy test passes on both and pins behavior that already existed. A before/after CLI transcript reproduces the reported failure on base: a forced teardown of a pool copy whose .git admin dir is gone aborts with "treehouse return: not a git repository", and the task stays in flight. On the change, the same teardown closes the record and the backlog item, leaves the copy's files in place, reports the lost slot with a treehouse destroy hint, and exits 4. The transcript also shows that on base, a forced teardown of a copy whose link points at another task's copy deleted that other task's branch. On the change the other branch survives, and unforced teardowns refuse with a broken-link message. This is CLI-only, so there is no visual artifact. I removed the temporary test scripts and the worktree is clean.

Evidence: Before/after CLI transcript: fm-teardown on broken-link copies (gone admin dir in a pool slot; link pointing at another task's copy), forced and unforced

Source: Before/after CLI transcript: fm-teardown on broken-link copies (gone admin dir in a pool slot; link pointing at another task's copy), forced and unforced

===== BEFORE (base 4123a5eb) =====
\### gone-unforced: fm-teardown.sh task-x1    (copy .git link: gone)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-gone-unforced/pool/1/repo/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-gone-unforced/project/.git/worktrees/wt
REFUSED: cannot inspect worktree <tmp>/demo-gone-unforced/pool/1/repo for uncommitted changes.
Restore the git index state, or get the captain's explicit OK to discard, then --force.
exit=1
task record: still-in-flight   backlog: in_flight   copy draft.txt: draft

\### gone-forced: fm-teardown.sh task-x1 --force   (copy .git link: gone)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-gone-forced/pool/1/repo/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-gone-forced/project/.git/worktrees/wt
Error: not a git repository: <tmp>/demo-gone-forced/pool/1/repo
error: treehouse return failed for worktree <tmp>/demo-gone-forced/pool/1/repo; teardown aborted
exit=1
task record: still-in-flight   backlog: in_flight   copy draft.txt: draft

\### crossed-unforced: fm-teardown.sh task-x1    (copy .git link: crossed)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-crossed-unforced/wt/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-crossed-unforced/project/.git/worktrees/other-wt
REFUSED: worktree <tmp>/demo-crossed-unforced/wt has uncommitted changes.
uncommitted changes present (untracked-only leftovers)
untracked paths (up to 10):
  draft.txt
Commit them (or get the captain's explicit OK to discard, then --force).
exit=1
task record: still-in-flight   backlog: in_flight   copy draft.txt: draft
other task branch fm/other-task: 23d2539

\### crossed-forced: fm-teardown.sh task-x1 --force   (copy .git link: crossed)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-crossed-forced/wt/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.9YGe9z/demo-crossed-forced/project/.git/worktrees/other-wt
<tmp>/demo-crossed-forced/project: already current
teardown task-x1 complete (window firstmate:fm-task-x1, worktree <tmp>/demo-crossed-forced/wt)
Backlog: task-x1 is closed in <tmp>/demo-crossed-forced/data/backlog.md. Run bin/fm-tasks-axi.sh ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.
exit=0
task record: closed   backlog: done   copy draft.txt: MISSING
other task branch fm/other-task: DELETED

===== AFTER (e011bac8) =====
\### gone-unforced: fm-teardown.sh task-x1    (copy .git link: gone)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-gone-unforced/pool/1/repo/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-gone-unforced/project/.git/worktrees/wt
REFUSED: task task-x1's copy at <tmp>/demo-gone-unforced/pool/1/repo has a broken git link: its .git names <tmp>/demo-gone-unforced/project/.git/worktrees/wt, which no longer exists. It cannot be inspected for unlanded work, so nothing was changed.
Repair the link (git worktree repair) and re-run, or get the captain's explicit OK to discard the copy, then --force: cleanup then closes the task without touching the copy.
exit=1
task record: still-in-flight   backlog: in_flight   copy draft.txt: draft

\### gone-forced: fm-teardown.sh task-x1 --force   (copy .git link: gone)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-gone-forced/pool/1/repo/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-gone-forced/project/.git/worktrees/wt
warning: task task-x1's copy at <tmp>/demo-gone-forced/pool/1/repo has a broken git link (its .git names <tmp>/demo-gone-forced/project/.git/worktrees/wt, which no longer exists), so it was neither returned nor cleaned; its files stay in place and its work is discarded with this task.
warning: the pool lost slot 1 (<tmp>/demo-gone-forced/pool/1/repo); preview its removal with: treehouse destroy <tmp>/demo-gone-forced/pool/1/repo
<tmp>/demo-gone-forced/project: already current
teardown task-x1 finished its cleanup and removed its task record, but its pool slot holds a copy with a broken git link (see the warning above); remove that slot so the pool can replace it
Backlog: task-x1 is closed in <tmp>/demo-gone-forced/data/backlog.md. Run bin/fm-tasks-axi.sh ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.
exit=4
task record: closed   backlog: done   copy draft.txt: draft

\### crossed-unforced: fm-teardown.sh task-x1    (copy .git link: crossed)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-crossed-unforced/wt/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-crossed-unforced/project/.git/worktrees/other-wt
REFUSED: task task-x1's copy at <tmp>/demo-crossed-unforced/wt has a broken git link: its .git names <tmp>/demo-crossed-unforced/project/.git/worktrees/other-wt, which git has bound to the copy at <tmp>/demo-crossed-unforced/other-wt. It cannot be inspected for unlanded work, so nothing was changed.
Repair the link (git worktree repair) and re-run, or get the captain's explicit OK to discard the copy, then --force: cleanup then closes the task without touching the copy.
exit=1
task record: still-in-flight   backlog: in_flight   copy draft.txt: draft
other task branch fm/other-task: 03c3b43

\### crossed-forced: fm-teardown.sh task-x1 --force   (copy .git link: crossed)
$ cat /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-crossed-forced/wt/.git
gitdir: /private/var/folders/y9/b8qt1d396lv9cfh42ft2gt7r0000gn/T/fm-teardown-tests.gnjjr0/demo-crossed-forced/project/.git/worktrees/other-wt
warning: task task-x1's copy at <tmp>/demo-crossed-forced/wt has a broken git link (its .git names <tmp>/demo-crossed-forced/project/.git/worktrees/other-wt, which git has bound to the copy at <tmp>/demo-crossed-forced/other-wt), so it was neither returned nor cleaned; its files stay in place and its work is discarded with this task.
Remove that copy once nothing else needs it.
<tmp>/demo-crossed-forced/project: already current
teardown task-x1 complete (window firstmate:fm-task-x1, worktree <tmp>/demo-crossed-forced/wt)
Backlog: task-x1 is closed in <tmp>/demo-crossed-forced/data/backlog.md. Run bin/fm-tasks-axi.sh ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.
exit=0
task record: closed   backlog: done   copy draft.txt: draft
other task branch fm/other-task: 4b229bb

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • ⚠️ bin/fm-teardown.sh:2156 - teardown_copy_link_broken treats any back-pointer mismatch as "bound to a different copy", including when no copy exists at the back-pointer's location. Example: a copy that was moved or renamed without git worktree move. Its admin dir still exists and its gitdir names the old path. canonical_existing_dir fails, so owner falls back to the raw old dirname, and owner != copy returns 0. Git can still inspect that copy normally (git status/log work through the .git file, and git worktree repair fixes it). Even so, an unforced ship is now REFUSED with "git has bound to the copy at <nonexistent path>", and a forced or scout close skips the return or scrub and reports the pool slot as lost. Only claim the crossed shape when the owner directory exists (ideally also check that its .git names the same admin dir). Otherwise return 1 and keep the ordinary path.
  • ⚠️ bin/fm-teardown.sh:4093 - On the Orca backend, a copy flagged broken (TEARDOWN_COPY_BROKEN=1) still goes to fm_backend_remove_worktree (orca worktree rm --force), and teardown_note_broken_copy is never called. This contradicts the new header contract (lines 105-114): a broken copy is 'never handed to git or Treehouse' and 'leaves every file of the copy in place'. For the crossed-link shape, Orca's forced git-backed removal runs on a copy whose .git names another task's admin dir, which is the exact hazard the guard exists to prevent. No test covers Orca with a broken copy. Needs a decision: either skip the Orca removal and report the leftover worktree for broken copies, or narrow the documented contract to non-Orca backends.
  • ℹ️ bin/fm-teardown.sh:114 - The intent's first case (fm-skills-adopt-k4, 'missing, empty, or ambiguous worktree identity') is refused in fm_backend_validate_task_endpoint (bin/fm-backend.sh:721), and this change does not touch that path. It can still be closed through a supported path: follow the existing repair hint (add the worktree= line), then --force. With the line back, the deleted-copy path closes the task, and test z5d covers that. Noted for clarity only.

🔧 Fix: Keep Orca from removing copies with broken git links
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-teardown.test.sh filtered to the 5 new tests (gone-link close, crossed-link close, unforced refusal for both shapes, deleted-copy close, Orca crossed-link close) plus the neighbouring tests test_return_that_removes_copy_warns_cannot_verify and test_scout_ignored_files_survive_scratch_clean: all pass
  • Regression check: ran each new test against base bin/fm-teardown.sh (4123a5eb). 4 of 5 fail as expected. The deleted-copy test already passed on base, so it pins existing behavior.
  • Manual CLI transcript before and after the fix: ran bin/fm-teardown.sh (with and without --force) through the test harness, with the copy's .git naming a deleted admin dir (a Treehouse pool slot) and with it naming another task's admin dir
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ing it

Cleanup now proves a copy's .git link broken when it names a worktree admin
directory that is gone, or one git has bound to a different copy. Such a copy
is never handed to git or Treehouse: a ship refuses without --force, and a
forced close (or a scout's scratch copy) closes the record, endpoint, and
backlog item, drops the slot claim, and reports a pooled copy as a lost slot.
Before this, the gone-link shape failed at the Treehouse return, and the
crossed-link shape deleted the other copy's branch.
@demy00
demy00 merged commit 1cb5661 into main Nov 9, 2026
52 of 56 checks passed
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