Repository navigation
fix(bin): close a task whose copy has a broken git link without touching it - #22
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.shaddsteardown_copy_link_broken. It detects a task copy whose.gitlink 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.--force, a ship task with a broken copy is refused before anything changes, with a hint to rungit worktree repairor 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:treehouse destroypreview to clear it.--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 rmand 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 destroyhint, 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
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_brokentreats 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 withoutgit worktree move. Its admin dir still exists and itsgitdirnames the old path.canonical_existing_dirfails, soownerfalls back to the raw old dirname, andowner != copyreturns 0. Git can still inspect that copy normally (git status/logwork through the .git file, andgit worktree repairfixes 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.gitnames 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 tofm_backend_remove_worktree(orca worktree rm --force), andteardown_note_broken_copyis 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 infm_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 theworktree=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.shfiltered 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 teststest_return_that_removes_copy_warns_cannot_verifyandtest_scout_ignored_files_survive_scratch_clean: all passRegression check: ran each new test against basebin/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: ranbin/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.