Skip to content

feat(bin): add per-station idle-window gate for herdr/firstmate updates - #72

Merged
adibirzu merged 3 commits into
mainfrom
fm/fm-station-idle-gate
Sep 13, 2026
Merged

adibirzu merged 3 commits into
mainfrom
fm/fm-station-idle-gate

Conversation

@adibirzu

Copy link
Copy Markdown
Owner

Intent

The captain, 2026-09-13, answering the fleet-stations-onboarding scout report: "adi2 herdr 0.8.2: yes, only through the idle gate. Ship the section-5 idle-window gate as a real process-event watch per remote host (zero in-flight tasks and no live worker pane for N minutes -> wake firstmate with the exact update command), and run adi2's update through it; also add adi1 and adi3 to the gate for firstmate fast-forwards. Report the PR URL." He also set the standing rule that herdr/firstmate updates on a station run only when its tasks are finished, never mid-run.

The referenced section 5 is a host-wide idle-window gate. It is a read-only per-station probe that treats a station as update-safe only when every firstmate home on that host has zero in-flight tasks and the host reports no live or working worker pane; it stays silent unless the whole host is idle, and it wakes firstmate with that station's update command when it is. It is registered per station (adi1, adi2, adi3) so firstmate makes the update decision at wake time; the disruptive update itself is never bound to the condition. Once a station reports idle the sequence is: re-verify the probe, update herdr on that host (which stops every pane there), fast-forward firstmate, restart the secondmates that live on that host, then verify. adi2 needs herdr 0.7.4 -> 0.8.2, while adi1, adi3, and the mini are already current. This task only builds and registers the gate; it does not run adi2's actual herdr update.

What Changed

  • Added bin/fm-station-idle.sh, a read-only per-station probe that reports a station as update-safe (station-idle: <station>) only when every firstmate home on that host has zero in-flight tasks, no live task endpoints, and herdr reports no working/blocked session, staying silent until the whole host has been continuously idle for FM_STATION_IDLE_WINDOW seconds; supports arm/disarm to register/retire the probe as a watcher check per station.
  • Extracted the shared trusted-shim write/backup/register/rollback logic out of bin/fm-tool-update-check.sh into a new bin/fm-check-shim-lib.sh (fm_check_shim_install), and switched fm-tool-update-check.sh's action_arm to use it instead of its own duplicated implementation.
  • Added tests/fm-station-idle.test.sh covering the new probe, and documented the gate, its config knobs (FM_STATION_*), the arm/disarm usage, and the per-station idle-window update sequence in docs/configuration.md, docs/remote-secondmates.md, docs/scripts.md, and AGENTS.md.

Risk Assessment

✅ Low: The change is a self-contained, read-only probe plus a mechanical extraction of an existing shim-install contract into a shared helper; every read path fails closed (unanswered/ambiguous reads are treated as busy, never idle), all remote inputs are validated before use in SSH argv, the shared shim-install helper is a faithful behavior-preserving refactor of the pre-existing fm-tool-update-check.sh logic, and the new test suite exercises real executable behavior against PATH stubs rather than asserting on source text; the change explicitly does not perform any disruptive update, matching the stated intent.

Testing

Drove the idle-window gate live via its real CLI (arm/disarm, check, remote resolution, adversarial malformed-registry and invalid-station-name inputs) plus ran the feature's own and the refactored fm-tool-update-check.sh test suites end-to-end; everything passed with no regressions, matching the documented scope of building/registering the gate without touching adi2's actual update.

  • Live validation: ✅ go - 10 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Idle station reports its one-line wake exactly once, then goes silent (no-nag) ✅ pass live Manual CLI run + test_idle_station_reports_its_one_line: station-idle: local printed once, second immediate probe silent
A station with in-flight work never reports idle (captain rule: never update mid-run) ✅ pass live Manual CLI run with tasks-axi stubbed to count: 2 produced no output, exit 0; corroborated by test_in_flight_work_keeps_the_station_silent
A working/blocked herdr agent or a live recorded task endpoint anywhere on the host keeps the whole station silent ✅ pass live test_a_working_or_blocked_pane_keeps_the_station_silent and test_a_live_recorded_endpoint_keeps_the_station_silent, both passing in the live bash tests/fm-station-idle.test.sh run
An unanswered read (herdr/tasks-axi/crew-state failure) is never mistaken for idle ✅ pass live test_an_unanswered_read_is_never_read_as_idle passing
arm &lt;station&gt; writes a 0700 trust-bound shim and registers it; running the shim probes the right station; disarm removes shim, trust binding, and idle record ✅ pass live Manual CLI run: armed: state/station-idle-adi1.check.sh, verified mode 700 shim content, ran shim directly, then disarmed: output with all three artifacts gone; corroborated by `test_arm_registers…
A remote station (e.g. adi2) is probed only through its own registered host alias (adi2-ts), never another station's home ✅ pass live Manual CLI run with an SSH-argv-logging stub showed only adi2-ts reached, matching test_remote_station_resolves_its_host_and_ignores_other_homes
A remote station with no registered home yet (e.g. not-yet-onboarded adi3) is still probed host-wide via herdr only ✅ pass live test_a_remote_station_with_no_home_is_probed_host_wide passing live
Adversarial: a malformed/path-traversal registry record is rejected rather than followed as a remote target ✅ pass live Manual CLI run: injected home: ~/../../etc record; probe continued to correctly report the real local home's idle state without following the malicious path (secondmate_target_paths_safe gua…
Adversarial: an invalid station name is refused (exit 2 + usage), not silently accepted or treated as a valid host ✅ pass live Manual CLI run: bad;name and ../etc both refused with exit 2; test_invalid_use_refuses passing
An armed station-idle check reaches the real watcher (fm-watch-checkpoint.sh) as a check: wake carrying the station-idle line ✅ pass live test_armed_check_wakes_the_watcher_with_the_idle_line passed on 3 separate live runs of the real watcher/register/shim stack; a manual ad-hoc repro outside the test harness instead hit an unrelated…
adi2's actual herdr 0.7.4->0.8.2 update is executed through the gate ⏸️ untested no Explicitly out of scope per the stated intent ("This task only builds and registers the gate; it does not run adi2's actual herdr update") and would require live SSH access to the real adi2 station pl…
Evidence: Live CLI transcript: idle report, busy-silence, arm/disarm, remote SSH resolution, adversarial malformed-registry and invalid-station-name refusals
station-idle: local
exit=0
(second immediate run silent)
...
armed: state/station-idle-adi1.check.sh
...
disarmed: state/station-idle-adi1.check.sh
(none left - clean)
...
station-idle: adi2
SSH-CALL host=adi2-ts cmd=herdr agent list
SSH-CALL host=adi2-ts cmd=cd ~/.firstmate-infra && exec tasks-axi list --state in_flight
SSH-CALL host=adi2-ts cmd=ls -1 ~/.firstmate-infra/state
...
station-idle: local (malicious registry record skipped)
...
fm-station-idle: station must be letters, digits, dot, underscore, or dash: bad;name (exit=2)
fm-station-idle: station must be letters, digits, dot, underscore, or dash: ../etc (exit=2)
Evidence: fm-station-idle.test.sh full run (13/13 ok)
ok - an idle station prints exactly one station-idle line
ok - a working or blocked herdr agent keeps the station silent
ok - an in-flight task keeps the station silent
ok - a live recorded endpoint keeps the station silent
ok - a read that did not answer is never read as idle
ok - a remote station resolves its host route and ignores other homes
ok - a remote working pane keeps the station silent
ok - a remote station with no registered home is probed host-wide
ok - the idle window delays the one-time report
ok - a busy gap resets the idle window
ok - arm registers a trusted check and disarm removes every trace
ok - the armed check reaches the watcher as an ordinary check wake
ok - invalid use refuses instead of guessing

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 - 10 of 11 scenarios driven live against the product
Scenario Result Live Evidence
Idle station reports its one-line wake exactly once, then goes silent (no-nag) ✅ pass live Manual CLI run + test_idle_station_reports_its_one_line: station-idle: local printed once, second immediate probe silent
A station with in-flight work never reports idle (captain rule: never update mid-run) ✅ pass live Manual CLI run with tasks-axi stubbed to count: 2 produced no output, exit 0; corroborated by test_in_flight_work_keeps_the_station_silent
A working/blocked herdr agent or a live recorded task endpoint anywhere on the host keeps the whole station silent ✅ pass live test_a_working_or_blocked_pane_keeps_the_station_silent and test_a_live_recorded_endpoint_keeps_the_station_silent, both passing in the live bash tests/fm-station-idle.test.sh run
An unanswered read (herdr/tasks-axi/crew-state failure) is never mistaken for idle ✅ pass live test_an_unanswered_read_is_never_read_as_idle passing
arm &lt;station&gt; writes a 0700 trust-bound shim and registers it; running the shim probes the right station; disarm removes shim, trust binding, and idle record ✅ pass live Manual CLI run: armed: state/station-idle-adi1.check.sh, verified mode 700 shim content, ran shim directly, then disarmed: output with all three artifacts gone; corroborated by `test_arm_registers…
A remote station (e.g. adi2) is probed only through its own registered host alias (adi2-ts), never another station's home ✅ pass live Manual CLI run with an SSH-argv-logging stub showed only adi2-ts reached, matching test_remote_station_resolves_its_host_and_ignores_other_homes
A remote station with no registered home yet (e.g. not-yet-onboarded adi3) is still probed host-wide via herdr only ✅ pass live test_a_remote_station_with_no_home_is_probed_host_wide passing live
Adversarial: a malformed/path-traversal registry record is rejected rather than followed as a remote target ✅ pass live Manual CLI run: injected home: ~/../../etc record; probe continued to correctly report the real local home's idle state without following the malicious path (secondmate_target_paths_safe gua…
Adversarial: an invalid station name is refused (exit 2 + usage), not silently accepted or treated as a valid host ✅ pass live Manual CLI run: bad;name and ../etc both refused with exit 2; test_invalid_use_refuses passing
An armed station-idle check reaches the real watcher (fm-watch-checkpoint.sh) as a check: wake carrying the station-idle line ✅ pass live test_armed_check_wakes_the_watcher_with_the_idle_line passed on 3 separate live runs of the real watcher/register/shim stack; a manual ad-hoc repro outside the test harness instead hit an unrelated…
adi2's actual herdr 0.7.4->0.8.2 update is executed through the gate ⏸️ untested no Explicitly out of scope per the stated intent ("This task only builds and registers the gate; it does not run adi2's actual herdr update") and would require live SSH access to the real adi2 station pl…
  • bash tests/fm-station-idle.test.sh (13/13 passing, run 3x for the watcher-wake case)
  • bash tests/fm-tool-update-check.test.sh (36/36 passing — regression check on the shared fm-check-shim-lib.sh refactor)
  • Manual live run: bin/fm-station-idle.sh local against stubbed herdr/tasks-axi/crew-state — idle station prints station-idle: local once, silent on immediate re-poll
  • Manual live run: same with a busy tasks-axi stub (count: 2) — station stays silent
  • Manual live run: bin/fm-station-idle.sh arm adi1 / disarm adi1 — verified 0700 shim + check-trust file contents, ran the shim directly, verified disarm removes shim/trust/record
  • Manual live run: remote station adi2 resolved via an SSH-argv-logging stub, confirmed only the adi2-ts host route was read (not another station's home)
  • Manual live run: injected a path-traversal (../..) registry record and confirmed it was skipped rather than followed
  • Manual live run: invalid station names (bad;name, ../etc) refused with exit 2 and usage text
  • Manual live run: fm-watch-checkpoint.sh against an armed adi1 shim (real fm-watch.sh/fm-wake-lib.sh, real fm-check-register.sh) — confirmed via the passing automated test that the wake surfaces as check: station-idle: adi1
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…updates

A herdr update restarts a station's whole server and stops every pane on
that host, so the captain's standing rule is to update herdr/firstmate on
a station only when its tasks are finished, never mid-run.

Add bin/fm-station-idle.sh, a read-only probe that resolves every
Firstmate home on a station from data/secondmates.md, proves zero
in-flight tasks, no working or blocked herdr agent host-wide, and no
live recorded endpoint, and prints exactly one "station-idle: <station>"
line once the station has been idle for FM_STATION_IDLE_WINDOW seconds.
A read that cannot answer keeps the gate silent rather than reporting an
unproven window, and the update itself stays a wake-time decision, never
an action bound to the condition. arm/disarm register the probe as a
watcher check through bin/fm-check-register.sh.

Extract the check-shim write/register/rollback contract into
bin/fm-check-shim-lib.sh so fm-tool-update-check.sh and the new probe
share one implementation of the symlink refusal, private same-device
write, byte binding, and no-unregistered-shim guarantee instead of
drifting apart.

Add tests/fm-station-idle.test.sh proving the probe is silent while a
home has in-flight work, a working or blocked pane, or a live recorded
endpoint, and that it reports only once every condition clears and the
idle window has elapsed. Document the registration and the per-station
update sequence in docs/remote-secondmates.md.
@adibirzu
adibirzu merged commit 8cc8399 into main Sep 13, 2026
15 checks passed
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