Repository navigation
test(core): make MCP event tests deterministic - #65868
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
I reproduced the flake on the base branch. Under CPU load, 29 of 200 runs of the test failed on waited(2000, secondFailure), with gaps from 1211 to 1592ms, the same as CI. With this change and the same load, 200 of 200 passed. The whole MCP events suite also passes, and tsc -b for packages/core is clean.
The fix is sound. The failed reply is released only after each adjust returns, so the backoff starts at the clock time the test reads. The queue is unbounded, so releasing before the request arrives is safe, and failedOpens is only used by this test.
Public API is unchanged (test-only change).
No concerns.
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.
"MCP events > backs off failed opens, resets after active, and resumes with a replay gap once" fails now and then on Linux CI. In the last 400 failed check-test runs, plus the first attempts of runs that were rerun, I found 7 failures in the MCP events suite. All 7 were this test, all failed on the same line (
waited(2000, secondFailure)), and all measured a gap between 1318ms and 1551ms where the test expects at least 1600ms. Example: https://github.com/anomalyco/opencode/actions/runs/45211338655Why
The test reads the clock as soon as the client sees a failed open, and assumes the next backoff delay started at that time. The failed open is a real HTTP round trip.
TestClock.adjust("1200 millis")wakes the first reopen at about 1000ms, then waits only for Effect work it can track, not for HTTP I/O. On a busy runner, the server's error reply sometimes arrived while the adjust was still running. The client then started the 2000ms delay from the earlier clock time (around 850 to 1150ms), but the test read the clock after the adjust, at 1200ms, so the gap looked up to 400ms too short.I reproduced it locally by keeping the adjust busy right after the reopen: the old test failed 5 of 10 runs with the same errors as CI (1245ms to 1580ms).
What changed
Only the test changed. The test server now holds each failed open's reply until the test calls
failOpen. The test calls it after each adjust returns, so the failure, and the backoff delay it starts, always happen at the clock time the test reads. I did not change any timeouts or add retries, and production code is unchanged.Testing
From
packages/core, withbun run script/test.ts test/mcp.test.ts:-t "MCP events" --rerun-each 40: 280 of 280 passed (40 runs of each of the 7 tests).-t "backs off failed opens" --rerun-each 60in parallel on a 10 core machine: 600 of 600 passed.--rerun-each 3, 2 copies in parallel: 684 of 684 passed.bun typecheckinpackages/coreandbun script/lint-changed.ts origin/devpass.