Skip to content

Keep second mates running when a restart races the liveness check - #42

Merged
jjtylr merged 1 commit into
mainfrom
fm/fm-supervisor-clear-restart-fix
Nov 27, 2026
Merged

jjtylr merged 1 commit into
mainfrom
fm/fm-supervisor-clear-restart-fix

Conversation

@jjtylr

@jjtylr jjtylr commented Nov 27, 2026

Copy link
Copy Markdown
Owner

What broke

On 27 Nov the second mate restart left a mate with no agent twice: dpz under the supervisor clear policy (#40) at 16:30Z, and ui under the ordinary update restart at 17:01Z.

Cause: between the old agent's exit and the replacement's start, a mate's endpoint reads exactly like a dead mate.
The watcher's secondmate liveness tick probed it in that window, got dead, killed the endpoint (fm_backend_kill) under the restart, and then its own respawn was refused by the restart's spawn lock (another spawn is already creating task dpz).
The restart then could not confirm its replacement (its endpoint was gone; for ui, pane wW5:p2 not found) and reported an unknown outcome, so neither side relaunched the mate.
The restart never took the per-mate liveness lock that already serializes the watcher tick, the session-start sweep, alert wakes, and teardown.

The sync skipped before launch warning was not a cause: fm-spawn carries on past it, but fm-secondmate-restart.sh reported the first line of the relaunch output as the reason, and that line was the warning.

Fix

  • bin/fm-control.sh relaunch of a secondmate holds state/.secondmate-liveness-<id>.lock from before anything is touched to the end of the transaction, so liveness recovery skips the mate instead of killing it mid-launch. If another recovery still holds it after FM_CONTROL_LIVENESS_WAIT (180s), the relaunch refuses with nothing changed.
  • bin/fm-secondmate-restart.sh holds this home's liveness lock across a remote mate's host-local relaunch, since the host's transaction holds only the host's lock.
  • After a relaunch that did not complete, fm-secondmate-restart.sh probes the mate under its liveness lock. A live mate is reported as failed: <id>: ... the mate is still running. A dead or missing one gets the liveness library's guarded recovery launch, pinned to the recorded harness, model, and effort under --keep-profile, and is reported failed: ... a fresh agent was started in its place and is running once a probe reads it alive within FM_SECONDMATE_RECOVER_WAIT (90s). unreached now means no running agent could be confirmed. The summary gains a failed count, and exit 3 covers it.
  • The reported reason is the relaunch's first error: line, never a warning: line.
  • fm_secondmate_liveness_relaunch takes optional extra spawn args (used for the profile pin). fm-supervisor-clear.sh logs a failed: line as restart-failed. The /updatefirstmate skill lists the new outcome.

Tests

New, in tests/fm-secondmate-restart.test.sh:

  • T18 reproduces the incident: the restart's own replacement comes up with no agent, and the relaunch output starts with the real sync-skip warning. The mate is recovered on its recorded profile (with a moved config pin), the report is failed with the real error, and the warning is never the reason.
  • T19 runs the watcher's liveness-lock acquisition during the restart's launch. It must be refused. Without the fm-control.sh change this test fails (raced).

Changed: T5 (a pre-stop refusal is now failed ... still running) and T11 (a stopped mate gets a recovery launch, and is still unreached when that does not come up either). The tmux stand-in now models kill-window and new-window.
tests/fm-supervisor-clear.test.sh adds a case for a failed: outcome being logged as a failure, not a restart.

Run: tests/fm-secondmate-restart.test.sh, tests/fm-supervisor-clear.test.sh, tests/fm-secondmate-liveness.test.sh, tests/fm-alert-wake.test.sh, tests/fm-control-relaunch.test.sh: all pass. bin/fm-doc-audience-check.sh: ok.
bin/fm-lint.sh reports nothing in the changed files. It exits 1 only on three existing findings in tests/fm-daemon.test.sh, which this branch does not touch; bin/fm-lint.sh tests/fm-daemon.test.sh reports the same three on its own.
All reproduction used stand-ins. No live second mate or main was touched, and there was no Herdr lab run.

Rollout

Main's config/supervisor-clear is off until this lands; main removes it after the merge.

A restart left a mate's endpoint briefly agentless between the old agent's
exit and the replacement's start; the watcher's liveness tick read that as a
dead mate, killed the endpoint under the restart, then collided with the
restart's spawn lock and gave up, leaving the mate with no agent.

- fm-control relaunch of a secondmate holds the mate's liveness lock for the
  whole transaction, so liveness recovery skips it; the remote restart holds
  this home's lock across the host-local relaunch.
- fm-secondmate-restart recovers a mate whose restart failed with no agent,
  through the liveness library's guarded launch on the recorded profile, and
  reports it as failed with the mate's running state; unreached now means no
  running agent was confirmed.
- The reported reason is the relaunch's first error line, never a warning
  printed on the way such as a skipped pre-launch home sync.
@jjtylr
jjtylr merged commit a23e8c3 into main Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant