Skip to content

mac tests: wait for the reconciled receipt instead of a fixed sleep, and stop the watcher racing the fake helper (#800) - #830

Merged
d-q222 merged 1 commit into
mainfrom
fix/800-documentfiles-poll
Sep 17, 2026
Merged

d-q222 merged 1 commit into
mainfrom
fix/800-documentfiles-poll

Conversation

@d-q222

@d-q222 d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Fixes the last flaky test in #800 — the only thing keeping main CI red (DocumentFilesTests.swift:437, "no status reply from the project-files helper").

Root cause: not the sleep length

The fake helper writes the file before delaying its reply. That write fires the live DocumentWatcher (0.25s debounce). watcherFired defers once while the helper is busy, then retries after max(helperTimeout, 0.5) = 0.5s. When that retry lands after the helper's late reply, it runs refreshDiskStatus() — a status request to the same --mode late fake, which also answers late. That extra round trip:

  • appends a status … entry to files.lateReplies, breaking the "one late reply per save" invariant, and
  • overwrites captureNote with exactly the CI string.

Which timer wins is decided by machine load. That is also why widening the sleep to 6.0s made it worse: it gave the extra cycle room to finish.

Confirmed empirically, not by inspection: shortening the fake's delay from 1.2s to 0.6s, so the retry deterministically lands after the reply, reproduces the CI failure exactly on the old test — lateReplies count 2 instead of 1, same note string.

Is there a product race? No.

The watcher's status check was correct and answered unchanged: no state lost, no edit dropped, the late receipt still reconciled. What it clobbered was a transient note and a test-visible counter. Two product observations recorded for follow-up, neither hidden by this change:

  • a slow status probe can briefly replace "Late confirmation: … was saved" with "Could not check … on disk", reachable only when the helper is slow for both operations;
  • watcherFired(retry:) drops the event entirely if the helper is still busy on its single retry, so a genuine external change during a save goes unchecked until the next event. That is the deliberate design in its comment, and no test pins it.

The fix

  • Condition polling replaces all three pump(1.6) calls. "Reconciled" is observable: the late receipt only sets savedText when its hash matches the text sent, so the condition is model.savedText == "edited once\n" / "edited twice\n", and files.conflict != nil for the conflict case.
  • waitUntil copies mac tests: waitUntil throws, helper-exit bound logs instead of failing, carried-hold release tests (#809) #812's shape: 30s bound, XCTFail then throw, and a state closure printing lateReplies in every failure.
  • The watcher is stopped right after openTex, with the interaction explained in a comment. DocumentWatcherTests covers the watcher, and no save here succeeds, so nothing re-arms it.
  • The invariant is kept and tightened: exactly one late reply per save, now asserted in the third case too.

Runs

12/12 sequential passes of the single test; 3.70s fastest, 4.96s slowest (was a fixed 6.14s). Full DocumentFilesTests: 13 tests, 4 skipped (Rust helper not built locally, pre-existing), 0 failures, twice. The 0.6s deterministic reproducer passes in 1.93s.

🤖 Generated with Claude Code

`testLateSaveReceiptIsReconciledWithoutLosingLaterEdits` waited three fixed
1.6 s sleeps for a receipt the fake helper delays by 1.2 s. On a loaded runner
that margin is not the real problem: the fake's own write fires the live
`DocumentWatcher`, whose status check goes back to the same fake and so answers
late too — appending a `status` entry to `lateReplies` and overwriting
`captureNote` with "Could not check paper.tex on disk: no status reply from the
project-files helper within 0.4 s", which is exactly how main CI failed at
:437/:450. Which of the two timers wins (the watcher's single retry after
max(helperTimeout, 0.5) s versus the fake's 1.2 s delay) is decided by load, so
widening the sleep makes it worse: a wider window lets the extra round trip
complete and breaks the test's own reply-count invariant.

- Wait on the observable condition instead: the late receipt is reconciled when
  the text it confirms has become the baseline (`savedText`), and, in case 3,
  when the late conflict is surfaced. `waitUntil` follows the shape #812 added
  in NavigationMultiFileV2Tests — generous bound, XCTFail plus throw, with the
  late-reply list in the message.
- Stop the watcher for this test, which is about the save path only; its own
  timing is covered by DocumentWatcherTests, and no save here succeeds, so
  nothing re-arms it. The reply-count invariant is kept and tightened: exactly
  one late reply per save, now asserted in case 3 as well.

No product change: the status check the watcher made was correct (it reported
`unchanged`); it only clobbered a transient note and a test-visible counter.

Evidence: 12/12 sequential runs of the single test pass, 3.70-4.96 s (was a
fixed 6.1 s); full DocumentFilesTests 13 tests, 4 skipped (no Rust helper
locally), 0 failures. With the delay shortened to 0.6 s, which forces the
watcher's retry to land after the reply, the old test failed deterministically
with the CI message and lateReplies == 2; the new one passes.

Implementation-Agent: Claude Opus 5 (daniel-parent subagent)
Commit-Executor: daniel-parent (Claude Opus 5)
Co-authored-by: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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