Skip to content

fix(bin): allow cleanup of windowless legacy task records - #5236

Merged
kunchenguid merged 5 commits into
mainfrom
fm/afk-return-stale-record-gate-r1
Sep 22, 2026
Merged

kunchenguid merged 5 commits into
mainfrom
fm/afk-return-stale-record-gate-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

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:

  • The return archived the away posture and then refused to let ordinary work proceed. The visible block was "catch-up must finish before the captain request" because three task records had no readable status file. Those tasks were already merged days earlier and had no window: test: authorize isolated Herdr lab validation #4998, chore(main): release lavish-axi 0.1.74 lavish-axi#356, fix(server): record startup and runtime failures lavish-axi#357. Cleanup of those records had already refused because the records have no spawn generation and no window. Writing a readable done line for each made the next return check pass - that write is a WORKAROUND, not a fix, and those lines now exist in the main home. Reproduce with a fixture, not by deleting or editing them.
  • A second visible oddity on the same return: the stop line said a daemon terminal was torn down. No daemon was started for this Pi entry, and the daemon log has no entry for the window (the last daemon log lines are from 2026-09-07).

Constraints from the captain/main firstmate:

  • Separate the trigger, the condition that exposed it, and the visible symptom. Compare a return where every task record has a readable status file (which passed) against a return where a leftover record has no status file. Do not treat the most recent nearby edit as the cause without evidence.
  • If the catch-up gate is doing what it should, say so and name the REAL defect instead of weakening a check that is protecting a live endpoint.
  • Leave the away-words behavior and the later host work alone. The misleading stop line IS part of the same return experience - fix it too.

What Changed

  • Allow validated, backlog-tracked tmux records without a window or spawn generation to be cleaned up as missing-endpoint legacy leftovers, while preserving landed-work and metadata safety checks.
  • Keep the AFK catch-up gate strict for records with unreadable status files and add regression coverage for statusless versus readable-status leftovers.
  • Report that no daemon terminal was running when stopping Pi or native AFK sessions that never launched one.

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, and bin/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.

  • Live validation: ⚠️ inconclusive - 1 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Returning with a statusless leftover stays catch-up gated, while the same record with a readable status allows ordinary work ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; a live product run exercising both return states is required.
Ordinary cleanup retires a no-window, no-spawn-generation leftover and closes its backlog item without requiring --legacy-record ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; a live product cleanup of this stale-record shape is required.
Cleanup remains fail-closed for windowless records with a spawn generation, alternate endpoint identity, malformed identity, disabled backlog validation, or unlanded work ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; live product runs covering these refusal cases are required.
A partially completed windowless cleanup retries its retained legacy stamp without reintroducing the stale-record deadlock ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; a live product run exercising retained-stamp retry is required.
A real no-words Pi away posture creates no daemon state and return truthfully says no daemon terminal was running ✅ pass live Artifact “Real no-words Pi return transcript” shows absent .afk, daemon-terminal, and daemon-log state after confirmation, followed by successful archive and the corrected stop line
Evidence: AFK return catch-up comparison transcript

Source: AFK return catch-up comparison transcript

ok - return catch-up owns live blocker remediation, reports itself to Bearings as content, preserves evidence once, and clears idempotently
ok - tmux and Herdr blockers require the same explicit durable reclassification before ordinary work
ok - needs-decision remains reportable without masquerading as a firstmate-actionable blocker
ok - AFK return re-drains published wakes until handling acknowledges
ok - away-mode re-entry fails closed while the prior return catch-up is pending
ok - /quiet off's return path behaves identically for a quiet-content flag as for a legacy away-content one
ok - check retries recorded terminal teardown and keeps catch-up gated until success
ok - an unreadable superseded mandate stays required until its record validates
ok - the retained contract epoch requires its final archive on every check
ok - the return brief renders health, the words with the session account, waiting, could-not-fix, handled, and cost from durable records, and the gate shrinks to what the away session could not fix
ok - a refreshed posture keeps its original window, superseded mandate, and earlier outcomes
ok - a malformed posture record stays live and gates return catch-up
ok - an epochless malformed record remains required until restored valid
ok - an unreadable outcome store gates catch-up until a successful reread
ok - an unavailable held listing gates catch-up until a successful reread
ok - an unreadable status stays private and gates until a successful reread
ok - a status-file-less leftover record gates return; a readable status on that same record is the proven path that passes
ok - a leftover record with a readable status file lets return catch-up clear
ok - the read-only guard treats the away-posture record as active away mode without the legacy flag
ok - the return brief leads with supervisor health and names every detected gap
ok - the return brief does not report an already-acked watcher-down marker as an open gap
ok - a return with only the legacy away flag still renders the brief and measures the window from the flag
Evidence: Windowless stale-record teardown and refusal transcript

Source: Windowless stale-record teardown and refusal transcript

ok - local-only worktree with HEAD on a fork remote is torn down and the home summary is refreshed
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 0s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - teardown closes its own backlog item before reporting success
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 0s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
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 - fm-pr-check publishes the PR-ready line on a secondmate's parent channel once
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 - 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 - 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 - 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 - 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
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 0s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
WARNING: watcher still down (same stale episode; last beat: 1s ago, grace 300s) - full banner already printed this episode.
fm-contributions: data directory unavailable
contributions: observation not armed; coverage is unconfirmed
ok - fm-pr-check does not refresh PR head after HEAD moves
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
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 - content fallback refreshes origin default before comparing trees
ok - dirty worktree is refused even when its committed work has landed (dirty always wins)
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
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - a windowless leftover with no spawn_gen and no worktree tears down without --legacy-record
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
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
WARNING: watcher still down (same stale episode; last beat: 2s ago, grace 300s) - full banner already printed this episode.
ok - a windowless leftover retries its retained legacy stamp without --legacy-record
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 1s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/52b07e9083e7/01M33GF2PHGVGGVERHXPGMDVAH/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
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 - index-lock mtime fault injection is PATH-based; skipped on Darwin where stat is /usr/bin/stat
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 - a task's own parked no-mistakes run is aborted, not orphaned, before the worker is removed
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
Evidence: Isolated launcher and guarded Herdr/tmux E2E transcript

Source: Isolated launcher and guarded Herdr/tmux E2E transcript

ok - clear-stale: removes escalations buffer, sidecar, and wedge marker
ok - clear-stale: leaves the durable wake-queue intact (no pending work dropped)
ok - propose: the read-back carries the words verbatim with the expected return and spend cap, and writes only a proposal
ok - propose: the retired --grant flag is refused by name
ok - confirm: records the posture, announces hold-for-return only, and launches no daemon
ok - propose: refuses while the prior return catch-up is pending
ok - pi: start refuses to launch the daemon and writes no state
ok - pi: start-native refuses to prepare a daemon
ok - pi-signed: start refuses to launch the daemon and writes no state
ok - pi-signed: start-native refuses to prepare a daemon
ok - pi confirm stop: reports that no daemon terminal was running
ok - daemon entry: a pending proposal cannot bypass captain confirmation
ok - daemon entry: an explicitly confirmed record permits lifecycle preparation
ok - failed start: preserves the pre-confirmed posture record
ok - stop: clears the away flag and archives the posture record under its entry time
ok - launcher paths: relative home and state ignore CDPATH before daemon command construction
ok - launcher paths: absolute symlink spellings are preserved
ok - launcher paths: unresolved relative FM_HOME fails loudly
ok - launcher paths: unresolved relative FM_STATE_OVERRIDE fails loudly
ok - refresh: daemon already alive - stale artifacts preserved (current session's buffer kept)
ok - mode: a fresh entry with FM_AFK_MODE=quiet writes quiet
ok - mode: a fresh entry with FM_AFK_MODE unset defaults to away
ok - mode: a bare refresh (FM_AFK_MODE unset) of an already-running quiet daemon preserves quiet, never resets to away
ok - mode: an empty (legacy pre-mode) flag reads as away
ok - mode: a bare-epoch-timestamp (legacy pre-mode) flag reads as away
ok - mode: unrecognized content falls back to away
ok - mode: a missing flag reads as away
ok - stop-ordering: daemon SIGTERM'd while .afk still present (flush is not a no-op)
ok - stop-ordering: .afk cleared last
ok - stop-ordering: daemon-terminal record removed
ok - stop identity: stale lock cannot signal an unrelated live process
ok - failed start: away flag and delivery artifacts roll back
ok - concurrent start: one serialized daemon terminal remains tracked
ok - launcher lock: incomplete publication receives initialization grace
ok - launcher signal: TERM exits and releases the lifecycle lock
fm-afk-launch: daemon launched in non-visible herdr workspace ws-partial (pane lab:pane-exact), supervising lab:captain
ok - herdr create: malformed response recovers durable exact ownership
fm-afk-launch: herdr create failed after returning exact ids; closing lab:pane-exact
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr create error: unconfirmed exact id is persisted for reconciliation
fm-afk-launch: failed to run daemon in herdr pane lab:pane-exact; closing it
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - herdr run failure: unconfirmed exact id remains reconcilable
fm-afk-launch: failed to persist daemon terminal record; closing tmux:exact-session
ok - record failure: newly created terminal is closed by exact id
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
ok - readiness failure: exact terminal and durable record roll back
fm-afk-launch: daemon did not become ready; closing tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - readiness failure: unconfirmed terminal retains its reconciliation id
ok - tmux absence: clean missing differs from transport probe failure
ok - native lifecycle: launcher owns state with no terminal
ok - native lifecycle: uniform stop clears state without closing a terminal
ok - native entry: launcher-prepared lifecycle state is not rewritten
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: recorded terminal teardown is unconfirmed; preserving exact id
ok - teardown failure: exact terminal record is preserved
ok - record publication: failed atomic rename preserves the complete prior record
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
ok - record read: malformed record fails closed without acting on a partial id
fm-afk-launch: daemon terminal record is malformed; refusing to act on it
fm-afk-launch: malformed daemon terminal record; refusing to stop away mode
ok - stop: malformed terminal record preserves away state and fails closed
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-2345123713-41328-20241-1790048027'
ok - tmux launch: planned exact target is recorded before creation and removed on failure
fm-afk-launch: failed to create detached tmux daemon session 'fm-afk-daemon-1676614534-41391-9487-1790048027'
ok - tmux launch: unique names eliminate collision teardown
ok - stop validation: malformed record causes no daemon or state side effects
ok - launcher lock: incomplete metadata fails acquisition and releases lock
fm-afk-launch: failed to clear away-mode flag
fm-afk-launch: away mode stopped; terminal teardown or the record archive remains recorded for retry
ok - stop state: away-flag removal failure is surfaced
fm-afk-launch: away-mode daemon did not exit after SIGTERM; preserving lifecycle state
ok - stop liveness: captured live daemon preserves lifecycle state after lock release
fm-afk-launch: a confirmed away-posture record is required; run propose and confirm before starting the daemon
fm-afk-launch: a confirmed away-posture record is required; run propose and confirm before starting the daemon
ok - refresh record: malformed terminal identity fails closed
fm-afk-launch: a confirmed away-posture record is required; run propose and confirm before starting the daemon
ok - clear failure: native entry aborts and restores prior state
fm-afk-launch: reconciling leaked daemon terminal tmux:exact-session
fm-afk-launch: terminal close command failed, but exact absence was confirmed
ok - confirmed absence: cleanup succeeds and removes the stale record
fm-afk-launch: rollback restoration incomplete; backup retained at /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T//fm-afk-restore-fail.1PHi5p/state/.afk-launch-backup.CZGuyZ
ok - rollback restore: incomplete restoration retains its recovery backup
fm-afk-launch: a confirmed away-posture record is required; run propose and confirm before starting the daemon
ok - flag failure: lifecycle aborts without active state
ok - herdr e2e: captain tab pane count unchanged after start (no split)
ok - herdr e2e: daemon launched in a separate non-visible workspace
ok - herdr e2e: daemon pane is NOT in the captain's tab
ok - herdr e2e: daemon terminal scoped to the lab session
ok - herdr e2e: captain tab pane count restored after stop
ok - herdr e2e: daemon workspace removed by exact id on stop
ok - herdr e2e: record + .afk cleared on stop
ok - tmux e2e: captain window pane count unchanged after start (no split-window)
ok - tmux e2e: daemon launched in a separate detached session
ok - tmux e2e: captain window pane count unchanged after stop
ok - tmux e2e: daemon session killed by exact id on stop
ok - tmux e2e: record + .afk cleared on stop
Evidence: Real no-words Pi return transcript

Source: Real no-words Pi return transcript

$ bin/fm-afk-launch.sh propose
Away posture read-back (proposed, not yet confirmed):
  entered: 2026-09-22T03:33:59Z
  expected return: not given
  spend cap: 4 concurrent workers
  reach: hold-for-return only. No phone channel is configured; anything that needs you waits for your return.
  your words: (none)
Say go to confirm; restate your instructions first if this reading is not what you meant.
$ bin/fm-afk-launch.sh confirm
Away posture confirmed at 2026-09-22T03:33:59Z: hold-for-return only. No phone channel is configured; anything that needs you waits for your return. No away instructions were recorded; the away session acts on standing authority only, and anything that needs you waits for your return. Destructive, irreversible, and security-sensitive actions are never pre-authorizable, whatever the words say. Expected return: not given. Spend cap: 4 concurrent workers.
$ state after confirm
.afk=absent
.afk-daemon-terminal=absent
.supervise-daemon.log=absent
$ bin/fm-afk-launch.sh stop
fm-afk-launch: away-posture record archived at ~/.no-mistakes/evidence/01M33GF2PHGVGGVERHXPGMDVAH/live-pi-home/state/afk-contracts/1790048039.afk-contract
fm-afk-launch: away mode stopped; no daemon terminal was running, .afk cleared, and the posture record archived
$ state after stop
.afk-contract=absent
archived-contracts=1
- Outcome: ⚠️ 1 warning across 1 run (7m32s)

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 in terminal= and Herdr/Zellij/cmux retain backend-specific endpoint IDs. A legacy Orca record with no window/spawn_gen but backend=orca, terminal=term-7, and a valid worktree is classified windowless here; line 1002 skips endpoint validation, line 3460 skips the Orca close because T_ORCA remains empty, line 3464 removes the worktree, line 3517 skips generic close, and the metadata is later erased, leaving term-7 alive 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 stamps spawn_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-record is 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 whether spawn_gen is 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 in terminal= and Herdr/Zellij/cmux retain backend-specific endpoint IDs. A legacy Orca record with no window/spawn_gen but backend=orca, terminal=term-7, and a valid worktree is classified windowless here; line 1002 skips endpoint validation, line 3460 skips the Orca close because T_ORCA remains empty, line 3464 removes the worktree, line 3517 skips generic close, and the metadata is later erased, leaving term-7 alive 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 stamps spawn_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-record is 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 whether spawn_gen is 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 sets TEARDOWN_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-record use 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 or tmux backend, and exact worktree/project still qualifies even if endpoint_task_id belongs 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 in terminal= and Herdr/Zellij/cmux retain backend-specific endpoint IDs. A legacy Orca record with no window/spawn_gen but backend=orca, terminal=term-7, and a valid worktree is classified windowless here; line 1002 skips endpoint validation, line 3460 skips the Orca close because T_ORCA remains empty, line 3464 removes the worktree, line 3517 skips generic close, and the metadata is later erased, leaving term-7 alive 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 stamps spawn_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-record is 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 whether spawn_gen is 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 sets TEARDOWN_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-record use 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 or tmux backend, and exact worktree/project still qualifies even if endpoint_task_id belongs 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 ignores terminal, orca_worktree_id, Herdr, Zellij, and cmux identity fields in that branch. Thus a no-window/no-spawn record with valid worktree/project plus terminal=term-7 passes 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 selected windowless-shape-still-bypasses-malformed-identities sibling 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.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (1 of 5 scenarios were driven live against the product); untested: Returning with a statusless leftover stays catch-up gated, while the same record with a readable status allows ordinary work, Ordinary cleanup retires a no-window, no-spawn-generation leftover and closes its backlog item without requiring --legacy-record, Cleanup remains fail-closed for windowless records with a spawn generation, alternate endpoint identity, malformed identity, disabled backlog validation, or unlanded work, A partially completed windowless cleanup retries its retained legacy stamp without reintroducing the stale-record deadlock
  • Live validation: ⚠️ inconclusive - 1 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Returning with a statusless leftover stays catch-up gated, while the same record with a readable status allows ordinary work ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; a live product run exercising both return states is required.
Ordinary cleanup retires a no-window, no-spawn-generation leftover and closes its backlog item without requiring --legacy-record ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; a live product cleanup of this stale-record shape is required.
Cleanup remains fail-closed for windowless records with a spawn generation, alternate endpoint identity, malformed identity, disabled backlog validation, or unlanded work ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; live product runs covering these refusal cases are required.
A partially completed windowless cleanup retries its retained legacy stamp without reintroducing the stale-record deadlock ⏸️ untested no The prior payload provided only test-script and transcript evidence and explicitly marked this scenario live=false; a live product run exercising retained-stamp retry is required.
A real no-words Pi away posture creates no daemon state and return truthfully says no daemon terminal was running ✅ pass live Artifact “Real no-words Pi return transcript” shows absent .afk, daemon-terminal, and daemon-log state after confirmation, followed by successful archive and the corrected stop line
  • tests/fm-afk-return.test.sh
  • tests/fm-teardown.test.sh
  • tests/fm-afk-launch.test.sh (initial run exposed Pi-ancestry test-environment interference)
  • Re-ran tests/fm-afk-launch.test.sh inside a uniquely named detached tmux session to remove Pi ancestry; all launcher checks and isolated Herdr/tmux E2E scenarios passed
  • Ran the real bin/fm-afk-launch.sh propose, confirm, and stop commands 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.

kunchenguid and others added 5 commits September 21, 2026 19:52
…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]>
@kunchenguid
kunchenguid merged commit da9607d into main Sep 22, 2026
20 checks passed
@kunchenguid
kunchenguid deleted the fm/afk-return-stale-record-gate-r1 branch September 22, 2026 04:12
BohnBawerick added a commit to BohnBawerick/firstmate that referenced this pull request Sep 23, 2026