Skip to content

fix(bin): verify Orca worktree ownership before teardown - #4838

Open
MLA82 wants to merge 4 commits into
kunchenguid:mainfrom
MLA82:fm/werft-pr3723-ersatz
Open

MLA82 wants to merge 4 commits into
kunchenguid:mainfrom
MLA82:fm/werft-pr3723-ersatz

Conversation

@MLA82

@MLA82 MLA82 commented Sep 18, 2026 •

Copy link
Copy Markdown

What Changed

  • Verify existing Orca worktree ownership before teardown concludes validation runs, reaps processes, or removes hooks, including scout and forced ship cleanup.
  • Skip Orca path comparison when the recorded worktree is already absent, and document the teardown behavior.
  • Add regressions proving stale Orca worktree records refuse cleanup before destructive actions.

Risk Assessment

✅ Low: The change is well-bounded - it folds one already-existing Orca proof into the single early ownership determination, deletes a now-dead verified flag, and adds two behavioral regression tests; every traced path (scout, ship with and without --force, absent/mismatched/unresolvable worktree, existing Orca fixtures' CLI call order) keeps or improves its prior outcome, and the only finding is precision of the new safety wording.

Testing

The focused endpoint/worktree safety family passed. Three live marked-lab runs then confirmed early stale-identity refusal for scout and forced-ship teardown, plus successful cleanup when the recorded path is already absent. CLI transcripts were captured and all transient worktree artifacts were removed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Scout teardown rejects a stale Orca worktree identity before touching the recorded worktree ✅ pass live Live Orca teardown transcript, SCENARIO: scout-stale
Forced ship teardown cannot bypass a stale Orca worktree identity check ✅ pass live Live Orca teardown transcript, SCENARIO: forced-ship-stale
A vanished recorded path skips path comparison and still releases the recorded Orca resources ✅ pass live Live Orca teardown transcript, SCENARIO: absent recorded path skips comparison but releases recorded Orca resources
Evidence: Focused automated endpoint safety run

Source: Focused automated endpoint safety run

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, and cmux records validate while 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
skip - tmux not installed
skip - tmux not installed
skip - tmux not installed
skip - tmux not installed
skip - tmux not installed
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 Orca scout task's stale recorded worktree refuses before any process is reaped or hook removed
ok - fm-teardown: a forced Orca ship teardown's stale recorded worktree still refuses before any process is reaped or hook removed
skip - tmux not installed
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: 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: 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
Evidence: Live Orca teardown transcript

Source: Live Orca teardown transcript

SCENARIO: scout-stale
exit_code=1
stderr: fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-live-orca-teardown.QzFnaF/scout-stale/home
stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stderr: ●  WATCHER DOWN - SUPERVISION IS OFF
stderr: ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
stderr: ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
stderr: ●  This is a supervision warning only; the guarded operation WILL still run.
stderr: ●  repair missing watcher supervision according to the session-start block for this harness; do not use shell &.
stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stderr: REFUSED: Orca worktree id worktree-scout-stale-task::/orca/worktree-scout-stale-task resolves to /tmp/fm-live-orca-teardown.QzFnaF/scout-stale/elsewhere, not inspected worktree /tmp/fm-live-orca-teardown.QzFnaF/scout-stale/worktree.
stderr: Cannot verify dirty or unlanded work for the worktree Orca would remove; preserving metadata.
orca_calls:
  worktree|show|--worktree|id:worktree-scout-stale-task::/orca/worktree-scout-stale-task|--json
worker_alive_after_refusal=yes
hook_preserved=yes
metadata_preserved=yes
destructive_orca_calls=0

SCENARIO: forced-ship-stale
exit_code=1
stderr: fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-live-orca-teardown.QzFnaF/forced-ship-stale/home
stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stderr: ●  WATCHER DOWN - SUPERVISION IS OFF
stderr: ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
stderr: ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
stderr: ●  This is a supervision warning only; the guarded operation WILL still run.
stderr: ●  repair missing watcher supervision according to the session-start block for this harness; do not use shell &.
stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stderr: REFUSED: Orca worktree id worktree-forced-ship-stale-task::/orca/worktree-forced-ship-stale-task resolves to /tmp/fm-live-orca-teardown.QzFnaF/forced-ship-stale/elsewhere, not inspected worktree /tmp/fm-live-orca-teardown.QzFnaF/forced-ship-stale/worktree.
stderr: Cannot verify dirty or unlanded work for the worktree Orca would remove; preserving metadata.
orca_calls:
  worktree|show|--worktree|id:worktree-forced-ship-stale-task::/orca/worktree-forced-ship-stale-task|--json
worker_alive_after_refusal=yes
hook_preserved=yes
metadata_preserved=yes
destructive_orca_calls=0

SCENARIO: absent recorded path skips comparison but releases recorded Orca resources
exit_code=0
stderr: fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-live-orca-teardown.QzFnaF/absent-path/home
stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stderr: ●  WATCHER DOWN - SUPERVISION IS OFF
stderr: ●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
stderr: ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
stderr: ●  This is a supervision warning only; the guarded operation WILL still run.
stderr: ●  repair missing watcher supervision according to the session-start block for this harness; do not use shell &.
stderr: ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
stdout: teardown absent-path-task complete (window terminal-absent-path-task, worktree /tmp/fm-live-orca-teardown.QzFnaF/absent-path/already-gone-worktree)
stdout: Backlog: absent-path-task just finished (this home keeps no markdown backlog at /tmp/fm-live-orca-teardown.QzFnaF/absent-path/home/data/backlog.md). Update /tmp/fm-live-orca-teardown.QzFnaF/absent-path/home/data/backlog.md - move absent-path-task 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.
orca_calls:
  terminal|close|--terminal|terminal-absent-path-task|--json
  worktree|rm|--worktree|id:worktree-absent-path-task::/orca/worktree-absent-path-task|--force|--json
metadata_removed=yes

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ⚠️ docs/orca-backend.md:66 - The change's three new safety claims assert a guarantee the code does not give when the recorded worktree path is already gone. docs/orca-backend.md:66 says "A recorded worktree path that no longer exists has nothing left to protect, so cleanup proceeds without asking Orca", docs/orca-backend.md:64 says --force "never act[s] on a worktree that may not be this task's", and bin/fm-teardown.sh:174 repeats "An Orca worktree path that is already gone has nothing left to protect and needs no proof" (same sentence again at bin/fm-teardown.sh:2504-2505; bin/fm-teardown.sh:3648 then states the match was "already verified"). Concrete sequence: a record with worktree=/path/gone (directory removed by hand or by a crashed earlier teardown) and orca_worktree_id=wt-7::/orca/wt-7, run as fm-teardown.sh <id> --force. At bin/fm-teardown.sh:2507 require_orca_worktree_path_match_if_present sees [ -e /path/gone ] false and returns 0 without calling Orca; --force skips the inspectable-worktree gate at bin/fm-teardown.sh:3507; execution reaches bin/fm-teardown.sh:3665 and runs orca worktree rm --worktree id:wt-7::/orca/wt-7 --force against whatever Orca now resolves that id to, with no path proof at all. The identical shape exists on the sibling secondmate-child path at bin/fm-teardown.sh:3325 (child removal gated only by [ -e "$child_wt" ] around the match at bin/fm-teardown.sh:3080-3082). So there IS something still at stake in that case: the id, not the vanished path. The behavior is pre-existing, intentional, and pinned by tests/fm-backend-orca.test.sh:919 ("releases terminal/worktree when path is absent", which asserts terminal close + worktree rm with no worktree show call), and round 1 already decided the tolerance is intended - I am not asking for it to change. The smallest honest remedy is to narrow the four sentences to state what is actually skipped (the path comparison, because there is no recorded path left to compare) instead of claiming nothing is at stake and that --force never acts on a worktree that may not be this task's; this is an ask-user because the sentences are the author's deliberate claim and the alternative remedy (gating the id-only release) would contradict a pinned test and a recorded decision.
  • ℹ️ bin/fm-teardown.sh:2499 - Scope note for the record, not a blocker. The User intent enumerates exactly eight contributions to update ("Acht Beitraege: 3722, 3725, 4170, 4186, 4683, 4773, 4838, 4845") and four explicitly out of scope (3726, 4190, 4366, 5288). This branch is fm/werft-pr3723-ersatz; upstream fix(bin): refuse teardown when the recorded worktree is not a Treehouse pool slot, and guard Claude hook removal #3723 ("fix(bin): refuse teardown when the recorded worktree is not a Treehouse pool slot, and guard Claude hook removal", author MLA82) is closed and appears in neither list. The branch is also not a transfer of a pre-verified staging state: its entire content relative to origin/main is the three commits c2b45f1/36dd879b/e063fbb6 authored on top of current main 4cca7d0. Nothing in the intent forbids 3723, and the recorded decisions show this same branch has already been through review round 1, lint round 1, and CI round 2, so this reads as a deliberate ninth, replacement contribution - stating it once so the mapping is explicit. No action needed unless that is not the case.

🔧 Fix applied.
2 infos still open:

  • ℹ️ bin/fm-teardown.sh:2499 - Scope note for the record, not a blocker. The User intent enumerates exactly eight contributions to update ("Acht Beitraege: 3722, 3725, 4170, 4186, 4683, 4773, 4838, 4845") and four explicitly out of scope (3726, 4190, 4366, 5288). This branch is fm/werft-pr3723-ersatz; upstream fix(bin): refuse teardown when the recorded worktree is not a Treehouse pool slot, and guard Claude hook removal #3723 ("fix(bin): refuse teardown when the recorded worktree is not a Treehouse pool slot, and guard Claude hook removal", author MLA82) is closed and appears in neither list. The branch is also not a transfer of a pre-verified staging state: its entire content relative to origin/main is the three commits c2b45f1/36dd879b/e063fbb6 authored on top of current main 4cca7d0. Nothing in the intent forbids 3723, and the recorded decisions show this same branch has already been through review round 1, lint round 1, and CI round 2, so this reads as a deliberate ninth, replacement contribution - stating it once so the mapping is explicit. No action needed unless that is not the case.
  • ℹ️ bin/fm-teardown.sh:3652 - Tradeoff note for the record, no action needed. Removing the deferred check at the old bin/fm-teardown.sh:3652 means no path proof runs adjacent to the destructive Orca calls any more: for kind=scout and forced ship teardowns the proof used to execute immediately before the branch delete, terminal close, and fm_backend_remove_worktree (bin/fm-teardown.sh:3670), and now runs only once at the single gate (bin/fm-teardown.sh:3405), with conclude_task_no_mistakes_run and up to several reap passes in between. That is exactly the window the non-forced ship path has always had (its proof sat at the old :3513, also well before :3670), so this is a deliberate uniform single-gate design, not a regression in kind; the trade is strictly in the right direction, since the reap and hook removal are now covered for every kind. Flagging only so the loss of the immediately-pre-removal re-check is a known, chosen property rather than an oversight.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Scout teardown rejects a stale Orca worktree identity before touching the recorded worktree ✅ pass live Live Orca teardown transcript, SCENARIO: scout-stale
Forced ship teardown cannot bypass a stale Orca worktree identity check ✅ pass live Live Orca teardown transcript, SCENARIO: forced-ship-stale
A vanished recorded path skips path comparison and still releases the recorded Orca resources ✅ pass live Live Orca teardown transcript, SCENARIO: absent recorded path skips comparison but releases recorded Orca resources
  • bash tests/fm-teardown-endpoint-safety.test.sh
  • Temporary evidence driver invoking real bin/fm-teardown.sh in marked disposable lab homes with an isolated Orca CLI fixture (driver and fixtures removed afterward)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

MLA82 added 4 commits October 11, 2026 18:33
An Orca scout teardown, or any Orca teardown run with --force, skipped the
early Orca path-match check and only re-verified it after
reap_task_worktree_processes had already run against the recorded worktree
path, so a stale or reassigned Orca worktree id could have its processes
signalled before ownership was ever proven.

Fold the Orca proof into require_owned_task_worktree_slot, the same
early, single-owner ownership determination the treehouse pool-slot claim
already uses, so it runs once, well before Fix 1/Fix 2, for every kind and
--force alike, instead of being re-checked ad hoc at each later call site.
@MLA82
MLA82 force-pushed the fm/werft-pr3723-ersatz branch from e2eeed0 to 88ea1c5 Compare October 11, 2026 17:00
@MLA82 MLA82 changed the title fix(bin): prove Orca worktree ownership before any destructive teardown step fix(bin): verify Orca worktree ownership before teardown Oct 11, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @MLA82 — this closes a real safety gap, and the three live Orca teardown scenarios are exactly the evidence we look for.

Where it stands: waiting on CI. I reviewed the diff (bin/fm-teardown.sh ownership ordering, docs, regression tests; no workflow, secret, or network changes) and approved the fork CI runs, which are queued now. Nothing is needed from you unless CI comes back red.

contract-class: restore. Main already promises that Orca cleanup verifies the recorded worktree id/path before release and that ownership refusals are not relaxed by --force. On main, scout and forced-ship teardown only ran that proof at the branch-drop step, after the no-mistakes conclude and process reap had already touched $WT. This tip moves the existing proof into the single ownership determination, before every destructive step; the absent-path skip matches main's existing _if_present behavior.

VISION.md: one captain — aligns · authority explicit — aligns (destructive steps gated on proof) · scripts own mechanics — aligns · restart non-event — aligns · delegation with a spine — aligns (strengthens the refusal path; unlanded work never torn down on a stale identity) · fleet outlives vendor — aligns (Orca adapter uses its own CLI proof) · scope — aligns.

If CI and no-mistakes are green and it stays mergeable, it is eligible to merge on a following pass.

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