Repository navigation
Make the http timeout test deterministic with a fake clock (#324) - #325
Merged
Merged
Conversation
The test compared real elapsed time to a real 500 ms timeout (>= 450, < 2000), which failed when load delayed the event loop. It now fakes setTimeout and clearTimeout only, checks the request is pending at 499 ms, rejects with 'timed out after 500ms' at 500 ms, and checks the connection was closed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…meout # Conflicts: # CHANGELOG.md
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.
Closes #324
What made it flaky
src/tools/built-in/http.test.ts"rejects near the configured timeout" ran a real request against a real server that never answers and asserted450 <= elapsed < 2000against the real 500 ms timeout. Under load (the full coverage run, many vitest workers) the event loop can be delayed by more than 1.5 s, so the upper bound failed. Production code is fine: the timer is an ordinarysetTimeout(() => controller.abort(), timeoutMs)inrunHttpRequest.Fix (test only, no production change)
The test now fakes only
setTimeout/clearTimeout(vi.useFakeTimers({ toFake: [...] })); the sockets stay real. It waits until the server has the request (so the timer is armed), then asserts: still pending after 499 ms, rejects with "timed out after 500ms" at 500 ms, and the server sees the connection close (the abort tore it down). That is stricter than before (exact boundary and the exact message, plus the connection teardown) and has no wall-clock comparison. Real timers are restored infinally.Other tests named in the ticket
credentialBroker.test.tshas no timing assertion.src/execution/guardrails.test.tshaselapsed < 2000checks around real child processes (100 ms command timeout); a fake clock does not apply there (the child and the kill are real), so I left them alone as the ticket says "only if the fix is the same".Repeat-run evidence (Windows 11, Node 26)
npx vitest run src/tools src/security src/execution/guardrails.test.tsrun 20 times, 4 runs at a time in parallel (about 4x the normal load):http.test.ts(23 tests) passed 20/20. Two unrelated tests failed in some of those 20 runs, not touched here:src/security/SubprocessSandbox.test.tsintegration (Docker daemon required) in 5 runs andsrc/tools/workspace/checkpoints.node.test.ts"rewinds three turns" in 1 run.Verification
npx tsc --noEmit: cleannpm run lint: 0 warningsnpm run test:coverage(after merging origin/main at fe54100): 268 files passed, 1 skipped; 3878 tests passed, 6 skippednpm run fallow: exit 0npm run docs:llms:check: clean🤖 Generated with Claude Code