Skip to content

fix(bin): resolve a pending reply only from its own task's status line - #6792

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
falkoro:fix/pending-reply-task-bound-corr-6538
Oct 7, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
falkoro:fix/pending-reply-task-bound-corr-6538

Conversation

@falkoro

@falkoro falkoro commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Intent

Fix kunchenguid/firstmate issue #6538: a parent's pending reply (the durable expectation recorded when firstmate sends a marked, reply-bearing request to a secondmate) can be resolved by a status line from a different task, because the corr= token was matched as a substring and nothing checked that the line came from the task the request was sent to.

Maintainer triage (ready-for-pr, contract-class restore, security FYI between mates sharing a parent channel): restore resolve-only-on-matching task plus exact corr, treat quoted or relayed token text from another task as non-resolving, and pin it with a two-mate regression where mate B's line echoes mate A's token and A's request stays open.

The concrete cross-task path on main is bin/fm-procevent-remote-reply.sh: after ingesting remote mate B's payload it calls fm_pending_reply_try_resolve for every corr= token found in that payload, passing B's own status log as the status-file override, so B echoing or quoting A's token resolved A's request from B's log. All other override callers (the recovery send and escalation paths in bin/fm-pending-reply-lib.sh) already pass the record's own parent_status.

Decisions:

  • The guard lives once in the shared _fm_pending_reply_try_resolve_locked, not in the remote-reply caller, so every present and future caller is covered. An override is honored only when it is the same file as the record's own parent_status (compared with test -ef, so a differently spelled path to the same log still works, e.g. the ingest's $STATE/.status). Any other file leaves the request open. The default no-override path already scans only the record's own parent_status and is unchanged.
  • fm_pending_reply_text_has_corr now matches the token as a whole word: corr= must not be preceded or followed by a letter, digit, or underscore, so corr=ff or xcorr= no longer count, while the existing [corr=], "corr= ", and line-end forms still resolve. This matches the unbracketed strictness bin/fm-classify-lib.sh already applies to corr tokens.
  • "Quoted or relayed" text is handled by the task check: a line in another task's log never resolves, whatever its shape. No attempt is made to parse quoting inside the asked task's own log, because that log is the asked task's own reply channel and the issue's scenario is cross-task.
  • The library header's resolution contract sentence was updated to say resolution comes only from the asked task's own parent status log.
  • The regression lives in tests/fm-pending-reply.test.sh as test_another_mates_echo_cannot_resolve, exercising the public fm_pending_reply_try_resolve exactly as the remote-reply ingest calls it. It was confirmed to fail on the unfixed library and pass with the fix. The whole pending-reply suite, the 24 other suites that reference pending replies or corr tokens (two skipped by their own environment gates), and bin/fm-lint.sh pass.
  • Contributor PR from the falkoro fork per CONTRIBUTING.md; no agent co-author in the commit.

What Changed

  • _fm_pending_reply_try_resolve_locked in bin/fm-pending-reply-lib.sh now honors a status-file override only when it is the same file (test -ef) as the record's own parent_status. Any other file leaves the request open. This stops mate B's log, which echoes or quotes mate A's corr= token, from resolving A's request. The no-override path is unchanged.
  • fm_pending_reply_text_has_corr now matches the token as a whole word. corr=<id> can't be preceded or followed by a letter, digit or underscore, so xcorr=<id> and corr=<id>ff no longer count. Bracketed, space-terminated and end-of-line forms still resolve.
  • Added test_another_mates_echo_cannot_resolve to tests/fm-pending-reply.test.sh, a two-mate regression where B's line echoes A's token and A's request stays open. The library header and docs/remote-secondmates.md now say a mirrored line settles a record only when it comes from the task the request was sent to.

Risk Assessment

✅ Low: The guard sits once in the shared resolver, and the only override callers (remote-reply ingest and the recovery path) pass the record's own status log. The whole-word match is a narrow tightening, and the regression test exercises the public API.

Testing

I ran the pending-reply suite on the fixed code and it passed. I then swapped in the base-commit library, and the new two-mate test failed there, which reproduces the reported bug. I restored the fix and the worktree is clean. I did not stand up a Herdr lab. The test calls the public fm_pending_reply_try_resolve the same way the remote-reply ingest does. I did not run the 24 other suites or the whole-word corr matching on its own.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Mate B's status line echoing mate A's corr token leaves A's request open ✅ pass live tests/fm-pending-reply.test.sh: ok - another mate&#39;s echoed token cannot resolve a request
The same test fails on the unfixed library, so it reproduces the bug ✅ pass live Base-commit lib swapped in: not ok - another mate&#39;s line echoing the token must not resolve the request
Legitimate resolution paths still work: mirrored remote reply, same-basename self-home, recovery boundary ✅ pass live The existing pending-reply suite tests for these all print ok

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.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Mate B's status line echoing mate A's corr token leaves A's request open ✅ pass live tests/fm-pending-reply.test.sh: ok - another mate&#39;s echoed token cannot resolve a request
The same test fails on the unfixed library, so it reproduces the bug ✅ pass live Base-commit lib swapped in: not ok - another mate&#39;s line echoing the token must not resolve the request
Legitimate resolution paths still work: mirrored remote reply, same-basename self-home, recovery boundary ✅ pass live The existing pending-reply suite tests for these all print ok
  • bash tests/fm-pending-reply.test.sh on the fixed tree: all pass, including the new two-mate test
  • Same suite with bin/fm-pending-reply-lib.sh temporarily swapped for the base-commit version: the new test fails with not ok - another mate&#39;s line echoing the token must not resolve the request
  • Restored the fixed library afterwards; git status --short was clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Issues

Closes #6538

Remote reply ingestion handed every corr= token in a mate's payload to
fm_pending_reply_try_resolve together with that mate's own status log,
so one mate echoing another mate's token resolved the other request.
Honor a status-file override only when it is the record's own
parent_status, and match the corr= token as a whole word.

Fixes kunchenguid#6538
@falkoro

falkoro commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

CI failed in Behavior portable serial 4: tests/fm-remote-reply.test.sh reported "the NUL-bearing line was not captured". That looks like the flake in #6790: the same check failed the same way on #6784, which changes unrelated code, and the test passes locally on this head (42 ok, 0 not ok, two runs). Could you re-run the failed job? I do not have the rights to.

@kunchenguid
kunchenguid merged commit 9b85a95 into kunchenguid:main Oct 7, 2026
36 of 37 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks, @falkoro. I read the whole diff of head 035f4832 against main, plus #6538 and its thread.

What I checked: _fm_pending_reply_try_resolve_locked now honors a status-file override only when it is the same file (-ef) as the record's own parent_status. The only override caller on main, bin/fm-procevent-remote-reply.sh ingest, passes $STATE/<id>.status. For the asked task that is the same file fm_pending_reply_create records, so a legitimate mirrored reply still resolves. Another mate's log no longer does. fm_pending_reply_text_has_corr now does a whole-word match and keeps the bracketed, space-terminated and end-of-line forms. The new two-mate regression pins the issue's scenario. There are no workflow, network or secret changes.

CI: "Behavior portable serial 4" failed on attempt 2 with not ok - the NUL-bearing line was not captured. That is the ambient #6790 flake, with the same ~60 s signature as on main. I re-ran it (run 37660818232, attempt 3) and every check is green. The no-mistakes attestation matches this head, and the PR was MERGEABLE/CLEAN.

Contract-class: restore. The library already promised that a request resolves only from a correlated line in its own parent status. Cross-task resolution broke that existing default path, and this restores it.

VISION, rule by rule: one captain/honest interface aligns (a captain-facing ask can't be silently closed); authority aligns (evidence in another mate's line authorizes nothing); scripts own the mechanics aligns; restart is a non-event aligns (obligations close only on the durable event that answers them); delegation with a spine aligns; fleet outlives any vendor n/a; scope aligns.

Closes #6538.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @falkoro — really appreciate you taking the time on this.