Fix two flaky tests: Jev prefetch timeout reporting and ACP gateway port collisions
Summary
Two tests failed intermittently under full-suite load and passed when run alone. Both causes are fixed; one was also a real telemetry bug.
Jev prefetch: a deadline hit during collection was reported as no-candidates
buildJevPrefetch gives candidate collection and the provider call one shared deadline. Source reads swallow aborts, so when the deadline lapsed mid-collection the pool came back empty and the run was logged as no-candidates instead of timeout. The fail-open test's 50 ms budget could expire during collection under load, so it flaked.
src/shared/jev-prefetch.ts: check the deadline before concluding the pool is empty. Both orderings now reporttimeout.test/jev-prefetch.test.ts: a zero-budget case pins the collection-time path deterministically. It failed 3/3 before the fix and passes 5/5 after.
ACP remote test: a taken port became a silent 15 s timeout
The test started the gateway on a random port and waited 15 s for its listening line. The gateway starts in about 0.1 s, but exits on EADDRINUSE, and the test neither noticed the exit nor kept its stderr.
test/acp-remote.test.ts: startup retries on a fresh port when the gateway exits before listening (up to 3 attempts), kills it on timeout, and includes its stderr in any failure. With the first port deliberately occupied, the test now passes in about 0.7 s instead of timing out.
Review-quality gate
Neither file is a trigger path, and model inputs are unchanged; no benchmark run.
Validation
npm run lint, npm run typecheck (only the pre-existing @cline/sdk resolution errors), npm test (1163 pass, 0 fail), npm run build.
Summary by cubic
Fixes two flaky tests and a real telemetry bug behind one of them: Jev prefetch deadline hits during candidate collection were logged as no-candidates instead of timeout, and the ACP remote test silently timed out when its randomly chosen port was taken.
- Jev prefetch: the deadline is now checked before concluding the candidate pool is empty, so both timeout orderings report
timeout; a zero-budget test case pins the collection-time path and asserts no provider call was made. - ACP remote test: gateway startup retries on a port that wasn't previously tried when the gateway exits before listening (up to 3 attempts), waits for the close event so stderr drains, kills the gateway on timeout, and includes stderr from every failed attempt in failure output.
Summary by CodeRabbit
- Bug Fixes
- Improved timeout handling during context preparation. When a request’s deadline expires while candidates are being collected, it now returns the baseline context and is reported as a timeout instead of appearing to have no candidates. This makes timeout outcomes more accurate and consistent.