Repository navigation
fix(bin): allow cleanup of windowless legacy task records - #5236
Merged
Merged
Conversation
…eardown Catch-up correctly refuses while a leftover task record has no status file. Cleanup used to deadlock on those same records when they also had no spawn_gen and no window, so they lingered and wedged every later away-mode return. Teardown now treats a windowless leftover as a missing-endpoint legacy record, and stop reports that no daemon terminal was running when none was launched. Co-authored-by: Cursor <[email protected]>
… endpoint validator
…nds' endpoint identity
BohnBawerick
added a commit
to BohnBawerick/firstmate
that referenced
this pull request
Sep 23, 2026
Intent
Investigate the away-mode (AFK) return experience and fix it if it is a real bug. Do NOT change the live home's records to reproduce it - reproduce with a fixture/synthetic home only.
What happened, from the real return on 2026-09-22 after a no-words away entry on Pi:
Constraints from the captain/main firstmate:
What Changed
Risk Assessment
✅ Low: The change is well-bounded, preserves the catch-up gate, narrowly authorizes validated endpointless legacy cleanup, and corrects the Pi stop message with behavioral fixture coverage.
Testing
Validation is fixture-based by design: this task forbids touching live home records and endpoints. The fixtures drive the real teardown, return/catch-up, and AFK stop binaries (
bin/fm-teardown.sh, the return/catch-up gate, andbin/fm-afk-launch.sh) against a synthetic home. That is the required product-exercising coverage here, not a live-home run.The payload recorded automated transcript evidence for catch-up gating, stale-record teardown, fail-closed cleanup, and retained-stamp retry behavior, but marked those scenarios live=false, so they remain untested under the live-validation contract. The real no-words Pi return scenario was driven live and passed.
.afk, daemon-terminal, and daemon-log state after confirmation, followed by successful archive and the corrected stop lineEvidence: AFK return catch-up comparison transcript
Source: AFK return catch-up comparison transcript
Evidence: Windowless stale-record teardown and refusal transcript
Source: Windowless stale-record teardown and refusal transcript
Evidence: Isolated launcher and guarded Herdr/tmux E2E transcript
Source: Isolated launcher and guarded Herdr/tmux E2E transcript
Evidence: Real no-words Pi return transcript
Source: Real no-words Pi return transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed (3) ✅
bin/fm-teardown.sh:455-window=absence is treated as proof that no endpoint exists, but Orca records name their actual endpoint interminal=and Herdr/Zellij/cmux retain backend-specific endpoint IDs. A legacy Orca record with no window/spawn_gen butbackend=orca,terminal=term-7, and a valid worktree is classified windowless here; line 1002 skips endpoint validation, line 3460 skips the Orca close becauseT_ORCAremains empty, line 3464 removes the worktree, line 3517 skips generic close, and the metadata is later erased, leavingterm-7alive without its durable identity. Line 3562 similarly skips Herdr close confirmation. Restrict the exception to legacy records with no alternate endpoint-bearing metadata (and validate all remaining identity fields); otherwise refuse.bin/fm-teardown.sh:484- The new flag-free windowless cleanup is not retry-safe. It stampsspawn_gen=legacy-*before destructive cleanup; if a later operation fails—for example Treehouse return at line 3485 or outcome delivery at line 3575—the record remains. On an ordinary retry, line 507 rejects that retained stamp unless--legacy-recordis supplied, so the stale record can again keep AFK catch-up blocked after a routine transient failure. Permit a retained legacy stamp to retry without the flag when it is the same safely classified windowless legacy shape.bin/fm-teardown.sh:1002- The new global windowless bypass applies regardless of whetherspawn_genis absent and also applies in homes where backlog incarnation validation is disabled. The stated defect is specifically records that “have no spawn generation and no window”; no intent requirement needs current-generation or unrelated windowless records to bypass the shared endpoint validator. Narrow this branch to the missing-spawn legacy acceptance path and retain the previous fail-closed behavior for every other malformed record.🔧 Fix applied.
6 issues (4 errors, 2 warnings) still open:
bin/fm-teardown.sh:455-window=absence is treated as proof that no endpoint exists, but Orca records name their actual endpoint interminal=and Herdr/Zellij/cmux retain backend-specific endpoint IDs. A legacy Orca record with no window/spawn_gen butbackend=orca,terminal=term-7, and a valid worktree is classified windowless here; line 1002 skips endpoint validation, line 3460 skips the Orca close becauseT_ORCAremains empty, line 3464 removes the worktree, line 3517 skips generic close, and the metadata is later erased, leavingterm-7alive without its durable identity. Line 3562 similarly skips Herdr close confirmation. Restrict the exception to legacy records with no alternate endpoint-bearing metadata (and validate all remaining identity fields); otherwise refuse.bin/fm-teardown.sh:484- The new flag-free windowless cleanup is not retry-safe. It stampsspawn_gen=legacy-*before destructive cleanup; if a later operation fails—for example Treehouse return at line 3485 or outcome delivery at line 3575—the record remains. On an ordinary retry, line 507 rejects that retained stamp unless--legacy-recordis supplied, so the stale record can again keep AFK catch-up blocked after a routine transient failure. Permit a retained legacy stamp to retry without the flag when it is the same safely classified windowless legacy shape.bin/fm-teardown.sh:1002- The new global windowless bypass applies regardless of whetherspawn_genis absent and also applies in homes where backlog incarnation validation is disabled. The stated defect is specifically records that “have no spawn generation and no window”; no intent requirement needs current-generation or unrelated windowless records to bypass the shared endpoint validator. Narrow this branch to the missing-spawn legacy acceptance path and retain the previous fail-closed behavior for every other malformed record.bin/fm-teardown.sh:494- The automated fix round introduced a branch-order regression: for a no-spawn-generation, windowless leftover invoked with--legacy-record, the pre-existing branch at line 489 wins, but never setsTEARDOWN_WINDOWLESS; execution then reaches line 1019 and the shared validator refuses the missing window. Thus the documented deadlock remains reachable whenever an operator supplies the legacy flag. Classify the safe windowless shape independently of the flag so both ordinary cleanup and--legacy-recorduse the same missing-endpoint path.bin/fm-teardown.sh:466- The automated fix round narrowed backend/worktree/project cardinality but left the endpoint-safety sibling incomplete. A record with no window/spawn_gen, absent ortmuxbackend, and exact worktree/project still qualifies even ifendpoint_task_idbelongs to another task, worktree/project contain forbidden control characters, or backend-specific identity remains (terminal, Orca worktree id, Herdr session/workspace/tab/pane, Zellij session/tab/pane, or cmux workspace/surface). Lines 494 and 518 accept that shape, line 1015 bypasses the shared validator, and line 3552 skips endpoint closure; cleanup can then erase the durable record while a named endpoint remains alive. Ensure these malformed or alternate-endpoint-bearing records retain the fail-closed validator path.bin/fm-teardown.sh:3696- The${WT:-none}output fallback introduced here and at line 3698 is not required by the windowless-endpoint intent: both the new accepted shape and the existing endpoint validator require exactly one nonempty worktree. Keep the required${T:-none}window rendering, but remove the unrelated worktree fallback.🔧 Fix applied.
7 issues (5 errors, 2 warnings) still open:
bin/fm-teardown.sh:455-window=absence is treated as proof that no endpoint exists, but Orca records name their actual endpoint interminal=and Herdr/Zellij/cmux retain backend-specific endpoint IDs. A legacy Orca record with no window/spawn_gen butbackend=orca,terminal=term-7, and a valid worktree is classified windowless here; line 1002 skips endpoint validation, line 3460 skips the Orca close becauseT_ORCAremains empty, line 3464 removes the worktree, line 3517 skips generic close, and the metadata is later erased, leavingterm-7alive without its durable identity. Line 3562 similarly skips Herdr close confirmation. Restrict the exception to legacy records with no alternate endpoint-bearing metadata (and validate all remaining identity fields); otherwise refuse.bin/fm-teardown.sh:484- The new flag-free windowless cleanup is not retry-safe. It stampsspawn_gen=legacy-*before destructive cleanup; if a later operation fails—for example Treehouse return at line 3485 or outcome delivery at line 3575—the record remains. On an ordinary retry, line 507 rejects that retained stamp unless--legacy-recordis supplied, so the stale record can again keep AFK catch-up blocked after a routine transient failure. Permit a retained legacy stamp to retry without the flag when it is the same safely classified windowless legacy shape.bin/fm-teardown.sh:1002- The new global windowless bypass applies regardless of whetherspawn_genis absent and also applies in homes where backlog incarnation validation is disabled. The stated defect is specifically records that “have no spawn generation and no window”; no intent requirement needs current-generation or unrelated windowless records to bypass the shared endpoint validator. Narrow this branch to the missing-spawn legacy acceptance path and retain the previous fail-closed behavior for every other malformed record.bin/fm-teardown.sh:494- The automated fix round introduced a branch-order regression: for a no-spawn-generation, windowless leftover invoked with--legacy-record, the pre-existing branch at line 489 wins, but never setsTEARDOWN_WINDOWLESS; execution then reaches line 1019 and the shared validator refuses the missing window. Thus the documented deadlock remains reachable whenever an operator supplies the legacy flag. Classify the safe windowless shape independently of the flag so both ordinary cleanup and--legacy-recorduse the same missing-endpoint path.bin/fm-teardown.sh:466- The automated fix round narrowed backend/worktree/project cardinality but left the endpoint-safety sibling incomplete. A record with no window/spawn_gen, absent ortmuxbackend, and exact worktree/project still qualifies even ifendpoint_task_idbelongs to another task, worktree/project contain forbidden control characters, or backend-specific identity remains (terminal, Orca worktree id, Herdr session/workspace/tab/pane, Zellij session/tab/pane, or cmux workspace/surface). Lines 494 and 518 accept that shape, line 1015 bypasses the shared validator, and line 3552 skips endpoint closure; cleanup can then erase the durable record while a named endpoint remains alive. Ensure these malformed or alternate-endpoint-bearing records retain the fail-closed validator path.bin/fm-teardown.sh:3696- The${WT:-none}output fallback introduced here and at line 3698 is not required by the windowless-endpoint intent: both the new accepted shape and the existing endpoint validator require exactly one nonempty worktree. Keep the required${T:-none}window rendering, but remove the unrelated worktree fallback.bin/fm-teardown.sh:470- The latest automated fix still does not enforce its claimed invariant for backend-specific endpoint fields. The shared validator defaults an absent backend to tmux and ignoresterminal,orca_worktree_id, Herdr, Zellij, and cmux identity fields in that branch. Thus a no-window/no-spawn record with valid worktree/project plusterminal=term-7passes here, is marked windowless at line 499, bypasses validation at line 1020, skips endpoint closure at line 3557, and can erase the record while the named endpoint remains alive. This fix round left the selectedwindowless-shape-still-bypasses-malformed-identitiessibling unresolved; reject every backend-specific endpoint identity inconsistent with the accepted endpointless tmux shape at the earliest shared validation boundary.🔧 Fix applied.
✅ Re-checked - no issues remain.
.afk, daemon-terminal, and daemon-log state after confirmation, followed by successful archive and the corrected stop linetests/fm-afk-return.test.shtests/fm-teardown.test.shtests/fm-afk-launch.test.sh(initial run exposed Pi-ancestry test-environment interference)Re-rantests/fm-afk-launch.test.shinside a uniquely named detached tmux session to remove Pi ancestry; all launcher checks and isolated Herdr/tmux E2E scenarios passedRan the realbin/fm-afk-launch.sh propose,confirm, andstopcommands against an evidence-directory synthetic Pi home with no away words✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.