Skip to content

fix: close REPL servers after each test to prevent Jest worker from hanging#1847

Merged
pmcelhaney merged 2 commits intomainfrom
copilot/fix-worker-process-exit
Apr 13, 2026
Merged

fix: close REPL servers after each test to prevent Jest worker from hanging#1847
pmcelhaney merged 2 commits intomainfrom
copilot/fix-worker-process-exit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Summary

Each test in test/repl/repl.test.ts called startRepl()repl.start(), creating a Node.js REPLServer that holds process.stdin open. Nothing ever closed them, so Jest workers couldn't exit, producing the "worker process has failed to exit gracefully" error.

Changes:

  • test/repl/repl.test.ts: track every REPLServer created by createHarness() in a module-level array; drain and close all of them in afterEach
const openServers: REPLServer[] = [];

afterEach(() => {
  for (const server of openServers) {
    server.close();
  }
  openServers.length = 0;
});

function createHarness(scenarioRegistry?: ScenarioRegistry) {
  // ...
  openServers.push(harness.server);
  return { config, contextRegistry, harness, registry };
}
Original Prompt

Jest is reporting open handles. Fix the issue so Jest can exit gracefully.

Manual acceptance tests

  • yarn test completes without "A worker process has failed to exit gracefully" in the output
  • All 47 test suites pass after the change
  • Running the repl test suite in isolation (yarn node --experimental-vm-modules ./node_modules/jest-cli/bin/jest --testPathPatterns=repl.test --coverageThreshold='{}') finishes in under 5 seconds instead of hanging

Tasks

  • Confirmed repl.test.ts hangs indefinitely when run in isolation (timed out after 20 s)
  • Added openServers tracking array and afterEach cleanup to test/repl/repl.test.ts
  • Modified createHarness to register each new server for cleanup
  • Verified repl test now completes in ~0.6 s; full suite (47 suites, 573 tests) passes clean

Copilot AI changed the title [WIP] Fix worker process to exit gracefully in Jest fix: close REPL servers after each test to prevent Jest worker from hanging Apr 13, 2026
Copilot AI requested a review from pmcelhaney April 13, 2026 21:15
@pmcelhaney pmcelhaney marked this pull request as ready for review April 13, 2026 21:17
@pmcelhaney pmcelhaney enabled auto-merge April 13, 2026 21:17
@pmcelhaney pmcelhaney added this pull request to the merge queue Apr 13, 2026
Merged via the queue into main with commit 60a320e Apr 13, 2026
8 of 11 checks passed
@pmcelhaney pmcelhaney deleted the copilot/fix-worker-process-exit branch April 13, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

worker process has failed to exit gracefully

2 participants