Repository navigation
mac tests: wait for the reconciled receipt instead of a fixed sleep, and stop the watcher racing the fake helper (#800) - #830
Merged
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).watcherFireddefers once while the helper is busy, then retries aftermax(helperTimeout, 0.5)= 0.5s. When that retry lands after the helper's late reply, it runsrefreshDiskStatus()— a status request to the same--mode latefake, which also answers late. That extra round trip:status …entry tofiles.lateReplies, breaking the "one late reply per save" invariant, andcaptureNotewith 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 —
lateRepliescount 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: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
pump(1.6)calls. "Reconciled" is observable: the late receipt only setssavedTextwhen its hash matches the text sent, so the condition ismodel.savedText == "edited once\n"/"edited twice\n", andfiles.conflict != nilfor the conflict case.waitUntilcopies mac tests: waitUntil throws, helper-exit bound logs instead of failing, carried-hold release tests (#809) #812's shape: 30s bound,XCTFailthen throw, and a state closure printinglateRepliesin every failure.openTex, with the interaction explained in a comment.DocumentWatcherTestscovers the watcher, and no save here succeeds, so nothing re-arms it.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