Skip to content

fix(bin): let teardown retire tasks with an absent or reassigned worktree - #6229

Open
AgardnerAU wants to merge 15 commits into
kunchenguid:mainfrom
AgardnerAU:fm/fm-teardown-empty-worktree-unreapable
Open

AgardnerAU wants to merge 15 commits into
kunchenguid:mainfrom
AgardnerAU:fm/fm-teardown-empty-worktree-unreapable

Conversation

@AgardnerAU

@AgardnerAU AgardnerAU commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Update the existing pull request #6229 (branch fm/fm-teardown-empty-worktree-unreapable, from the AgardnerAU fork) onto current upstream main and push so CI re-runs. The earlier CI failures came from GitHub moving ubuntu-latest to ubuntu-26.04, fixed on main by upstream PR 7798 (an ubuntu-24.04 pin), and were not caused by this change. That PR lets bin/fm-teardown.sh retire a task whose recorded local copy (worktree) is absent or now belongs to another task, when the task's own work has landed or is pushed; work that cannot be proven landed or pushed still refuses unless --force is given. Keep updating the existing PR; do not replace it. If only the known flaky cases fail on main itself (fm-supervision-host serial 1, fm-watch-wedge-cap serial 4), report that rather than chasing them.

What Changed

  • bin/fm-teardown.sh can now do a records-only cleanup of a ship or scout task that has no local copy to inspect. This applies when the record names no worktree (no worktree= line, or one empty line), when the recorded path is not a directory, or when the slot now belongs to another task. In each case teardown cleans up only the task's own endpoint, status, records, checks and backlog. It does not touch a slot. Two or more worktree= lines still refuse.
  • A new validate_recorded_work_landed gate keeps the landed-work check for these tasks. It proves the work from the record: every commit on the recorded branch in the project repository is on a remote-tracking branch (a fork counts), or the PR is merged and holds that work, or the branch content is already in the default branch. If none of these is true, teardown refuses, shows the evidence, and continues only with --force. To make this possible, the existing landed-work helpers now read from a configurable repository and revision (LANDED_REPO/LANDED_REV) instead of the worktree's HEAD.
  • fm_backend_validate_task_endpoint in bin/fm-backend.sh has a new --allow-unrecorded-worktree option, which only teardown uses. Teardown never passes it for secondmates, and the validator refuses it for Orca. All other callers still refuse an unrecorded worktree. docs/architecture.md describes the new boundary. The tests cover the new paths and add a fm_test_pushed_branch_project fixture helper.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is limited to the teardown gate. The validator opt-in only applies to teardown, and Orca, secondmates and duplicate worktree= lines still refuse. The new landed-work gate fails closed: it checks the project repository, which pool slots share as their git common dir, so the branch refs are visible. The merge from main adds no conflicting changes to the files this branch owns. The one known retry-convergence gap was already declined by the user.

Testing

I ran the real fm-teardown.sh in a disposable, marked lab home. The lab used a real git project with a bare remote and real tmux windows on a private socket. Two records retired cleanly when their branch was pushed: one with an empty worktree= line, and one whose recorded worktree path no longer exists. For each, the record was removed, the window was killed, and the run printed a records-only completion line. A record with no worktree and an unpushed commit refused, listed the commit, and kept the record and the window. With --force, it then retired. A record with two empty worktree= lines still refused as ambiguous. Both targeted teardown test files passed in full. I did not run two scenarios against the live product: the slot claimed by another live task, and the merged-PR or local-only proofs. Only the test suite covers them. I could not run the before-fix reproduction against the base commit because the permission system denied it.

  • Live validation: ✅ go - 5 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Operator tears down a ship whose record has an empty worktree= line and whose branch is pushed: teardown completes records-only, removes the record, and kills the window ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh emptywt -> 'teardown emptywt complete (... no worktree recorded, records-only cleanup)', exit 0, record removed, window gone
Operator tears down a ship whose recorded worktree directory no longer exists and whose branch is pushed: teardown completes ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh gonewt -> exit 0, record removed, window gone
Adversarial: a ship with no worktree and an unpushed commit refuses, lists the commit, and keeps its record and window ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh nowt-unpushed -> 'REFUSED: ... cannot be proven landed or pushed' listing 'work for nowt-unpushed', exit 1, record present, window alive
Operator overrides that refusal with --force and the task retires ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh nowt-unpushed --force -> exit 0, record removed, window gone
Adversarial: a record with two worktree= lines (ambiguous identity) still refuses and preserves its state ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh dupwt -> 'REFUSED: ... ambiguous worktree identity', exit 1, record present, window alive
A ship whose worktree slot is claimed by another live task refuses while unpushed, retires once pushed, and never touches the other task's slot ⏸️ untested no The prior payload did not establish a live result. This scenario needs a Treehouse pool slot with a cross-task claim file, and no live Treehouse pool was built in the lab. Only a fixture in tests/fm-t…
A ship with no worktree whose recorded PR is merged, or local-only work already merged into local main, retires without --force ⏸️ untested no The prior payload did not establish a live result. The merged-PR proof needs a GitHub PR that reports MERGED, and creating a real merged PR is outward-facing. Only tests/fm-teardown.test.sh covers thi…
Evidence: Live lab transcript: fm-teardown.sh on branch head against absent-worktree records

Source: Live lab transcript: fm-teardown.sh on branch head against absent-worktree records

=== branch head 9c413906: fm-teardown.sh from ~/.no-mistakes/worktrees/8b3eda8ad954/01M5Y24C05QHEZ4FD11ZY34NY5 ===
--- records ---
# dupwt.meta
window=firstmate:fm-dupwt
endpoint_task_id=dupwt
worktree=
worktree=
project=$LAB/projects/proj
kind=ship
mode=no-mistakes
branch=fm/dupwt
# emptywt.meta
window=firstmate:fm-emptywt
endpoint_task_id=emptywt
worktree=
project=$LAB/projects/proj
kind=ship
mode=no-mistakes
branch=fm/emptywt
# gonewt.meta
window=firstmate:fm-gonewt
endpoint_task_id=gonewt
worktree=$LAB/wt-gonewt
project=$LAB/projects/proj
kind=ship
mode=no-mistakes
branch=fm/gonewt
# nowt-unpushed.meta
window=firstmate:fm-nowt-unpushed
endpoint_task_id=nowt-unpushed
project=$LAB/projects/proj
kind=ship
mode=no-mistakes
branch=fm/nowt-unpushed

$ fm-teardown.sh emptywt
fm-gate-refuse: gate agent lifecycle permitted only against lab home $LAB
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  4 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
warning: task emptywt's record names no worktree, so there is no copy to inspect, reset, or return; only emptywt's own records-only cleanup runs.
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
proj: already current
teardown emptywt complete (window firstmate:fm-emptywt; no worktree recorded, records-only cleanup)
Backlog: emptywt just finished (this home keeps no markdown backlog at $LAB/data/backlog.md). Update $LAB/data/backlog.md - move emptywt to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
[exit 0] record: removed; window: gone

$ fm-teardown.sh gonewt
fm-gate-refuse: gate agent lifecycle permitted only against lab home $LAB
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
proj: already current
teardown gonewt complete (window firstmate:fm-gonewt, worktree $LAB/wt-gonewt)
Backlog: gonewt just finished (this home keeps no markdown backlog at $LAB/data/backlog.md). Update $LAB/data/backlog.md - move gonewt to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
[exit 0] record: removed; window: gone

$ fm-teardown.sh nowt-unpushed
fm-gate-refuse: gate agent lifecycle permitted only against lab home $LAB
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
warning: task nowt-unpushed's record names no worktree, so there is no copy to inspect, reset, or return; only nowt-unpushed's own records-only cleanup runs.
REFUSED: task nowt-unpushed has no worktree of its own to inspect, and its recorded work cannot be proven landed or pushed.
commits on fm/nowt-unpushed not on any remote:
b18e397 work for nowt-unpushed
recorded PR: none (not proven merged)
Push the branch, land its PR, or get the captain's explicit OK to discard, then --force.
[exit 1] record: present; window: alive

$ fm-teardown.sh nowt-unpushed --force
fm-gate-refuse: gate agent lifecycle permitted only against lab home $LAB
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
warning: task nowt-unpushed's record names no worktree, so there is no copy to inspect, reset, or return; only nowt-unpushed's own records-only cleanup runs.
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
proj: already current
teardown nowt-unpushed complete (window firstmate:fm-nowt-unpushed; no worktree recorded, records-only cleanup)
Backlog: nowt-unpushed just finished (this home keeps no markdown backlog at $LAB/data/backlog.md). Update $LAB/data/backlog.md - move nowt-unpushed to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
[exit 0] record: removed; window: gone

$ fm-teardown.sh dupwt
fm-gate-refuse: gate agent lifecycle permitted only against lab home $LAB
REFUSED: task dupwt has a missing, empty, or ambiguous worktree identity; preserving task state.
[exit 1] record: present; window: alive
Evidence: fm-teardown-endpoint-safety test log

Source: fm-teardown-endpoint-safety test log

ok - fm-teardown: missing, empty, malformed, ambiguous, and task-mismatched endpoints refuse before every mutation or runtime call
ok - fm-teardown: a concurrent lifecycle action refuses before mutation
ok - fm-teardown: non-pool cleanup ignores unrelated task publication locks
ok - fm-teardown: destructive cleanup serializes with metadata writers
ok - cleanup identity: valid tmux, Herdr, Zellij, Orca, cmux, Paseo, Rex, and tern records validate, inconsistent Rex records refuse, and every empty backend target refuses
ok - cleanup identity: an Orca record's real composite worktree id validates while a separatorless or newline-carrying id refuses
ok - tmux backend: direct empty target returns nonzero without invoking tmux
ok - process cleanup: creation-time PID identity removes only the exact child and preserves the control child
ok - fm-teardown: exact tmux cleanup preserves invalid and prefix-matched neighbors while removing only the recorded target
ok - fm-teardown: a close that genuinely failed refuses and keeps the record naming the surviving endpoint, and the same teardown finishes once the close works
ok - fm-teardown: --force continues past a close it could not make while still reporting it, and the same case refuses without --force
ok - fm-teardown: a close re-read that could not run refuses, while a definitively absent session or server still completes silently
ok - fm-teardown: forced secondmate cleanup still refuses on a child endpoint close that failed
ok - fm-teardown: an Orca close its missing CLI never attempted refuses even under --force, keeping the record naming the terminal
ok - fm-teardown: an already-exited endpoint, and a server that is already gone, still complete cleanup silently
ok - Treehouse locking resolves a bare local origin against its source project, matching the provisioned clone
ok - fm-teardown: a pool slot named by a second task record is never returned, killed, or reset
ok - fm-teardown: a pool slot held by another firstmate home is never returned
ok - fm-teardown: a task that solely holds its slot still returns it
ok - fm-teardown: a pool slot claimed by another task is left alone while the task's own cleanup finishes
ok - fm-teardown backend=t3code: a reassigned pool slot keeps its claimant's Codex overlay while the task's own thread is archived
ok - fm-teardown: a stale record on a claimed slot retires, then the claimant tears down
ok - fm-teardown: a task's own slot claim, and an unclaimed slot, both still tear down
ok - fm-teardown: a record naming no worktree retires records-only while an ambiguous one still refuses
ok - fm-teardown: a landed task whose recorded worktree no longer exists retires records-only
ok - fm-teardown: a record whose slot another live task holds refuses while its branch is unpushed, retires records-only once pushed, and never touches that task
ok - fm-teardown: an exact recorded endpoint still tears down after changing cwd outside its worktree
ok - Treehouse project locking anchors at the local root for main-home, local-secondmate, and remote-seeded layouts
ok - fm-teardown: a remote-seeded secondmate home returns its own uncontested pool slot
ok - fm-teardown: slot ownership across a remote-seeded home and its local child still refuses
ok - Treehouse project locking still serializes two homes across the remote-seeded boundary

real	2m10.469s
user	0m58.544s
sys	1m15.520s
Evidence: fm-teardown test log

Source: fm-teardown test log

ok - teardown leaves opencode's busy plugin in the returned pool worktree as on main
ok - status archival is opt-in and preserves the complete log
ok - config-absent teardown does not read or invoke record export
ok - unopted teardown ignores symlinked config when record export is absent
ok - teardown commits the record archive before deleting sources and fails closed when export cannot commit
ok - forced secondmate teardown exports task records from the child sub-state
ok - record export waits for endpoint quiescence and retry captures records changed after refusal
ok - forced secondmate retirement preserves two descendant levels and refuses linked child directories
ok - local missing-status retirement stays lock-free without creating an archive
ok - reused task IDs never overwrite archives and retention removes only old owned logs
ok - archive sources and directories reject symlinks; pruning never follows children links
ok - failed archive publication preserves presentation and watcher bookkeeping
ok - cursor retirement failure removes its archive so retry publishes one history
ok - archive publication and cold logs never re-wake or re-present
ok - retention failures warn without aborting unrelated teardown
ok - a missing teardown startup source refuses before cleanup
ok - an unreadable teardown startup source refuses before cleanup
ok - a missing adapter sibling refuses before cleanup
ok - a forced descendant with a missing adapter sibling refuses before cleanup
ok - a forced secondmate with a missing own adapter sibling refuses before child cleanup
ok - present required sources still reach the ordinary teardown refusal
ok - local-only worktree with HEAD on a fork remote is torn down and the home summary is refreshed
ok - teardown closes its own backlog item before reporting success
ok - teardown closes a landed Gerrit task with its change URL as a note and a GitHub task with --pr
ok - teardown closes a landed GitLab task with its merge request URL as a note and GitHub and Forgejo tasks with --pr
ok - teardown honors config/backlog-backend=manual and still finishes cleanly
ok - local-only worktree with truly unpushed work is refused (safety preserved)
ok - local-only worktree with work merged into local main is torn down (no regression)
ok - no-mistakes worktree with HEAD on origin is torn down (no regression)
ok - no-mistakes worktree with genuinely unlanded work is refused (safety preserved)
ok - local-only worktree with unpushed work is torn down under --force (escape hatch)
ok - a record naming no worktree whose PR merged retires records-only
ok - a record naming no worktree whose branch is pushed retires with its PR still open
ok - a record naming no worktree refuses unpushed branch commits, and --force overrides
ok - a local-only record naming no worktree whose branch is merged into local main retires without --force
ok - fm-pr-check publishes the PR-ready line on a secondmate's parent channel once
ok - fm-pr-check withholds the PR-ready line until checks are green when config/ready-after-green is present
ok - fm-pr-check releases the PR-ready line on a checks-green report that carries surrounding text
ok - a secondmate home's teardown delivers the child's final line or refuses until it can
ok - teardown completes when an exact busy-state sidecar is already absent
ok - teardown retires a polytoken task's generated worktree wiring on pool return
ok - teardown never deletes a tracked .polytoken hook layer
ok - teardown never deletes a .polytoken hook layer firstmate did not generate
ok - teardown scopes .polytoken wiring removal to polytoken tasks
ok - herdr teardown removes pane-owned escalation dedupe state
ok - herdr flat teardown refuses before returning the isolated copy under lock contention and the retry completes cleanly
ok - herdr flat teardown never erases records when pane presence is unparseable
ok - herdr flat teardown preflight refuses before every destructive change
ok - herdr teardown takes its lock in a per-account namespace another account cannot block, and still refuses a foreign-owned or wrong-mode one
ok - forced secondmate teardown preflights every Herdr child before cleanup mutation
ok - forced secondmate teardown holds every descendant lifecycle and metadata lock
ok - forced secondmate teardown retains Herdr child identity until exact pane disappearance
ok - forced teardown retains a nested secondmate home and its grandchild's Herdr identity when the grandchild close is unconfirmed
ok - herdr projection teardown retires its journal only after confirming the exact recorded pane is gone
ok - herdr projection teardown retains every record when post-close presence is unknown
ok - herdr projection teardown surfaces failed focus restoration without turning confirmed cleanup into a hard failure
ok - teardown retires the task's own watcher markers and orphaned presentation journal, leaving other tasks' markers alone
ok - teardown retains a presentation journal bound to a pane other than the closed endpoint
ok - teardown retires a v1 presentation journal once its token workspace is confirmed gone
ok - teardown retains a v1 presentation journal while its token workspace is still present
ok - teardown retains a v1 presentation journal when the workspace query is ambiguous
ok - squash-merged + deleted-branch worktree (PR merged) is torn down (the fix)
ok - squash-merged PR accepts a local HEAD that is an ancestor of the final PR head
ok - teardown discovers a merged PR by branch name and tears down when no pr= was ever recorded
ok - squash-merged PR accepts replayed unpushed local patches contained in the PR head
ok - merged PR does not allow teardown after a later local commit
ok - squash-merged task whose local branch followed the pipeline rebase is torn down
ok - teardown proves a Forgejo task landed from the merged pull request when the content check is inconclusive
ok - squash-merged same-path different content still refuses
ok - squash-merged rebased local still refuses a genuinely unlanded follow-up commit
ok - squash-merged stale local still refuses when the forge is unreachable
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
ok - fm-pr-check does not refresh PR head after HEAD moves
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
ok - fm-pr-check records the remote PR head when the local worktree lags
ok - worktree whose content already landed in the default branch is torn down (content fallback)
ok - the content-landed fallback checks a task's recorded base branch, not the default branch
ok - content fallback refreshes origin default before comparing trees
ok - dirty worktree is refused even when its committed work has landed (dirty always wins)
ok - untracked/no-mistakes: dirty refusal classifies leftovers and preserves work
ok - untracked/local-only: dirty refusal classifies leftovers and preserves work
ok - tracked/no-mistakes: dirty refusal classifies leftovers and preserves work
ok - tracked/local-only: dirty refusal classifies leftovers and preserves work
ok - mixed/no-mistakes: dirty refusal classifies leftovers and preserves work
ok - mixed/local-only: dirty refusal classifies leftovers and preserves work
ok - scout copy with a nested clone and a scratch file returns with no untracked entries
ok - ship copy with a nested clone is refused and its bytes stay
ok - a return that leaves residue names the lost slot and the remaining paths
ok - a dirty return is reported even when a later teardown step refuses
ok - a forced secondmate teardown returns a child scout copy with a nested clone clean
ok - a forced secondmate teardown warns about a dirty child return and still completes
ok - a return that leaves no readable copy reports the slot as unverified, not clean
ok - ignored files survive the scratch clean and plain scratch does not
ok - gh lookup error with content not in default refuses (fail-safe)
ok - a record predating spawn_gen refuses teardown until --legacy-record is passed
ok - a windowless leftover with no spawn_gen and no worktree tears down without --legacy-record
ok - a windowless leftover with no spawn_gen also tears down when --legacy-record is passed
ok - a windowless leftover still refuses while its worktree holds unlanded work
ok - a windowless record with a spawn_gen, a non-tmux backend or endpoint identity, no backlog validation, or ambiguous, foreign, or malformed identity still refuses
ok - a windowless leftover retries its retained legacy stamp without --legacy-record
ok - a landed legacy record with a dead endpoint tears down and logs its accepted incarnation
ok - --legacy-record never relaxes the unlanded-work refusal
ok - an endpoint that cannot be confidently read as dead refuses --legacy-record teardown
ok - --legacy-record teardown rolls its stamp back when the close marker write fails
ok - a legacy stamp a failed rollback left behind still faces the endpoint gate
ok - a corrupt spawn_gen is never accepted as a legacy record
ok - provably-stale worktree index.lock (old, no live holder) is cleared and teardown succeeds
ok - live-held worktree index.lock is never removed and teardown refuses
ok - lsof errors leave worktree index.lock in place and refuse teardown
ok - stale lock cleanup rechecks and refuses dirty worktree before return
ok - normal repo index.lock is resolved from the worktree and cleared when stale
ok - lock mtime read failures leave worktree index.lock in place and refuse teardown
ok - transient index.lock cleared after first failed return is retried successfully without force-remove
ok - persistent index.lock exhausts retries and refuses without force-removing the lock
ok - empty retry wait overrides use the default without aborting teardown
ok - fractional legacy retry wait remains supported without arithmetic
ok - teardown records the task's pipeline spend before removing its branch and record
ok - teardown skips all pipeline-spend recording when the home has not opted in
ok - teardown records unavailable pipeline spend for an owned ship task whose copy is gone
ok - a task's own parked no-mistakes run is aborted, not orphaned, before the worker is removed
ok - a parked run in a resolved workspace no-mistakes home is aborted before the worker is removed
ok - a run that lands on passed-with-override after abort is still recognized as terminal
ok - a run that lands on passed-with-skips after abort is still recognized as terminal
ok - a parked run the pipeline advanced past the task copy is still concluded from the runs ledger, not orphaned
ok - a ledger row for a different head never authorizes a parked-run abort
ok - a malformed ledger row never authorizes a parked-run abort
ok - an impossible ledger date never authorizes a parked-run abort
ok - a terminal status with a stale gate never reaches ledger cleanup
ok - an advanced head present locally aborts through the strict rule alone - the ledger fallback stays dormant
ok - an unresolvable active row with no same-branch anchor is never concluded (conservative refusal)
ok - an ancestor-only anchor never binds an advanced parked run to this task
ok - a terminal unfetched-head row is stale history and never concludes a run
ok - a terminal newest row anchored at this worktree's head never authorizes an abort
ok - a resolvable diverged newer same-branch row makes every older row stale history; no run is concluded
ok - consecutive unresolvable rows are ambiguous and never conclude a run
ok - a ledger-proven continuation is still left alone while the run is autonomously active
ok - teardown refuses before reap or removal when a task-owned run remains parked
ok - a different run cannot confirm the targeted abort
ok - empty post-abort status is not accepted as confirmation
ok - the CLI's exact run-not-found signal confirms completion
ok - a parked run on another branch is never aborted by this task's teardown (ownership is precise)
ok - a task-owned autonomous running step is left alone rather than aborted
ok - a leaked descendant process rooted under the task's worktree is reaped by teardown, not left surviving
ok - a leaked descendant process rooted under the task's per-task tasktmp is reaped by teardown too
ok - missing lsof falls back to reaping the tmux pane process group
ok - an erroring lsof scan refuses teardown and preserves the task
ok - a reused pid with a different start time is never force-killed
ok - an exec change preserves birth identity and the process is reaped
ok - a process spawned during grace is reaped on a later pass
ok - persistent leaked processes refuse teardown after bounded retries
ok - a process exiting during identity lookup does not block teardown
ok - the run abort and the leaked-process reap both complete before the destructive worktree return

real	9m40.027s
user	4m29.541s
sys	5m7.254s

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Operator tears down a ship whose record has an empty worktree= line and whose branch is pushed: teardown completes records-only, removes the record, and kills the window ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh emptywt -> 'teardown emptywt complete (... no worktree recorded, records-only cleanup)', exit 0, record removed, window gone
Operator tears down a ship whose recorded worktree directory no longer exists and whose branch is pushed: teardown completes ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh gonewt -> exit 0, record removed, window gone
Adversarial: a ship with no worktree and an unpushed commit refuses, lists the commit, and keeps its record and window ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh nowt-unpushed -> 'REFUSED: ... cannot be proven landed or pushed' listing 'work for nowt-unpushed', exit 1, record present, window alive
Operator overrides that refusal with --force and the task retires ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh nowt-unpushed --force -> exit 0, record removed, window gone
Adversarial: a record with two worktree= lines (ambiguous identity) still refuses and preserves its state ✅ pass live live-lab-teardown-branch.txt: fm-teardown.sh dupwt -> 'REFUSED: ... ambiguous worktree identity', exit 1, record present, window alive
A ship whose worktree slot is claimed by another live task refuses while unpushed, retires once pushed, and never touches the other task's slot ⏸️ untested no The prior payload did not establish a live result. This scenario needs a Treehouse pool slot with a cross-task claim file, and no live Treehouse pool was built in the lab. Only a fixture in tests/fm-t…
A ship with no worktree whose recorded PR is merged, or local-only work already merged into local main, retires without --force ⏸️ untested no The prior payload did not establish a live result. The merged-PR proof needs a GitHub PR that reports MERGED, and creating a real merged PR is outward-facing. Only tests/fm-teardown.test.sh covers thi…
  • Live lab run: bin/fm-lab-home.sh create $LAB, a real git project with a bare origin, a private tmux server (tmux -L fm-lab), real fm-<id> windows, and task records, then FM_HOME=$LAB bin/fm-teardown.sh &lt;id&gt; [--force] for emptywt, gonewt, nowt-unpushed, nowt-unpushed --force, and dupwt. The lab was torn down with kill-server and rm -rf.
  • bash tests/fm-teardown-endpoint-safety.test.sh (31 ok, 0 not ok). This includes the unrecorded-worktree, gone-worktree, and slot-held-by-another-live-task records-only cases.
  • bash tests/fm-teardown.test.sh (150 ok, 0 not ok). This includes the absent-worktree cases: merged PR, open PR with pushed branch, unpushed branch refused then --force, and local-only work merged to local main.
  • Tried to run the same lab against the base commit 7da4c362 to reproduce the old refusal. The permission system denied that command.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…r task

Teardown now finishes a records-only cleanup - endpoint, status, records,
checks, backlog - when a ship or scout record names no worktree, when its
recorded path provably no longer exists, or when its slot's owner claim names
another task even while that task's record also names the slot. No step
reads, resets, kills under, or returns that path, and --force is unchanged.
Duplicated worktree identities, collisions the claim does not resolve, Orca,
and secondmates keep their existing refusals.
…own copy

Run the recorded-work landed proof for every ship whose own copy is not
inspected - no worktree recorded, no directory at the recorded path, or a
slot another task claims - so only --force retires unproven work. Move the
landed-proof globals above pr_number_from_branch's comment, and give the
test fixtures that record a ship with an absent copy a pushed branch.
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects task retirement in the teardown workflow.

The PR should not merge until the records-only proof stops accepting mirror-only work as pushed.

Reviews (4) · Last reviewed commit: "Merge branch 'main' of https://github.co..." · Reviewed by Greptile

Comment thread bin/fm-teardown.sh Resolved
…worktree-unreapable

# Conflicts:
#	docs/architecture.md
@AgardnerAU AgardnerAU changed the title fix(bin): retire tasks whose recorded worktree is absent or held by another task fix(bin): let teardown retire a task whose worktree is absent or reassigned once its work has landed Sep 30, 2026
@zachlandes zachlandes mentioned this pull request Oct 12, 2026
…worktree-unreapable

# Conflicts:
#	bin/fm-teardown.sh
…deleted

A teardown that proves a ship's own copy landed now records landed_proven=1
before deleting the task branch, so a retry whose returned slot another task
has claimed accepts that proof instead of refusing on the missing branch.
Also give upstream's gone-worktree pipeline-spend test the landed-work proof
that records naming no inspectable copy now require.
The retry-after-partial-teardown concern (Greptile 'Retries lose pushed-work
proof') was declined in earlier review rounds, so remove the landed_proven
writer, its reader, its header text, and its two tests. Keep the merged-PR
proof in upstream's gone-worktree pipeline-spend test, which this PR's
landed-work gate requires.
@AgardnerAU AgardnerAU changed the title fix(bin): let teardown retire a task whose worktree is absent or reassigned once its work has landed fix(bin): let teardown retire a task whose worktree is absent or reassigned once its work is landed Oct 13, 2026
@AgardnerAU

Copy link
Copy Markdown
Contributor Author

Merged current main into this branch (head 2a3cd16) and resolved the conflicts in bin/fm-teardown.sh, keeping both upstream's Forgejo and base-branch changes and this PR's absent-worktree handling. Upstream's new gone-worktree pipeline-spend test now records a merged PR, because this PR requires landed-work proof for a copy it cannot inspect. The Greptile finding 'Retries lose pushed-work proof' was considered and declined in earlier review rounds, so there is no code change for it. Up to date with main and ready for CI.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @AgardnerAU — and thanks for the main merge today. Records-only teardown once landed work is proved (and a hard refuse when it is not) matches the spine we already promised.

VISION (each rule):

  • One captain, one interface: aligns (stranded records stop becoming captain noise).
  • Authority is explicit: aligns (--force remains the only discard path for unlanded work).
  • Scripts own the mechanics: aligns (landed-proof helpers stay deterministic).
  • A restart is a non-event: aligns (records can retire when the copy is gone).
  • Delegation with a spine: aligns ("Unlanded work is never torn down").
  • The fleet outlives any vendor: aligns (Orca still refuses unrecorded worktree; secondmates untouched).
  • Scope: aligns.

Contract-class: restore. Existing default: teardown retires a finished task when its work is landed/pushed, and refuses discard without proof or --force. Absent/reassigned worktrees were stranding records because endpoint validation refused unconditionally — a broken path on that promise. Opt-in --allow-unrecorded-worktree is teardown-only.

Where it stands: attestation MATCH 2a3cd164, live go 6/6, up to date with main. I reviewed the diff (no workflow/secret surface; landed gate + secondmate/Orca refusals held) and approved first-time fork CI for this tip. Main is red, so no merge this wake. Overlap note: also touches fm-teardown.sh / fm-backend.sh with #5435 — land serially when green. Waiting on CI.

…n gate

fm-project-capacity's teardown fixture records an absent worktree with no
branch or PR, so the landed-work gate refuses it. Record a pushed branch,
as the other absent-worktree fixtures do.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @AgardnerAU. 8d63c269 gives the capacity-cleanup fixture a pushed branch so it passes the new gate. The no-mistakes attestation matches 8d63c269, and the PR is still mergeable. I approved the held fork runs: CI 38420578299 and Require no-mistakes 38420578261.

Contract-class: I'm revising my earlier read from restore to new-default. That fixture change is what showed me why. On main, a ship whose recorded worktree path is no directory, or whose pool slot another task now claims, tears down without a landed-work proof. Main's own tests specify that: test_windowless_legacy_record_with_gone_worktree_tears_down, test_teardown_records_unavailable_spend_for_a_gone_worktree, test_reassigned_pool_slot_finishes_own_cleanup_without_touching_the_slot, plus the capacity, gotmp, backlog-atomicity and public-followup fixtures. Main's header also says skipping the inspection discards nothing.

This PR adds a landed-work gate to those paths: teardown refuses unless the branch is pushed, its PR is merged, or its content is already in the default branch, or the caller passes --force. It also adds records-only cleanup for a record that names no worktree. Both follow VISION's "unlanded work is never torn down." But a new refusal on a specified default path is Kun's call. You don't need to change anything.

VISION.md: one captain / authority / scripts / restart / spine / vendor / scope all align. It strengthens a refusal path, and --force stays the only discard. Security: none material.

Status: waiting-ci. Once this is green on a green main, it goes to Kun to merge or leave instead of auto-merging. It overlaps #5435 (fm-teardown.sh/fm-backend.sh) and #6760.

…worktree-unreapable

# Conflicts:
#	bin/fm-backend.sh
#	bin/fm-teardown.sh
@AgardnerAU AgardnerAU changed the title fix(bin): let teardown retire a task whose worktree is absent or reassigned once its work is landed fix(bin): let teardown retire a task with an absent or reassigned worktree once its work is landed Oct 26, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @AgardnerAU for bringing this up to date with main. I'm sorry it sat this long after the last round.

What I checked: head 828c8ac3 is your branch with current main 127f0f30 merged in. Compared with main, the PR is the same 10 files and the same behavior as 8d63c269: records-only teardown for a record with no worktree of its own, and the validate_recorded_work_landed gate for a ship whose copy teardown can't inspect. --allow-unrecorded-worktree is passed only by teardown and never for a secondmate. Nothing touches workflows, credentials or the network, so I approved this head's fork runs: CI 40293172153 and no-mistakes 40293172127 / 40293275519. The no-mistakes attestation binds 828c8ac3 with review, test and document all completed. Live validation is go (5/7). The two untested scenarios need a real pool slot or a real merged PR, and tests cover both.

Verdict (unchanged from 10-13): contract-class is new-default. On main, a gone-worktree or reassigned-slot ship tears down without any landed-work proof, and main's own tests specify that. This PR puts a new refusal on that default path. It does follow VISION's "unlanded work is never torn down," but a new refusal on a specified default path is the captain's call. VISION.md: one captain aligns · authority aligns (--force is still the only discard) · scripts own mechanics aligns · restart aligns · delegation with a spine aligns · vendor aligns (Orca still refuses) · scope aligns. Security: nothing material.

Where it stands: waiting on CI. Nothing is needed from you. Once this head is green and mergeable, it goes to the captain for a merge-or-leave decision instead of auto-merging. It still overlaps the open #5435 and #6760 in fm-teardown.sh/fm-backend.sh. If one of them lands first and a conflict appears, that's ours to fix.

@AgardnerAU AgardnerAU changed the title fix(bin): let teardown retire a task with an absent or reassigned worktree once its work is landed fix(bin): let teardown retire tasks with an absent or reassigned worktree Oct 27, 2026
…worktree-unreapable

# Conflicts:
#	bin/fm-teardown.sh
…fm/fm-teardown-empty-worktree-unreapable

# Conflicts:
#	bin/fm-backend.sh
#	bin/fm-teardown.sh
Comment thread bin/fm-teardown.sh
LANDED_REV=
if [ -n "$branch" ] && git -C "$PROJ" show-ref --verify --quiet "refs/heads/$branch"; then
LANDED_REV=refs/heads/$branch
if ! unpushed_raw=$(git -C "$PROJ" log --oneline "$LANDED_REV" --not --remotes -- 2>/dev/null); then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Mirror-only work is marked done

When an absent-worktree task's branch exists only on the local no-mistakes mirror, this check treats it as pushed and returns success before checking its PR or content. Teardown can then close the endpoint, remove the task record, and mark unfinished work done without --force.

The existing worktree check deliberately excludes that mirror because it is not a forge. Add the same --exclude='no-mistakes/*' before --remotes here.

Suggested change
if ! unpushed_raw=$(git -C "$PROJ" log --oneline "$LANDED_REV" --not --remotes -- 2>/dev/null); then
if ! unpushed_raw=$(git -C "$PROJ" log --oneline "$LANDED_REV" --not --exclude='no-mistakes/*' --remotes -- 2>/dev/null); then

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @AgardnerAU for merging main into this tip (2f1fe291).

Waiting on you for two gates:

  1. Attestation is stale. The body still binds 5396ea8a, not current head 2f1fe291. Please re-raise through git push no-mistakes so a fresh attestation binds this tip with every step completed (no skipped steps).
  2. Greptile P1 is open on bin/fm-teardown.sh ("Mirror-only work is marked done"): an absent-worktree branch that exists only on the local no-mistakes mirror is treated as pushed. Please add the same --exclude='no-mistakes/*' before --remotes (or reply on the thread if you disagree), resolve it, and re-raise.

Contract-class stays new-default (gone-worktree / reassigned-slot teardown now gated). Overlaps #5435 / #6760 unchanged; any conflict is ours. Rockets: none. Unlabelled Full suite failure is our label gate.

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.

2 participants