Repository navigation
heavy: guard tests and hardening from the #687 reviews - #727
Conversation
Tests pin what the guard and heavy's clean-up rely on: setsid (a kill -9 of heavy's process group), the guard ignoring heavy's signals, the parent-gone refusal, no guard for a kept scope, heavy's own exact label check, and the container removal on the signal path (grace time and second signal). Hardening: the guard is double-forked (a tree kill of heavy misses it); a stop by hand signals only pids still in the scope (pidfd + cgroup check) and kills with cgroup.kill; docker-label names the scope it is in, HEAVY_SCOPE only when the cgroup cannot be read; a Docker context counts as reachable; the sweep takes only an absolute HEAVY_DOCKER; heavy asks Docker only after a run that labelled a container. CI weight of sweep.test.py ~37s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review lens A (wrong kills and wrong removals): SAFEHead Blocking: none. What I checked and found safe
Minor
State question (lens A view)
🤖 Generated with Claude Code |
#569: the CI failure tested a merge onto a base from before #560. There, the test's live() look ran on the fake clock, so its 30 s lock wait passed in no real time. #560 already moved live() to the real clock. Reproduced: 3 of 50 runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock release after SIGKILL is the kernel's flock drop, and tests on main cover it. #744: - signal_in signals only through a pidfd; no fallback to kill(pid) - docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS - the refusal under a shell after leaving heavy's scope names the cause - tests: done() waits for the guard; the install test leaves no note; every read and wait of a test process has a timeout, checked by an AST test - README: cgroup.kill reaches sudo/setuid processes; who refuses to start; the --value exit code Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Tests pin what the guard and heavy's clean-up rely on: setsid (a kill -9 of heavy's process group), the guard ignoring heavy's signals, the parent-gone refusal, no guard for a kept scope, heavy's own exact label check, and the container removal on the signal path (grace time and second signal). Hardening: the guard is double-forked (a tree kill of heavy misses it); a stop by hand signals only pids still in the scope (pidfd + cgroup check) and kills with cgroup.kill; docker-label names the scope it is in, HEAVY_SCOPE only when the cgroup cannot be read; a Docker context counts as reachable; the sweep takes only an absolute HEAVY_DOCKER; heavy asks Docker only after a run that labelled a container. CI weight of sweep.test.py ~37s. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
#569: the CI failure tested a merge onto a base from before #560. There, the test's live() look ran on the fake clock, so its 30 s lock wait passed in no real time. #560 already moved live() to the real clock. Reproduced: 3 of 50 runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock release after SIGKILL is the kernel's flock drop, and tests on main cover it. #744: - signal_in signals only through a pidfd; no fallback to kill(pid) - docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS - the refusal under a shell after leaving heavy's scope names the cause - tests: done() waits for the guard; the install test leaves no note; every read and wait of a test process has a timeout, checked by an AST test - README: cgroup.kill reaches sudo/setuid processes; who refuses to start; the --value exit code Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Tests pin what the guard and heavy's clean-up rely on: setsid (a kill -9 of heavy's process group), the guard ignoring heavy's signals, the parent-gone refusal, no guard for a kept scope, heavy's own exact label check, and the container removal on the signal path (grace time and second signal). Hardening: the guard is double-forked (a tree kill of heavy misses it); a stop by hand signals only pids still in the scope (pidfd + cgroup check) and kills with cgroup.kill; docker-label names the scope it is in, HEAVY_SCOPE only when the cgroup cannot be read; a Docker context counts as reachable; the sweep takes only an absolute HEAVY_DOCKER; heavy asks Docker only after a run that labelled a container. CI weight of sweep.test.py ~37s. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
#569: the CI failure tested a merge onto a base from before #560. There, the test's live() look ran on the fake clock, so its 30 s lock wait passed in no real time. #560 already moved live() to the real clock. Reproduced: 3 of 50 runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock release after SIGKILL is the kernel's flock drop, and tests on main cover it. #744: - signal_in signals only through a pidfd; no fallback to kill(pid) - docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS - the refusal under a shell after leaving heavy's scope names the cause - tests: done() waits for the guard; the install test leaves no note; every read and wait of a test process has a timeout, checked by an AST test - README: cgroup.kill reaches sudo/setuid processes; who refuses to start; the --value exit code Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Tests pin what the guard and heavy's clean-up rely on: setsid (a kill -9 of heavy's process group), the guard ignoring heavy's signals, the parent-gone refusal, no guard for a kept scope, heavy's own exact label check, and the container removal on the signal path (grace time and second signal). Hardening: the guard is double-forked (a tree kill of heavy misses it); a stop by hand signals only pids still in the scope (pidfd + cgroup check) and kills with cgroup.kill; docker-label names the scope it is in, HEAVY_SCOPE only when the cgroup cannot be read; a Docker context counts as reachable; the sweep takes only an absolute HEAVY_DOCKER; heavy asks Docker only after a run that labelled a container. CI weight of sweep.test.py ~37s. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
#569: the CI failure tested a merge onto a base from before #560. There, the test's live() look ran on the fake clock, so its 30 s lock wait passed in no real time. #560 already moved live() to the real clock. Reproduced: 3 of 50 runs failed on the old base with 8 CPU hogs, 0 of 50 on this branch. The lock release after SIGKILL is the kernel's flock drop, and tests on main cover it. #744: - signal_in signals only through a pidfd; no fallback to kill(pid) - docker-label notes go to ~/.local/state/heavy/labelled when the /run/user note cannot reach heavy; heavy passes the folders it reads as HEAVY_MARKS - the refusal under a shell after leaving heavy's scope names the cause - tests: done() waits for the guard; the install test leaves no note; every read and wait of a test process has a timeout, checked by an AST test - README: cgroup.kill reaches sudo/setuid processes; who refuses to start; the --value exit code Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
(Reposted 2026-11-22 with private details removed; original 2026-11-21.) Review lens B (state and leaks): SAFEHead What I ran (locally, in a temp worktree, temp names and the fake
State question
What can leak now that main cleaned up. All are minor. Each is left to the sweep and none is a wrong kill:
Minor
The 37 s estimate: right for CI in general, not for this PR's run.
Public diff: no personal paths, host names, VM ids, user names or emails. 🤖 Generated with Claude Code |
What and why
This PR adds the missing tests and the hardening listed in #690, which came from the two #687 reviews. Each item is fixed at its root; none is skipped.
Tests (in
fork-kit/heavy/tests/heavy.test.py):setsidpin: akill -9 -PGIDof heavy's process group still lets the guard stop the scope and remove its container.kill -9of heavy.Parts, no systemd needed).docker pscan now match on the key only (psMatchesKeyOnly), so heavy's own exact check is what keeps another scope's container alive.Hardening:
systemd-run --scopeinside the command) still carriesHEAVY_SCOPE, but it now gets the process owner, so heavy no longer removes its container while it still runs.HEAVY_SCOPEis used only when the cgroup cannot be read.cgroup.kill, falling back to the pidfd path when it is missing.pkill -9 -P) no longer reaches it. A pipe handshake letsdone()wait until the guard has really finished.docker context usecounts as reachable.HEAVY_DOCKER, the same rule asbin/heavy.heavy docker-labelwrites a note for the scope in/run/user/<uid>/heavy/labelled/, a folder only that user can write. heavy runsdocker psonly when the note exists, then deletes it. Without a usable folder, heavy asks after every run as before, so no container is ever skipped.sweep.test.pychanged from~52sto~37s.State question
forgetof a note is a no-op (tested).docker-labelsays why it could not write a note, still prints the label, and exits 0. Both cases are tested.HEAVY_SCOPE(not throughheavy docker-label) leaves no note. heavy does not remove that container, and the leftover sweep removes it later. The README only documentsheavy docker-labelas the way to label a container.Tests
All suites pass locally:
heavy.test.py: 53 tests, with real systemd andHEAVY_REAL_TESTS=1.sweep.test.py: 76 tests.queue.test.py: 70 tests.install.test.py: 16 tests.Red checks:
Against origin/main's code (
HEAVY_TEST_BINset to the old kit'sbin/heavy), these tests fail:With the old
heavy_sweep.py, these fail:test_docker_label_names_the_scope_the_process_is_intest_heavy_docker_must_be_an_absolute_pathPins of behaviour origin/main already had. Each was checked by breaking the rule in a copy of
bin/heavy, and the test then fails:os.setsid()removedgetppid() != parentcheck removedclean_containerscall removedThe sweep's own red check (
MUTATIONS) gains entries for "own cgroup first" and "HEAVY_DOCKER absolute".The tests touch only scopes and containers they start. Containers go through the fake
docker, the marks test uses a private folder, and a note a sweep test makes under heavy is removed again.General vs project
All general. This is the fork-kit
heavytool with no project facts: the paths are the standard/run/user/<uid>and the cgroup v2 root, and no repo, VM or plugin names appear. The only project-adjacent change is the CI weight line in.github/fork-ci-tests.txt. There are no lines in upstream files, and the seam check passes.Closes #690
🤖 Generated with Claude Code