Repository navigation
test: fix flaky stdio auto-refresh polling timeout (partial evidence for #654) - #682
Conversation
…t diagnostics Partial evidence for #654 — does not close the issue. The 'refreshes an active stdio session after an agent changes its workspace' test in tests/unit/stdio-server.test.ts intermittently timed out at its 10s limit when run alongside other files (observed in the 4-file group compare-native-agent/extract-frameworks/retrieve/stdio-server at --maxWorkers=4). Root cause: the test relied on the production default auto-refresh poll interval to observe a workspace-watcher event, which is too slow under concurrent load to reliably land inside the test timeout. Fix (test-only, uses pre-existing production seams, no product-semantic change): - inject a fast pollIntervalMs/maxPollIntervalMs via the existing autoRefreshStarter injection point (src/runtime/stdio-server.ts) and startGraphAutoRefresh options (src/infrastructure/watch.ts) - add timeout-detail diagnostics to the local waitFor() helper so a future recurrence reports the pending watcher state instead of a bare 'Timed out waiting for expected condition' - end() the stdio input stream before destroy() in the test's finally block to close it cleanly Verified: the fix deterministically resolves this test's flakiness (4-file flagged group: 1 failure -> 0 failures across repeated runs; file alone: 41/41 passing). This does NOT resolve the broader full-suite symptom. Repeated npm run test:run / test:coverage runs on this machine still show '[vitest-pool]: Failed to start forks worker' (IPC handshake timeout, not EMFILE/ENOMEM) on 3-29 different, effectively random test files per run, including a run taken after this fix. Evidence points to worker handshake timeouts under local machine contention (concurrent unrelated node/vitest processes were confirmed running via lsof during a failing run), independently corroborated by a teammate reproducing the identical signature on an unrelated branch/codebase at wider batch width. No narrowly-scoped repository fix for that broader symptom is evidenced yet. Acceptance criteria for #654 (three consecutive clean full-suite runs, or a documented local-resource distinction plus repeatable protected CI success) are not met. Full findings posted as an evidence-only comment on #654. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe pull request updates stdio auto-refresh test synchronization and cleanup. It adds configurable timeout diagnostics, short watcher polling intervals, and explicit input stream termination. It also ignores issue-specific artifacts. ChangesStdio test synchronization
Issue artifact exclusion
Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
mohanagy
left a comment
There was a problem hiding this comment.
Review verdict: the submitted diff is acceptable as a standalone, test-only flakiness improvement, but it is not a resolution of #654.
The scope is narrow: .gitignore plus tests/unit/stdio-server.test.ts; no production source changed. The existing protected CI run completed successfully across the six OS/Node jobs, which supports reviewing this PR independently from the broader worker-start investigation.
Two conditions remain:
- Keep
Refs #654, notCloses #654, and leave #654 open. Closing #654 still requires the issue's documented local-resource distinction plus repeated protected-CI success, or the alternative clean-local-run criterion. - Correct the orchestration record before merge: the remote PR/branch head is currently
af16e41b14a4e63f2dc6b92025c520effc79ecfc, while the final #648 comment reportsdb7300ce. GitHub has no remote commit matching that latter prefix. Either push the intended later commit or amend the record to the actual reviewed head.
Subject to resolving that provenance mismatch, I support merging this PR as a standalone flakiness fix. Do not treat the merge as satisfying #654.
Summary
Partial, evidence-based progress on #654. This PR fixes one real, deterministic test flakiness bug and adds diagnostic output. It does not close #654 — the broader complete-suite "Failed to start forks worker" symptom that #654 exists to resolve remains unexplained by a repository-level cause and unresolved.
Problem and evidence
Issue #654's baseline flagged four files near a timeout/worker-start failure:
compare-native-agent.test.ts,extract-frameworks.test.ts,retrieve.test.ts,stdio-server.test.ts.What I found and fixed: in the 4-file flagged group at
--maxWorkers=4,stdio-server.test.ts > stdio runtime > refreshes an active stdio session after an agent changes its workspaceintermittently timed out at its 10s limit. Debug instrumentation showed it was blocked inevent_mode: 'polling', waiting on the production default auto-refresh poll interval to observe a workspace-watcher event — too slow to reliably land inside the test's timeout under concurrent load. Injecting a fast poll interval through the pre-existingautoRefreshStarterseam made the failure disappear deterministically (verified across repeated runs, file-alone and in-group).What is NOT fixed and remains open: repeated full-suite runs — both before and after this fix — show
Error: [vitest-pool]: Failed to start forks worker for test files ..., traced toCaused by: Error: [vitest-pool-runner]: Timeout waiting for worker to respond(an IPC handshake timeout — notEMFILE/ENOMEM;ulimit -nis 1048576 on this machine). The affected files are different and effectively random on every run (12+ distinct file sets observed across 6 full runs, see Validation below), which argues against any single broken test and for suite-level/environmental worker-startup starvation. During one failing run,lsofat the time of failure showed multiple unrelated concurrentnodeprocesses (a different worktree's checkout, plus other agent/test workloads) competing for CPU on this shared machine. An independent teammate reproduced the identical signature (Failed to start forks worker+compare-native-agent.test.tstimeouts) on a completely unrelated branch/codebase at a wider batch width (21 files), with zero failures in small batches — cross-branch, cross-code reproduction that further points to local machine contention rather than a defect in this repository's code or tests.No mechanism has been demonstrated that connects the
stdio-server.test.tspolling fix to the broader worker-start-failure symptom, and no other narrowly-scoped repository correction is evidenced yet.Exact scope
tests/unit/stdio-server.test.ts: fix one flaky test's dependency on the production default poll interval; add timeout-detail diagnostics to the localwaitFor()helper; close the stdio input stream (end()beforedestroy()) in the test'sfinallyblock..gitignore: ignore the.issue-654-artifacts/investigation-evidence directory (raw logs, an isolated repo clone used for controlled full-suite reruns,lsof/memory snapshots) so it is never accidentally committed.Explicit non-goals (per issue contract, honored)
--maxWorkers=1forced — not applied; no evidence justifies it as global policy.Files and symbols changed
tests/unit/stdio-server.test.tswaitFor(condition, timeoutMs, timeoutDetail?)— new optional third parameter (string or thunk) included in the thrown timeout error.'refreshes an active stdio session after an agent changes its workspace': passesautoRefreshStarter: (watchPath, debounceSeconds, options) => startGraphAutoRefresh(watchPath, debounceSeconds, { ...options, pollIntervalMs: 10, maxPollIntervalMs: 20 }), using the pre-existingautoRefreshStarterinjection point already present insrc/runtime/stdio-server.tsand the pre-existingpollIntervalMs/maxPollIntervalMsoptions already present insrc/infrastructure/watch.ts'sstartGraphAutoRefresh. No new seam was added to production code — both injection points already existed atorigin/main.finallyblock:input.end()added before the existinginput.destroy()..gitignore: added.issue-654-artifacts/.No
src/files changed.Tests
tests/unit/stdio-server.test.tsalone: 41/41 passing.compare-native-agent.test.ts,extract-frameworks.test.ts,retrieve.test.ts,stdio-server.test.ts) at--maxWorkers=1/2/4: before fix, 1 failure (the timeout above) at--maxWorkers=4; after fix, 303/303 passing at--maxWorkers=1/2/4, repeated.Differential behavior
None for production code (unchanged). Test-only: the fixed test no longer depends on the production default poll interval to complete within its timeout; a future timeout in this
waitFor()helper will report the pending watcher state instead of a bare "Timed out waiting for expected condition".Validation commands and results
Environment: worktree
/Users/mohammednaji/Desktop/projects/works/madar-654, branchroadmap/654-vitest-gate, base06b373a447acfce895412ac10eb4e5228c5df0b7. Nodev22.22.3(matches issue reference). npm12.0.2— the issue names12.0.1; this is an unresolved, flagged discrepancy, not normalized away.package-lock.jsonSHA-2560144eb0ddf92f78c69f10089d0e0414485594966ff5be4f36f655c7aa5cff53e— matches the issue's audited value exactly; unchanged by this PR.npm cinpm run typechecknpm run buildnpm run verify:pack-paritynpm pack --dry-runnpm run registry:validatenpm run release:verifytests/unit/stdio-server.test.tsalonenpm run test:run(full suite, after fix, my own fresh run)Failed to start forks workererrors on:benchmark-artifact,extract-go,generate-spi-flag,mcp-registry-metadata,pack-quality-fixtures,pipeline,spi-cache,spi-calls,spi-framework-nextjs,spi-framework-route-metadata,spi-projector,spi-symbols. The 2 direct test failures were 60s timeouts incompare-native-agent.test.ts(matches the issue's originally recorded symptom). Duration 511s.npm run test:run/npm run test:coverage(5 additional full-suite runs across the investigation, 3 before this fix, 2 after, captured with full logs/env/lsof/vm snapshots)Failed to start forks workeron a different, non-overlapping set of 3–29 files. No two runs failed on the same file set.Not completed:
npm run test:coveragewas not run as a final post-fix check in this session (the plaintest:runruns above already demonstrate the unresolved symptom without adding coverage-instrumentation overhead); three-consecutive-clean-full-runs was attempted and did not succeed even once post-fix, so it was not repeated a third time once the pattern was established.Compatibility impact
None. No production code, public API, CLI, MCP surface, or artifact format changed.
Risks
Rollback
Revert this commit;
stdio-server.test.tsand.gitignorereturn to their prior state. No source regeneration, migration, or data changes are involved.Ready for review verdict
Ready for review. The diff is small, narrowly scoped, uses pre-existing production seams, does not weaken any assertion, and is independently verified (by both the implementing session and this reviewing session, on two separate full local reproductions).
Ready for merge verdict
Not ready for merge as a resolution to #654. The PR's own change is safe to merge as a standalone flakiness fix, but #654's acceptance criteria (three consecutive clean full-suite runs, or a documented local-resource distinction plus repeated protected-CI success) are not met, and closing #654 on this evidence would be an overclaim. Recommend: merge this PR as a partial improvement (does not close #654), then continue #654 with either (a) evidence from the actual protected CI matrix (dedicated, non-shared runners) to establish whether the worker-start-starvation symptom is exclusively a local/shared-machine artifact, or (b) further investigation into whether a Vitest/tinypool configuration change (e.g., a longer worker-handshake timeout, or a lower default
maxWorkers) is justified — neither of which is evidenced yet.Related issues
Refs #654 (not closing — see verdicts above)
🤖 Generated with Claude Code
Summary by CodeRabbit
Tests
Chores