Skip to content

fix: auto-relaunch dead secondmates during supervision - #5496

Merged
kunchenguid merged 13 commits into
mainfrom
fm/fm-secondmate-auto-relaunch-r1
Sep 24, 2026
Merged

kunchenguid merged 13 commits into
mainfrom
fm/fm-secondmate-auto-relaunch-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Intent

When ongoing monitoring sees a registered persistent secondmate's recorded agent session positively dead or missing, relaunch it automatically during ordinary supervision and report it in one captain-visible line, instead of leaving the mate down until the next fleet/session startup. The user chose this option after a real incident where a secondmate's Claude session exited gracefully after hours of idleness and stayed down about an hour until the next session-start liveness sweep. Requirements: extract the existing sweep's probe/classification/relaunch mechanics from bin/fm-bootstrap.sh into a shared library (bin/fm-secondmate-liveness-lib.sh) so the session-start sweep and the watcher use identical evidence and paths; add a cadence-gated poll tick in bin/fm-watch.sh (FM_SECONDMATE_LIVENESS_SECS default 60s); relaunch only on the backend's positive dead or missing verdict through FM_SPAWN_NO_GUARD=1 fm-spawn.sh --secondmate; never relaunch on alive, ambiguous, unreadable, unverified, or remote transport failure (ssh 255 is not evidence of death); never replace a remote route with a local endpoint; kill a local endpoint only when positively dead, never pre-kill a missing one; serialize probe/kill/relaunch per mate via a shared lock so the sweep and tick cannot interfere; bound each watcher-driven spawn with a timeout; bound total attempts per mate per window (default 3 per hour) and park a flapping mate with one escalation until a live probe rearms it; emit exactly one check wake per relaunch attempt outcome and keep a durable per-mate ledger (state/.secondmate-relaunch-) so relaunch frequency is visible. Preserve bootstrap sweep output compatibility and FM_BOOTSTRAP_DETECT_ONLY behavior. Exit-status/exit-reason instrumentation was intentionally deferred - the notification lines and durable records are meant to reveal frequency first.

What Changed

  • Extract secondmate liveness probing and guarded relaunch into a shared library used by the bootstrap sweep and watcher, with per-mate locking and durable attempt records.
  • Add a cadence-gated watcher tick that relaunches only positively dead or missing endpoints, bounds spawn time and retry attempts, and emits check wakes for outcomes and a one-time escalation when a mate is parked.
  • Preserve remote routes on inconclusive or failed probes, and clear relaunch state when a secondmate is torn down.

Risk Assessment

🚨 High: The session-start path bypasses the required attempt limit, and ledger failures can also permit unbounded, unrecorded relaunches.

Testing

The sweep, watcher, remote-route and retirement checks passed against isolated test environments. A real named Herdr lab confirmed that an exited agent is classified dead while a live idle agent remains alive. The current gate prevented repeating a successful live spawn; no UI-facing surface changed, so no visual artifact was captured.

  • Live validation: ✅ go - 1 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A registered mate’s exited agent is distinguished from a live idle agent ✅ pass live tests/fm-backend-herdr-agent-exit-shell-e2e.test.sh ran in a named Herdr lab and tore it down
Ordinary supervision relaunches dead or missing mates, records attempts and emits one check wake per outcome ⏸️ untested no NO_MISTAKES_GATE blocks a fresh fleet spawn here. Repeating this scenario live requires an authorized isolated Herdr lab launch.
Ambiguous, unreadable and unreachable routes are preserved without relaunch or local failover ⏸️ untested no The adversarial transport failures were exercised through fixtures, not a live unreachable host. Provide an isolated authorized remote lab host to repeat them live.
Cadence, attempt parking, rearm and per-mate locking constrain watcher recovery ⏸️ untested no These cases used controlled endpoints rather than a running fleet; an authorized isolated lab is needed for live repetition.
Session-start recovery and detect-only behavior remain compatible, and retirement clears relaunch state ⏸️ untested no The lifecycle tests used isolated backend fixtures; an authorized isolated fleet lab is needed to repeat the full lifecycle live.
  • Outcome: 🔧 2 issues found → no changes applied ✅ across 2 runs (29m57s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 issues (1 error, 1 warning)
  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-secondmate-liveness-lib.sh:82 - If a mate's ledger is unwritable, the attempt append silently succeeds and relaunch proceeds at line 249; an unreadable ledger is counted as zero at line 92. A dead mate can therefore be relaunched on every watcher cadence without a durable record or effective bound. Fail closed on ledger read/write errors before killing or spawning.
  • ⚠️ bin/fm-teardown.sh:3671 - This ledger and park-marker cleanup runs only for local teardown: successful remote teardown exits at bin/fm-teardown.sh:1013-1015. Retire a flapping remote mate and register a new mate with the same ID within the window, and its first dead probe inherits the old attempts or park marker and may be incorrectly parked. Clear the per-mate relaunch state on successful remote retirement too.

🔧 Fix applied.
5 issues (3 errors, 2 warnings) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-secondmate-liveness-lib.sh:82 - If a mate's ledger is unwritable, the attempt append silently succeeds and relaunch proceeds at line 249; an unreadable ledger is counted as zero at line 92. A dead mate can therefore be relaunched on every watcher cadence without a durable record or effective bound. Fail closed on ledger read/write errors before killing or spawning.
  • ⚠️ bin/fm-teardown.sh:3671 - This ledger and park-marker cleanup runs only for local teardown: successful remote teardown exits at bin/fm-teardown.sh:1013-1015. Retire a flapping remote mate and register a new mate with the same ID within the window, and its first dead probe inherits the old attempts or park marker and may be incorrectly parked. Clear the per-mate relaunch state on successful remote retirement too.
  • 🚨 bin/fm-secondmate-liveness-lib.sh:258 - The round-1 fail-closed fix checks whether an attempt can be appended, but leaves the bootstrap sibling at bin/fm-bootstrap.sh:756 without a ledger read check. If an existing ledger is writable but unreadable, a dead mate is killed and spawned despite the explicit requirement to refuse either action when the ledger cannot be read. Check readability at the shared relaunch boundary before the attempt append or endpoint kill; the watcher already checks it at bin/fm-watch.sh:1028.
  • ⚠️ bin/fm-teardown.sh:988 - The round-1 remote-teardown fix introduced cleanup without coordinating with the liveness lock. A watcher can hold that lock while probing a dead remote mate; teardown can then retire the route and delete its ledger and lock at lines 988–990. The watcher can recreate a failed-attempt ledger for the retired ID, which a later same-ID mate inherits. Local teardown has the same lock-removal site at lines 3673–3676. Coordinate retirement and state cleanup with active liveness episodes without removing an owned lock.

🔧 Fix applied.
4 issues (3 errors, 1 warning) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-bootstrap.sh:200 - The criterion “Preserve ... FM_BOOTSTRAP_DETECT_ONLY behavior” is contradicted by the new unconditional library import: bin/fm-secondmate-liveness-lib.sh:57 sources fm-wake-lib.sh, whose line 16 runs mkdir -p "$STATE". A detect-only bootstrap with no state directory now creates one. Load the mutating dependency only when a sweep runs.
  • 🚨 bin/fm-watch.sh:1075 - The criterion “park a flapping mate with one escalation until a live probe rearms it” is not met: this branch removes only the park marker. If three attempts remain inside the hour, a live probe followed by another death immediately meets the unchanged count at bin/fm-watch.sh:1028 and parks again without attempting recovery. The new test at tests/fm-wake-queue.test.sh:2971 avoids this sequence by raising the limit to 10. Preserve the historical ledger while resetting the effective budget on a live rearm.
  • ⚠️ bin/fm-watch.sh:1055 - After a successful spawn, failure to append the check wake exits the watcher. On restart the endpoint probes alive, so that attempt's outcome is never queued or reported, contrary to “emit exactly one check wake per relaunch attempt outcome.” The failed-spawn branch at bin/fm-watch.sh:1068 and parked escalation at :1042 have the same lost-notification path. Making publication recoverable would require durable pending-delivery handling beyond this change; that remedy needs authorization.

🔧 Fix applied.
4 issues (3 errors, 1 warning) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-watch.sh:1075 - The criterion “park a flapping mate with one escalation until a live probe rearms it” is not met: this branch removes only the park marker. If three attempts remain inside the hour, a live probe followed by another death immediately meets the unchanged count at bin/fm-watch.sh:1028 and parks again without attempting recovery. The new test at tests/fm-wake-queue.test.sh:2971 avoids this sequence by raising the limit to 10. Preserve the historical ledger while resetting the effective budget on a live rearm.
  • ⚠️ bin/fm-watch.sh:1055 - After a successful spawn, failure to append the check wake exits the watcher. On restart the endpoint probes alive, so that attempt's outcome is never queued or reported, contrary to “emit exactly one check wake per relaunch attempt outcome.” The failed-spawn branch at bin/fm-watch.sh:1068 and parked escalation at :1042 have the same lost-notification path. Making publication recoverable would require durable pending-delivery handling beyond this change; that remedy needs authorization.
  • 🚨 bin/fm-watch.sh:1057 - With two registered mates whose endpoints are dead, the first relaunch calls wake, which exits the watcher (bin/fm-push-transition-lib.sh:88–110) before the loop reaches the second mate. The global cadence marker was already stamped at bin/fm-watch.sh:1008, so even a restarted watcher delays that mate's probe. The failure and parked-bound branches at bin/fm-watch.sh:1070 and :1048 exit the same way. This contradicts the required ordinary-supervision recovery for registered mates. Reporting every outcome while completing the tick needs a change to wake delivery or scheduling; authorize that remedy rather than retaining the early-exit path.

🔧 Fix applied.
5 issues (3 errors, 2 warnings) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-watch.sh:1075 - The criterion “park a flapping mate with one escalation until a live probe rearms it” is not met: this branch removes only the park marker. If three attempts remain inside the hour, a live probe followed by another death immediately meets the unchanged count at bin/fm-watch.sh:1028 and parks again without attempting recovery. The new test at tests/fm-wake-queue.test.sh:2971 avoids this sequence by raising the limit to 10. Preserve the historical ledger while resetting the effective budget on a live rearm.
  • ⚠️ bin/fm-watch.sh:1055 - After a successful spawn, failure to append the check wake exits the watcher. On restart the endpoint probes alive, so that attempt's outcome is never queued or reported, contrary to “emit exactly one check wake per relaunch attempt outcome.” The failed-spawn branch at bin/fm-watch.sh:1068 and parked escalation at :1042 have the same lost-notification path. Making publication recoverable would require durable pending-delivery handling beyond this change; that remedy needs authorization.
  • 🚨 bin/fm-watch.sh:1057 - With two registered mates whose endpoints are dead, the first relaunch calls wake, which exits the watcher (bin/fm-push-transition-lib.sh:88–110) before the loop reaches the second mate. The global cadence marker was already stamped at bin/fm-watch.sh:1008, so even a restarted watcher delays that mate's probe. The failure and parked-bound branches at bin/fm-watch.sh:1070 and :1048 exit the same way. This contradicts the required ordinary-supervision recovery for registered mates. Reporting every outcome while completing the tick needs a change to wake delivery or scheduling; authorize that remedy rather than retaining the early-exit path.
  • ⚠️ bin/fm-watch.sh:1030 - Round 4 deferred the captain-visible wake until after the loop, but left early returns inside it. If the first dead mate relaunches and queues its check row, then the next mate's ledger is unreadable, this return exits the watcher without printing the first recovery line or checking later mates. The same invariant is left behind at bin/fm-watch.sh:1036-1038 (bound-marker write), :1044-1047 (bound wake append), :1057 (success wake append), :1062-1065 (skipped relaunch), :1070 (failure wake append), :1077-1080 (rearm append), and :1082-1084 (marker removal). Preserve the pending wake and finish or explicitly handle the remaining mates on these error paths.

🔧 Fix applied.
7 issues (3 errors, 4 warnings) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-watch.sh:1075 - The criterion “park a flapping mate with one escalation until a live probe rearms it” is not met: this branch removes only the park marker. If three attempts remain inside the hour, a live probe followed by another death immediately meets the unchanged count at bin/fm-watch.sh:1028 and parks again without attempting recovery. The new test at tests/fm-wake-queue.test.sh:2971 avoids this sequence by raising the limit to 10. Preserve the historical ledger while resetting the effective budget on a live rearm.
  • ⚠️ bin/fm-watch.sh:1055 - After a successful spawn, failure to append the check wake exits the watcher. On restart the endpoint probes alive, so that attempt's outcome is never queued or reported, contrary to “emit exactly one check wake per relaunch attempt outcome.” The failed-spawn branch at bin/fm-watch.sh:1068 and parked escalation at :1042 have the same lost-notification path. Making publication recoverable would require durable pending-delivery handling beyond this change; that remedy needs authorization.
  • 🚨 bin/fm-watch.sh:1057 - With two registered mates whose endpoints are dead, the first relaunch calls wake, which exits the watcher (bin/fm-push-transition-lib.sh:88–110) before the loop reaches the second mate. The global cadence marker was already stamped at bin/fm-watch.sh:1008, so even a restarted watcher delays that mate's probe. The failure and parked-bound branches at bin/fm-watch.sh:1070 and :1048 exit the same way. This contradicts the required ordinary-supervision recovery for registered mates. Reporting every outcome while completing the tick needs a change to wake delivery or scheduling; authorize that remedy rather than retaining the early-exit path.
  • ⚠️ bin/fm-watch.sh:1030 - Round 4 deferred the captain-visible wake until after the loop, but left early returns inside it. If the first dead mate relaunches and queues its check row, then the next mate's ledger is unreadable, this return exits the watcher without printing the first recovery line or checking later mates. The same invariant is left behind at bin/fm-watch.sh:1036-1038 (bound-marker write), :1044-1047 (bound wake append), :1057 (success wake append), :1062-1065 (skipped relaunch), :1070 (failure wake append), :1077-1080 (rearm append), and :1082-1084 (marker removal). Preserve the pending wake and finish or explicitly handle the remaining mates on these error paths.
  • ⚠️ bin/fm-watch.sh:1069 - Round 5 introduced this path while preserving the pending wake. If appending the first mate’s check row fails, first_reason is still set; after scanning the remaining mates, wake prints that unqueued outcome and exits 0, hiding the failure. The same path applies to relaunch success, relaunch failure, and bound escalation at lines 1034–1045. Set the wake reason only for a successfully queued or already-present row, while retaining the error when no row was queued.
  • ⚠️ bin/fm-teardown.sh:1001 - The earlier fix-round teardown cleanup treats a busy liveness lock as successful retirement and leaves both the ledger and park marker. A subsequent secondmate registered with the same ID inherits the old marker and can remain parked despite its own dead endpoint. Both remote teardown at line 989 and local teardown at line 3687 use this helper. Make retirement report incomplete cleanup for retry, or serialize cleanup before reporting teardown complete.

🔧 Fix applied.
7 issues (3 errors, 4 warnings) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • 🚨 bin/fm-watch.sh:1075 - The criterion “park a flapping mate with one escalation until a live probe rearms it” is not met: this branch removes only the park marker. If three attempts remain inside the hour, a live probe followed by another death immediately meets the unchanged count at bin/fm-watch.sh:1028 and parks again without attempting recovery. The new test at tests/fm-wake-queue.test.sh:2971 avoids this sequence by raising the limit to 10. Preserve the historical ledger while resetting the effective budget on a live rearm.
  • ⚠️ bin/fm-watch.sh:1055 - After a successful spawn, failure to append the check wake exits the watcher. On restart the endpoint probes alive, so that attempt's outcome is never queued or reported, contrary to “emit exactly one check wake per relaunch attempt outcome.” The failed-spawn branch at bin/fm-watch.sh:1068 and parked escalation at :1042 have the same lost-notification path. Making publication recoverable would require durable pending-delivery handling beyond this change; that remedy needs authorization.
  • 🚨 bin/fm-watch.sh:1057 - With two registered mates whose endpoints are dead, the first relaunch calls wake, which exits the watcher (bin/fm-push-transition-lib.sh:88–110) before the loop reaches the second mate. The global cadence marker was already stamped at bin/fm-watch.sh:1008, so even a restarted watcher delays that mate's probe. The failure and parked-bound branches at bin/fm-watch.sh:1070 and :1048 exit the same way. This contradicts the required ordinary-supervision recovery for registered mates. Reporting every outcome while completing the tick needs a change to wake delivery or scheduling; authorize that remedy rather than retaining the early-exit path.
  • ⚠️ bin/fm-watch.sh:1030 - Round 4 deferred the captain-visible wake until after the loop, but left early returns inside it. If the first dead mate relaunches and queues its check row, then the next mate's ledger is unreadable, this return exits the watcher without printing the first recovery line or checking later mates. The same invariant is left behind at bin/fm-watch.sh:1036-1038 (bound-marker write), :1044-1047 (bound wake append), :1057 (success wake append), :1062-1065 (skipped relaunch), :1070 (failure wake append), :1077-1080 (rearm append), and :1082-1084 (marker removal). Preserve the pending wake and finish or explicitly handle the remaining mates on these error paths.
  • ⚠️ bin/fm-watch.sh:1069 - Round 5 introduced this path while preserving the pending wake. If appending the first mate’s check row fails, first_reason is still set; after scanning the remaining mates, wake prints that unqueued outcome and exits 0, hiding the failure. The same path applies to relaunch success, relaunch failure, and bound escalation at lines 1034–1045. Set the wake reason only for a successfully queued or already-present row, while retaining the error when no row was queued.
  • ⚠️ bin/fm-watch.sh:1063 - Round 7 made teardown hold the per-mate liveness lock through retirement, but left wake publication outside that lock. After a relaunch, the watcher can unlock; teardown can then remove the mate's route and ledger; and the watcher can append a check wake for the retired mate. The same gap affects failed-relaunch and parked-bound wakes at lines 1032–1045. Queue each outcome while the liveness lock is still held so retirement cannot finish before publication.

🔧 Fix applied.
2 issues (1 error, 1 warning) still open:

  • 🚨 bin/fm-bootstrap.sh:756 - The intent requires a bound on total attempts per mate per window and parking until a live probe rearms the mate. The changed sweep relaunches every dead or missing mate without checking the ledger or park marker; only the watcher checks them at bin/fm-watch.sh:1024-1045. After three watcher attempts park a flapping mate, a session-start sweep can relaunch it while it is still dead, bypassing the bound. Enforce the shared limit before either driver acts on a relaunchable verdict.
  • ⚠️ bin/fm-watch.sh:1055 - After a successful spawn, failure to append the check wake exits the watcher. On restart the endpoint probes alive, so that attempt's outcome is never queued or reported, contrary to “emit exactly one check wake per relaunch attempt outcome.” The failed-spawn branch at bin/fm-watch.sh:1068 and parked escalation at :1042 have the same lost-notification path. Making publication recoverable would require durable pending-delivery handling beyond this change; that remedy needs authorization.
🔧 **Test** - 2 issues found → no changes applied ✅
  • ⚠️ The live watcher correctly detected a missing Herdr secondmate and published one failure wake, but NO_MISTAKES_GATE refused the spawn. A live successful-relaunch demonstration requires an authorized environment where that fleet-spawn guard permits an isolated lab launch.
  • ⚠️ live validation verdict: inconclusive (2 of 5 scenarios were driven live against the product); untested: Ordinary supervision successfully relaunches a dead or missing mate and preserves its route, Inconclusive or unreachable endpoints remain untouched, while cadence, attempt parking, and live rearm constrain recovery, Session-start recovery remains compatible, detect-only stays read-only, and retirement clears relaunch state
  • Live validation: ⚠️ inconclusive - 2 of 5 scenarios driven live against the product
Scenario Result Live Evidence
An exited Herdr agent is classified dead while a live idle agent remains alive ✅ pass live tests/fm-backend-herdr-agent-exit-shell-e2e.test.sh drove real Pi panes in a guarded Herdr lab.
Ordinary supervision detects a missing registered mate and reports a failed relaunch exactly once ✅ pass live live-watch-transcript.log shows the captain line, one queued check row, and an attempt/failure ledger in the guarded Herdr lab.
Ordinary supervision successfully relaunches a dead or missing mate and preserves its route ⏸️ untested no NO_MISTAKES_GATE forbids the fleet spawn in this process. Provide an authorized isolated lab execution context that permits the guarded spawn.
Inconclusive or unreachable endpoints remain untouched, while cadence, attempt parking, and live rearm constrain recovery ⏸️ untested no These watcher paths were not driven with live endpoints in this run; provide an authorized isolated lab execution context for lifecycle spawns and controllable endpoint failures.
Session-start recovery remains compatible, detect-only stays read-only, and retirement clears relaunch state ⏸️ untested no Live recovery spawning is blocked by NO_MISTAKES_GATE; provide an authorized isolated lab execution context that permits it.
  • tests/fm-secondmate-liveness.test.sh
  • tests/fm-wake-queue.test.sh
  • tests/fm-remote-secondmate-lifecycle-e2e.test.sh
  • tests/fm-secondmate-lifecycle-e2e.test.sh
  • tests/fm-backend-herdr-agent-exit-shell-e2e.test.sh in a guarded Herdr lab
  • bash ~/.no-mistakes/evidence/01M38TF2KZXC1QXX3WV5GG523P/live-watch-lab.sh against a guarded, non-default Herdr session

🔧 No changes applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 1 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A registered mate’s exited agent is distinguished from a live idle agent ✅ pass live tests/fm-backend-herdr-agent-exit-shell-e2e.test.sh ran in a named Herdr lab and tore it down
Ordinary supervision relaunches dead or missing mates, records attempts and emits one check wake per outcome ⏸️ untested no NO_MISTAKES_GATE blocks a fresh fleet spawn here. Repeating this scenario live requires an authorized isolated Herdr lab launch.
Ambiguous, unreadable and unreachable routes are preserved without relaunch or local failover ⏸️ untested no The adversarial transport failures were exercised through fixtures, not a live unreachable host. Provide an isolated authorized remote lab host to repeat them live.
Cadence, attempt parking, rearm and per-mate locking constrain watcher recovery ⏸️ untested no These cases used controlled endpoints rather than a running fleet; an authorized isolated lab is needed for live repetition.
Session-start recovery and detect-only behavior remain compatible, and retirement clears relaunch state ⏸️ untested no The lifecycle tests used isolated backend fixtures; an authorized isolated fleet lab is needed to repeat the full lifecycle live.
  • tests/fm-secondmate-liveness.test.sh
  • tests/fm-wake-queue.test.sh
  • tests/fm-remote-secondmate-lifecycle-e2e.test.sh
  • tests/fm-secondmate-lifecycle-e2e.test.sh
  • tests/fm-backend-herdr-agent-exit-shell-e2e.test.sh
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

…supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.
…liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally
…tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass
…legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
@kunchenguid

Copy link
Copy Markdown
Owner Author

Live validation results (disposable Herdr session fm-lab-liveval-63043-16676, disposable FM_HOME, HERDR_SESSION pinned to the lab on every command; fm-remote/default session/real homes untouched; lab torn down after):

Scenario 1 - ordinary supervision relaunch: PASS. Killed the mate's agent -> one check: secondmate labmate auto-relaunched after confirmed agent absence on existing endpoint (backend=herdr) line, attempt+relaunched ledger pair, new pane w2:p2 in the lab session. Closed the workspace entirely -> ...recorded endpoint confidently missing..., second attempt+relaunched pair, w3:p2. Route preserved in-session throughout; the earlier isolated demo additionally showed three consecutive relaunches.

Scenario 2 - safety states: PASS. Remote mate rsm1 registered against a scripted stub ssh. Replies ambiguous (rc 0), empty+rc 1 (unreadable), and empty+rc 255 (unreachable) each produced exactly one read-only state call and nothing else: no ledger file, no wake, no relaunch, no local failover endpoint (lab workspace count unchanged).

Scenario 3 - cadence, budget, rearm, locking: PASS. Gated leg (FM_SECONDMATE_LIVENESS_SECS=3600, fresh tick marker) left the dead mate untouched. Fourth death after three attempts emitted the park line auto-relaunch paused after 3 attempts in 3600s plus the bound marker, no fourth attempt. After a manual respawn was probed alive, the tick wrote rearmed, cleared the marker, and the next death relaunched again (budget restored). With .secondmate-liveness-labmate.lock held by a live pid, ticks skipped the mate silently - no probe side effects.

Scenario 4 - session-start, detect-only, retirement: PASS. FM_BOOTSTRAP_NETWORK=only fm-bootstrap.sh relaunched the dead mate (BOOTSTRAP_INFO line, attempt+relaunched, w6:p2). FM_BOOTSTRAP_DETECT_ONLY=1 printed nothing, made no ssh call, and left state/ byte-identical - fully read-only. fm-teardown.sh labmate removed the relaunch ledger, meta, and registry entry.

Full evidence: data/fm-secondmate-auto-relaunch-r1/live-validation.md in the task home. No defect found; no code changed.

@kunchenguid
kunchenguid merged commit d1ce6b6 into main Sep 24, 2026
19 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-secondmate-auto-relaunch-r1 branch September 24, 2026 16:27
mituso89 pushed a commit to mituso89/firstmate that referenced this pull request Sep 26, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
RooseveltAdvisors pushed a commit to RooseveltAdvisors/firstmate that referenced this pull request Sep 29, 2026
)

* feat(bin): auto-relaunch dead persistent secondmates during ordinary supervision

A persistent secondmate whose primary agent exits mid-session previously
stayed down until the next session-start liveness sweep. Extract the
sweep's probe/classify/relaunch mechanics into a shared library and drive
the same contract from a cadence-gated watcher tick, so a positively dead
or missing endpoint is relaunched through the guarded spawn path within a
poll cycle instead of an hour later.

Only the recovery-grade `dead` and `missing` verdicts authorize relaunch;
ambiguous, unreadable, unverified, and unreachable-remote reads stay
fail-closed and a remote route is never replaced by a local endpoint.
Each relaunch emits exactly one `check` wake and appends to a durable
per-mate ledger; a mate exceeding the bounded attempt budget is parked
behind a marker until a live probe rearms it. A per-mate liveness lock
serializes the tick against a concurrent session-start sweep.

* no-mistakes(review): Fail closed on relaunch ledger errors; clear state on remote teardown

* no-mistakes(review): Share ledger read guard; retire relaunch state under liveness lock

* no-mistakes(review): Lazy-load wake lib; live rearm restores full relaunch budget

* no-mistakes(review): Finish liveness tick for every mate before waking once

* no-mistakes(review): Keep liveness tick scanning past per-mate errors, then wake

* no-mistakes(review): Wake only on queued rows; teardown holds liveness lock

* no-mistakes(review): Queue liveness outcome wake before releasing mate lock

* no-mistakes(document): Update secondmate liveness documentation for mid-session recovery

* no-mistakes(lint): Fix empty assignments flagged by ShellCheck

* no-mistakes(ci): Added ShellCheck analysis boundaries for the shared liveness library in both callers and marked its result globals as intentional library outputs. Changed-file lint passed; full CI partitions were not run locally

* no-mistakes(ci): Fixed Lint 2 by removing an unused test variable in tests/fm-wake-queue.test.sh. ShellCheck, bash syntax, and the full wake-queue test script pass

* no-mistakes(ci): Fixed the CI wake-queue fixture: stall-only watcher legs now seed the liveness cadence marker, preventing the new endpoint probe from interfering with their assertions. The full wake-queue test, ShellCheck, and diff checks pass locally
nikzorz added a commit to nikzorz/firstmate that referenced this pull request Oct 4, 2026
* fix(bin): bound the startup-network worker's lock waits by its budget (#5528)

* fix(bin): bound the startup-network worker's lock waits by its budget

Fixes #5377

The deferred startup network worker bounded its sweeps with a stage budget but
took the publish lock and the fleet-lock lease with an unbounded wait, so a live
holder of that lock kept the detached worker alive for hours past its timeout
with its output discarded at the end. Every wait now goes through the bounded
acquire and shares the remaining stage or