Repository navigation
test: re-check reply listener ownership while awaiting capture - #6241
guanchengh-lgtm wants to merge 1 commit into
Conversation
await_reply_result in tests/fm-remote-reply.test.sh sampled listener ownership once. The test's own manual `handle` re-arms the source, and a listener that had already adopted the previous registration then exits as superseded at its next launch check. A sample taken before that exit read `live`, so the helper started nothing and the whole 40-second wait ran with no listener. The helper now re-reads ownership on a bounded cadence (every 20 polls) and starts a listener when none owns the source, with at most one launch in flight per wait. The 800-poll bound is unchanged, so a capture that never arrives still fails. On that failure the helper prints the owner state and whether the wait launched a listener. Evidence: - 13 of 378 completed CI runs failed in this test since 2026-09-27T23:30Z (3.4%): 8 "the NUL-bearing line was not captured", 5 "the header-collision line was not captured". Each shows a constant 41-second gap after the previous ok line. - With a delay of 0.5 s or more injected before the listener's launch check in a scratch clone: unpatched 0 of 8 runs pass, patched 12 of 12. - The failure was not reproduced at natural timing locally, so the link to the CI failures is an inference from the assertion text, the constant gap, and the injected-delay result. Acceptance check after merge: 0 failures of this test in the next 150 completed ci.yml runs. At the previous 3.4% rate the chance of 0 in 150 by luck is 0.5%. Any failure of this test in that window reopens the diagnosis. Test code only. No product change.
|
| if [ $((poll % 20)) -eq 0 ] && ! kill -0 "$starter" 2>/dev/null \ | ||
| && [ "$(reply_owner)" != live ]; then | ||
| remote_env "$ROOT/bin/fm-procevent.sh" start "$SID" >/dev/null 2>&1 & | ||
| starter=$! |
There was a problem hiding this comment.
Retry path lacks regression coverage The new re-check fixes a rare case where a listener disappears after the first ownership sample, but the committed tests do not force that transition. Ordinary runs can therefore pass even if a later change removes the retry. A deterministic test of that transition would protect this fix.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
Another data point for this one. #6970 hit the same failure in "Behavior portable serial 4": |
Intent
Context: the firstmate CI job "Behavior portable serial 4" failed on an open pull request that does not touch the test, with "not ok - the NUL-bearing line was not captured" in tests/fm-remote-reply.test.sh, after the 40-second await_reply_result wait (800 polls of 0.05 s). The same test failed on an unrelated upstream branch (CI run 36703475299, "not ok - the header-collision line was not captured"). Two local runs pass. A failed job cannot be re-run from here because that needs admin rights on the repository, so the flake blocks every firstmate pull request that hits it.
What Changed
tests/fm-remote-reply.test.sh,await_reply_resultno longer checks reply ownership once before the wait. It now re-readsreply_ownerevery 20th poll (about once a second) inside the existing 800-poll loop. It startsfm-procevent.sh startonly when no listener owns the source and no starter launched by this wait is still running. A listener that reads as live and then exits as superseded no longer leaves the source without a listener for the whole 40-second wait.none), then returns 1 as before.Risk Assessment
✅ Low: The change edits only one test helper. It replaces a single ownership sample with a re-check about once per second, guarded by a live-starter check. This closes the traced race where a manual
handlere-arm supersedes a listener that still reads as live, and I found no path where it masks a real failure or double-launches a listener.Testing
I ran the changed test file end to end once. Then I ran 5 concurrent copies of both the base and the changed version on a loaded 28-CPU host. All 11 runs passed. The natural flake did not reproduce at base, so I built probes from the real test prefix (generations 1-3) that replay the reported race against the real fm-procevent runner. In the forced race, base waited 142s and never captured the line, while the change captured it in 7s. When the listener was killed mid-wait, base failed after 136s and the change recovered in 7s. A healthy listener was not launched twice. When capture was impossible, the wait timed out with the new diagnostic and launched at most once a second. The probes emulate the race window - they do not hit it naturally. Natural reproduction of the flake at base is untested. No visual surface applies, because the change is to a shell test only.
bash tests/fm-remote-reply.test.shrc=0; also 5 of 5 concurrent copies exit=0 (stress-head-*.log)Evidence: Base vs change comparison across all probes and the stress run
Source: Base vs change comparison across all probes and the stress run
Evidence: Injected race, base: not captured after 142s
Source: Injected race, base: not captured after 142s
Evidence: Injected race, change: captured after 7s
Source: Injected race, change: captured after 7s
Evidence: Listener killed mid-wait, base fails
Source: Listener killed mid-wait, base fails
Evidence: Listener killed mid-wait, change recovers
Source: Listener killed mid-wait, change recovers
Evidence: Healthy listener, no double launch
Source: Healthy listener, no double launch
Evidence: Timeout diagnostic and bounded relaunch cadence
Source: Timeout diagnostic and bounded relaunch cadence
Evidence: Probe generators and stress driver
Source: Probe generators and stress driver
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
tests/fm-remote-reply.test.sh:121- Simplification: the new timeout diagnostic is not required by the intent. The intent requires the flaky wait to stop failing. It does not ask for extra failure output. The addedprintf ... >&2at the end ofawait_reply_resultalso costs one morefm-procevent.sh listspawn on every timeout. The re-sampling loop already covers the flake, including the launch-then-superseded case. The narrower form is to drop the trailingprintfand itsreply_ownercall, and keep the loop only. The added stderr text is harmless, so the remedy is a scope decision for the author.✅ **Test** - passed
✅ No issues found.
bash tests/fm-remote-reply.test.shrc=0; also 5 of 5 concurrent copies exit=0 (stress-head-*.log)bash tests/fm-remote-reply.test.shat 93ae5875 (rc=0, ALL TESTS PASSED)bash evidence/stress.sh <worktree> <evidence> 5: 5 concurrent full copies of the base test and 5 of the changed test (10 of 10 exit=0)race-probe-base.shandrace-probe-head.sh: real test prefix, listener stopped, firstreply_ownersample forced tolive, thenawait_reply_resultfor generation 4mode-probe-{base,head}.shwith PROBE_MODE=steady (healthy listener, line arrives after 4s)mode-probe-{base,head}.shwith PROBE_MODE=killed (listener killed at 2.5s, line arrives at 6s)mode-probe-head.shwith PROBE_MODE=timeout (FM_REMOTE_REPLY_FAIL_READ=1, so no capture is possible)tests/fm-remote-secondmate-lifecycle-e2e.test.sh:296- This file has its own copy of await_reply_result and reply_owner. It still uses the old one-sample ownership check that this change replaced in tests/fm-remote-reply.test.sh. It can fail in the same way. A follow-up could move one shared helper into tests/lib.sh. This is a test change, so the document phase did not edit it.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.