Skip to content

fix(fm-secondmate-restart): check capacity before stopping mate on relaunch - #78

Merged
adibirzu merged 2 commits into
mainfrom
fm/fm-secondmate-restart-dead-on-capacity-refusal
Sep 14, 2026
Merged

adibirzu merged 2 commits into
mainfrom
fm/fm-secondmate-restart-dead-on-capacity-refusal

Conversation

@adibirzu

@adibirzu adibirzu commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

bin/fm-secondmate-restart.sh stopped a mate's agent before checking machine capacity; when the replacement launch was then refused by the 10-agent guard, the mate was left dead with a bare shell and reported as unreached. This change moves the capacity guard into bin/fm-control.sh do_relaunch() so it runs before the old agent is stopped, and reports the refusal honestly.

What changed

  • bin/fm-control.sh: sources fm-capacity-lib.sh and consults the machine-capacity guard immediately after resolving the relaunch profile, before any checkpoint/journal/agent-stop work. A refusal exits with a clear relaunch of <id> refused: machine capacity declined the replacement launch message and leaves the running agent untouched.
  • bin/fm-secondmate-restart.sh: recognizes a capacity refusal from the relaunch output and reports it as refused: <id>: ... instead of unreached. Added refused_count, updated the summary line, and updated the exit-code help.
  • docs/configuration.md: noted in the "Machine capacity" section that relaunches consult capacity before stopping the existing agent.
  • tests/fm-secondmate-restart.test.sh: updated existing summary assertions to the new format and added regression test T5b that forces a capacity refusal and verifies the mate stays alive and the refusal is reported.

Verification

Local test runs, serialized with the host's one-suite-at-a-time lock (Actions minutes are exhausted on this fork, so these are the CI evidence):

$ flock -o /home/adi/.firstmate-infra/state/.suite.lock -c './tests/fm-secondmate-restart.test.sh'
ok - T1 persist is a gate, and asks for open records and task status only
ok - T2 the mate persists before anything is stopped
ok - T2b an arrived persist answer is resolved before timeout
ok - T2c a reply between the resolution and timeout decision wins
ok - T3 a runtime that cannot prove a restart falls back to the re-read message
ok - T4 every named mate is accounted for, including one this home does not know
ok - T5 a refused restart leaves the mate running and reports an unknown outcome
ok - T5b a capacity refusal leaves the mate alive and reports the refusal
ok - T8 a local restart re-resolves this home's pin and reports what ran
ok - T6 a remote mate restarts through the host-local control plane over the fm-on hop
ok - T7 an unreachable host is reported honestly instead of claimed as reloaded
ok - T9 the persist gate retains its explicitly allocated correlation
ok - T10 pending persist answers are polled as one fleet
ok - T11 post-stop failure is reported unreached
ok - T12 relaunch waits do not block persist polling
ok - T13 a dead restart worker cannot hang the parent
ok - T14 a result published during reaping is honored
ok - T15 an already-current live mate is named by the update pass and genuinely restarted
ok - T16 an already-current mate with an unprovable runtime keeps the honest nudge path
# all fm-secondmate-restart tests passed

$ flock -o /home/adi/.firstmate-infra/state/.suite.lock -c 'bash tests/fm-spawn-capacity.test.sh'
ok - fm-capacity-lib admits when llm-router-axi reports headroom
ok - fm-capacity-lib declines with the router's reasons and the refused work named
ok - fm-capacity-lib declines rather than spawning blind when the router is absent
ok - fm-capacity.sh reports the llm-router-axi capacity reading
ok - fm-capacity.sh check exits 1 when the router reports no headroom
ok - fm-capacity.sh reports usage-axi machine only when the tool is installed
ok - an occupied suite slot is context for spawn admission and never refuses a spawn
All fm-spawn-capacity tests passed.

$ bin/fm-lint.sh bin/fm-control.sh bin/fm-secondmate-restart.sh tests/fm-secondmate-restart.test.sh
(no output; success)

Code Review (Stage 1)

# Code Review Verdict

**Stage 1: Deterministic Review (zero LLM tokens)**

- Files reviewable: 18 / 23
- Changes: +1904 / -30 (1934 lines)
- Linter: ran, 1 finding(s)
- LLM tokens: 0

fm-lint.sh: ShellCheck 0.9.0 (pinned 0.11.0)
fm-lint.sh: ShellCheck 0.11.0 required for CI parity, found 0.9.0. Install 0.11.0 with bin/fm-install-shellcheck.sh <destination-directory>.

**Stage 2: Escalated** (changeset (1934 lines) exceeds threshold (1000))

Mode: `delegate`
No LLM call made. The host agent must review the selected files against the rules below before this PR is ready.

Note: the changeset size is inflated because this branch merged the latest adibirzu/firstmate main (including PRs #75 and #76) so the Require no-mistakes workflow runs the new direct-PR attestation validator. The fix itself remains the same small set of changes in bin/fm-control.sh, bin/fm-secondmate-restart.sh, tests/fm-secondmate-restart.test.sh, and docs/configuration.md.

Independent Second-Level Review

Reviewer: opencode-go/muse-spark-1.3-contributor (independent of the authoring lane opencode-go/kimi-k2.7-code)
Report: data/fm-pr78-second-level-review/report.md
Verdict: PASS (reviewed at 86a8c0a; head 0fcc125 adds only a merge of main)

adi added 2 commits September 14, 2026 18:19
…launch

A capacity refusal in fm-spawn.sh --relaunch left a secondmate agent-free
with a bare shell, because the old agent had already been stopped. Move the
capacity guard into fm-control.sh do_relaunch() so it runs before anything
is stopped. A refusal is now reported as refused: in
fm-secondmate-restart.sh, with the agent still alive.

- Source fm-capacity-lib.sh in fm-control.sh and guard relaunch before
  safe_checkpoint / journal writes.
- Add refused_count and refused: reporting in fm-secondmate-restart.sh.
- Update summary format and exit-code help.
- Document the pre-stop relaunch capacity check in docs/configuration.md.
- Add regression test T5b covering a capacity refusal during restart.
@adibirzu
adibirzu merged commit b873055 into main Sep 14, 2026
16 of 19 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.

2 participants