Skip to content

fix: bound remote secondmate convergence and preserve owed re-reads - #7394

Merged
kunchenguid merged 10 commits into
kunchenguid:mainfrom
arthurcruzd:fm/fm-remote-convergence-upstream
Oct 18, 2026
Merged

kunchenguid merged 10 commits into
kunchenguid:mainfrom
arthurcruzd:fm/fm-remote-convergence-upstream

Conversation

@arthurcruzd

@arthurcruzd arthurcruzd commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Send our good Firstmate fixes upstream to kunchenguid/firstmate as pull requests (asked as: "pode enviar o que temos de bom"). This task is one of them: the three remote second-mate convergence fixes our fleet has run since 2026-10-11, as one upstream PR.

The fixes, from the captain's fork branch fleet (arthurcruzd/firstmate): 01cad32e fit remote second-mate convergence inside the startup network bound (parallel inherit push via FM_REMOTE_INHERIT_PUSH_JOBS, per-mate FM_SECONDMATE_CONVERGENCE_TIMEOUT of 75s); a43e0433 nudge a remote second mate to re-read only when something changed; 2cc02218 keep a remote mate's re-read owed when its convergence is cut short (depends on the first two). Without them, startup with several remote second mates overran the network-check bound and nudged every mate to re-read on every start.

What Changed

  • Parallelize remote inheritance transfers with configurable concurrency and ordered output; give remote startup sync and inheritance a shared 75-second per-mate budget.
  • Send re-read nudges only for instruction or inherited-material changes, or an outstanding re-read obligation.
  • Preserve owed re-reads across partial transfers, unknown completion, timeouts, and interrupted attempts; document the behavior and add regression coverage.

Risk Assessment

✅ Low: The changes are bounded to remote convergence scheduling and re-read obligations, preserve existing access controls, and contain no substantiated material defects.

Testing

Ran the three requested suites serially, then isolated nine existing regressions that all passed. Captured bootstrap diagnostics and test transcripts. The network suite encountered timing failures, two suites exceeded their bounds, and Cursor coverage was skipped because its executable was unavailable. Previously declined validation limitations were not raised again. Live validation remains unproven under the recorded regression-only scope.

  • Live validation: ⚠️ inconclusive - 0 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Startup overlaps remote inheritance within its concurrency limit and preserves ordered diagnostics ⏸️ untested no Focused scheduler regressions passed, but the full network suite failed when simulated calls exceeded timing budgets. Live SSH validation was excluded by the recorded user decision; changing that scop…
A hung remote mate times out while healthy mates converge and its retry obligation survives ⏸️ untested no The focused regression passed with simulated transport. The recorded user decision limits this run to regression suites instead of a live SSH lab.
An unchanged remote home receives no notification unless a re-read is already owed ⏸️ untested no The regression passed using simulated endpoints. Running-agent validation requires authorization to expand the recorded regression-only scope.
A partially applied inheritance push retains the owed re-read through an unchanged retry ⏸️ untested no Bootstrap and config-push regressions passed with injected transport responses. Live SSH validation was excluded by the recorded user decision.
Unknown transport completion preserves the owed re-read even alongside another item's failure ⏸️ untested no Focused regressions passed for status 255 and unchanged retries. Transport failures were simulated, consistent with the recorded regression-only scope.
Termination during a remote mutation preserves the owed re-read for the next attempt ⏸️ untested no The regression killed actual bootstrap and config-push processes and passed, but remote calls were simulated. Live remote mutation validation requires expanded authorization.
Local config-push notifies after partial propagation and stays silent for unchanged homes ⏸️ untested no The requested harness suite reached its 540-second limit before these cases. No live agent was launched under the recorded regression-only scope; completing this proof requires a longer targeted run o…
Evidence: Bootstrap timeout diagnostics from simulated-transport regression

Source: Bootstrap timeout diagnostics from simulated-transport regression

Production bootstrap output from the simulated-transport regression (not live SSH):
SECONDMATE_LIVENESS: secondmate bravo: skipped: remote host unavailable or endpoint state unknown; route preserved on host-bravo
SECONDMATE_SYNC: secondmate alpha: skipped: remote tracked-file sync failed on host-alpha: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate alpha: skipped: remote inheritance failed on host-alpha: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate bravo: skipped: remote tracked-file sync failed on host-bravo: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate bravo: skipped: remote inheritance failed on host-bravo: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate charlie: skipped: remote tracked-file sync failed on host-charlie: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate charlie: skipped: remote inheritance failed on host-charlie: no answer within the 75s per-mate convergence budget
FLEET_SYNC: fleet: skipped: bootstrap refresh timed out (timeout=20s elapsed=20s)
Evidence: Requested regression suite transcript

Source: Requested regression suite transcript

FM_TEST_BEGIN 2026-10-17T22:06:50Z tests/fm-bootstrap-network-parallel.test.sh family=session-bootstrap expected_gate_skip=none
not ok - the dirty mate's skip line must still name dirtiness (missing: 'dirty')
--- output ---
SECONDMATE_LIVENESS: secondmate bravo: skipped: remote host unavailable or endpoint state unknown; route preserved on host-bravo
SECONDMATE_SYNC: secondmate alpha: skipped: remote tracked-file sync failed on host-alpha: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate alpha: skipped: remote inheritance failed on host-alpha: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate bravo: skipped: remote tracked-file sync failed on host-bravo: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate bravo: skipped: remote inheritance failed on host-bravo: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate charlie: skipped: remote tracked-file sync failed on host-charlie: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate charlie: skipped: remote inheritance failed on host-charlie: no answer within the 75s per-mate convergence budget
FLEET_SYNC: fleet: skipped: bootstrap refresh timed out (timeout=20s elapsed=20s)
FM_TEST_END 2026-10-17T22:11:51Z tests/fm-bootstrap-network-parallel.test.sh exit=1 duration_ms=300890 gate_skip=false
FM_TEST_BEGIN 2026-10-17T22:11:51Z tests/fm-secondmate-sync.test.sh family=secondmate expected_gate_skip=none
ok - T1 updated: a behind home fast-forwards to the primary's local HEAD
ok - T2 current: an already-current home is a no-op and reports no instruction change
ok - T3 dirty: an uncommitted home is skipped, its edit preserved
ok - scratchpad2/ does not mark a secondmate home dirty for the sync guard
ok - T4 diverged: a home that is not an ancestor of the primary's HEAD is skipped
ok - T5 in-flight: a home on a feature branch is skipped, its work preserved
ok - T6 no fetch: the local-HEAD sync never invokes git fetch
ok - T7 sweep nudges on a real instruction change only, but still fast-forwards
ok - T8 bootstrap sweeps live homes and sends exactly one marked nudge for the instruction change
ok - T8a bootstrap nudge send respects FM_STATE_OVERRIDE
ok - T8f bootstrap nudge retry rejects malformed marker ids
ok - T8c failed bootstrap nudge is surfaced and recorded for retry
ok - T8d bootstrap nudge retry is idempotent after success
ok - T8e bootstrap nudge retry refuses a changed home instead of guessing
ok - T8b a stale herdr endpoint cannot lose a durably enqueued nudge, and fm-<id> resolves through post-respawn metadata
ok - T9 bootstrap surfaces a skipped dirty live secondmate home
ok - T10 spawn fast-forwards a secondmate worktree to the primary's local HEAD before launch
ok - T11 spawn warns when pre-launch sync is skipped
ok - T12 gitignored marker: a freshly seeded home reads clean to fleet-sync and the ff sweep
ok - T13 gitignored marker: an existing marker-only-dirty home converges, then reads clean
ok - T14 marker tolerance does not mask a genuinely dirty home
ok - R1 a remote home ahead of the host's Firstmate copy still advances to the primary's commit
ok - R1b a remote sync names exactly which instruction paths its advance changed
ok - R2 a missing target is imported from the host's Firstmate copy without moving it
ok - R3 a target neither side holds is imported from the home's own origin
ok - R4 an already-present target advances the home with no fetch available
ok - R5 a target neither the host copy nor the origin holds skips with an actionable reason
ok - R6 dirty, diverged, and feature-branch remote homes skip and are left untouched
ok - R7 a sync with no target still follows the host's own refreshed Firstmate copy
ok - R8 session start converges a remote home on the primary's default-branch commit
ok - R10 a host too old for a parent-targeted sync is reported with the command that fixes it
ok - R11 a remote home is nudged only for an owed reread or a real instruction change, never for a cut-off attempt that changed nothing
not ok - tests/fm-secondmate-sync.test.sh exceeded the per-script bound of 540s and was terminated
FM_TEST_END 2026-10-17T22:20:53Z tests/fm-secondmate-sync.test.sh exit=124 duration_ms=540918 gate_skip=false
FM_TEST_BEGIN 2026-10-17T22:20:53Z tests/fm-secondmate-harness.test.sh family=secondmate expected_gate_skip=none
ok - A1 fm-harness.sh secondmate resolves the fallback chain; crew mode unchanged
ok - fm-harness detects only Cursor Agent CLI's exact invocation marker
ok - C1 fm-harness.sh secondmate-model/secondmate-effort resolve the optional tokens; bare harness stays empty (backward-compat)
ok - pi-signed identity: authoritative launch selection distinguishes shared wrapper ancestry
ok - harness identity: dash-leading ps command names are basename operands, not options
ok - B1 propagate_inheritable_config: copy, idempotence, convergence, absence-mirror, exclusion, no-op, skip diagnostics
ok - B2 spawn: secondmate runs the secondmate harness; its home inherits declared config
ok - B3 spawn: an absent secondmate-harness falls back to the crew harness (backward-compat)
ok - B4 spawn: no config at all -> own harness and no propagation side effects
ok - B5 spawn: an explicit per-spawn harness arg overrides config/secondmate-harness
ok - B6 spawn: an unverified resolved secondmate harness is refused (guard intact)
skip: cursor executable not resolvable in this environment, so the launch could not be built
ok - B5b spawn: FM_BACKEND wins over inherited config/backend
ok - B5c spawn: explicit --backend wins over FM_BACKEND and inherited config/backend
ok - C2 spawn: a bare harness-only secondmate-harness file launches with no model/effort flag (backward-compat)
ok - C3 spawn: config/secondmate-harness's model token threads --model into the launch and meta
ok - C4 spawn: config/secondmate-harness's model+effort tokens thread into the launch and meta
ok - C5 spawn: an explicit --model overrides config/secondmate-harness's model token; the file's effort token still applies
ok - C6 spawn: an explicit --effort overrides config/secondmate-harness's effort token; the file's model token still applies
ok - C7 spawn: an explicit --harness starts with clean model/effort defaults
ok - C8 spawn: an explicit --harness still honors explicit model/effort flags
ok - C9 spawn: secondmate launch pins supervision to its own harness
ok - C9 spawn: the harness fallback chain still resolves with no tokens; crew/scout launches are unaffected by this feature
ok - B7 bootstrap sweep pushes, re-converges, and mirrors absence; never inherits secondmate-harness
ok - B8 bootstrap sweep propagates config even when the home's tracked files are already current
ok - B9 bootstrap sweep defers new inherited config until the home ignores it
ok - B10 bootstrap sweep materializes and inherits the startup-memory default while fast-forwarding
not ok - tests/fm-secondmate-harness.test.sh exceeded the per-script bound of 540s and was terminated
FM_TEST_END 2026-10-17T22:29:54Z tests/fm-secondmate-harness.test.sh exit=124 duration_ms=540604 gate_skip=false
FM_TEST_SUMMARY total=3 failed=3 skipped_gate=0 duration_ms=1384398
FM_TEST_SUMMARY_FAMILY family=secondmate count=2 duration_ms=1081522 failed=2
FM_TEST_SUMMARY_FAMILY family=session-bootstrap count=1 duration_ms=300890 failed=1
FM_TEST_SLOWEST rank=1 script=tests/fm-secondmate-sync.test.sh duration_ms=540918
FM_TEST_SLOWEST rank=2 script=tests/fm-secondmate-harness.test.sh duration_ms=540604
FM_TEST_SLOWEST rank=3 script=tests/fm-bootstrap-network-parallel.test.sh duration_ms=300890
fm-test-run: wrote timing artifact: ~/.no-mistakes/evidence/01M55YA8AVJQK1MJFEFZYEHRHS/targeted-results.json
Evidence: Focused scheduler and interruption regressions

Source: Focused scheduler and interruption regressions

FM_TEST_BEGIN 2026-10-17T22:30:26Z tests/fm-convergence-focused-gate.test.sh family=unclassified expected_gate_skip=none
ok - remote inheritance push: items overlap up to the bound and replay in allowlist order
ok - remote inheritance push: a failed item fails the push and no later item is started
ok - remote inheritance push: a local refusal is decided before any item is sent
ok - parallel push preserves unknown completion status
ok - a kill during the remote call keeps the mate's re-read owed
FM_TEST_END 2026-10-17T22:32:18Z tests/fm-convergence-focused-gate.test.sh exit=0 duration_ms=111692 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=112892
FM_TEST_SUMMARY_FAMILY family=unclassified count=1 duration_ms=111692 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-convergence-focused-gate.test.sh duration_ms=111692
Evidence: Focused failure recovery and timeout regressions

Source: Focused failure recovery and timeout regressions

FM_TEST_BEGIN 2026-10-17T22:32:30Z tests/fm-convergence-focused-gate.test.sh family=unclassified expected_gate_skip=none
ok - a push that fails after applying an item keeps the mate's re-read owed
ok - config-push: a push that fails after applying an item keeps the mate's re-read owed
ok - unknown-completion sync or push keeps the mate's re-read owed across an unchanged retry
ok - per-mate convergence budget: a hung host is that mate's skip, keeps its retry marker, and does not hold the others
FM_TEST_END 2026-10-17T22:35:23Z tests/fm-convergence-focused-gate.test.sh exit=0 duration_ms=171938 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=172503
FM_TEST_SUMMARY_FAMILY family=unclassified count=1 duration_ms=171938 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-convergence-focused-gate.test.sh duration_ms=171938
- Outcome: ⚠️ 1 warning across 1 run (29m40s)

Notes for reviewers

  • Live evidence: these three fixes (01cad32e, a43e0433, 2cc02218 on the submitting fork) have run live on the submitting fleet since 2026-10-11, with four remote second mates on two other machines. The live scenarios in the Testing table need real remote hosts, so here they are exercised with fixtures by tests/fm-bootstrap-network-parallel.test.sh, tests/fm-secondmate-sync.test.sh, and tests/fm-secondmate-harness.test.sh.
  • Review fixes on top of the cherry-picks: the pipeline review found that the new owed= marker could still drop a re-read on a config-push that failed after applying an item, on an unknown-completion transport failure (fm-on.sh exit 255), and on a TERM/INT during the remote call. The follow-up commits keep the re-read owed in all three cases, with regressions in tests/fm-bootstrap-network-parallel.test.sh.
  • Live run and the write-ahead fix: the seven live scenarios were driven against a real remote second-mate home on a macOS host (evidence in a separate comment). The kill case failed there: the startup network bound stops its stage with TERM and then KILL one second later, bash defers the TERM trap while convergence waits on the remote call, and the KILL landed first, so a change the remote had already applied was never re-read. 4c55f368 now records the re-read as owed before any remote step can change the home and clears it only after a confirmed no-change outcome or a successful send; the TERM/INT traps are gone, and the kill regression now sends TERM then KILL after one second.
  • tests/fm-remote-secondmate-lifecycle-e2e.test.sh and Behavior portable serial 5: the first CI run failed its watcher auto-relaunch leg. Across 14 recent main runs that suite's remote-spawn leg took 30.8-35.6s and the watcher leg 27.3-34.5s, already near its 30s wait; on this PR remote spawn took 42.1s while legs that push nothing were only 5-10% slower. The relaunch is a remote spawn whose only changed step is the now-overlapped inheritance push, and this fixture has no transport latency while its job worker runs one home's commands one at a time, so overlap only adds submission overhead there. The suite now sends one item at a time (FM_REMOTE_INHERIT_PUSH_JOBS=1 in its remote_env); the production default of four and every wait bound are unchanged, and the overlapped scheduler stays covered by tests/fm-bootstrap-network-parallel.test.sh. The same suite was also flaky on our loaded 2-vCPU host, where it failed the same way on unmodified main, so CI is the verdict for it.
  • Relation to fix(bootstrap): send the secondmate re-read nudge fire-and-forget #4717: fix(bootstrap): send the secondmate re-read nudge fire-and-forget #4717 changes how the second-mate re-read nudge is sent (fm-send.sh --fire-and-forget, so no pending-reply expectation is created). a43e0433 changes whether a remote second mate is nudged (only when the re-read is owed). The two are complementary, but both edit the remote nudge send in secondmate_sync_remote_one in bin/fm-bootstrap.sh, so whichever lands second needs a small rebase there.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 7 scenarios were driven live against the product); untested: Startup overlaps remote inheritance within its concurrency limit and preserves ordered diagnostics, A hung remote mate times out while healthy mates converge and its retry obligation survives, An unchanged remote home receives no notification unless a re-read is already owed, A partially applied inheritance push retains the owed re-read through an unchanged retry, Unknown transport completion preserves the owed re-read even alongside another item's failure, Termination during a remote mutation preserves the owed re-read for the next attempt, Local config-push notifies after partial propagation and stays silent for unchanged homes
  • Live validation: ⚠️ inconclusive - 0 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Startup overlaps remote inheritance within its concurrency limit and preserves ordered diagnostics ⏸️ untested no Focused scheduler regressions passed, but the full network suite failed when simulated calls exceeded timing budgets. Live SSH validation was excluded by the recorded user decision; changing that scop…
A hung remote mate times out while healthy mates converge and its retry obligation survives ⏸️ untested no The focused regression passed with simulated transport. The recorded user decision limits this run to regression suites instead of a live SSH lab.
An unchanged remote home receives no notification unless a re-read is already owed ⏸️ untested no The regression passed using simulated endpoints. Running-agent validation requires authorization to expand the recorded regression-only scope.
A partially applied inheritance push retains the owed re-read through an unchanged retry ⏸️ untested no Bootstrap and config-push regressions passed with injected transport responses. Live SSH validation was excluded by the recorded user decision.
Unknown transport completion preserves the owed re-read even alongside another item's failure ⏸️ untested no Focused regressions passed for status 255 and unchanged retries. Transport failures were simulated, consistent with the recorded regression-only scope.
Termination during a remote mutation preserves the owed re-read for the next attempt ⏸️ untested no The regression killed actual bootstrap and config-push processes and passed, but remote calls were simulated. Live remote mutation validation requires expanded authorization.
Local config-push notifies after partial propagation and stays silent for unchanged homes ⏸️ untested no The requested harness suite reached its 540-second limit before these cases. No live agent was launched under the recorded regression-only scope; completing this proof requires a longer targeted run o…
  • bin/fm-test-run.sh --jobs 1 --per-script-timeout-secs 540 tests/fm-bootstrap-network-parallel.test.sh tests/fm-secondmate-sync.test.sh tests/fm-secondmate-harness.test.sh --json ~/.no-mistakes/evidence/01M55YA8AVJQK1MJFEFZYEHRHS/targeted-results.json: network assertion failed after convergence timeouts; sync and harness suites timed out.
  • bin/fm-test-run.sh --jobs 1 --per-script-timeout-secs 240 tests/fm-convergence-focused-gate.test.sh: five existing scheduler, failure-guard, unknown-status, and interruption regressions passed.
  • bin/fm-test-run.sh --jobs 1 --per-script-timeout-secs 180 tests/fm-convergence-focused-gate.test.sh: four existing partial-failure, unknown-completion, and hung-mate regressions passed.
  • Removed the temporary focused test selector; git status --short was empty and no selected test processes remained.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @arthurcruzd — I read head 959bb0ae (attestation MATCHES).

What it does: parallel inherit-push (FM_REMOTE_INHERIT_PUSH_JOBS), per-mate FM_SECONDMATE_CONVERGENCE_TIMEOUT (default 75s) so one hung remote cannot hold the network stage past its bound, and owed remote re-read markers so unchanged homes are not nudged every start while a budget cut-off still retries.

Contract-class: restore (own read). Startup already had a network bound and a re-read nudge path; this makes remote convergence fit that bound and stops false nudges without adding a new default-on captain surface.

VISION.md, rule by rule: One captain (aligns — less noisy re-reads). Authority explicit (aligns — timeouts are mechanics). Scripts own the mechanics (aligns). Restart a non-event (aligns — owed marker survives a cut-off). Delegation with a spine (blocked on live — see below). Outlives any vendor (neutral). Scope (aligns).

Live validation: the PR body marks live inconclusive — 0 of 7 (portable suites only; no live SSH lab). Warm ask: when you have a moment, could you live-test the named remote convergence / owed-reread scenarios against a real remote second-mate home and post evidence (or re-raise through no-mistakes with live=go)? We don't run our own live/lab for this.

CI: Behavior portable serial 5 FAILED on tests/fm-remote-secondmate-lifecycle-e2e.test.sh (the watcher did not exit on its auto-relaunch wake within the bound). I re-ran failed jobs once on run 38866751893. Outcome: waiting-author on live evidence (and green CI after the re-run).

@arthurcruzd
arthurcruzd force-pushed the fm/fm-remote-convergence-upstream branch from 959bb0a to a697f9b Compare October 17, 2026 19:06
@arthurcruzd arthurcruzd changed the title fix(bin): bound remote second-mate convergence and skip unchanged re-reads fix: bound remote secondmate convergence and preserve owed re-reads Oct 17, 2026
arthurcruzd and others added 10 commits October 17, 2026 22:04
…rk bound

The deferred startup network stage (120s) timed out once four second mates
were remote: the mates already converge concurrently, but each mate's
inheritance push sent its fifteen allowlisted items one SSH round trip after
another, so a single mate's convergence took 64-76s after a ~16s liveness
pass.

- fm-remote-inherit-push.sh validates and snapshots every item locally first,
  so a local refusal now sends nothing, then sends the items up to
  FM_REMOTE_INHERIT_PUSH_JOBS (default 4) at a time and replays their output in
  allowlist order. A failed item still fails the push with its own error, and
  no further item is started after it. The receiver is unchanged: each item is
  its own file and generation record, and the host's job worker still runs one
  home's commands one at a time.
- fm-bootstrap.sh gives each remote mate's convergence its own budget,
  FM_SECONDMATE_CONVERGENCE_TIMEOUT (default 75s). A mate whose sync or push
  hits it is reported as that mate's SECONDMATE_SYNC skip and keeps its retry
  marker, instead of holding the whole stage past its bound.
…hanged

Each remote convergence attempt records its retry marker before it starts,
so a sweep cut off by the startup network bound or failing before any change
left a marker that made the next session start nudge every remote mate even
though its instructions and inherited files were unchanged. The marker now
records whether a re-read is owed, set only once an attempt actually changed
the home, and a tracked-file sync that moved nothing under AGENTS.md, bin/,
or .agents/skills/ no longer counts as a change.
…ut short

A convergence step stopped by the per-mate budget loses its output, so a
push that had already applied an item reported nothing and left the retry
marker with no re-read owed; the next start then saw every item unchanged
and never told the mate to re-read. A step cut off by the budget now marks
the re-read owed, and so does a failed push whose output shows items it had
already pushed or removed.

The lifecycle e2e suite runs every remote leg through the real entrypoint
and job worker on the test machine, so it now gives convergence ample time;
the budget's own behavior is pinned in fm-bootstrap-network-parallel, whose
budget and failure cases are also made independent of machine load.
…fixture

Behavior portable serial 5 failed on the watcher auto-relaunch leg of
tests/fm-remote-secondmate-lifecycle-e2e.test.sh after the inheritance push
started overlapping its sends. Across 14 recent main CI runs that suite's
remote-spawn leg took 30.8-35.6s and the watcher leg 27.3-34.5s, already close
to its 30s wait; on the PR run remote spawn took 42.1s, well outside that range,
while legs that push nothing were only 5-10% slower. The watcher relaunch is a
remote spawn, and the only changed code on that path is the inheritance push.

This fixture's transport has no network latency and its job worker runs one
home's commands one at a time, so overlapping sends cannot hide any round trip
there and only add submission overhead to every remote spawn. The suite now
sends one item at a time, as it did before; the overlapped scheduler stays
covered by tests/fm-bootstrap-network-parallel.test.sh, and the production
default of four is unchanged. The watcher leg's failure now also prints the
watcher's output.
…an change its home

A live run against a real remote second-mate home showed the owed re-read
still lost when the startup network bound stopped the stage. That bound
stops it the way `timeout -k 1` does: TERM to the stage's process group, then
KILL one second later. Bash defers a TERM trap while the convergence worker
waits in a command substitution, and the remote call runs in its own timed
process group, so the KILL landed before the trap could record the re-read.
The remote home had already applied the change, the next start saw every item
unchanged, sent nothing, and deleted the marker, so the mate was never told
to re-read.

Bootstrap convergence and config-push now write the record owed before any
remote step can change the home, and write it back only after the attempt has
reported: removed after confirmed unchanged convergence or a successful send,
and back to owed=0 when a failed attempt's outcome proves nothing changed. A
kill at any point therefore leaves the re-read owed. The TERM/INT traps are
gone. The kill regression now sends TERM and then KILL one second later, as
the startup bound does; it fails on the previous head and passes here.
@arthurcruzd
arthurcruzd force-pushed the fm/fm-remote-convergence-upstream branch from a697f9b to f0ea3c0 Compare October 17, 2026 22:45
@arthurcruzd

Copy link
Copy Markdown
Contributor Author

Live evidence for the seven remote convergence / owed re-read scenarios, run 2026-10-17 against a real remote second-mate home on a macOS host (Darwin arm64) over real SSH.

Setup

  • Primary side: a scratch FM_HOME on a Linux VPS. Scenarios 1-5 and 7, and the first 6a-6d run, used this PR's pre-rebase head 959bb0ae. The 6a-6d re-check and the over-nudge check used 959bb0ae plus the write-ahead fix that is now 4c55f368 on this branch. With that fix applied, the four scripts this PR changes (fm-bootstrap.sh, fm-config-push.sh, fm-remote-inherit-push.sh, fm-secondmate-nudge-lib.sh) are code-identical to the current head f0ea3c03; only comments differ, plus two unrelated fm-bootstrap.sh lines from main. The rebased head itself could not drive this receiver: the rebase brought in config/herdr-project-groups (feat(herdr): opt-in project groups with status tags and a sorted agents view #7434), which the released receiver's allowlist does not have yet, and that item is refused (see 2c).
  • Receiver side: two scratch second-mate homes (lab-a, lab-b) on the Mac, executed by that host's existing Firstmate code root, which runs released fleet code (de9c6a81), not this PR. Everything this PR changes runs on the primary.
  • Transport: real ssh through FM_SSH_BIN pointing at a small lab wrapper. The wrapper refuses any call not aimed at the scratch homes; forwards sync, inheritance put/absent, and the read-only doctor for real; answers endpoint state/observe and the reply poll locally, because no agent was launched; refuses every other remote verb; and injects faults (hang, receiver failure on the Nth call, exit 255 after the real command completed with its output withheld, and a delay after completion to open a kill window).
  • No agent was launched, so a re-read nudge appears as a delivery attempt (the remote send is refused by the wrapper) plus the durable retry marker's owed= field. It is not a delivered message. Where a scenario needs a "nudge was delivered" starting state, the marker was removed by hand, which is what a successful send does.

1. Startup overlaps remote work with correctly attributed diagnostics - PASS
FM_BOOTSTRAP_NETWORK=only timeout 120 bin/fm-bootstrap.sh, with lab-a healthy and lab-b hung.
Timing records: secondmate convergence 9197 44606 lab-a@mac, secondmate convergence 9302 75191 lab-b@mac, phase secondmate-sync 8721 75974. Both started together; the phase took the longer mate's time, not the sum. Bootstrap wall time was 87.0s, inside the 120s bound. Only lab-b got skip lines:

SECONDMATE_SYNC: secondmate lab-b: skipped: remote tracked-file sync failed on mac: no answer within the 75s per-mate convergence budget
SECONDMATE_SYNC: secondmate lab-b: skipped: remote inheritance failed on mac: no answer within the 75s per-mate convergence budget

lab-a really advanced on the Mac (1a6714f2 -> 959bb0ae) and received its inherited config.

2. Inheritance concurrency bound, output order, and failure guards - PASS

  • 2a. Same 15-item no-change push to lab-a: FM_REMOTE_INHERIT_PUSH_JOBS=1 took 103.7s with at most 1 call in flight; =4 took 56.4s with at most 4 in flight. Output was replayed in allowlist order both times. The gain is about 1.8x, not 4x, because the receiver's job worker runs one home's commands one at a time, so overlap hides each call's roughly 7s of SSH and entrypoint overhead, not the work itself.
  • 2b. Receiver failure injected on the 6th call with JOBS=4: items 1-5, already in flight, finished, and no item after the failure was started (the wrapper log has no start line for items 7-15). Exit 1, with the error reported on its own item: error: lab-injected receiver failure on config/herdr-presentation-spaces.
  • 2c. Cross-version guard, observed by accident with the rebased head: the released receiver refused config/herdr-project-groups (error: path is not inherited material), the push failed closed, the three items already in flight finished, and the remaining six were never sent (10 of 16 calls).
  • 2d. A malformed data/captain-shared.md was refused locally (error: shared captain preferences have no valid primary-authoritative header) before anything was sent: 0 remote calls.

3. A hung remote times out without blocking healthy mates and keeps its retry obligation - PASS
Same run as 1. lab-b was cut at 75s, its retry marker kept owed=1, and lab-a finished at 35.4s.

4. An unchanged home stays silent while an owed re-read retries - PASS
Startup with both homes unchanged (current: 959bb0ae... plus 14 unchanged: each); lab-a owed nothing and lab-b had owed=1. lab-a made 0 send calls and its marker was removed. lab-b made 1 send attempt and kept owed=1 when delivery failed.

5. A partially applied inheritance push keeps the owed re-read - PASS
lab-a started with no marker. One inherited file changed, and the receiver failure was injected on call 7. Receiver output included pushed: config/crew-harness; startup reported remote inheritance failed on mac: error: lab-injected receiver failure on config/startup-memory-budget, and the marker became owed=1 with no premature send. On the next clean start everything was unchanged (current: plus 14 unchanged:), yet the owed re-read was retried: 1 send attempt, owed=1 kept.

6. Unknown transport completion or termination during mutation keeps the owed re-read - FAILED first, PASS after the write-ahead fix in 4c55f368

  • 6a. Exit 255 after the real inheritance push completed, output withheld: the Mac had applied crew-harness; the primary saw only remote inheritance failed on mac: lab-wrapper: connection lost after remote completion, and the marker became owed=1. PASS, before and after the fix.
  • 6b. Exit 255 after the real tracked-file sync completed, output withheld: the Mac advanced lab-b to 959bb0ae (withheld output synced: 959bb0ae... instr=bin,.agents/skills); marker owed=1. PASS, before and after the fix.
  • 6c. TERM to bootstrap's process group after the receiver had applied a change, with no KILL following. Before the fix, the TERM trap ran only once the in-flight remote call returned, about 13s later, and wrote owed=1. After the fix, the marker was already owed=1 before the TERM and stayed so. PASS.
  • 6d. The same, but with KILL 1s after TERM, which is how the startup network bound stops the stage (fm_run_timed -> timeout -k 1).
    • Before the fix: FAIL. Bash defers the TERM trap while the worker waits in inherit_out=$(fm_run_timed ...), and the inheritance push runs in its own timeout process group, so it is not signalled and the KILL lands before the trap runs. The marker stayed owed=0 although the Mac had applied the change (crew-harness = codex on the remote). The orphaned push finished, the next clean start saw current: plus 14 unchanged:, sent nothing, and deleted the marker, so the mate would never be told to re-read.
    • Fix (4c55f368): bootstrap convergence and config-push now write the record as owed=1 before any remote step can change the home. They write it back only after the attempt reports: removed after confirmed unchanged convergence or a successful send, and back to owed=0 when a failed attempt's outcome proves nothing changed. The TERM/INT traps are gone. The kill regression in tests/fm-bootstrap-network-parallel.test.sh now sends TERM and then KILL 1s later; it fails on the previous head a697f9bf and passes with the fix.
    • After the fix: PASS. The marker read owed=1 before the kill and after TERM+KILL. The next clean start saw everything unchanged and still retried the re-read: 1 send attempt, owed=1 kept.
    • No over-nudge after the fix: an attempt that failed with a known no-change outcome (sync current:, every inheritance item refused with an error) wrote the marker back to owed=0 and sent nothing.

7. Local config-push re-reads after partial propagation and skips unchanged homes - PASS

  • 7a. One inherited file changed; receiver failure injected on lab-a's 7th call. lab-a: pushed: config/crew-harness, then the error, owed=1, no send attempt. lab-b: pushed: config/crew-harness, a send attempt, config-reread: send failed; retry retained, owed=1. Exit 1.
  • 7b. No change, lab-a still owed, lab-b marked delivered: lab-a retried (config-reread: send failed; retry retained, owed=1); lab-b was silent (0 send calls, no marker); all 30 other item lines were unchanged:.

Not driven live
A delivered re-read message: no agent ran in the scratch homes, so delivery is shown as the attempt plus the durable marker.

Raw logs (wrapper call log with timestamps, receiver output, bootstrap output, timing records, marker snapshots) are kept privately and can be shared on request.

@kunchenguid
kunchenguid merged commit 63fc5eb into kunchenguid:main Oct 18, 2026
20 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @arthurcruzd — really appreciate you taking the time on this.

(Contract-class, own read: restore — remote convergence now fits the existing startup network bound and re-read nudges follow the documented changed-transfer contract. Thanks for the thorough live SSH evidence.)

@arthurcruzd
arthurcruzd deleted the fm/fm-remote-convergence-upstream branch October 18, 2026 23:42
max-metaplanet added a commit to max-metaplanet/firstmate that referenced this pull request Oct 19, 2026
## Commits taken

- d20196a feat(herdr): opt-in project groups with status tags and a sorted agents view (kunchenguid#7434)
- ce69740 fix(bin): pin LC_ALL=C for remote job process identity reads (kunchenguid#7410)
- 64dddf6 fix(opencode): ignore child stdin EPIPE in guard and encoder (kunchenguid#7447)
- 11becbb fix(bin): ignore crew state overrides for other tasks (kunchenguid#5881)
- eeeeb91 fix(bin): re-anchor a Claude session's lock so /clear keeps ownership (kunchenguid#7415)
- 66c300b feat: support version URLs for watched tool updates (kunchenguid#7449)
- 3094475 fix(pi): keep a live session's extension markers when a nested Pi command loads them (kunchenguid#7287)
- f05b628 fix: reclaim orphaned Claude auto-arm claims (kunchenguid#5939)
- c4f4333 feat(bin): add Polytoken crewmate/scout worker adapter (kunchenguid#7321)
- 11990a2 Fix away branch relaunch admission (kunchenguid#7444)
- 56074d0 fix(bin): show reported checks when a pull request's base requires none (kunchenguid#7450)
- 0791268 fix: support durable per-secondmate account pins (kunchenguid#7452)
- 4e6b9f5 feat(bin): consult operator evidence guards before wedge escalation (kunchenguid#6958)
- c7b7798 fix(bin): make inbox listing succeed when the inbox is empty (kunchenguid#7460)
- 63fc5eb fix: bound remote secondmate convergence and preserve owed re-reads (kunchenguid#7394)
- 8ba34f1 fix: require positive daemon running status in crew-state (kunchenguid#7317)
- 1aa2a21 fix(tests): stabilize supervision host drain and offer fixtures (kunchenguid#7467)
- 69f9d09 fix(bin): refuse spawn into a project with an unborn HEAD (kunchenguid#6987)
- 45dd50a feat(bin): add GitLab --allow-no-pipeline merge waiver and close backlog items for GitLab MRs (kunchenguid#7462)

## Conflict decisions

- `.agents/skills/operational-home-layout/SKILL.md`: Fork seat configuration; upstream per-secondmate account configuration. Decision: Keep both configuration entries.
- `bin/backends/herdr.sh`: Fork send-failure/recovery semantics and harness variable; upstream Polytoken busy override. Decision: Keep fork send-failed and recovery handling; add Polytoken busy identity without losing the fork harness variable.
- `bin/fm-backlog-transition-lib.sh`: Fork cached library directory; upstream GitLab completion support. Decision: Keep cached source path and extend forge ownership comment to GitLab; accept GitLab completion path.
- `bin/fm-config-inherit-lib.sh`: Fork Claude/Codex seat inheritance; upstream Herdr project groups. Decision: Union the allowlist; per-secondmate account pins remain local to the primary home.
- `bin/fm-control.sh`: Fork pre-stop seat checks; upstream per-mate pins and Polytoken launch checks. Decision: Select the per-mate pin while retaining its returned account for seat conflict validation; keep all Polytoken pre-stop checks. A valid explicit pin supersedes the old recorded Claude store on relaunch.
- `bin/fm-harness.sh`: Fork in-process HARNESS_VERDICT result; upstream echo-based Polytoken detection. Decision: Add Polytoken through the fork verdict convention, retaining existing adapter detection.
- `bin/fm-lock.sh`: Fork handover reservation and runtime publication; upstream session re-anchor lease/auto-arm locks. Decision: Share the existing claim lock and release helper, add lease/auto-arm locking, then publish runtime and clear an admitted handover before releasing locks.
- `bin/fm-pr-state.sh`: Fork shared required-check evaluator from dbe11b1 and 91371c8; upstream 56074d0 adds a second gh pr checks fallback. Decision: Keep one evaluator through fm-pr-checks.sh and fm-pr-checks-lib.sh. It already checks non-advisory reported checks on unprotected bases, includes missing configured requirements, and fails closed on read errors. Adapt upstream regressions to this API; preserve the fork REQUIRED CHECK label and advisory policy.
- `bin/fm-spawn.sh`: Fork parked-session resume, seats, unclaimed-worktree guard and ticket hook; upstream Polytoken, per-mate accounts and Herdr groups. Decision: Compose both paths, retain validate_spawn_worktree_unclaimed, seat gates, profile trust and metadata, and both hooks. Extend pin/seat refusal to the selected per-mate pin while retaining the primary-home seat guard. The selected durable Claude pin owns trust and recorded store on relaunch so old seats cannot override it.
- `bin/fm-teardown.sh`: Fork merged-at/park record cleanup and isolation protections; upstream generated Polytoken wiring cleanup. Decision: Keep fork cleanup and guards; add only task-owned Polytoken files and generated untracked wiring to existing guarded teardown.
- `bin/fm-test-run.sh`: Fork timing entries and pipeline-spend suite; upstream Herdr-group and Polytoken suites. Decision: Union suite entries, preserve fork timing measurements for existing suites.
- `bin/fm-wake-lib.sh`: Fork single-read auto-arm ledger parser; upstream session-owner identity fields. Decision: Extend the single-read parser with owner_session_id and the third-line lock identity; retain orphan recovery and lease logic.
- `bin/fm-watch.sh`: Fork bounded run-activity deferral and escalation wording; upstream operator evidence guard. Decision: Keep both bounded deferrals and append operator guard evidence to both ordinary and deep-inspection escalations. Keep exact owned watcher termination semantics.
- `docs/agent-control.md`: Fork seat relaunch policy; upstream per-mate account selection. Decision: Describe both policies with account pin checked before stopping the live agent.
- `docs/configuration.md`: Fork seat sections and ticket timeout; upstream per-mate pins and remote convergence settings. Decision: Keep all sections, place per-mate pins under worker accounts before the seat sections, and retain all timeout entries.
- `tests/fm-control-relaunch.test.sh`: Fork fixture cleanup and seat regressions; upstream account and away-admission regressions. Decision: Keep fixture-scoped cleanup and all regression calls; extend the changed-pin case to check trust in the new store and recorded profile.
- `tests/fm-crew-state.test.sh`: Fork no-fork metadata parsing test; upstream override-identity tests. Decision: Keep both test bodies and calls, plus upstream positive daemon-status cases.
- `tests/fm-pr-merge.test.sh`: Fork named-case local selector; upstream GitLab waiver test definitions. Decision: Place upstream definitions before the named-case selector and retain every case.
- `tests/fm-supervision-host.test.sh`: Fork split helper/suite layout; upstream snapshot-aware offer fixture. Decision: Update the shared supervision-host-helpers.sh implementation and retain its split consumers rather than duplicate the helper in one suite.
- `tests/fm-teardown.test.sh`: Fork collision/released-claim cases; upstream Polytoken cleanup cases. Decision: Keep all regression calls.
- `tests/fm-watch-triage.test.sh`: Fork split classifier/stale/delivery suites; upstream unsplit suite with four new operator-guard cases. Decision: Keep the split and move only new guard fixtures/cases into fm-watch-triage-stale.test.sh; do not resurrect duplicated legacy test bodies.

## Additional integration and verification decisions

- Preserve fork teardown, merge, push, worktree ownership/isolation, and exact-owned watcher termination guards. GitLab no-pipeline waiver remains explicit, attended-only, GitLab-only, and only accepts an explicit null pipeline; default and existing-pipeline safety checks remain in force.
- Existing pull-request CI selects subsets and cannot prove the requested full suite. Add a manual CI workflow trigger using the existing full-suite fallback, so the feature head can run every required lane before landing; document that entry point. No local full suite or real Herdr lifecycle run is authorized.
max-metaplanet added a commit to max-metaplanet/firstmate that referenced this pull request Oct 19, 2026