Skip to content

fix(test): stop leaking workflow-artifact temp dirs from vitest workers - #2560

Merged
flora131 merged 1 commit into
mainfrom
fix/setup-artifact-dir-leak
Aug 21, 2026
Merged

flora131 merged 1 commit into
mainfrom
fix/setup-artifact-dir-leak

Conversation

@flora131

@flora131 flora131 commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

test/setup-workflow-durability.ts created one mkdtemp per vitest worker process and never removed it. Under the default isolated forks pool that is one directory per test file per run. Measured damage on a dev machine: 330k leaked atomic-test-workflow-artifacts-* entries (of 1.3M total temp-dir entries), which made every mkdtemp under tmpdir() machine-wide take seconds and pushed real-CLI tests (e.g. release-publisher-contracts) past their structural budgets — 145 s for a sequence that takes 5 s in a clean temp dir.

Changes

  • test/global-setup-workflow-artifacts.ts (new): creates one directory per run in the orchestrator process; every worker inherits ENV_WORKFLOW_ARTIFACT_DIR and creates nothing; the globalSetup teardown removes it after the pool is gone. Wired into all three projects.
  • test/setup-workflow-durability.ts: keeps a fallback for invocations that bypass the repo config, now with exit-time cleanup plus a SIGTERM→exit conversion — tinypool ends forks with SIGTERM (then SIGKILL after 500 ms), and Node's default SIGTERM disposition skips exit listeners entirely.
  • test/ci/ci-workflow-contracts.test.ts: the globalSetup contract now asserts the artifact setup on all three projects and the native build on unit/integration only.

Notes

  • Why not worker-side cleanup alone: tinypool's 500 ms SIGTERM→SIGKILL teardown race means a loaded worker still leaks; the orchestrator teardown has no such race. The worker fallback exists only for non-repo-config invocations.
  • Verified: three repeated multi-file suite runs leak zero directories (previously one per test file); npm run check and all 47 ci-contract tests green.
  • Unrelated to but discovered via build: raise the Bun floor to 1.4.0 and drop the bun:sqlite fallback #2559, where the pre-push hook timed out on the polluted temp dir.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Greptile Summary

This change centralizes workflow-artifact temporary-directory ownership in Vitest’s orchestrator and retains worker-side cleanup for configuration-bypassing test runs. The artifact lifecycle was exercised twice through the root Vitest configuration with concurrent workers: each run used one shared directory while tests were active, and that directory no longer existed after Vitest exited. The temporary-directory leak concern was disproved by these executions. No defects were found.

Confidence Score: 5/5

Safe to merge based on the exercised root-config test lifecycle.

Two independent concurrent-worker executions confirmed that workers inherit one orchestrator-owned artifact directory, can use it during the run, and that it is removed after the run exits. No publishable defects remain.

Files Needing Attention: No files need follow-up attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran the root-config workflow-artifact end-to-end harness twice with two Vitest workers to validate that a shared orchestrator-owned directory is inherited by workers and cleaned up when tests finish.
  • In run 1, workers 3342 and 3343 observed /tmp/greptile-run-run-3/opencode-tmp/atomic-test-workflow-artifacts-NgzoEF, and the directory existed during the run with files from both workers and was removed after exit.
  • In run 2, workers 3410 and 3411 observed /tmp/greptile-run-run-3/opencode-tmp/atomic-test-workflow-artifacts-WxzT0o, and the directory was likewise removed after exit.
  • The two runs were compared and shown a consistent cleanup pattern across runs.
  • Security status was checked and no security issues were identified.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix(test): stop leaking workflow-artifac..." | Re-trigger Greptile

The setup file created one mkdtemp per worker process and never removed
it. Under the default isolated forks pool that is one directory per test
file per run, and tinypool tears workers down with SIGTERM then SIGKILL
after 500 ms, so even an exit-hook cleanup loses that race under load.
Measured damage: 330k leaked atomic-test-workflow-artifacts-* entries in
the OS temp dir (of 1.3M total), enough to make every mkdtemp under
tmpdir() machine-wide take seconds and push real CLI tests past their
structural budgets.

- New test/global-setup-workflow-artifacts.ts creates one directory per
  run in the orchestrator; workers inherit the env var and create
  nothing; teardown removes it after the pool is gone. Wired into all
  three projects.
- setup-workflow-durability.ts keeps a fallback for invocations that
  bypass the repo config, now with exit cleanup and a SIGTERM-to-exit
  conversion (Node's default SIGTERM disposition skips exit listeners).
- The globalSetup contract test now asserts the artifact setup on all
  three projects and the native build on unit/integration only.

Verified: three repeated suite runs leak zero directories.
Assistant-model: Claude Fable 5
@flora131
flora131 enabled auto-merge August 21, 2026 04:19
@flora131
flora131 merged commit 2ee7f76 into main Aug 21, 2026
17 checks passed
@lavaman131
lavaman131 deleted the fix/setup-artifact-dir-leak branch October 27, 2026 19:32
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