Skip to content

ci: harden pre-commit vitest hook against teardown hangs - #2542

Merged
bokelley merged 1 commit into
mainfrom
bokelley/vitest-precommit-slow
Apr 20, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/vitest-precommit-slow

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • Switch test:unit to --pool=threads. Vitest 4.1.4's default forks pool zombies workers for days when something in the module graph leaks an open handle at process exit (37 such processes were found across Conductor workspaces, some running 2 days at 0% CPU, stuck at teardown).
  • Wrap npm run test:unit in scripts/with-timeout.sh 60 for pre-commit. A sporadic hang now aborts in 60s instead of blocking the developer indefinitely. The wrapper is portable (uses timeout/gtimeout when present, bash trap/kill fallback otherwise) and sends SIGTERM first with a 5s grace window before SIGKILL.
  • Add the full tests/ suite to the Build Check CI workflow. It was only running via pre-commit — any skip (--no-verify, hung hook) previously meant zero coverage.
  • Run Build Check on pushes to main, not just PRs. Concurrency group avoids duplicate runs on PR merge.
  • 15-minute job timeout on Build Check so CI itself can't be held hostage if the hang recurs.

Root-cause investigation tracked in #2541 — likely candidates to audit for unclean shutdown: DB pool, addie singletons, stripe client, email clients.

Test plan

  • Full suite passes under --pool=threads (587 tests in ~3s)
  • Pre-commit self-test: this commit went through the new wrapper
  • Wrapper exit codes verified: clean exit passes through, SIGTERM on timeout yields 143, invalid secs arg yields 2
  • CI Build Check passes on this PR

🤖 Generated with Claude Code

vitest 4.1.4 forks pool zombies workers for days when something in the
module graph leaves an open handle at process exit — 37 such processes
found across workspaces, some running 2 days at 0% CPU. Switch test:unit
to --pool=threads and wrap npm run test:unit in a portable shell timeout
so a sporadic hang aborts pre-commit in 60s instead of blocking the
developer indefinitely.

Add the full tests/ suite to Build Check CI (it previously only ran via
pre-commit) and run Build Check on pushes to main, not just PRs. Root
cause of the hang tracked in #2541.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley merged commit 46fb4c9 into main Apr 20, 2026
11 checks passed
bokelley added a commit that referenced this pull request Apr 20, 2026
The pino-pretty transport spawns a worker thread and registers
process.on('exit', ...), which holds the event loop open at vitest
teardown — resulting in zombie workers that could hang pre-commit for
hours. 37 such processes had accumulated across Conductor workspaces,
some running 2 days at 0% CPU.

Treat NODE_ENV=test and VITEST=true (auto-set by vitest) as non-dev so
tests use the default synchronous stdout destination with no worker
thread and no exit listener. Six back-to-back runs confirm the hang is
eliminated.

The defensive timeout wrapper and threads pool from #2542 stay as
belt-and-suspenders against future regressions.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request Apr 20, 2026
The pino-pretty transport spawns a worker thread and registers
process.on('exit', ...), which holds the event loop open at vitest
teardown — resulting in zombie workers that could hang pre-commit for
hours. 37 such processes had accumulated across Conductor workspaces,
some running 2 days at 0% CPU.

Treat NODE_ENV=test and VITEST=true (auto-set by vitest) as non-dev so
tests use the default synchronous stdout destination with no worker
thread and no exit listener. Six back-to-back runs confirm the hang is
eliminated.

The defensive timeout wrapper and threads pool from #2542 stay as
belt-and-suspenders against future regressions.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
bokelley added a commit that referenced this pull request Jun 11, 2026
…ets (#5484)

Root-cause fix for the sporadic vitest pre-commit teardown hang (#2541): 7 background setInterval loops (crawler x3, luma/sync, addie/jobs/scheduler, 2 scheduled/*) were missing .unref(), so a test that triggers one keeps the worker's event loop alive at exit. These are server-internal background loops (the server stays alive via its HTTP listener, not these timers), so unref is correct in production and matches the 12+ siblings that already do it.

Also raises with-timeout budgets (test:unit 60->180s, server-unit 120->240s): the suites grew past the caps set in #2542, so under multi-workspace CPU contention they were SIGTERM'd mid-run even without a hang.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

1 participant