Skip to content

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

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

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

Conversation

@Freudator86

Copy link
Copy Markdown
Contributor

Intent

Push already-reviewed content (PR #391) through the no-mistakes gate; PR #761 was closed because it was opened by a bare gh pr create and never carried the pipeline signature

What Changed

  • Added fm_sup_resting_secondmate to bin/fm-supervision-lib.sh and wired it into fm_supervision_status so a persistent secondmate whose meta is marked supervision=resting is excluded from in-flight work counting (used by fm-guard.sh and fm-turnend-guard.sh), while any other/absent value still counts as active for backward compatibility.
  • Documented the new supervision= meta field and resting/active semantics in AGENTS.md, docs/architecture.md, and docs/turnend-guard.md, including when firstmate should set a secondmate to resting vs. active.
  • Added/updated tests: new resting-vs-active coverage in tests/fm-turnend-guard.test.sh, a new tests/fm-secondmate-liveness.test.sh verifying supervision=resting doesn't affect liveness probing or respawn, and portability/assertion fixes across tests/fm-backend-orca.test.sh, tests/fm-session-start.test.sh, tests/fm-pi-watch-extension.test.sh, and tests/fm-watcher-lock.test.sh.

Risk Assessment

✅ Low: The change adds a narrowly-scoped, opt-in exclusion (supervision=resting) to the shared in-flight predicate in fm-supervision-lib.sh, defaults safely to "active" when the field is absent (so no existing secondmate is silently dropped from supervision), is consumed consistently by the one real caller (fm-turnend-guard.sh) that matters, and is covered by direct unit tests for the predicate, the hook, and a liveness-sweep test proving the field has zero effect on respawn behavior; the remaining diff is test-portability fixes and documentation unrelated to functional risk.

Testing

Completed 1 recorded test check.

  • Outcome: ⏭️ skipped across 1 run (19m9s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⏭️ **Test** - skipped
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
✅ **Document** - passed

✅ No issues found.

⏭️ **Lint** - skipped
  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

@Freudator86
Freudator86 force-pushed the fm/secondmate-rest-q4 branch 2 times, most recently from 1fbd0e3 to 5c2e3b1 Compare July 21, 2026 12:45
@kunchenguid

kunchenguid commented Jul 21, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#773 at 5c2e3b1b.

@Freudator86
Freudator86 force-pushed the fm/secondmate-rest-q4 branch from 5c2e3b1 to cd8252a Compare July 23, 2026 12:25
@kunchenguid kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Jul 23, 2026
@Freudator86
Freudator86 force-pushed the fm/secondmate-rest-q4 branch from 3d1265a to 842851d Compare July 23, 2026 17:45
@kunchenguid

kunchenguid commented Jul 24, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#773 at 842851d3.

…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.
Same-SHA commit d466792 was shared by closed PR #761 and current PR #773;
the 'PR must be raised via no-mistakes' check resolved the old closed PR's
context for that SHA. An empty commit gives GitHub a fresh SHA to key the
check off of the correct, currently open PR.
Same-SHA commit d466792 was shared by closed PR #761 and current PR #773;
the 'PR must be raised via no-mistakes' check resolved the old closed PR's
context for that SHA. An empty commit gives GitHub a fresh SHA to key the
check off of the correct, currently open PR.
… mis-merge

The rebase's automatic conflict resolution picked the wrong side of a
conflicting assertion in test_spawn_releases_orca_resources_when_metadata_write_fails,
expecting "mkdir"/"xists" in the output. bin/fm-spawn.sh's metadata-write
failure path is an unguarded `} > "$STATE/$ID.meta"` redirection with no
preceding mkdir check, so the actual (and origin/main's original, correct)
failure output is "Is a directory".
Behavior portable serial failed on cd8252a for an environment-specific
reason unrelated to this branch's diff (test_send_conformance_old_vs_new's
BASE_REF resolution behaves differently under the fork-PR checkout);
every other check passed and the test suite is clean locally against the
same commit. An empty commit gives GitHub a fresh SHA to re-evaluate
against, consistent with the same recovery already used earlier in this
PR (e94ce1b, 8f8d65b).
@Freudator86
Freudator86 force-pushed the fm/secondmate-rest-q4 branch from 842851d to cebf348 Compare July 26, 2026 23:54
@kunchenguid kunchenguid removed the wheelhouse:pending-contributor-action Managed by Wheelhouse label Jul 27, 2026
@kunchenguid

kunchenguid commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#773 at cebf3489.

@Freudator86

Copy link
Copy Markdown
Contributor Author

Closing this ourselves. The upstream gap is real and still present, but this particular change has
been overtaken by a safer design that has since landed on our fork, and it is mildly hazardous as
written.

Still valid upstream: the liveness sweep counts every task metadata file, so a resting secondmate
is indistinguishable from a live one. That problem stands.

Why this change should not be the fix:

  • It carries a stale schema. Our fork landed state=active|resting on 2026-07-21; this PR still uses
    the earlier field name.
  • It has no atomic transition helper, so a state change can be observed half-applied.
  • It has no reactivation at send time, so a resting secondmate that receives work stays marked
    resting.
  • A hand-edited flag can therefore hide real work, which is the opposite of what the sweep is for.

It also bundles three unrelated test fixes - roughly 90 of its 226 added lines - and now conflicts
with the base branch.

If an upstream port is wanted, the honest form is a fresh cut from the landed design with the
transition helper and send-time reactivation, and the unrelated test fixes split into their own small
changes. That rewrites most of this diff, so keeping this PR open preserves only its number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants