Repository navigation
fix(pending-reply): force bounded remote-reply poll before escalating - #2
Merged
Merged
Conversation
A correlated reply from a remote secondmate can still be crossing the wire through fm-procevent-remote-reply.sh when the recovery grace window lapses, which read as genuinely missing and triggered a false pending-reply-missed escalation demanding a repost. Observed twice on pc02-llm-lab on 2026-08-16 (corrs 17c80a045ac950f9, 6dea3b70d14ee5dd); see this home's data/learnings.md "Remote secondmate reply-window race" entry for the incident record. fm_pending_reply_maybe_escalate now forces one bounded poll of that task's remote-reply source immediately before it would otherwise escalate, so an already-arrived or still-arriving reply resolves locally instead. The poll no-ops instantly when a live poller already owns the source, so the bounded wait is only ever paid in the gap that let the race happen. A genuinely missing reply still escalates exactly as before.
…y forced-ingest wait env var
This was referenced Nov 19, 2026
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix a firstmate pending-reply recovery race: the timed reply window lapses while a secondmate's correlated reply is still in remote-reply ingest transit, so the watcher escalates pending-reply-missed and sends false REPOST demands (observed twice on pc02-llm-lab 2026-08-16, correlations 17c80a045ac950f9 and 6dea3b70d14ee5dd). Before escalating or demanding a repost, recovery must re-scan the parent status file for the correlation id and/or force one bounded ingest poll of the remote-reply source, so a reply that already arrived or is mid-transit resolves locally instead of escalating. The fix stays inside the recovery path in bin/fm-pending-reply-lib.sh and bin/fm-procevent-remote-reply.sh, and must not weaken the escalation guarantee for a genuinely missing reply: a reply absent after the re-scan/poll still escalates. Add colocated regression tests proving both behaviors: reply-in-transit resolves without escalation, and genuinely-missing reply still escalates. Must be shellcheck-clean.
What Changed
bin/fm-pending-reply-lib.sh: extracted the escalation-eligibility check into a sharedfm_pending_reply_escalation_pendinghelper, and addedfm_pending_reply_force_remote_reply_ingest, which forces one bounded poll of a task's remote-reply source (viafm-procevent.sh start, orFM_PENDING_REPLY_FORCE_INGEST_HOOKin tests) immediately beforefm_pending_reply_maybe_escalatewould otherwise escalate.fm_pending_reply_maybe_escalatenow runs this forced ingest (unlocked, before acquiring the per-correlation lock) whenever the record is escalation-eligible, so a correlated reply already in ingest transit resolves locally instead of triggering a false repost; a genuinely missing reply still proceeds to escalate afterward.docs/configuration.md: documented the newFM_PENDING_REPLY_FORCE_INGEST_WAIT_SECSenv var (default 5s) controlling the forced poll's bounded wait.tests/fm-pending-reply.test.sh: added regression tests covering both the reply-in-transit-resolves-without-escalation case and the genuinely-missing-reply-still-escalates case.Risk Assessment
✅ Low: The change is a well-bounded addition confined to bin/fm-pending-reply-lib.sh (invoking the pre-existing fm-procevent-remote-reply.sh/fm-procevent.sh interfaces without modifying them), correctly reuses a single extracted escalation-eligibility predicate for both the pre-escalation gate and the real decision to avoid drift, places the forced ingest before the per-correlation lock to avoid deadlocking against fm-procevent-remote-reply.sh's own lock acquisition, relies on a size/mtime file-signature check that correctly invalidates the resolve short-circuit when the forced ingest appends a reply, and is covered by regression tests that exercise real state transitions (phase, published status lines) via hook substitution rather than source-text matching, proving both the in-transit-resolves and genuinely-missing-still-escalates behaviors the intent requires.
Testing
Targeted the colocated tests/fm-pending-reply.test.sh, which exercises the real fm_pending_reply_maybe_escalate / fm_pending_reply_force_remote_reply_ingest behavior end-to-end (record files, status lines, escalation phase transitions) rather than inspecting source text. All 31 tests pass at the target commit. To validate the regression test is real (not vacuously passing), I temporarily reverted only bin/fm-pending-reply-lib.sh to the base commit and re-ran: the new in-transit-resolves test failed exactly as expected (escalated instead of resolved), then restored the fixed file and confirmed the full suite is green again with a clean working tree. This directly demonstrates both required behaviors from the user intent: a reply that arrives during ingest transit resolves locally without a false repost, and a genuinely missing reply still escalates — plus that local secondmates (no remote_host) never pay the forced-poll cost.
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.
bash tests/fm-pending-reply.test.sh (full run at target commit f4c5170) — 31/31 passbash tests/fm-pending-reply.test.sh with bin/fm-pending-reply-lib.sh reverted to base commit 6f7d08e — test_remote_reply_in_transit_resolves_without_escalation fails as expected, proving it is a genuine regression test for the racebash tests/fm-pending-reply.test.sh re-run after restoring the fixed lib file — 31/31 pass, worktree left clean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.