Skip to content

fix(test): stop processes a test run leaves in its temp directory - #4093

Merged
thymikee merged 3 commits into
mainfrom
fix/test-run-process-leaks
Oct 30, 2026
Merged

thymikee merged 3 commits into
mainfrom
fix/test-run-process-leaks

Conversation

@thymikee

@thymikee thymikee commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Test runs left fixture processes running for weeks. On one host, 13 orphaned fake daemons and a validation command group were still alive 5–16 days after their runs ended.

Vitest global teardown and the node --test wrapper removed the run directory without stopping processes that still held it as TMPDIR. Teardown now stops leftover process trees and lists them on stderr. A root is a Node process in the run directory whose parent is neither the run owner nor another run process. Its descendants are stopped with it. This covers subreapers and a PID 1 runner. Shared tools such as adb or an emulator run another executable, so teardown leaves them alone. The wrapper stops leftovers only after its child exits, including after a forwarded Ctrl-C. Teardown always removes the directory.

The check-affected execution tests now kill the recorded command group when they fail before learning its PID.

6 files, test tooling only. No linked issue.

Validation

  • pnpm check:tmpdir-leaks:test: 28/28 at 598c4b1. The new wrapper tests (a fixture tree with a surviving non-Node tool, and an interrupted wrapper) fail at b985f53.
  • pnpm check:affected --run --head b985f53176: passed (66 checks).
  • At 8a3d724 and 598c4b1 the local unit check failed, at load average 40–73. At 598c4b1 all 1,849 test files pass; the only failures are unhandled errors from explicit-lifecycle-fixture.ts. Those errors reproduce with the base teardown files, and the changed code runs only after all workers exit. The CI unit lane at this head is the evidence.
  • CI covers the Linux /proc path.

🤖 Generated with Claude Code

Vitest global teardown and the node --test wrapper removed the run
directory without stopping processes that still held it as TMPDIR, so
fixture daemons from killed or timed-out tests ran for weeks. Teardown
now SIGKILLs the orphaned Node processes still in the run directory and
reports them. Shared tools a test started (adb, emulator) and processes
whose parent still runs are left alone. The check-affected execution
tests also kill the recorded command group when they fail before
learning its pid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-device-website Ready Ready Preview Oct 30, 2026 9:59am UTC

Request Review

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.61 MB 5.61 MB 0 B
Package (unpacked) 5.61 MB 5.61 MB 0 B
Package (download) 1.71 MB 1.71 MB -6 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 32.1 ms 33.0 ms +0.9 ms
CLI --help 67.7 ms 67.7 ms -0.0 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/vitest-tmpdir-global-setup.ts Resolved
Comment thread scripts/check-tmpdir-leaks-model.ts Resolved
Comment thread scripts/node-test-tmpdir.ts Resolved
Comment thread scripts/check-tmpdir-leaks-model.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

At b985f53 I found no blocking problems in the code. All 21 checks pass, and the ubuntu "Check the tmpdir redirection model" step plus every Vitest and node --test lane run the new teardown. No conflicts. I did not run the tests or the revert-to-base experiment, and I did not confirm on a live host that Vitest 4 fork workers have exited before global teardown runs. The green Linux run is the evidence for that.

Not blocking, take or leave: the SIGKILL loop in scripts/check-tmpdir-leaks-model.ts (https://github.com/callstack/agent-device/blob/b985f53/scripts/check-tmpdir-leaks-model.ts#L76) repeats signalPidsBestEffort from @agent-device/host-kit/process, which also de-duplicates pids and skips the current process, and expandProcessTree from the same package already covers "this root and its descendants". Also, "parent gone" is tested as ppid === 1 (https://github.com/callstack/agent-device/blob/b985f53/scripts/check-tmpdir-leaks-model.ts#L69). On a Linux host with a child subreaper, such as a systemd --user session, an orphan reparents to the subreaper, so teardown could remove the directory while the fixture still runs. I inferred this from systemd semantics and did not observe it. Stating the rule as "its parent is not a live process of this run", or documenting the PID 1 assumption, would cover it.

The four Cubic threads that still apply: the missing descendant orphans (#4093 (comment)), the signal path skipping the stop (#4093 (comment)), and the ps ENOENT abort on hosts without procps (#4093 (comment)) all hold on the stated goal. The container PID 1 thread (#4093 (comment)) is real but low impact, since no repo workflow uses a container. Please fix it, or dismiss it with that reasoning.

Before merge, please answer those threads.

Address review: a root is now a Node process in the run directory whose
parent is neither the run owner nor another run process, so subreapers
and a PID 1 runner are handled, and each root's descendants are stopped
too. Reuse the host-kit process table and signal helpers. The vitest
teardown always removes the directory and restores env, and the node
--test wrapper waits for its child after a forwarded signal, then stops
leftovers; a second signal still exits at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

Addressed at 8a3d724:

  • Both take-or-leave notes taken. The stop now reuses listHostProcesses, expandProcessTree and signalPidsBestEffort from @agent-device/host-kit/process, and the scan reverts to its original pid/TMPDIR shape. "Parent gone" is now "its parent is neither the run owner nor another process of this run". That covers a systemd --user subreaper and a runner that is itself PID 1.
  • All four Cubic threads are fixed and answered: descendants, the signal path, try/finally teardown, and container PID 1.
  • The two new wrapper tests (a fixture tree with a surviving non-Node tool, and an interrupted wrapper) fail at b985f53 and pass at 8a3d724. pnpm check:tmpdir-leaks:test: 28/28.
  • pnpm check:affected --run --head 8a3d724 failed twice in unit, in different daemon-client timing tests each run, while the host load average was 40–73. The same unhandled errors from explicit-lifecycle-fixture.ts reproduce with the base teardown files. The failed files pass on their own at HEAD. The changed code runs only after every worker has exited. I'm relying on the CI unit lane at this head as the evidence.

Comment thread scripts/node-test-tmpdir.test.ts Fixed

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/node-test-tmpdir.test.ts Resolved
Comment thread scripts/node-test-tmpdir.test.ts Resolved
Pass probe paths through env and argv instead of building them into
source, publish pid files by rename so a reader never sees pid 0, and
interrupt a still-running wrapper before SIGKILL in cleanup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member Author

The code looks good at 598c4b1. The fixes for the earlier findings (#4093 (comment)) are in, and nothing from that review remains open. All 21 checks pass at this commit, and the changed teardown runs in every Vitest and node --test lane, with the ubuntu tmpdir-model step exercising it directly. There are no conflicts.

Not blocking, and fine to take or leave: in https://github.com/callstack/agent-device/blob/598c4b1/scripts/check-tmpdir-leaks-model.ts#L72 the consumer set comes from the /proc (or ps -E) scan, but ppid and command come from a later ps -ax listing, so a consumer pid that exits and is reused by an unrelated Node process could be matched as a root and have its tree killed; building the process rows from the same single pass and passing them to expandProcessTree would remove the second listing and the Linux dependency on procps.

The inline threads from other reviewers are all fixed at this head and already resolved: #4093 (comment) (global-setup cleanup after rejection), #4093 (comment) (descendants now stopped), #4093 (comment) (signal forwarding and exit code), #4093 (comment) (PID 1 runner children spared), #4093 (comment) (no value spliced into code), #4093 (comment) (signal-test cleanup order), #4093 (comment) (pid guard and rename publish).

I read the code and the CI results but did not run the new tests or pnpm check:tmpdir-leaks:test. I did not confirm on a live host that Vitest 4 fork workers have exited when global teardown runs. I checked the PID 1 and container cases by reading the predicate, not by observing them, and no test covers a Linux host without procps.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Oct 30, 2026
@thymikee
thymikee merged commit f2c69f7 into main Oct 30, 2026
21 of 22 checks passed
@thymikee
thymikee deleted the fix/test-run-process-leaks branch October 30, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants