Flaky on Windows: connect_reconnect_replays_only_after_both_cursors hits EOF in the reconnect window
Symptom
copilot::relay::tests::connect_reconnect_replays_only_after_both_cursors fails intermittently on Test (windows-latest):
thread '...connect_reconnect_replays_only_after_both_cursors' panicked at crates\core\src\copilot\relay.rs:1274:52:
called `Result::unwrap()` on an `Err` value:
Io(Custom { kind: UnexpectedEof, error: "capture relay closed the connection" })
Seen on a PR that touches only tauri/src-tauri/src/commands.rs, tauri/src/index.html and generated site files, so it is not caused by the change under test. The rest of that same run passed 1516 tests.
Why it is the test rather than the product
The test deliberately exercises a disconnect:
let cursor = first.cursor();
drop(first); // client goes away
server.publish_transcript_for_test(utterance("second"));
server.publish_nudge(nudge("nudge-2"));
let mut second = CaptureRelayClient::connect_from(&discovery_path, cursor).unwrap();
The panic is inside the shared polling helper:
fn wait_for_frame(client: &mut CaptureRelayClient, predicate: ...) -> RelayFrame {
let deadline = Instant::now() + Duration::from_secs(3);
while Instant::now() < deadline {
if let Some(frame) = client.try_recv().unwrap() { // <- relay.rs:1274
try_recv() is unwrapped, so a connection that closes during the reconnect window is a panic rather than a retry. On Windows named pipes the teardown of the first connection and the accept of the second are not ordered with respect to each other, so the second client can observe EOF immediately after a successful connect.
Suggested direction, not applied here
Do not make wait_for_frame swallow UnexpectedEof in general: it is shared by other tests where a closed connection is a real failure, and hiding it would weaken the capture-reliability invariants this suite exists to protect.
Better to make the reconnect explicit in this one test: retry connect_from until the server has finished retiring the previous connection, and keep the unwrap strict everywhere else. That preserves the invariant being asserted (replay resumes from both cursors) while removing the ordering assumption.
Frequency
One observed failure so far, passing on rerun of the same commit. Filing rather than fixing inline, since the fix belongs to the copilot relay owner and should not ride along in an unrelated PR.
Reproduced on real Windows: 20% failure rate, not a rare race
Ran the test 25 times in a loop on a Windows 11 VM (26100), --no-default-features --test-threads=1, matching how CI runs the core suite:
result: 5 failures in 25 runs
runs that failed: 4, 12, 13, 15, 22
Identical panic and location to the CI occurrence:
thread 'copilot::relay::tests::connect_reconnect_replays_only_after_both_cursors' panicked at
crates\core\src\copilot\relay.rs:1274:52:
called `Result::unwrap()` on an `Err` value:
Io(Custom { kind: UnexpectedEof, error: "capture relay closed the connection" })
One in five, not one in a hundred. It looks rare only because CI runs the test once per job. Any Windows CI run has roughly a 20% chance of failing on this test alone, which matches how often it has been showing up and blocking unrelated PRs.
What this changes
A fix is now verifiable rather than hopeful. 25 consecutive clean runs on this machine is real evidence; before, a single green CI run proved nothing at a 20% base rate.
The diagnosis in the issue body stands: wait_for_frame unwraps try_recv(), so a connection closing during the reconnect window is a panic instead of a retry, and on Windows named pipes the server's retirement of the dropped client is not ordered against accepting the next one.
Still the right shape of fix: make the reconnect explicit in this one test rather than teaching the shared helper to swallow UnexpectedEof, which other tests rely on to catch a genuinely closed connection.
Reproduction harness is on the QA VM; I can re-run the 25x loop against any candidate fix.