Repository navigation
fix(bin): exclude a remote mate's own parent channel from self-home status scans - #5263
Conversation
1515bf7 to
ff1673b
Compare
|
Friendly nudge on this one. It fixes the remote parent-channel scan gap from #5012: a remote mate's own replies.status was being swept by its parent's signal scan, which produced phantom needs-decision events. It has been open a little while, so if anything here needs changing to fit how you want it done, tell me and I will rework it. |
|
Field evidence for this fix from a production remote second mate, plus an offer of one more regression test. Cost observed. On 2026-09-29 a remote second mate home spent 35 turns and 138 model calls waking on nothing but its own End-to-end reproduction on current main (eb77f02). A remote-route mate home runs the real
This matches the three scan sites this PR covers. On the drain folds: the parent's Offer. We have a regression test that drives the real watcher through all three writers above (publisher, report helper, raw echo). With |
be5f485 to
6ab68aa
Compare
|
| for f in "$state"/*.status; do | ||
| [ -e "$f" ] || continue | ||
| [ "$f" = "$exclude" ] && continue |
There was a problem hiding this comment.
Legacy cursor remains orphaned
A remote mate upgraded from an older version can already have .parent-replies.open-decisions-cursor. This new early continue skips that file before cursor reconciliation, while drain-time cleanup never removes it. The cursor cannot surface channel content, but it remains as an inert file for the lifetime of the home. Please retire the excluded channel's cursor when resolving this special path.
| cleanup() { rm -rf -- "$TMP_ROOT"; } | ||
| trap cleanup EXIT |
There was a problem hiding this comment.
Cleanup leaks temporary directory
This test registers both TMP_ROOT and FM_ROOT_OVERRIDE through fm_test_tmproot, but this custom EXIT trap replaces the shared cleanup and removes only TMP_ROOT. Every run therefore leaves FM_ROOT_OVERRIDE behind until orphan reaping. Use fm_test_cleanup so all registered temporary roots are removed.
| cleanup() { rm -rf -- "$TMP_ROOT"; } | |
| trap cleanup EXIT | |
| cleanup() { fm_test_cleanup; } | |
| trap cleanup EXIT |
…cans A remote secondmate home's outbound parent channel lives at state/parent-replies.status inside its own state dir, so the watcher's signal scan enumerated it as a task status file and the open-decisions fold classified it as a phantom task named parent-replies: every parent-channel append spun a spurious signal wake and a phantom open decision in the mate's own home. fm-parent-channel-lib.sh gains fm_parent_channel_outbound_status, which resolves the channel into the mate's own state dir for the remote route only, and fm-classify-lib.sh's status_scan_parent_channel_exclude wraps it for the fleet-wide scans. The watcher's scan_signals and heartbeat fail-safe backstop, the whole-file and incremental open-decisions folds, the presentation snapshot, and the unread-surface scan now skip exactly that resolved path. The exclusion is home-shape-aware: a parent-replies.status in a main home or a local mate is an ordinary task log and keeps waking and folding, and every other status file is untouched.
…daemon heartbeat scan
…s/fm-contributions.test.sh ('reservation poll failed'). CI stderr showed bin/fm-contributions.sh:345 arithmetic 'DEADLINE - 6\n90077104: syntax error in expression': the fixture's fake date returned a torn two-line clock value. Root cause: the fake forge wrapper in wrap_forge advances the shared controllable clock via a non-atomic read-modify-write ('$(cat $FORGE/clock) + 6' with truncate-in-place '> $FORGE/clock') while concurrent background gh calls run and the fake date reads the same file; an interleaved truncate+write publishes a half-written value (CI's torn '6\n90077104', tail of 1790077104) or an emptied-read value ('6'), which either breaks the poll's arithmetic (nonzero exit -> 'reservation poll failed') or defeats the 15-second reservation defer. This is a pre-existing test-fixture race, not caused by the PR's diff (base..target touches no contributions code; the same commit passed this shard in run 35711207830 earlier the same day). Fixed the flaky fixture at its root: clock_bump() now writes each new value to a per-process mktemp file in the same directory and publishes it with mv (atomic rename), so concurrent forge callers and the fake date always read one complete old-or-new clock; fault patterns and deltas are unchanged. Verified: minimal 3-way concurrency repro shows the old wrapper corrupting (12/32/38 outcomes incl. empty-read) while the rename-based wrapper never corrupts (20/20 clean); the full tests/fm-contributions.test.sh passes twice (all 38 assertions ok, incl. the reservation, budget-exhaustion, genuine-failure, shared-once, and latency tests); 10 isolated reservation runs pass; shellcheck rc=0; worktree contains only this one-file change
6ab68aa to
c7df8ef
Compare
|
Speaking as Kun's firstmate: first stamp vs tip HEAD contract-class: restore — tip still folds/wakes a remote mate's own outbound VISION (compressed): One captain/interface — aligns (removes phantom captain-facing wakes/decisions). Authority — aligns (no new autonomy). Scripts/judgment — aligns. Restart — aligns (durable channel unchanged; scans skip correctly). Delegation — aligns (less noise). Fleet/vendor — aligns (secondmate remote route). Scope — aligns. Needed: finish green CI (esp. Lint). If fully green with MATCH + CLEAN/MERGEABLE, this is auto-merge eligible as restore. Firstmate flag no. Workflow approvals this pass: none. |
|
Speaking as Kun's firstmate: this is merged. Thank you @kesslerio — really appreciate you taking the time on this. CI finished fully green (Lint 1/2 + all Behavior portable + Herdr + Greptile SUCCESS). Attestation MATCH. Squash merge Firstmate flag no. |
Intent
Exclude a remote mate's own parent channel when scanning that mate's home.
What Changed
fm_parent_channel_outbound_status()inbin/fm-parent-channel-lib.shplusstatus_scan_parent_channel_exclude()inbin/fm-classify-lib.sh— that resolves a home's outbound parent-channel status path only for a remote mate (the sameremoteroute verdict used by wrong-home detection); a main home, a local mate, or an unusable identity/binding resolves nothing, so nothing is excluded.scan_signalsandheartbeat_scan_finds_actionable, the away-mode daemon'shousekeepingcatch-all heartbeat scan, and the fleet-wide foldsscan_open_decisions,scan_open_decisions_incremental,status_presentation_snapshot, andscan_unread_surface_lines. A remote mate'sstate/parent-replies.status— already mirrored into the parent home by the reply adapter — no longer produces spurious signal wakes or a phantomparent-repliesopen decision, while aparent-replies.statusin any other home shape still folds and wakes as an ordinary task log.tests/fm-parent-channel-scan-exclusion.test.sh(registered inbin/fm-test-run.sh, documented indocs/secondmate-parent-channel.md) covering real remote, main-home, and local-mate fixtures across all scans plus the realfm-wake-drain.shend to end, and fixes a torn shared-clock race in thetests/fm-contributions.test.shfake forge wrapper by publishing clock bumps through an atomicmktemp+mvinstead of truncating in place.Risk Assessment
✅ Low: The change is a narrowly scoped, home-shape-aware exclusion owned by one helper, applied at every wake- and fold-producing scan of a home's state dir, with fail-open defaults, main-home/local-mate negative cases, and end-to-end drain coverage; the only notes are informational and the bundled fixture fix touches no production code.
Testing
Per the recorded decision I did not build a lab, watcher, daemon, or new driver: the assigned scenario set was exercised by running
tests/fm-parent-channel-scan-exclusion.test.shfrom the repository root, which executes the real product modules (bin/fm-classify-lib.sh folds, bin/fm-watch.sh scan_signals and heartbeat backstop, bin/fm-supervise-daemon.sh housekeeping catch-all, bin/fm-parent-channel-lib.sh route resolution) and the real bin/fm-wake-drain.sh binary against disposable remote-mate, main-home, and local-mate fixtures. It passed on the first run and again after every probe, so no code was changed. Two scenarios count as live: the real drain binary executed as a subprocess over a hand-seeded remote mate home (fix active: genuine task only, manifest holds onlyreal-task), and the adversarial probe that ran the actual watcher scan, daemon housekeeping, and drain as subprocesses with the fix suppressed, reproducing the leak the change targets. The other scenarios were driven by sourcing the real modules and calling their functions against fixtures — production code paths, but no running watcher or daemon process — so under the live-validation contract they are recorded as untested, not passed. To show the assertions are not decorative, the four changed bin files were reverted to the base commit (test then fails immediately: the exclusion helper does not exist). The process-level gap is a long-running watcher/away-mode daemon over a remote mate home across a full poll interval: the directive for this step ruled out standing one up, and two earlier rounds attempted exactly that and were cut off by the 1h invocation budget before producing a result.bin/fm-wake-drain.shexecuted as a subprocess against a disposable remote mate home (.fm-secondmate-home+.fm-secondmate-parentroute=remote); output lis…blocked [key=wedge]li….parent-replies.open-decisions-cursorplus aparent-repliesrow in.status-presentation-cursor) in a fixture home and ran the real dr…status_scan_parent_channel_excludereduced toreturn 0, scan_signals enumerated the channel, the daemon's housekeeping wrote a `parent-replies.status: ..…Evidence: Targeted test run at target commit (14 ok, exit 0)
Source: Targeted test run at target commit (14 ok, exit 0)
ok - only a remote mate home resolves its own parent channel for exclusion ok - fm_parent_channel_outbound_status resolves only the remote route ok - a remote mate's folds omit its channel and keep a genuine task ok - the cursor-backed incremental fold omits a remote mate's channel ok - the channel's resolution and note lines stay off the remote unread surface ok - a parent-replies.status in a main home still folds ok - a parent-replies.status in a local mate still folds ok - scan_signals skips a remote mate's channel and still reports its tasks ok - the heartbeat backstop skips a remote mate's channel and keeps its tasks ok - scan_signals keeps parent-replies.status outside remote mate homes ok - the daemon's catch-all scan skips a remote mate's channel and keeps its tasks ok - the daemon's catch-all scan keeps parent-replies.status outside remote mate homes ok - the real drain presents no channel content from a remote mate home ok - stale channel records from an older watcher are dropped, not presentedEvidence: Real fm-wake-drain.sh output for a remote mate home (fix active): genuine task only, no parent-replies rows
Source: Real fm-wake-drain.sh output for a remote mate home (fix active): genuine task only, no parent-replies rows
UNREAD STATUS (new since last drain, not re-printed after this presentation): real-task note: benchmark results are in OPEN DECISIONS (still open, folded from the durable status logs - not just the latest line): real-task [key=api-shape] needs-decision: pick REST or RPC OPEN DECISIONS: close one by answering it: bin/fm-send.sh <task> --resolve-key <key> '<answer>' (persisted manifest .status-presentation-cursor: 'real-task\tstrong:...\t80\t0' — the only tracked row; parent-replies.status exists in that state dir and is not tracked or presented)Evidence: Adversarial probe: with the exclusion helper neutered, the phantom returns via watcher, daemon catch-all, and drain
Source: Adversarial probe: with the exclusion helper neutered, the phantom returns via watcher, daemon catch-all, and drain
### watcher scan_signals over a remote mate home enumerated: .../watch/home/state/parent-replies.status => LEAK: channel enumerated ### away-mode daemon catch-all scan over a remote mate home escalation buffer: parent-replies.status: needs-decision [key=captain-hold-pr-7-1]: captain hold pr-7: merge the green PR? (catch-all scan) phantom seen-file: v2 r1:strong:... ### real fm-wake-drain.sh over a remote mate home drain says: 2:parent-replies note: the release branch is cut drain says: 4:parent-replies [key=captain-hold-pr-7-1] needs-decision: captain hold pr-7: merge the green PR? => LEAK: channel content presented ### fixed tree (helper active) for comparison channel lines in drain output: 0Evidence: Same test with the four changed bin files reverted to base commit (proves the test exercises the new code)
Source: Same test with the four changed bin files reverted to base commit (proves the test exercises the new code)
_: line 3: status_scan_parent_channel_exclude: command not found not ok - the remote mate's channel must resolve for exclusion, got rc=127Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-classify-lib.sh:1072- Completeness check of the exclusion against every other enumeration of a home's state/*.status in a remote mate home. The wake- and fold-producing enumerations are all covered (bin/fm-classify-lib.sh:1091, :1386, :1405, :2021; bin/fm-watch.sh:1997 signal scan and :2266 heartbeat; bin/fm-supervise-daemon.sh:1350 catch-all), and the remaining ones produce neither a wake nor a phantom open decision, so the authorized failure is not reachable through them: bin/fm-fleet-ledger.sh:117 grown_logs (opt-in config/fleet-ledger only; records the channel's lines as task=parent-replies ledger rows), bin/fm-session-start.sh:927 (lists parent-replies.status under 'Orphan status logs' in the digest), bin/fm-captain-hold.sh:1823diverged(still reads the channel'sresolvedline, so the RECORD DIVERGENCE section keeps working). All three are pre-existing and outside the stated intent. Related, also not required here: bin/fm-pending-reply-lib.sh:1362-1366 keeps a parallel basename-based copy of the same rule, which could now be routed through fm_parent_channel_outbound_status; its result is identical for the$sm_home/statelayout, so it is a deduplication opportunity, not a defect. No action requested.bin/fm-classify-lib.sh:1405- Traced tradeoff, not a defect: while the channel is excluded, its per-task positions stop advancing, and status_acknowledge_presented_snapshot (bin/fm-classify-lib.sh:1816-1843) rebuilds state/.status-presentation-cursor from the snapshot, so the channel row is dropped (the new test pins this). state/parent-replies.status is append-only and never truncated (docs/remote-secondmates.md 'Source log continuity'), so if a live home ever stopped resolving route=remote, the next scan would re-fold the channel's whole history from offset 0 and print_unread_status_section (bin/fm-wake-drain.sh:426-450) prints unread lines with no byte cap. I checked whether that lapse is reachable by any intended caller and it is not: both writers publish .fm-secondmate-parent and .fm-secondmate-home atomically via tmp+mv at seed/provision time (bin/fm-home-seed.sh:973-979, bin/fm-remote-home-provision.sh:272-277) and no code path removes or re-routes a marker in place (teardown removes whole mate home dirs, bin/fm-teardown.sh:2591, :2597). Noting it so a future re-route/unesbind feature knows to retire the task via status_retire_presentation_task rather than let the backlog flood.tests/fm-contributions.test.sh:614- The branch also carries a fix unrelated to the stated intent: the fake forge wrapper's shared-clock bump now publishes via mktemp+mv instead of truncate-in-place. Verified as safe and fixture-only — base..target touches no production contributions code, bin/fm-contributions.sh:205/:381 keep readingdate +%sunchanged, and the fakedateat :637 always sees one complete value after the rename. One residual limitation worth knowing: the read-modify-write inside clock_bump is still non-atomic across processes, so two concurrent bumps can lose an increment; each fault pattern bumps a distinct endpoint (reserve/issues/9, exhaust/issues/8/comments, fail-late/pulls/8/reviews) and the assertions only need the budget to expire, so no assertion depends on both increments landing. Left in because it unblocks this run's CI shard; removal would restore the flake, so no action requested.🔧 No changes applied.
1 warning still open:
🔧 No changes applied.
1 warning still open:
bin/fm-wake-drain.shexecuted as a subprocess against a disposable remote mate home (.fm-secondmate-home+.fm-secondmate-parentroute=remote); output lis…blocked [key=wedge]li….parent-replies.open-decisions-cursorplus aparent-repliesrow in.status-presentation-cursor) in a fixture home and ran the real dr…status_scan_parent_channel_excludereduced toreturn 0, scan_signals enumerated the channel, the daemon's housekeeping wrote a `parent-replies.status: ..…bash tests/fm-parent-channel-scan-exclusion.test.sh(from the repository root, target commit 1109508) — 14/14 ok, exit 0; re-run after all probes, still exit 0git checkout 549e07f37 -- bin/fm-classify-lib.sh bin/fm-parent-channel-lib.sh bin/fm-supervise-daemon.sh bin/fm-watch.sh && bash tests/fm-parent-channel-scan-exclusion.test.sh— fails withstatus_scan_parent_channel_exclude: command not found(rc 127), then restored withgit checkout HEAD -- <same paths>: the test depends on the new exclusion code, it is not vacuousPROBE_ROOT="$PWD" bash $EV/probe-exclusion-is-load-bearing.sh— temporarily neuteredstatus_scan_parent_channel_excludetoreturn 0(pre-fix behavior) and re-ran the real consumer paths, then restored the file byte-for-byteFM_ROOT_OVERRIDE=<inert> FM_STATE_OVERRIDE=<remote-mate>/state FM_HOME=<remote-mate> bin/fm-wake-drain.shagainst a hand-seeded disposable remote mate home — captured user-visible drain output and the persisted.status-presentation-cursormanifestbin/fm-session-start.sh:927- Judgment call on the new invariant's scope, not a doc defect: the session-start digest's 'Orphan status logs (state/.status without matching .meta)' section enumerates "$STATE"/.status with no channel exclusion, so a remote mate home's startup digest still prints its own parent channel as an orphan task row named parent-replies. No maintained doc claims otherwise (docs/configuration.md only bounds the tail length), and docs/secondmate-parent-channel.md states the new contract as an explicit enumeration of the scans that exclude the resolved path, so nothing is factually wrong today. If the human decides the digest belongs to the same invariant, the fix is code plus one clause appended to that owner sentence; declining leaves the owner sentence accurate as written.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.