Skip to content

Tests: the lint, screenshot and replay runs delete their temp trees - #1244

Merged
GLinnik21 merged 3 commits into
mainfrom
worktree-agent-a571d52048d765bfe
Nov 5, 2026
Merged

GLinnik21 merged 3 commits into
mainfrom
worktree-agent-a571d52048d765bfe

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

What leaked

$TMPDIR on the owner's Mac held about 940 folders, about 10 GiB, left by three test drivers. Each had a cause that is not the one first suspected, so each was reproduced before it was fixed.

Prefix Count Made by
_check_deps_tree_* 524 (about 40 MB each, 40.7 MB measured) tests/test_harness.py, DepGates.tree
plxnative-shot-<scene>-* some, up to 0.7 GiB each (a 120-frame virtual capture) tools/screenshots.py, capture
plxnative-replay-gate-* some tests/replay_fixtures.py, main

Out of scope, left alone: plxnative-relcheck-target (a deliberately reused cargo target dir). A few unrelated tmp* folders (plxnative-crash-evidence, case_a.stderr.log) also remain after a harness run; they are other tests and tiny.

Causes and fixes

_check_deps_tree_*: a run stopped by SIGTERM, not a failing rmtree

The suspicion (rmtree(ignore_errors=True) failing on a read-only entry) was tested and does not hold:

  • 0 of the 661 entries under TREE_INPUTS are non-writable.
  • A whole-module run, TMPDIR private: Ran 554 tests in 462.430s, OK, and zero _check_deps_tree_* left. A normal run does not leak.
  • A DepGates run that the tool killed at its time limit left exactly one: _check_deps_tree_683365o8.

The cause is that make check runs the harness as a fail-fast branch (tools/check-parallel.py, Branch.stop: killpg SIGTERM, 10 s, SIGKILL), and Python's default SIGTERM action ends the process before any addCleanup runs. _ParallelSuite has min(8, cpus) workers, each holding a copy, which is the batch of 8 seen at 15:43. Ctrl-C was already safe: a KeyboardInterrupt unwinds _ParallelSuite and each running test cleans up.

Fix (tests/test_harness.py):

  • _unwind_on_termination(), called from __main__, turns SIGTERM and SIGHUP into KeyboardInterrupt. Not sys.exit: unittest's testPartExecutor records a SystemExit out of a test body as that test's error and carries on.
  • DepGates.run runs doCleanups() and re-raises on KeyboardInterrupt, because unittest skips the cleanups then. This covers a serial run (a named test, PLX_TEST_JOBS=1), which left a tree on interrupt even with the handler.
  • DepGates.tree raises once _ParallelSuite has been interrupted, and every gate run builds its command from tree. A test still on the pool therefore starts no further ~11 s check-deps.sh: one the group signal never reached would outlast the 10 s grace and be SIGKILLed with its copy on disk.

Not fixed: SIGKILL cannot be handled, so a kill -9, or a teardown that outlasts the 10 s grace, still leaves the copies in flight.

plxnative-shot-<scene>-*: SIGTERM skips the finally

capture's finally removes the instance root on every exit that unwinds: a settled capture, a refused one, a timeout and a failing prepare all leave nothing (tested). The only exit that skips the finally is a kill, and that is the cause I could reproduce: SIGTERM's default action runs no finally and leaves the simulator running, so the root (and render_set's plxnative-shots-* staging directory) stays. The leftover scene names (same-scene-background-cycle-*, reference, minimal, pr13-01) are HUD-preview scenes, a long run that a tool timeout would stop. A virtual capture's frames.rgb is 1920x1080x3x120 bytes, which is the 0.7 GiB.

I also probed a simulator that leaves a non-writable subdirectory: rmtree(ignore_errors=True) does fail silently then. No non-test Rust code makes a directory under the runtime root non-writable (the only set_permissions calls with 0o500/0o400 are in test code), so I left that path alone.

Fix: screenshots.unwind_on_signals() (SIGTERM and SIGHUP raise SystemExit(128 + n), the idiom tools/build-bench.py uses), called from screenshots.main and hud_preview.main. The SystemExit passes through render_set's except Exception, subprocess.run kills the simulator it is waiting on, and the existing finally blocks remove the root and the staging directory.

plxnative-replay-gate-*: printed as evidence, never removed

main made the folder with mkdtemp, printed it as "evidence" and never removed it, even when every replay passed. It is now removed after a clean run and kept, with its path printed, when a replay failed. A folder passed with --output is never removed (CI passes --output "$RUNNER_TEMP/plxnative-replay", so the artifact upload is unaffected). If the removal itself fails the folder is kept and the error printed to stderr instead of being hidden. The module docstring ("Evidence roots are retained") is updated.

Red, then green

Each test below was run against the unfixed code first.

Test Red against the old behaviour Green
tests/test_harness.py DepGatesLeaveNothingWhenStopped AssertionError: Lists differ: ['_check_deps_tree_0dmp_pux', '_check_deps_tree_m_vxyw4q', '_check_deps_tree_mlmamsiz'] != [], FAILED (failures=1) (SIGTERM to 3 tests on a pool); the serial subtest alone left _check_deps_tree__hzlrhho without DepGates.run; a test that runs on after the stop left ran-after-stop without the tree check Ran 1 test, OK
tests/test_hud_capture.py InstanceRoot Lists differ: ['plxnative-shots-_0f8qu14', 'plxnative-shot-home-xf2osssg'] != [], Ran 5 tests, FAILED (failures=1) Ran 5 tests, OK
tests/test_hud_preview.py False is not true : the default action ends the process at once for SIGTERM and SIGHUP, Ran 8 tests, FAILED (failures=2) Ran 8 tests, OK
tests/test_replay_fixtures.py OutputFolderTests Lists differ: [PosixPath('.../plxnative-replay-gate-dbwwtmhz')] != [], Ran 16 tests, FAILED (failures=1) Ran 16 tests, OK

The screenshot test runs the real screenshots.main as a child process against a fake simulator script and a fake mock server (the real catalogue mock takes about 36 s to start), sends it SIGTERM, and requires an empty $TMPDIR and a dead simulator. The probe for the harness does the same with a DepGates subclass that holds its private copy.

Other runs on the final tree: tests/test_demo_library.py Ran 167 tests, OK (skipped=5); tests/test_site_stills.py Ran 28 tests, OK; the whole tests/test_harness.py with a private TMPDIR, Ran 555 tests, OK, zero _check_deps_tree_* left.

make check, cargo and the simulator were not run; CI is the gate.

🤖 Generated with Claude Code

GLinnik21 and others added 3 commits November 5, 2026 22:00
Three test drivers left folders in $TMPDIR: about 940 of them, about 10 GiB, on one Mac.

- tests/test_harness.py: each DepGates test copies the lint inputs into
  `_check_deps_tree_*` (40 MB) and removes it with addCleanup. A completed run
  removes every copy; a run stopped by SIGTERM does not, because the default
  action ends Python before any cleanup runs. `make check` stops the harness
  branch with SIGTERM when its sibling fails (check-parallel is fail-fast), and
  up to min(8, cpus) copies are in flight. `__main__` now turns SIGTERM and
  SIGHUP into KeyboardInterrupt, which `_ParallelSuite` already unwinds.
- tools/screenshots.py, tools/hud_preview.py: the same for a scene's
  `plxnative-shot-<scene>-*` instance root (up to 0.7 GiB for a virtual capture)
  and the `plxnative-shots-*` staging directory; SIGTERM and SIGHUP now exit
  through the existing `finally` blocks, and subprocess.run kills the simulator.
- tests/replay_fixtures.py: a `plxnative-replay-gate-*` folder the driver made
  for itself was printed as evidence and never removed; it is now removed after a
  clean run and kept (and named) when a replay failed. `--output` is never removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ial run

unittest skips doCleanups when a KeyboardInterrupt ends a test, so a run on the
main thread (a named DepGates test, PLX_TEST_JOBS=1, a one-CPU host) left its
`_check_deps_tree_*` behind on Ctrl-C or SIGTERM. DepGates.run now runs the
cleanups and re-raises; the probe covers both the pool and the serial path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ve their test

A DepGates test still running on the pool when the run is stopped could start one
more ~11 s check-deps.sh that the group SIGTERM never reached, outlast
check-parallel's 10 s grace and be SIGKILLed with its copy on disk. `tree` now
raises once `_ParallelSuite` has been interrupted, and every gate run builds its
command from it. The probe holds its tests until the stop and requires that none
runs on; its held tests also have a deadline, and the fake "never settles"
simulator execs its sleep so the timeout kills it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 6d50893 into main Nov 5, 2026
22 checks passed
@GLinnik21
GLinnik21 deleted the worktree-agent-a571d52048d765bfe branch November 5, 2026 19:43
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