Skip to content

fix(bin): keep a take-over following a watcher whose TERM lands late - #6916

Open
arthurcruzd wants to merge 1 commit into
kunchenguid:mainfrom
arthurcruzd:fm/fm-host-takeover-resurface
Open

arthurcruzd wants to merge 1 commit into
kunchenguid:mainfrom
arthurcruzd:fm/fm-host-takeover-resurface

Conversation

@arthurcruzd

Copy link
Copy Markdown
Contributor

Intent

Fix the Firstmate bug behind the supervision wake loop seen on a secondmate home on 2026-10-08, so the supervision host can be turned back on.

Context (from the affected home's report, copied in full to data/fm-host-takeover-resurface/mac-loop-report.md in the firstmate home): with the supervision host on, every turn end of that home's Claude session produced a new empty check: rearm-resurface wake that the host passed back to main, so each handled wake ended a turn that produced the next one, indefinitely (one model turn per loop, roughly every 25 seconds). Code at 19fcbbd, which already includes 3c58ec8 (#6787). Observed sequence: a watcher delivers check: rearm-resurface; the host passes it through and leaves a successor arm in its own process group; at the next turn end a new host logs take-over arm=<pid>; the taken-over watcher then exits signal=TERM reason=signal-exit, and the taking arm's ledger row is origin=attached ... reason=attached-cycle-ended (in a later repeat, reason=taken-over), so the handover restore in take_over_cycle (bin/fm-watch-arm.sh) appears not to run or to run without effect; .watcher-down is left as downtime (announced:handling:<gen>, later acked:handling:<gen>), and the next fresh cycle immediately resurfaces check: rearm-resurface within 1-2 s. Two sibling homes on the same machine and code were not looping. The loop began within about two minutes of a live Herdr server handoff on that machine (herdr --remote <host> --session fm-remote --handoff), which may be the initiating trigger. The interim mitigation is config/supervision-host-off set fleet-wide.

What Changed

  • --take-over no longer abandons a watcher that outlives the five-second TERM wait: it follows that cycle as an attached arm until the watcher exits or its beacon hits the stall bound, then applies the existing handover restore instead of leaving downtime.
  • A watcher that dies of any signal other than the take-over TERM still leaves downtime that resurfaces as check: rearm-resurface.
  • Adds a take-over test for a late-landing TERM (held with SIGSTOP until CONT) and the genuine-outage path, and updates watcher-continuity docs to match.

Risk Assessment

✅ Low: Well-bounded take-over wait so a late TERM still runs handover restore, with a behavioral regression covering both the quiet restore and a genuine outage.

Testing

Drove the real watch-arm take-over path in disposable marked lab homes: a watcher that held TERM past the five-second wait was followed, its acknowledged handling episode was restored (same .watcher-down generation, ledger reason=taken-over with a started successor, no empty check: rearm-resurface), a held watcher killed by SIGKILL still resurfaced recovery, and a prompt TERM take-over stayed quiet. The matching take-over regressions in fm-watch-arm.test.sh also passed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Late-TERM take-over of an acknowledged episode stays quiet (no empty check: rearm-resurface) ✅ pass live ~/.no-mistakes/evidence/01M4EZQTAXYDFBF6C3DDB7GFQ0/live-transcript.txt
Held watcher killed by another signal still resurfaces a genuine outage ✅ pass live ~/.no-mistakes/evidence/01M4EZQTAXYDFBF6C3DDB7GFQ0/late-term-genuine-outage/take-over.out
Prompt-TERM take-over of an acknowledged episode stays quiet ✅ pass live ~/.no-mistakes/evidence/01M4EZQTAXYDFBF6C3DDB7GFQ0/prompt-term-restore/take-over.out
Evidence: Live take-over transcript (stdout, watcher-down, cycle ledger)

Source: Live take-over transcript (stdout, watcher-down, cycle ledger)

Live product drive of bin/fm-watch-arm.sh --take-over in marked fm-lab homes
Reproduction: SIGSTOP holds TERM past the five-second wait (portable stand-in
for stock macOS bash 3.2 holding TERM until a command substitution exits).

=== Scenario: late-TERM take-over restores acknowledged episode ===
-- take-over stdout --
watcher: attached pid=3982206 (beacon 7s)
watcher: started pid=3986537 (beacon fresh)
-- .watcher-down before/after (same acked generation; no downtime) --
before: acked:handling:3982759.1791505590.QSvJ8N
after:  acked:handling:3982759.1791505590.QSvJ8N
-- cycle ledger (TERM then taken-over -> started successor) --
arm_pid=3982183	watcher_pid=3982206	origin=started	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=7	successor=none
arm_pid=3984411	watcher_pid=3982206	origin=attached	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=7	successor=started:3986537

=== Scenario: held watcher killed by another signal resurfaces ===
-- take-over stdout --
watcher: attached pid=3988066 (beacon 7s)
watcher: started pid=3991191 (beacon fresh)
check: rearm-resurface

=== Scenario: prompt-TERM take-over stays quiet ===
-- take-over stdout --
watcher: started pid=3994043 (beacon fresh)
-- .watcher-down before/after --
before: acked:handling:3992515.1791505615.xKZC6A
after:  acked:handling:3992515.1791505615.xKZC6A

=== Focused regression (tests/fm-watch-arm.test.sh take-over cases) ===
ok - watch-arm: --take-over owns a fresh cycle without a recovery wake and still surfaces queued work
ok - watch-arm: takeover preserves self-exit downtime and surfaces a recovery wake
ok - watch-arm: --take-over restores a stop whose TERM lands late and still resurfaces a genuine outage
Evidence: Live scenario results

Source: Live scenario results

PASS late-term-restore: followed held TERM, restored acked episode, no rearm-resurface; down=acked:handling:3982759.1791505590.QSvJ8N PASS late-term-genuine-outage: genuine outage (KILL while held) resurfaced as check: rearm-resurface PASS prompt-term-restore: prompt TERM restored acked episode, no rearm-resurface; down=acked:handling:3992515.1791505615.xKZC6A

PASS late-term-restore: followed held TERM, restored acked episode, no rearm-resurface; down=acked:handling:3982759.1791505590.QSvJ8N
PASS late-term-genuine-outage: genuine outage (KILL while held) resurfaced as check: rearm-resurface
PASS prompt-term-restore: prompt TERM restored acked episode, no rearm-resurface; down=acked:handling:3992515.1791505615.xKZC6A
Evidence: Late-TERM take-over stdout (attached then started, no rearm-resurface)

Source: Late-TERM take-over stdout (attached then started, no rearm-resurface)

watcher: attached pid=3982206 (beacon 7s) watcher: started pid=3986537 (beacon fresh)

watcher: attached pid=3982206 (beacon 7s)
watcher: started pid=3986537 (beacon fresh)
Evidence: Genuine-outage take-over stdout (check: rearm-resurface)

Source: Genuine-outage take-over stdout (check: rearm-resurface)

watcher: attached pid=3988066 (beacon 7s) watcher: started pid=3991191 (beacon fresh) check: rearm-resurface

watcher: attached pid=3988066 (beacon 7s)
watcher: started pid=3991191 (beacon fresh)
check: rearm-resurface

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Late-TERM take-over of an acknowledged episode stays quiet (no empty check: rearm-resurface) ✅ pass live ~/.no-mistakes/evidence/01M4EZQTAXYDFBF6C3DDB7GFQ0/live-transcript.txt
Held watcher killed by another signal still resurfaces a genuine outage ✅ pass live ~/.no-mistakes/evidence/01M4EZQTAXYDFBF6C3DDB7GFQ0/late-term-genuine-outage/take-over.out
Prompt-TERM take-over of an acknowledged episode stays quiet ✅ pass live ~/.no-mistakes/evidence/01M4EZQTAXYDFBF6C3DDB7GFQ0/prompt-term-restore/take-over.out
  • Live bin/fm-watch-arm.sh --take-over in marked bin/fm-lab-home.sh homes with SIGSTOP holding TERM past the five-second wait, then SIGCONT so the pending TERM lands
  • Adversarial live take-over of a held watcher killed with SIGKILL, expecting check: rearm-resurface
  • Live prompt-TERM --take-over of an acknowledged episode staying quiet on the same acked generation
  • Focused take-over cases from tests/fm-watch-arm.test.sh: test_take_over_owns_a_fresh_cycle_and_keeps_queued_work_surfacing, test_take_over_preserves_downtime_from_watcher_self_exit, test_take_over_restores_a_stop_whose_term_lands_late
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

A supervision-host take-over stopped the left successor's watcher and
waited only five seconds for it to exit. A shell that holds the TERM past
that wait (stock macOS bash 3.2 holds it until a running command
substitution exits, such as the watcher's Herdr event wait) let the
take-over fall back to a plain attach. The watcher then died of that
TERM, published downtime over main's acknowledged episode with no
handover restore, the attached arm found no successor and failed, and the
owner's fresh cycle resurfaced an empty check: rearm-resurface on every
turn end.

The take-over now keeps following the stopped cycle until it exits or its
beacon reaches the stall bound, then applies the existing handover
restore. A watcher that dies of anything else still leaves downtime that
resurfaces.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (OSS triage, not the captain).

Thanks @arthurcruzd. Head 1b4c26c7 against main 19fcbbde.

Contract-class: restore. Main's --take-over already waits ~5s for TERM then abandons if the watcher is still alive, leaving downtime that resurfaces as an empty recovery loop. Stock macOS bash 3.2 can hold TERM until a command substitution exits. The tip follows the stopped watcher (attached) until exit or stall bound, then restores the stop — the existing take-over continuity promise, repaired. A held watcher killed by another signal still resurfaces.

VISION.md: One captain / Authority / Scripts / Restart / Delegation / Vendor / Scope: all align (watcher continuity only).

Security: no workflows/secrets/network. Approved: 37865427548 (CI), 37865427809 (Require no-mistakes). Attestation MATCH. Outcome: waiting-ci. Auto-merge candidate as restore when green and CLEAN.

arthurcruzd added a commit to arthurcruzd/firstmate that referenced this pull request Oct 19, 2026
Sync the fleet branch with kunchenguid/firstmate main at 45dd50a.

Remote convergence and re-read handling (bootstrap, config push, remote
inheritance push, the nudge library, and their tests) take main's kunchenguid#7394
version; the fleet's t3code-instances inherited item stays in the
inheritable config list. The fleet's native T3 interrupt, exit, and
relaunch paths are kept alongside main's polytoken additions, and the
fleet's carried change from kunchenguid#6916 merged without
conflict.
arthurcruzd added a commit to arthurcruzd/firstmate that referenced this pull request Oct 28, 2026
Bring the fork's fleet branch up to upstream main, keeping the fleet-only
work upstream has not merged.

Upstream's explicit-only T3 Code backend (kunchenguid#7518) is the base for every T3
file; the fleet's earlier copy of that PR is superseded by it, along with
its own semantic-supervision push (upstream's pending-request watch), the
T3 capture, telemetry, interrupt-verdict, and launch-ownership fixes, and
the Claude env-channel ownership (upstream's FM_T3CODE_ENV_KEYS). On top of
it the fleet keeps: the T3-hosted primary and its wake relay
(bin/fm-t3-host.sh), remote second mates on a host's T3 server, quiet and
away mode and the supervision host under the relay, Grok and Muse T3
workers, exit by archive with a relaunch that resumes the same thread,
restart reconciliation, the foreign-slot refusal, local-interface
telemetry, and the T3 0.1.2 standard-scope sign-in.

Also kept: the open contributions for supervisor noise (kunchenguid#7726), one
launch-failed wake per outage (kunchenguid#7386), status-file birth times (kunchenguid#7384), the
take-over watcher TERM fix (kunchenguid#6916), and the fleet-only second-mate
reply-source and CI commits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants