Skip to content

fix: reduce routine supervision wakes in the primary conversation - #7726

Open
arthurcruzd wants to merge 10 commits into
kunchenguid:mainfrom
arthurcruzd:fm/fm-supervisor-noise-upstream
Open

arthurcruzd wants to merge 10 commits into
kunchenguid:mainfrom
arthurcruzd:fm/fm-supervisor-noise-upstream

Conversation

@arthurcruzd

@arthurcruzd arthurcruzd commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What was noisy

On the attended supervision host and the Pi supervision branch, several routine events still reached the primary conversation as if they needed attention:

  • A second mate re-recording a hold it already had open, or echoing a decision main had just answered with fm-send --resolve-key, was counted as decision-owned, so its signal went to main even though main already held that exact decision.
  • A stale wake that only rechecks a worker's declared external wait (for example a PR still waiting on maintainers) had no verdict rule telling the branch to stay silent while the wait still held.
  • An inactive-outcome check for a finished worker always reached main, even when the host had already reported that same finished result to main as a captain outcome, so the same ready branch was announced twice.

Separately, the home summary refresh folded every status stream with several command substitutions per line, which on a loaded 2-vCPU host pushed fm-home-summary-refresh.sh past its 60-second deadline on every attempt.

What each change does

  • Keep routine echo and wait-recheck wakes off main (.pi/extensions/lib/fm-branch-dispatch.ts, bin/fm-branch-prompt.sh, docs/pi-supervision-branch.md). A second mate's presented span no longer counts a needs-decision line that re-records an open decision with the same key and note, or a resolution this home appended itself (read from the existing state/.<task>.home-appends ledger), as decision-owned. A watcher-marked needs-decision: row from a second mate stays main's unless a cursor-bounded span explains the mark as such an unchanged re-record. The branch prompt now reports a still-holding declared wait, an answered-decision echo, an unchanged hold, and a persist reply as routine, and a cleared or unknown wait as captain.
  • Fold whole status streams without a subshell per line (bin/fm-classify-lib.sh). The fold helpers take an optional out-var (the status_line_verb convention), so status_open_decisions runs in the caller's shell and the record drop splits the set once into an array. Output is byte-identical, and a new tests/fm-fork-free-helpers.test.sh case compares the whole-file fold with the per-line fold; the CI bash 3.2 lane's expected regression count moves from 6 to 7 to match.
  • Let the host take inactive outcomes main already has (fm-branch-dispatch.ts, bin/fm-branch-prompt.sh, bin/fm-wake-drain.sh, docs/supervision-host.md, docs/pi-supervision-branch.md). On the attended host only, a check: inactive-outcome close is offered to the branch when every inactive row repeats a done result already reported: a done child whose current status log has a captain outcome in the outcome store recorded at or after its last done line. The row is claimed scoped to that child, and the prompt has the branch confirm nothing changed before reporting it silent. A failed child, an uncovered done, a reconcile notice, and the Pi watcher's own offer keep the close on main. The host log line for a close without a wake now keeps the arm's first line, so a run of them reads as the arm failure it is.
  • Find the last done line without findLast: Array.prototype.findLast is outside the Pi type-check lib, so tsc rejected the previous change; a reverse loop gives the same result.
  • Correct stale supervision dispatch documentation (bin/fm-classify-lib.sh comment, docs/pi-supervision-branch.md, docs/watcher-continuity.md): names the dispatch library as a second reader of the home-appends ledger, the re-record exception for marked rows, and the inactive-outcome report scope, and drops a stale statement that attended grants never name a check row; a follow-up pass removes duplicated routing prose those docs had restated.
  • Make two host outcome-presentation tests minute-tolerant (tests/fm-supervision-host.test.sh): test_branch_outcomes_present_a_long_away_window_once and test_branch_outcomes_only_on_a_host_home_off_pi asserted a hard-coded recorded 0m ago, which fails whenever building the fixture crosses a minute on a slow runner; they now accept any whole-minute age and keep their sequence, collapse, and acknowledgement checks.

Left out, and why

  • A sleeping second mate's reply-source launch failure. This change also takes process-event source failed to start closes for a second mate's reply source off main, backed by a once-per-outage reannouncement after six hours so a machine that never returns still surfaces. That backstop relies on a launch-failure episode staying open through a whole outage, which is fix: suppress repeated process-event wakes during continuous outages #7386 and is not merged yet. Without it, the episode closes and reopens every few cycles, and taking those notices off main would hide a machine that never comes back. It should follow once fix: suppress repeated process-event wakes during continuous outages #7386 lands.
  • Stale-row resolution by t3_thread_id, part of the first change on the fork, depends on the T3 Code backend, which upstream does not have yet (feat(bin): add an explicit-only T3 Code runtime backend #7518), so it and its test are omitted.
  • Other fork-only material - the fork's T3-hosted primary and wake relay, an unrelated idle-resurface offer change, and CI triggers for the fork's own branch - is not part of this PR.

None of the included changes was already present on upstream main.

Validation

Passing locally, run serially: tests/fm-branch-supervision.test.sh, tests/fm-fork-free-helpers.test.sh, tests/fm-pi-primary-types.test.sh, tests/fm-classify-decision-key.test.sh, tests/fm-classify-corr-token.test.sh, tests/fm-send-resolve-key.test.sh, bin/fm-lint.sh, bin/fm-doc-audience-check.sh, every dispatch case in tests/fm-pi-branch-extension.test.sh, and the dispatch and branch-outcome cases in tests/fm-supervision-host.test.sh, including the new inactive-outcome case.
The same four changes have run live in production supervision on a fork since 2026-10-17/18 with the intended effect: routine echoes, wait-rechecks, and repeated inactive outcomes stay off the primary conversation.
A fresh live drive of these scenarios was not feasible on the loaded 2-vCPU machine used for this port.
On that machine, the full Pi extension and supervision-host suites hit timing failures in host-loop and delivery cases, and unmodified main failed the same way, so CI is the authority for those suites.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 error
  • 🚨 bin/fm-procevent.sh:1645 - The required fifth port is absent: intent explicitly includes “7965ee01 fix(bin): keep a sleeping second mate's reply-source launch failure off main.” The branch contains only the other four ports. bin/fm-procevent.sh:1836 still announces every unconfirmed launch through report_launch_failure at :1645, without checking whether the second mate is sleeping; bin/fm-watch.sh:2791 and :2807 surface that announcement as a check, and .pi/extensions/lib/fm-branch-dispatch.ts:834 keeps that check on main. Include the approved sleeping-secondmate suppression before delivery, or obtain an explicit scope amendment.
⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 7 scenarios were driven live against the product); untested: Second-mate routine echoes stay off main while new decisions retain main routing, The host accepts a previously reported done result but rejects uncovered results, failures, and reconcile notices, Whole-stream status folding preserves the previous output without per-line subprocesses, Tracked extensions remain compatible with Pi 1.1.0 and 1.2.0, Returning from a long absence presents collapsed outcomes once and preserves unacknowledged results, An attended primary receives a captain outcome from the host, An agent silently confirms an unchanged external wait and surfaces a changed or uncertain wait
  • Live validation: ⚠️ inconclusive - 0 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Second-mate routine echoes stay off main while new decisions retain main routing ⏸️ untested no The prior payload records five passing automated dispatch cases, but establishes no live result. It reports that live supervision was prohibited by the recorded decision.
The host accepts a previously reported done result but rejects uncovered results, failures, and reconcile notices ⏸️ untested no The prior payload records execution of the dispatch CLI through isolated test fixtures, but establishes no live product result.
Whole-stream status folding preserves the previous output without per-line subprocesses ⏸️ untested no The prior payload records a passing focused behavioral comparison, but establishes no live product result.
Tracked extensions remain compatible with Pi 1.1.0 and 1.2.0 ⏸️ untested no The prior payload records passing automated compatibility checks for both Pi versions, but establishes no live product result.
Returning from a long absence presents collapsed outcomes once and preserves unacknowledged results ⏸️ untested no The prior payload records passing elapsed-minute and presentation regression tests, but establishes no live product result.
An attended primary receives a captain outcome from the host ⏸️ untested no The requested stub-engine attempt reproduced the previously recorded timeout. The user prohibited live supervision drives and assigned this timing-sensitive case to upstream CI; no retry or change was…
An agent silently confirms an unchanged external wait and surfaces a changed or uncertain wait ⏸️ untested no Emitted-prompt checks passed, but model behavior was not exercised. The recorded decision prohibits a live drive on this host and supplies prior operator production evidence instead.
  • nice -n 19 bash tests/fm-branch-supervision.test.sh — passed
  • nice -n 19 bash tests/fm-fork-free-helpers.test.sh — passed
  • nice -n 19 bash tests/fm-pi-primary-types.test.sh — passed for both Pi versions
  • nice -n 19 bash ~/.no-mistakes/evidence/01M5PZBASYY149HCSXDJEZM1B7/fm-pi-branch-extension-selected.sh — five dispatch cases passed
  • nice -n 19 bash ~/.no-mistakes/evidence/01M5PZBASYY149HCSXDJEZM1B7/fm-supervision-host-selected.sh — sixteen dispatch/outcome cases passed; final known timing-sensitive host-loop case timed out
  • Captured actual dispatch CLI responses; checked git status --short and process cleanup.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

🤖 Generated with Claude Code

A second mate's span no longer counts main's own --resolve-key close or
a hold re-recorded unchanged as decision-owned, and its marked row stays
main's unless a cursor-bounded span explains the mark as such a
re-record. The branch prompt reports a still-holding declared wait, an
answered-decision echo, an unchanged hold, and a persist reply as
routine, and a cleared or unknown wait as captain.
The home summary producer folds every task's whole status stream, and on
a loaded 2-vCPU host the four secondmate logs alone took ~68 s, pushing
fm-home-summary-refresh.sh past its 60-second deadline on every attempt.
The fold forked several command substitutions per decision line and read
the open set through a here-document one byte per syscall.

The fold helpers now take an optional out-var (the status_line_verb
convention) so status_open_decisions runs entirely in the caller's
shell, and the record drop splits the set once into an array. Output is
byte-identical; the summary refresh drops from 100-115 s to 21-40 s.
An inactive-outcome check for a done worker always reached main, even when
the supervision host had already reported that finished result to main as
a captain outcome, so the captain heard the same ready branch twice. On the
attended host, a done child's row is now the branch's, scoped to that
child, when the outcome store holds a captain outcome recorded on the
child's current status log at or after its last done line; the branch
prompt has it confirm the result is unchanged before reporting it silent.
A failed child, an uncovered done, a reconcile notice, and the Pi watcher's
offer keep the close on main.

The host log line for a close without a wake now keeps the arm's own line,
so a run of them reads as the watcher start failure it is.
Array.prototype.findLast is outside the Pi type-check lib, so tsc rejected
it; a reverse loop keeps the same result.
…host.test.sh: return-fail timed out at wait_until 250 (25s) on host_exited. Reproduced locally: the host was still in watcher/successor/handle_wake and only started the stub engine around 55s; the product path does hand the failed captain-return wake to main. The same 25s bound is used by the other single-turn away handoff cases and is already 2000 for the heavier siblings. Raised those host_exited waits from 250 to 2000 so they outlast 2-vCPU load without changing passing-test runtime. Focused return-fail and emptyresult both passed after the change
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @arthurcruzd. Echoes of decisions main already answered, re-checks of a wait that still holds, and the same finished result announced twice are exactly the noise this interface is meant to keep away from the captain. The write-up is very clear, including what you left out and why (the sleeping second mate piece waits on #7386, and the T3 thread-id piece is out too).

I read the diff at head d1fc1c3c (the no-mistakes CI repair landed just as I was writing this). The workflow edit only changes the bash 3.2 helper count from 6 to 7. The rest is dispatch, prompt, and fold logic plus tests and docs, with no network or credential surface. The no-mistakes attestation in the body is bound to this head.

A few things before this can move:

  • Live validation. The no-mistakes test step reports 0 of 7 scenarios driven live. The fork production history is useful context, but it isn't evidence for this head. When you can, please drive the main scenarios live against this branch (at least: a second mate echo staying off main while a new decision still reaches main, the host taking an already-reported done result while rejecting a failed or uncovered one, and an unchanged external wait staying silent while a changed one surfaces). Then post the evidence here, or re-raise through git push no-mistakes so it lands in the pipeline block.
  • CI. On 4dc8d37a, Behavior portable serial 1 failed with return-fail: the host did not hand the wake to main, and I'd re-run it (run 40098065690). The new head supersedes that. Raising those host_exited waits from 250 to 2000 matches the timing family we've been seeing on other PRs (test: intermittent 'latch: the later failed probe did not hand the wake back' in supervision-host #7709), and fresh CI is queued on d1fc1c3c. One cleanup: that commit also adds tests/.ci-host-focused.sh, which is a 3,275-line copy of tests/fm-supervision-host.test.sh from before the fix and looks like a scratch file the repair step left behind. Please drop it in your next push.
  • Contract-class. My read is new-default, not a restore. On an unconfigured home, the attended host and the Pi branch now keep wakes off main that reach main today: second mate echoes and re-recorded holds, still-holding wait re-checks, and inactive-outcome closes that repeat a reported done result. That fits VISION's "progress and internal mechanics are never news." But it changes what reaches the captain by default, so once this is otherwise ready it goes to Kun as a merge-or-leave decision, not auto-merge.

For now this is waiting on you for the live evidence. No rush.

… copy added by d1fc1c3) and reverted the six host_exited wait_until raises in tests/fm-supervision-host.test.sh from 2000 back to 250. The file now matches the pre-d1fc1c3c version; the two pre-existing 2000 waits (many receipts, lookup failure) were left alone. ci-1 through ci-15 are provider cancellations with no verdict, so no other files were changed. The fix push re-triggers CI
@arthurcruzd

Copy link
Copy Markdown
Contributor Author

CI note: 18 of 19 checks pass. The one failure, Behavior portable serial 2 (job), is test_wedge_escalation_deferred_while_worktree_is_written in tests/fm-watch-triage.test.sh.

Every product assertion in that case passed: the poll cycle completed, no wake was sent, writing-since was recorded, and the idle timer restarted.
The only failing step is the test's post-TERM cleanup (ack_stopped_cycle), where the drain did not yield a parseable WAKE_ACK_REQUIRED line.
This PR does not change that helper, bin/fm-watch.sh, or drain behavior (its bin/fm-wake-drain.sh change is a comment only); the suite ran because bin/fm-classify-lib.sh changed, and its fold and classifier cases passed.
The same shard passed on the base commit, so this looks like a pre-existing timing flake rather than a regression.

Could a maintainer re-run the failed serial 2 job? Merging is of course your call.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @arthurcruzd. Head 7b8119e7 drops the stray tests/.ci-host-focused.sh and puts the six host_exited waits back to 250, so the test file matches its pre-d1fc1c3c version. That covers my cleanup note. I compared it with d1fc1c3c. The product diff is unchanged (the same 13 files, and the workflow edit is still only the bash 3.2 helper count 6→7). The no-mistakes attestation binds this head.

CI: 18 of 19 checks pass. The one red is Behavior portable serial 2, in tests/fm-watch-triage.test.sh ("could not acknowledge the intentional phase-A watcher stop"). I've seen that same failure on another, unrelated PR this week, and your read of it (post-TERM cleanup, and this PR doesn't change the drain or the watcher) sounds right to me. As you asked, I re-ran the failed job (run 40102415845).

Still open: live validation. The pipeline block still says 0 of 7 scenarios were driven live. When you can, please drive the main ones against this branch and post the evidence here, or re-raise through git push no-mistakes: a second mate echo staying off main while a new decision still reaches main, the host taking an already-reported done result while rejecting a failed or uncovered one, and an unchanged external wait staying silent while a changed one surfaces.

Contract-class: new-default (unchanged). Once the live evidence is in and CI is green, this goes to Kun as a merge-or-leave decision. For now it's waiting on you for the live evidence. No rush.

arthurcruzd added a commit to arthurcruzd/firstmate that referenced this pull request Oct 28, 2026
Bring the fork's fleet branch up to upstream main, keeping the fleet-only
work upstream has not merged.

Upstream's explicit-only T3 Code backend (kunchenguid#7518) is the base for every T3
file; the fleet's earlier copy of that PR is superseded by it, along with
its own semantic-supervision push (upstream's pending-request watch), the
T3 capture, telemetry, interrupt-verdict, and launch-ownership fixes, and
the Claude env-channel ownership (upstream's FM_T3CODE_ENV_KEYS). On top of
it the fleet keeps: the T3-hosted primary and its wake relay
(bin/fm-t3-host.sh), remote second mates on a host's T3 server, quiet and
away mode and the supervision host under the relay, Grok and Muse T3
workers, exit by archive with a relaunch that resumes the same thread,
restart reconciliation, the foreign-slot refusal, local-interface
telemetry, and the T3 0.1.2 standard-scope sign-in.

Also kept: the open contributions for supervisor noise (kunchenguid#7726), one
launch-failed wake per outage (kunchenguid#7386), status-file birth times (kunchenguid#7384), the
take-over watcher TERM fix (kunchenguid#6916), and the fleet-only second-mate
reply-source and CI commits.
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