Skip to content

feat(supervision): add resting vs active state for secondmate in-flight counting - #761

Closed
Freudator86 wants to merge 6 commits into
kunchenguid:mainfrom
Coditan:fm/secondmate-rest-q4
Closed

Freudator86 wants to merge 6 commits into
kunchenguid:mainfrom
Coditan:fm/secondmate-rest-q4

Conversation

@Freudator86

Copy link
Copy Markdown
Contributor

Resubmission note

This is a clean resubmission of #391, which was already reviewed and repeatedly confirmed mergeable across several rebase rounds, then held pending human maintainer review. On 2026-07-18 the Freudator86/firstmate fork silently lost its GitHub fork relationship with this repo, which auto-closed #391 without a merge - a fork-relationship glitch, not a review rejection. The branch content survived intact on the (now-renamed) detached repo and has been rebased cleanly onto current main here. See #391 for the original review history and discussion.

One small adjustment was needed during the rebase: bin/fm-bootstrap.sh's secondmate liveness sweep went silent on a successful respawn somewhere between the original PR and current main (an unrelated upstream change), so tests/fm-secondmate-liveness.test.sh's test_sweep_unaffected_by_supervision_resting case was updated to expect silence on success (matching the pre-existing sibling test) while still verifying via the tmux call log that kill-then-respawn happens for a resting secondmate exactly as before.


Intent

Add a 'resting vs active' supervision state for persistent secondmates, so a resting secondmate does not count as in-flight work for stop-hook/turnend-guard supervision, while an active one still does.

Background: state/<id>.meta records kind=secondmate for persistent secondmates; previously ANY secondmate meta counted as in-flight for supervision purposes exactly like an ordinary crewmate/scout task, so a secondmate that is deliberately idle-but-alive still blocked the primary's turn-end whenever there was no fresh watcher beacon. This is purely a supervision-COUNTING change, not a lifecycle change: persistent secondmates stay alive regardless of this field.

Implementation: bin/fm-supervision-lib.sh's fm_supervision_status (the shared predicate used by both fm-guard.sh and fm-turnend-guard.sh) now reads kind= and supervision= from each state/*.meta file via a new fm_sup_resting_secondmate helper, and skips a meta file only when it is BOTH kind=secondmate AND supervision=resting when computing FM_SUP_IN_FLIGHT. supervision=active and legacy meta with no supervision= field at all still count exactly as before - a deliberate safe default so pre-existing secondmates are never silently dropped from supervision. Ordinary crewmate/scout meta is completely unaffected.

dormant is a distinct, pre-existing, unrelated concept (a registry-only entry in data/secondmates.md with no live state/<id>.meta at all) and this change does not touch or conflate it.

Deliberately out of scope: no command or plumbing was added to actually set/toggle supervision=resting on a live secondmate - that lifecycle mechanism is left for a future task; this change only wires the counting predicate and documents the field.

bin/fm-turnend-guard.sh itself was deliberately NOT modified: the predicate change in fm-supervision-lib.sh alone was sufficient to fix its behavior (verified by tests), keeping the change minimal.

Secondmate liveness probing and respawn behavior in bin/fm-bootstrap.sh (the SECONDMATE_LIVENESS sweep) is unrelated to this predicate and is verified unaffected by supervision=resting via a dedicated test.

What Changed

  • bin/fm-supervision-lib.sh's fm_supervision_status (shared by fm-guard.sh and fm-turnend-guard.sh) now reads kind=/supervision= from each state/*.meta via a new fm_sup_resting_secondmate helper, excluding a meta only when it is both kind=secondmate and supervision=resting from FM_SUP_IN_FLIGHT; supervision=active, legacy meta with no supervision= field, and ordinary crewmate/scout meta all still count exactly as before.
  • Added predicate- and hook-level test coverage to tests/fm-turnend-guard.test.sh (resting excluded, active/legacy counts, ordinary crewmate/scout unaffected, resting-secondmate-plus-real-in-flight-work still counts, silent-vs-blocking hook behavior) and a new test in tests/fm-secondmate-liveness.test.sh proving the liveness/respawn sweep is unaffected by supervision=resting.
  • Documented the new optional state/<id>.meta supervision= field and the resting/active exception in AGENTS.md and docs/turnend-guard.md.

Risk Assessment

Low: a small, well-scoped change to a single shared predicate function with a safe default (absent/non-"resting" values still count as in-flight), backed by tests covering the predicate, the hook-level behavior, and non-interference with the unrelated liveness/respawn sweep; docs are updated consistently with the code.

Testing

After rebasing onto current main:

bash tests/fm-turnend-guard.test.sh

All resting/active/legacy predicate assertions and hook-level silent-vs-block assertions pass. (The suite's separate, pre-existing live-Pi-TUI regression case fails in this sandbox for an unrelated environmental reason - no live Pi tooling available - and fails identically against unmodified main.)

bash tests/fm-secondmate-liveness.test.sh

All 11 assertions pass, including the resting-secondmate-liveness-sweep case (updated per the resubmission note above).

bash tests/fm-watcher-lock.test.sh
bash tests/fm-session-start.test.sh
bash tests/fm-backend-orca.test.sh

All pass (these were incidentally touched by the branch's own earlier lint/portability fix commits, carried through the rebase).

…ht counting

A persistent secondmate's own state/<id>.meta counted as in-flight for
stop-hook/turnend-guard supervision exactly like a crewmate/scout, so a
secondmate that is deliberately idle-but-alive still blocked turn-end
whenever its supervising primary had no fresh watcher beacon. kind=secondmate
meta can now carry supervision=resting to exclude it from that count while
staying fully alive; supervision=active and legacy meta with no field still
count as before. Liveness probing/respawn and dormant registry entries are
untouched - this is purely a supervision-counting change.
secondmate_liveness_sweep() in bin/fm-bootstrap.sh no longer echoes a
"respawned" success line (it went silent independently of this feature,
matching the sibling test_sweep_respawns_confirmed_dead_secondmate case).
The resting-vs-active test still asserted the old noisy behavior; update
it to expect silence on success while still verifying via the tmux call
log that kill-then-respawn actually happens, unaffected by
supervision=resting.
@Freudator86

Copy link
Copy Markdown
Contributor Author

Closing to let no-mistakes open a fresh PR carrying the pipeline signature. This PR was originally opened by pushing directly (bypassing no-mistakes), so it never carried the required '## Pipeline' signature and the 'Require no-mistakes' check could never pass. Not merged; content is preserved on branch fm/secondmate-rest-q4 and is being resubmitted through no-mistakes.

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