Repository navigation
fix: remove the timing races behind three intermittently failing tests - #214
Merged
Merged
Conversation
Each of these failed on CI or on a loaded box while the same tree passed alone; none was a wrong answer from the code under test. - integrations doctor "completes the live MCP handshake": the handshake probe had a 5 s bound for strictly more work than the 10 s version probe (the server must load the CLI's module graph and open and migrate the store's database before it can answer initialize). HANDSHAKE_TIMEOUT_MS is now 20 s and the test's own vitest timeout 45 s, above the sum of both probe bounds. Failed 2026-09-14 (twice, locally under a11y/Lighthouse load) and on CI for #207 on 2026-09-22. - store "compensates an INTERRUPTED archive": the test interrupted on a 200 ms wall clock while claiming to interrupt at the hanging commit. On a slow runner 200 ms landed inside `git mv` or `git add`; the aborted child still held .git/index.lock when the compensation's `git reset` ran, so restore failed as a whole and the moved file was never put back (CI for #211, 2026-09-23: ENOENT on the first readFile). The fake commit now signals a Deferred when reached and hangs; the test forks the archive, waits for the signal, interrupts the fiber, and asserts the exit carries an interrupt. The interruption lands at the commit on every box, which is the production case the comment names. - consolidator "removes the temp parent it created": the census counted every memhtml-corpus-snapshot-* entry in tmpdir(), which reachability.test.ts creates and removes in a parallel worker (5 before, 3 after on 2026-09-08). The census now reads only the two names this case created; dropping the rm(parent) from release still leaves both and fails the assertion. Merged under the standing authority Laith granted on 2026-09-23 for addressing flakes.
Contributor
Author
|
Local gate on this head (fd59693): |
laithalsaadoon
added a commit
that referenced
this pull request
Oct 20, 2026
…nalizers run (#216) The abort signal handed to execFile sends SIGTERM when the fiber is interrupted, but the child is still alive for a moment afterwards, and if it is `git mv` or `git add` it still holds .git/index.lock. Interruption then proceeded straight to the caller's finalizers, and store.ts's compensation opened with `git reset -q -- <paths>` against a lock that had not been released: exit 128, the whole restore abandoned, and the half-done mv left on disk with nothing to put the memory back. An MCP client timeout landing mid-archive is exactly this path in production; the same race surfaced as a CI flake in store.test.ts on 2026-09-23 (fixed on the test side in #214). spawnGit's Effect.callback register now returns a cleanup effect that resolves on the child's exit (or close, for a spawn that never started), which Effect.callback runs and awaits on an interrupting cause before the cause propagates (effect 4.0.0-rc.115 internal/effect.js asyncFinalizer). The signal stays, so a git that ignores SIGTERM is still killed. Test: blocks a real `git commit -a` on a hand-made refs/heads/<branch>.lock with core.filesRefLockTimeout=-1, interrupts the fiber, and asserts the pid is gone and index.lock absent by the time Fiber.interrupt returns, then that the compensation's `git reset` succeeds. Removing the wait fails it 3 of 3.
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.
Three tests failed intermittently on CI or on a loaded box while the same tree passed alone. Each failure was a race between the test and something it did not control, and none was a wrong answer from the code under test. This PR removes the races.
apps/cli/tests/integrations.test.ts> integrations doctor > completes the live MCP handshakepackages/integrations/src/doctor.ts) had a 5 s bound for strictly more work than the 10 s version probe: the spawned server must load the CLI's module graph and open and migrate the sandbox store's database before it can answerinitialize. Under the fullmise run checkon a 2-vCPU runner that cold start exceeded 5 s (2026-09-14 twice locally, CI attempt 1 of #207 on 2026-09-22).HANDSHAKE_TIMEOUT_MS5 s -> 20 s with the reasoning in its doc comment; the test's vitest timeout 30 s -> 45 s so a slow box fails on the doctor's own row rather than on vitest's clock. A moved entry script, a missing binary, an exiting server or a wrongserverInfo.namestill fail immediately through theerror/exit/name branches.packages/store/tests/store.test.ts> compensates an INTERRUPTED archiveEffect.timeout(200)while its comment said the interruption lands at the hangingcommit. On a slow runner 200 ms landed insidegit mvorgit add; the abort killed that child,Effect.onErrorstartedrestoreat once, and its first stepgit resetraced the dying child for.git/index.lock, lost with exit 128, and the whole restore was abandoned with the renamed file still on disk (CI attempt 1 of #211, 2026-09-23:ENOENT ... areas/inbox/a-remembered-fact.html).commitsucceeds aDeferredwhen reached and then hangs. The test forks the archive withEffect.forkDetach, awaits the Deferred, interrupts the fiber withFiber.interrupt, and assertsExit.hasInterruptson its exit. The interruption now lands at the commit on every box, which is the production case the comment describes (client timeout after the rename is staged). The four original assertions (bytes restored, no archived file, clean tree, no new commit) are unchanged.apps/consolidator/tests/mount.test.ts> removes the temp parent it createdcountSnapshotscounted everymemhtml-corpus-snapshot-*entry intmpdir(), andreachability.test.tscreates and removes directories under the same prefix in a parallel vitest worker (5 before, 3 after on 2026-09-08).basename(parent)for each of its two cycles and asserts none of those names remains intmpdir(). The mutation the comment names (droppingrm(parent)fromrelease) still leaves both names and fails.Each test was run alone on this head and passes; the full local gate result is in the first comment.
One latent hazard the store flake exposed is left for a separate PR: in production an MCP client timeout that lands mid-
git mvproduces the same uncompensated half-archive, because the interrupt does not wait for the aborted git child to exit beforerestorespawnsgit reset. Returning a cleanup effect fromspawnGit'sEffect.callbackthat waits for the child'sclosewould close that window; it needs its own test and a check of rc.115's cleanup semantics, so it is not folded in here.Authority: Laith's 2026-09-23 grant in #bonk-place (bring deps to latest aggressively and address flakes) covers merging on green.