Skip to content

fix(pending-reply): force bounded remote-reply poll before escalating - #2

Merged
sKeLe100 merged 2 commits into
mainfrom
fm/fm-pending-reply-ingest-race
Aug 18, 2026
Merged

sKeLe100 merged 2 commits into
mainfrom
fm/fm-pending-reply-ingest-race

Conversation

@sKeLe100

Copy link
Copy Markdown
Owner

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 shared fm_pending_reply_escalation_pending helper, and added fm_pending_reply_force_remote_reply_ingest, which forces one bounded poll of a task's remote-reply source (via fm-procevent.sh start, or FM_PENDING_REPLY_FORCE_INGEST_HOOK in tests) immediately before fm_pending_reply_maybe_escalate would otherwise escalate.
  • fm_pending_reply_maybe_escalate now 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 new FM_PENDING_REPLY_FORCE_INGEST_WAIT_SECS env 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 pass
  • bash 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 race
  • bash 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.

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.
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.

1 participant