Skip to content

ci: rebalance portable serial test shards - #3489

Merged
kunchenguid merged 2 commits into
mainfrom
fm/fm-ci-serial-shard-budget-rebalance-r1
Sep 2, 2026
Merged

kunchenguid merged 2 commits into
mainfrom
fm/fm-ci-serial-shard-budget-rebalance-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix the over-budget CI serial-3 shard AT ITS CAUSE, with measured evidence; a blind timeout bump was explicitly ruled out as unacceptable.

Problem: the 'Behavior portable serial 3' CI shard ran ~20m12s against its timeout-minutes: 20 budget and timed out 1-3s after a passing test, on branches and on main alike (run 33574154856). Not a hang, not a cancellation - simply over its allowance, intermittently blocking every PR's path to clean-green.

Required approach, followed in order: (1) MEASURE first - determine exactly which behavior tests the serial-3 shard runs, their individual runtimes, and the shard total, and do the same for serial shards 1, 2 and 4 to expose the imbalance. (2) THEN fix the cause, choosing the cleaner of rebalancing the shards so no shard sits near its budget, or raising shard 3's timeout-minutes ONLY with the measured runtime and explicit headroom recorded in the PR body. Rebalancing was preferred because the imbalance was the real cause.

Measurement performed: per-shard test-step wall times were read from the CI job timings and the uploaded fm-test-timing-portable-serial-* artifacts of three green runs (33558082172, 33523597838, 33463326167). Shard 1 ran 11.3-11.7 min, shard 2 12.5-14.5 min, shard 3 17.3-19.7 min, shard 4 15.2-17.1 min. Shard 3's timed-out step in run 33574154856 ran 20m06s with only ~6s of setup.

Diagnosed cause: shards are packed longest-processing-time from per-script duration hints embedded in bin/fm-test-run.sh. Those hints were last measured on 2026-08-21 at 116 scripts; the lane has since grown to 139 scripts and from ~42 to ~63 minutes. 17 scripts had no hint at all and fell back to the 20s PORTABLE_SERIAL_DEFAULT_WEIGHT_MS default, and several existing hints were low by 2-5x (fm-watch-triage hinted 142409 ms vs 262626 ms measured; fm-public-followup 36301 ms vs 196745 ms). So the partition looked perfectly balanced in hint space at 734.6s per shard while really running 11.5/13.6/18.8/16.5 minutes. The existing tests asserted script-COUNT balance, which stayed normal (35 of 139 scripts on shard 3) and hid the duration skew.

Deliberate decisions a reviewer should not re-litigate:

  • timeout-minutes stays 20. It was deliberately NOT raised; the fix is the rebalance.
  • Hints were refreshed from THREE green runs taking the SLOWEST measurement per script, not a single run, because individual scripts varied up to 20% between runs and the balance must hold on a slow runner. The documented refresh procedure in docs/fm-test-portable-shards.md was updated to match and was verified to reproduce the committed table exactly.
  • The shard count was deliberately raised from 4 to 5. At 4 shards the refreshed partition still puts the worst shard at 15.7 min (78% of cap) on a lane that is actively growing, which does not satisfy the requirement that no shard sit near its budget. At 5 shards, replaying the partition against the three runs' real per-script durations puts the worst shard at 12.54 min = 63% of the 20-minute cap with 60% headroom, and the serial lane's wall-clock critical path drops from ~20 to ~12.5 min. The shard count is a single constant plus the ci.yml matrix, which already cross-validate via strategy.job-total, so this is a parameter change and not new machinery.
  • PORTABLE_SERIAL_DEFAULT_WEIGHT_MS was moved 20000 -> 27000 to track the new measured per-script mean (27409 ms), per its own comment.
  • A drift bound was added deliberately: --check-coverage now reports serial_unhinted= and refuses past PORTABLE_SERIAL_MAX_UNHINTED_PERCENT (15%). This recurrence has now happened twice (docs record the same timeout at PR 1495), and the repo's own coding guidelines prefer deterministic enforcement over relying on agent memory for critical infrastructure. The refusal path was verified by dropping 25 hints: exit 1 naming the count, the bound, the refresh doc, and the offending scripts. It currently reports serial_unhinted=0.

Constraints that were required and honored: do not change what any test asserts or which tests run - only how they are partitioned across shards and/or the shard timeout budget. This edits firstmate SHARED, TRACKED material (.github/workflows/ and bin/), so .agents/skills/firstmate-coding-guidelines/SKILL.md was read and followed. Keep any shell bash-3.2-safe, and bin/fm-timeout-lib.sh stays the single owner of bounded execution. Every commit is authored with NO co-author / Co-Authored-By trailer.

Acceptance the PR must meet: the PR body records the measured per-shard runtimes (all four serial shards), which approach was taken (rebalance vs raise) and why, and the resulting headroom so no shard sits at its budget; and the serial shards complete within budget with headroom on a CI run on this branch.

Verification already run locally: bin/fm-lint.sh clean, bin/fm-doc-audience-check.sh clean, tests/fm-test-run.test.sh 26/26 pass, --check-coverage reports total=175 parallel=24 serial=139 serial_shards=5 serial_unhinted=0 herdr=12.

What Changed

  • Refresh serial-test duration hints from the slowest per-script measurements across three green runs; the former four shards measured 11.3–11.7, 12.5–14.5, 17.3–19.7, and 15.2–17.1 minutes.
  • Rebalance the lane from four to five shards while retaining the 20-minute timeout. Replay against measured runtimes puts the worst shard at 12.54 minutes—63% of the cap, leaving 7.46 minutes of headroom—rather than raising the timeout around the imbalance.
  • Raise the default unmeasured-script weight to 27 seconds and make coverage checks report and enforce a 15% maximum unhinted share, with tests and refresh documentation for the new guard.

Risk Assessment

✅ Low: The change is well-bounded, preserves complete test coverage, aligns the five-shard workflow and runner configuration, and produces evenly balanced measured weights with substantial timeout headroom.

Testing

The initial bounded runner-test attempt timed out after the shard-focused cases had passed, and a longer targeted rerun completed successfully; coverage reports 139 serial tests across five disjoint shards with zero unhinted scripts, the drift refusal works end-to-end, and replaying three green CI timing sets puts the worst new shard at 12.54 minutes with 59.5% runtime headroom. Reviewer-visible replay, refusal, and normalized workflow artifacts were captured; no branch CI run existed yet, so actual branch-run confirmation remains for the outer mandatory CI phase.

Evidence: Measured three-run serial shard replay and headroom

Source: Measured three-run serial shard replay and headroom

Portable serial shard replay against three green CI timing-artifact runs
Current executable interface: bin/fm-test-run.sh --list --lane portable-serial-<k>of5
Unchanged CI timeout: 20.00 min (1,200,000 ms)

run 33558082172: original 4-shard script totals = 11.63m, 13.68m, 19.28m, 17.11m
run 33558082172: replayed 5-shard totals        = 12.25m, 11.99m, 12.54m, 12.34m, 12.45m
run 33558082172: worst replay shard             = 12.54m (62.7% of cap; 59.5% runtime headroom)

run 33523597838: original 4-shard script totals = 11.68m, 12.46m, 19.67m, 15.18m
run 33523597838: replayed 5-shard totals        = 11.84m, 11.30m, 12.07m, 11.74m, 11.93m
run 33523597838: worst replay shard             = 12.07m (60.3% of cap; 65.7% runtime headroom)

run 33463326167: original 4-shard script totals = 11.33m, 14.52m, 17.33m, 17.09m
run 33463326167: replayed 5-shard totals        = 11.96m, 12.22m, 11.54m, 12.49m, 11.92m
run 33463326167: worst replay shard             = 12.49m (62.5% of cap; 60.1% runtime headroom)

Worst across all replayed runs: run 33558082172, shard 3, 12.54m, 62.7% of cap, 59.5% runtime headroom.
Coverage check: every current shard script had a real timing in every source run.
Evidence: Unhinted-duration drift refusal

Source: Unhinted-duration drift refusal

fm-test-run: coverage guard: 25 of 164 portable serial scripts have no measured duration hint (max 15%)
fm-test-run: refresh the hints from a green run's timing artifacts: docs/fm-test-portable-shards.md
tests/fm-unhinted-drift-evidence-01.test.sh
tests/fm-unhinted-drift-evidence-02.test.sh
tests/fm-unhinted-drift-evidence-03.test.sh
tests/fm-unhinted-drift-evidence-04.test.sh
tests/fm-unhinted-drift-evidence-05.test.sh
tests/fm-unhinted-drift-evidence-06.test.sh
tests/fm-unhinted-drift-evidence-07.test.sh
tests/fm-unhinted-drift-evidence-08.test.sh
tests/fm-unhinted-drift-evidence-09.test.sh
tests/fm-unhinted-drift-evidence-10.test.sh
tests/fm-unhinted-drift-evidence-11.test.sh
tests/fm-unhinted-drift-evidence-12.test.sh
tests/fm-unhinted-drift-evidence-13.test.sh
tests/fm-unhinted-drift-evidence-14.test.sh
tests/fm-unhinted-drift-evidence-15.test.sh
tests/fm-unhinted-drift-evidence-16.test.sh
tests/fm-unhinted-drift-evidence-17.test.sh
tests/fm-unhinted-drift-evidence-18.test.sh
tests/fm-unhinted-drift-evidence-19.test.sh
tests/fm-unhinted-drift-evidence-20.test.sh
tests/fm-unhinted-drift-evidence-21.test.sh
tests/fm-unhinted-drift-evidence-22.test.sh
tests/fm-unhinted-drift-evidence-23.test.sh
tests/fm-unhinted-drift-evidence-24.test.sh
tests/fm-unhinted-drift-evidence-25.test.sh

exit_code=1
Evidence: Normalized CI serial matrix configuration

Source: Normalized CI serial matrix configuration

{
  "job_name": "Behavior portable serial ${{ matrix.shard }}",
  "timeout_minutes": 20,
  "matrix_shards": [
    1,
    2,
    3,
    4,
    5
  ],
  "fail_fast": false,
  "lane_env": "portable-serial-${{ matrix.shard }}of${{ strategy.job-total }}"
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • tests/fm-test-run.test.sh with a 180-second bound (timed out during later unrelated cases after all shard-focused cases passed), then rerun with a 600-second bound to completion
  • bin/fm-test-run.sh --check-coverage and bin/fm-test-run.sh --list-lanes
  • bin/fm-test-run.sh --list --lane portable-serial-{1,2,3,4,5}of5 to verify shard counts and memberships
  • Downloaded all portable-serial timing artifacts from green CI runs 33558082172, 33523597838, and 33463326167 with npx -y gh-axi run download, then replayed their measured script durations through the current executable shard memberships
  • Added 25 temporary unhinted test executables, ran bin/fm-test-run.sh --check-coverage, verified exit 1 with the count, 15% bound, refresh documentation, and offending paths, then removed all temporary files
  • Parsed .github/workflows/ci.yml with Ruby YAML and verified the serial matrix is [1,2,3,4,5], timeout-minutes remains 20, and lane names derive their total from strategy.job-total
  • npx -y gh-axi run list --workflow ci.yml --branch fm/fm-ci-serial-shard-budget-rebalance-r1 --limit 5 --fields headSha,number,updatedAt,url (no branch CI run existed yet; the outer CI phase remains required)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

The "Behavior portable serial 3" shard ran 17-20 minutes against its
20-minute job cap and intermittently timed out seconds after a passing
test, on branches and on main alike.

Shards are packed longest-processing-time from per-script duration hints,
and those hints were last measured on 2026-08-21 at 116 scripts. The lane
has since grown to 139 scripts and from ~42 to ~63 minutes: 17 scripts had
no hint at all and fell back to the 20 s default, and several existing
hints were low by 2-5x (fm-watch-triage 142 s hinted vs 263 s measured,
fm-public-followup 36 s vs 197 s). The partition therefore looked
perfectly balanced in hint space, 734.6 s per shard, while really running
11.5, 13.6, 18.8 and 16.5 minutes. Script-count balance, which is what the
tests asserted, stayed normal throughout and hid it.

Refresh the hints from the timing artifacts of three green runs, taking
the slowest measurement of each script so the balance holds on a slow
runner, and split the lane across five shards instead of four. Replayed
against those runs' real per-script durations the worst shard is now
12.54 minutes, 63% of the unchanged 20-minute cap, and the serial lane's
wall clock drops from ~20 to ~12.5 minutes.

Bound the drift that caused this rather than relying on the hints being
refreshed by hand: the coverage guard now reports the unmeasured share as
serial_unhinted= and refuses past PORTABLE_SERIAL_MAX_UNHINTED_PERCENT,
which leaves room for newly added tests while making a stale table fail
the guard instead of silently pushing one shard into its cap.

No test changes what it asserts and no test stops running; only the
partition across shards changes.
@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge with no concrete blocking or non-blocking defect identified.

The workflow and runner agree on five shards, coverage checks preserve a complete disjoint partition, and the new unhinted-duration guard fails closed on command errors.

Reviews (1): Last reviewed commit: "no-mistakes(document): Clarify conservat..." | Re-trigger Greptile

@kunchenguid

Copy link
Copy Markdown
Owner Author

Post-fix verification on this branch (CI run 33583386304, attempt 2, 15/15 checks green).

Measured script time per serial shard from the uploaded fm-test-timing-portable-serial-* artifacts:

shard before (4-shard) this branch (5-shard) vs 20m cap
1 11.3-11.7m 11.63m 58%
2 12.5-14.5m 9.84m 49%
3 17.3-19.7m, timed out at 20m06s 10.28m 51%
4 15.2-17.1m 15.75m 79%
5 - 12.10m 61%

Lane total 59.6 min, mean 11.92 min/shard, all shards within budget with headroom. Shard 3, the one that was timing out, now finishes in about half its budget.

Shard 4 at 15.75m is above the 12.5m replay model, and that is runner variance rather than a partitioning error: every script on shard 4 ran at or above its hint (median 1.30x, minimum 0.98x), while shards 1/2/3/5 sat at 0.97-0.99x median. So shard 4 absorbed a roughly 30% slow runner and still finished with 4m15s to spare. Under the previous 4-shard layout that same slow runner would have pushed the 18.8m shard 3 to about 24 minutes, well past the cap.

Note on attempt 1: Behavior portable serial 1 was cancelled at the cap by a pre-existing intermittent hang in tests/fm-watch-triage.test.sh - one case stalled 16m37s immediately after bin/fm-wake-lib.sh: trap: line 2: unexpected EOF while looking for matching ). That file and that test are untouched by this branch; the hang is tracked separately. Attempt 2 passed cleanly in 11.63m.

@kunchenguid
kunchenguid merged commit 1459c4d into main Sep 2, 2026
27 of 28 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-ci-serial-shard-budget-rebalance-r1 branch September 2, 2026 03:35
Marcos-Leyva added a commit to Marcos-Leyva/firstmate that referenced this pull request Sep 3, 2026
)

* fix: surface inbound Relay media to responding agents (kunchenguid#3442)

* fix: surface inbound Relay attachments to the responding agent

A Discord support thread's screenshots were never seen by the agent
handling the mention. The relay delivered them and the poll stashed
them: the reporter's images arrived on the `thread_starter` entry of
`in_reply_to_chain` while the mention's own media list was empty. The
gap was in the responder's playbook, which enumerated a fixed field
list (`request_id`, `text`, `in_reply_to`, `in_reply_to_chain`) and so
made every other field, attachments included, invisible.

Fix it where the gap is, in prose:

- Read the complete payload object rather than a fixed field list, so
  media and later relay fields are never skipped again.
- Fetch and view attached media with the agent's own tools, on the
  mention and on every chain entry, and call out the common shape where
  only the thread starter carries the screenshots.
- Restrict those fetches to known-good platform media hosts over https
  (Discord: cdn.discordapp.com, media.discordapp.net,
  images-ext-1.discordapp.net, images-ext-2.discordapp.net; X:
  pbs.twimg.com, video.twimg.com), report a blocked host instead of
  working around it, and treat everything fetched as untrusted public
  input on the same terms as the surrounding thread text.

The poll stays out of it and downloads nothing, so no third-party bytes
are pulled on the polling path.

The new test pins the contract the playbook depends on: a mention in the
incident's shape, with an empty top-level media list and screenshots on
the thread starter, must reach the inbox with the payload intact and its
media URLs unfetched.

* no-mistakes(review): Preserve media authority and enforce poll-only fetching

* no-mistakes(document): Clarify Relay attachment safety prose

* fix(bin): defer inactive reconciliation during startup (kunchenguid#3480)

* Defer inactive startup reconciliation

* no-mistakes(review): Queue deferred inactive reconciliation diagnostics durably

* no-mistakes(review): Require worker phases to cover startup requests

* no-mistakes(review): Make diagnostic wakes safely acknowledgeable

* no-mistakes(document): Document deferred startup phase coverage

* fix(bin): bound wake drain presentation lock waits (kunchenguid#3475)

* fix: bound status presentation lock waits

* no-mistakes(review): Distinguish malformed presentation locks from live contention

* no-mistakes(review): Bound no-ack drain queue lock acquisition

* no-mistakes(document): Document bounded presentation-lock drain behavior

* no-mistakes(lint): Annotate bounded lock output global

* no-mistakes(ci): Added deterministic regression coverage for successful bounded-lock acquisition after live contention, verifying helper-to-caller PID ownership handoff and caller release. Verified with bash syntax checks, git diff checks, and the full fm-wake-queue test suite

* fix(bin): retire public follow-ups in remote homes (kunchenguid#3479)

* fix(relay): close a public loop whose work lives in a remote secondmate home

A public-followup loop bound to a REMOTE secondmate could never be closed.
`clear_public_followup_link` (bin/fm-public-followup.sh:701) required an
absolute recorded `work_home_path` for a `secondmate:*` work home, but a remote
route has no local path on this machine, so registration records that field
empty (bin/fm-public-followup.sh:291). Every close ran that clear first, so
`retire` died with "could not clear the legacy X link ... retained for
reconciliation" forever, and `deliver` posted the public reply and then stranded
the loop at `posted`. `--force` never covered that step.

The clear now goes to the remote home over that route's SSH transport, running
`fm-x-followup.sh --clear <work-id>` through `bin/fm-on.sh`. The route is decided
from `data/secondmates.md` before any local path is consulted, so a same-named
local directory can never stand in for a remote home, and registrations already
on disk retire without needing a new field. `fm-on.sh` passes ssh's status
through, so 255 stays the established "delivered but completion unknown" result
this codebase already reconciles: the close is refused, the registration and the
remote link are left exactly as they were, and the message names the unknown
completion instead of claiming a definite failure.

Local secondmate and `main` work homes are untouched, and `--force` still
governs only the unresolved-obligation refusal.

Three regression cases drive a remote route end to end, faking only the ssh
binary at the FM_SSH_BIN seam and then running the real remote entrypoint
against a local checkout, so the clear that must reach the remote home actually
happens there.

* no-mistakes(review): Guard remote link clears by request identity

* no-mistakes(review): Fail guarded clears on unreadable remote state

* no-mistakes(review): Reject guarded clears on non-writable remote state

* no-mistakes(review): Allow no-link retirement in non-writable remote state

* no-mistakes(document): Correct public-followup verification guarantee count

* no-mistakes(ci): Fixed the guarded link-clear race by ensuring absence is decided under the metadata lock whenever publication is possible. Added a behavioral concurrency regression test. Verified with fm-x-mode and fm-public-followup suites, Bash syntax checks, diff checks, and bin/fm-lint.sh

* no-mistakes(ci): Fixed the guarded link-clear race by refusing an unlocked absence decision when a publisher already owns the metadata lock in a non-writable directory. Added a behavioral concurrency regression test. Verified with fm-x-mode, fm-public-followup, syntax/diff checks, and fm-lint

* no-mistakes(ci): Fixed the guarded-clear race by refusing all guarded clears when the metadata parent is non-writable, including apparent link absence. Added a behavioral regression with a publisher waiting to create the lock, updated remote-retirement expectations and verification docs. Passed fm-x-mode, fm-public-followup, fm-lint, documentation audience, Bash syntax, and diff checks

* fix(relay): bound the guarded remote link clear so it refuses instead of hanging

The guarded clear checks that the remote state directory is writable before
taking the metadata lock, but that check cannot close the window: the parent can
turn non-writable between the check and lock creation, and a lock held by a live
holder is indistinguishable from that at the acquire. `fm_lock_acquire_wait` is
an unbounded `while ! try; do sleep 0.1; done`, so either case retried forever
and `deliver` or `retire` wedged with nothing reported, instead of returning the
retained-for-reconciliation refusal the guard exists to produce. This path runs
unattended over the secondmate transport, where a wedge is worse than either
outcome the guard defines.

The guarded clear now acquires through `fm_lock_acquire_wait_bounded`
(FMX_LINK_CLEAR_LOCK_TIMEOUT, default 10 seconds) and refuses on timeout through
the existing failure path. Unguarded local callers keep the ordinary unbounded
wait, so local behavior is unchanged.

The bounded primitive's header no longer claims presentation-only scope, since
this is a second authorized caller; nothing else in the shared lock
infrastructure changed.

The regression holds the metadata lock with a genuinely live process while
leaving the state directory writable, so the refusal can only come from the
bound and never from the writability precondition. Against the unbounded wait it
does not terminate at all; with the bound it refuses, retains the registration,
writes no receipt, and leaves the remote link untouched.

* no-mistakes(review): Harden lock-timeout regression with independent deadline

* no-mistakes(review): Restore no-op guarded clears on read-only state

* no-mistakes(document): Clarify remote public-followup cleanup contract

* fix(bin): support process events under symlinked homes (kunchenguid#3484)

* fix(bin): resolve process-event state roots before validating them

The process-event module validated the caller's spelling of a home's state
root instead of the directory it operates on: it required the supplied path
to equal its own lexical normalization, which rejects any path reached
through a symlinked ancestor. On macOS both /tmp and $TMPDIR are symlinks,
so an operator home under either could never claim a source. Reconcile still
reported the runner started, while the detached runner died writing "cannot
claim source" to the discarded stderr, and the source silently never fired.

Resolve the state root to its physical directory once, then apply the
existing private-directory validation to that resolved directory and derive
every path, recorded claim identity, and later confinement check from it.
This keeps the confinement contract for the directory actually operated on
rather than only for callers that already spelled it physically, and removes
the window where an ancestor symlink could be repointed between check and
use. Homes already spelled physically behave identically.

This was the single cause of both deterministic macOS failures in
tests/fm-procevent.test.sh ("reconcile never claimed the registered source")
and tests/fm-procevent-when.test.sh ("the winning concurrent arm did not
produce an outcome"). The new case pins the behavior with an explicit
symlinked-ancestor home, so it fails without the fix on any platform rather
than only where the temp root happens to be a symlink.

* fix(bin): pin the external capture staging boundary to its physical path

The extension capture path pinned its registry staging boundary by comparing
`pwd -P` against the caller-spelled registry directory, so a home reached
through a symlinked ancestor still refused to start an extension-backed
source after the state root itself resolved correctly. That left such a home
half working: built-in sources ran while external ones failed.

The staging preparer now prints the physical registry directory it validated,
matching the inbox and reservation preparers beside it, and the start path
pins on that returned path. The new end-to-end case drives the shipped
file-signal package from a symlinked home spelling.

* no-mistakes(review): Propagate canonical process-event state roots

* no-mistakes(review): Propagate canonical state to process-event adapters

* no-mistakes(document): Document physical process-event state roots

* fix(pi): deliver captain outcomes as deterministic transcript entries (kunchenguid#3312)

* fix(pi): persist captain outcomes visibly

* no-mistakes(review): Recover captain outcomes after cold-start lock acquisition

* no-mistakes(document): Document cold-start captain-outcome recovery

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* no-mistakes(review): Prove immediate Pi captain-outcome transcript delivery

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* no-mistakes: apply CI fixes

* fix(pi): process captain outcomes through a sequence-keyed turn

PR kunchenguid#3312 made every captain-facing supervision outcome a durable, exact-once
visible transcript entry with the read cursor advancing only after that entry
exists. That is the display half of the delivery contract. Left alone it turns
a probabilistic silent loss into a deterministic one: the captain sees an
anchor line, and firstmate never acts, because nothing opens a turn and
nothing records whether main ever processed the outcome.

The 2026-08-31 timeline showed the two shapes this must survive on the
previous hidden-turn path: seven delivered decision outcomes each answered by
an empty assistant message (cursor advanced, no retry, unanswered for close
to three hours), and two answered by an unrelated prior reply. Both happened
because delivery advanced the cursor at enqueue and accepted whatever the
next assistant message was.

Add the processing half on top of the persistence half:

- bin/fm-branch-outcome.sh keeps a processed marker separate from the read
  cursor (`unprocessed`, `mark-processed --through`, `processed-init`). It
  only advances through an explicit sequence-bound acknowledgement, never
  past the read cursor and never backwards; an absent marker reads as zero
  and `processed-init` migrates delivered history once so an upgraded home
  is not re-presented its past.
- After the visible entry for a captain outcome exists, the extension hands
  every still-unprocessed captain row to main as one hidden, typed
  `fm-branch-process` request listing each `[seq N] task: summary`, opening
  exactly one main turn. Main closes it only by calling the new
  `fm_branch_processed` tool with the highest sequence listed. An unrelated,
  empty, or paraphrased answer leaves the sequence open, and the same request
  is presented again at the end of the next main run and at session start.
  The first two presentations of a sequence set open a turn of their own;
  after that the request rides the captain's next prompt so an ignored
  request cannot loop, and a session replacement resets that budget.
  Routine outcomes stay turn-free.
- The regressions cover exactly those incident shapes against the real store
  scripts: an empty answer and an unrelated prior answer neither advance the
  marker nor stop re-presentation, the acknowledgement is refused beyond the
  read cursor and outside lock ownership, a partial acknowledgement keeps the
  newer sequence open, and kunchenguid#3312's own assertions now forbid an unkeyed turn
  rather than any turn. The store suite pins the marker's bounds and the
  migration; the real-SDK guard for appendEntry persistence and model
  exclusion is unchanged.

Docs move the protocol from "no model turn" to "one sequence-keyed processing
turn closed only by its acknowledgement", and the verification record carries
the dated run against Pi 0.84.4.

* no-mistakes(review): Harden outcome listing and sequence-bound acknowledgements

* no-mistakes(review): Harden outcome state validation and request pacing

* no-mistakes(review): Reject unsafe sidecars and unterminated outcome stores

* no-mistakes(review): Validate canonical mark-read cursor state

* no-mistakes(review): Guard cursor advancement against corrupt processed state

* no-mistakes(review): Bind acknowledgements to active processing requests

* no-mistakes(review): Reset pacing when processing sequence membership changes

* no-mistakes(review): Enforce silent outcome invariants at storage boundary

* no-mistakes(document): Document hardened captain outcome processing contracts

---------

Co-authored-by: kunchenguid <[email protected]>

* feat: add bounded concurrent Bearings ledger collection (kunchenguid#3481)

* feat: bound Bearings remote ledger collection

* no-mistakes(review): Clarify default remote-ledger collection behavior

* no-mistakes(review): Detach reconcile delivery from watcher loop

* no-mistakes(review): Enforce bounded snapshot and request captures

* no-mistakes(review): Bound legacy summary capture before parsing

* no-mistakes(review): Bound primary remote ledger captures

* no-mistakes(document): Correct snapshot and reconcile documentation

* no-mistakes(lint): Fix ShellCheck quoting in bounded collector

* no-mistakes(ci): Fixed all three CI failures: updated the macOS Bearings assertion to 44 tests, made the home-summary test deterministic and aligned with default ledger consumption, and increased the asynchronous reconcile retirement wait for loaded CI. Verified both focused suites, all 44 Bearings tests, ShellCheck, actionlint, Bash parsing, and git diff checks

* test: await reconcile request retirement

* no-mistakes(review): Avoid empty reconcile queue process churn

* no-mistakes(review): Read ledger summaries from immutable snapshots

* no-mistakes(review): Reject multi-document home ledger streams

* no-mistakes(review): Coalesce durable reconcile requests per target

* no-mistakes(review): Unify reconcile keys and reject snapshot streams

* no-mistakes(review): Key reconcile requests by stable target ID

* no-mistakes(document): Document per-target reconcile request coalescing

* no-mistakes(lint): Remove unused snapshot summary file variable

* no-mistakes(ci): Adjusted the concurrent collector regression’s end-to-end timing ceiling to account for stock macOS process/jq overhead outside the three-second remote collection budget, while remaining below the 15-second serial-read floor. Verified with stock /bin/bash 3.2: all 44 Bearings tests pass; bash syntax and git diff checks pass

* no-mistakes(ci): Fixed legacy summary validation to require exactly one top-level JSON document and added behavioral regression coverage. Stabilized CI by conditionally waiting longer for durable reconcile delivery and synchronously stopping the fm-on worker tree before fixture cleanup. Removed a redundant flaky healthy-path timing assertion; the wedged-reader test still proves concurrent bounded collection. Verified fm-bearings-snapshot, fm-secondmate-reconcile, and fm-on tests, plus project ShellCheck, bash syntax, and git diff checks

* ci: rebalance portable serial test shards (kunchenguid#3489)

* fix(ci): rebalance the portable serial shards on measured durations

The "Behavior portable serial 3" shard ran 17-20 minutes against its
20-minute job cap and intermittently timed out seconds after a passing
test, on branches and on main alike.

Shards are packed longest-processing-time from per-script duration hints,
and those hints were last measured on 2026-08-21 at 116 scripts. The lane
has since grown to 139 scripts and from ~42 to ~63 minutes: 17 scripts had
no hint at all and fell back to the 20 s default, and several existing
hints were low by 2-5x (fm-watch-triage 142 s hinted vs 263 s measured,
fm-public-followup 36 s vs 197 s). The partition therefore looked
perfectly balanced in hint space, 734.6 s per shard, while really running
11.5, 13.6, 18.8 and 16.5 minutes. Script-count balance, which is what the
tests asserted, stayed normal throughout and hid it.

Refresh the hints from the timing artifacts of three green runs, taking
the slowest measurement of each script so the balance holds on a slow
runner, and split the lane across five shards instead of four. Replayed
against those runs' real per-script durations the worst shard is now
12.54 minutes, 63% of the unchanged 20-minute cap, and the serial lane's
wall clock drops from ~20 to ~12.5 minutes.

Bound the drift that caused this rather than relying on the hints being
refreshed by hand: the coverage guard now reports the unmeasured share as
serial_unhinted= and refuses past PORTABLE_SERIAL_MAX_UNHINTED_PERCENT,
which leaves room for newly added tests while making a stale table fail
the guard instead of silently pushing one shard into its cap.

No test changes what it asserts and no test stops running; only the
partition across shards changes.

* no-mistakes(document): Clarify conservative shard timing aggregate

* fix(pi): fall back on incomplete supervision branch prompts (kunchenguid#3491)

* fix(pi): fall back after settled branch errors

* no-mistakes(review): Detect provider errors across prompt compaction

* no-mistakes(review): Preserve in-flight branch state across selection changes

* fix(pi): re-probe supervision branch after cooldown (kunchenguid#3497)

* fix(pi): recover supervision branch after cooldown

* no-mistakes(review): Defer branch recovery until prompt settlement

* no-mistakes(document): Clarify supervision cooldown recovery contract

* fix(bin): remove legacy remote snapshot reads (kunchenguid#3501)

* refactor: remove legacy remote summary reads

* no-mistakes(document): Document ledger-only snapshot reads

* no-mistakes(ci): Fixed the snapshot test fixture so ledger refreshes use the same fake executable PATH as the snapshot consumer. This preserves observable endpoint freshness after removing legacy summary computation. Verified stock Bash parsing and all 44 Bearings tests pass under /bin/bash; git diff checks pass

* no-mistakes(ci): Fixed the CI-only snapshot fixture failure by ensuring the bounded-ledger refresh uses its fake tmux backend. This removes host tmux availability as a source of nondeterminism. Verified all 44 Bearings tests pass, Bash syntax passes, and git diff checks are clean

* no-mistakes(ci): Fixed CI nondeterminism in the Bearings fixture: all local ledger refreshes now use the fixture’s fake tmux backend when available, instead of depending on host tmux state. Verified stock /bin/bash syntax, git diff checks, and all 44 Bearings tests with a deliberately failing host tmux

* fix(pi): preserve watcher continuity across session replacement (kunchenguid#3498)

* fix(pi): rearm watcher after session replacement

* no-mistakes(review): Queue actionable closes across Pi session replacement

* no-mistakes(review): Stop replacement arm when handoff persistence fails

* no-mistakes(review): Preserve actionable wakes through branch and late child races

* no-mistakes(review): Surface late handoff failures without crashing Pi

* no-mistakes(review): Coordinate replacement delivery settlement and unique handoff tokens

* no-mistakes(review): Retry stale deliveries and release settled claims

* no-mistakes(review): Distinguish branch settlement and retry handoff cleanup

* no-mistakes(review): Deduplicate persistent handoff cleanup alerts

* no-mistakes(review): Acknowledge watcher follow-ups only when consumed

* no-mistakes(review): Persist idle follow-ups until agent consumption

* no-mistakes(review): Preserve pending outcomes when handoff persistence fails

* no-mistakes(review): Arm replacement before awaiting prior delivery settlement

* no-mistakes(review): Adopt pending handoffs after lock reclamation

* no-mistakes(review): Prevent stale generations from adopting replacement handoffs

* no-mistakes(review): Scope replacement handoffs by watcher state

* no-mistakes(document): Clarify replacement handoff documentation

* no-mistakes(ci): Fixed the failing branch-extension tests to model the new settlement-promise contract. Failure cases now assert that delivery ownership returns to the watcher instead of expecting direct extension fallback. Verified the updated branch suite, Pi watcher suite, shell syntax, and diff checks

* no-mistakes(review): Update branch settlement tests and preserve chunked outcomes

* no-mistakes(document): Document watcher-owned replacement handoffs

* no-mistakes(document): Verify replacement handoff documentation

* test(pi): cover watcher-owned branch fallback

* no-mistakes(document): Refresh watcher-owned fallback documentation

* fix(bin): resurface task statuses missed by wake handling (kunchenguid#3495)

* fix(bin): resurface terminal statuses lost after branch handling

* test(watch): canonicalize process-event fixture homes

* no-mistakes(review): Index branch outcomes by causal status position

* no-mistakes(review): Recover outcome indexes and deduplicate resurfaced statuses

* no-mistakes(review): Handle legacy ambiguity and oversized status diagnostics

* no-mistakes(review): Keep unclassifiable oversized statuses silent

* no-mistakes(document): Document lost-wake outcome backstop

* no-mistakes(document): Update outcome backstop documentation

* no-mistakes(ci): Fixed CI regressions in wake-drain: parseable reserved-key decisions can no longer bypass the durable decision-fold guard, and status output is prepared and receipt-committed before presentation to prevent repeated one-shot outcomes after later failures. Added a behavioral regression for receipt commit failure and retry. Targeted backstop, correlation-token, decision-cursor, open-decision, unread-status, syntax, and diff checks pass locally. Shard-4 failures appeared unrelated/flaky; the network-parallel test passed locally

* no-mistakes(ci): Fixed the Greptile P1 data-loss issue by committing presentation receipts only after prepared output reaches stdout. Added behavioral coverage proving output failure leaves the backstop retryable and receipt failure may duplicate but never lose a presentation. Relevant wake-drain suites and syntax/diff checks pass. The shard-4 Pi extension failure is unrelated to this PR and did not warrant changes

* no-mistakes(ci): Stabilized tests/fm-bootstrap-network-parallel.test.sh by replacing scheduler-sensitive equal-sleep timing with bounded synchronization between mocked fetch and remote probes. This preserves detection of real serialization while avoiding false failures under CI load. Verified with five consecutive test runs, bash syntax validation, ShellCheck, and git diff checks. The separate Pi stock-rendering failure reproduces locally but is unrelated environment/version drift

* no-mistakes(ci): Fixed Behavior portable serial 4 by adding fm-classify-lib.sh and fm-timeout-lib.sh to the broken-root Pi test fixture; fm-branch-outcome.sh now depends on them. Verified the full Pi branch-extension suite with real-Pi checks skipped, the wake-drain outcome-backstop suite, Bash syntax, and git diff checks. Greptile findings are already addressed at HEAD; the no-mistakes attestation failure is external head-SHA state

* fix(bin): collect follow-up results from remote work homes (