Repository navigation
heavy: fix the #727 review minors; note why the queue test failed - #760
Conversation
#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>
Review lens A (kills and safety), head 4728326: SAFEVerdict: SAFE. No blocking or major findings. Two minors, two nits. What I checked
BlockingNone. MajorNone. Minor
Nits
Read-only review: nothing pushed, nothing installed. |
Review lens B (correctness, general vs project, tests): SAFEHead Blocking: none. What I ran (temp worktree, each run gated on
|
| Item | Change made | Result |
|---|---|---|
| 3 | signal_in: put back the os.kill(pid) fallback |
red: test_without_pidfds_nothing_is_signalled_by_pid (both cases) |
| 4 | done(): drop the while os.read(self.alive, 1) wait |
red: test_heavy_ends_only_after_its_guard (real systemd) |
| 5 | install test: drop --owner-pid (run under the installed heavy) |
red: "the test left a note behind" |
| 7 | queue.test.py:594: wait(timeout=60) back to wait() |
red: Hygiene finds queue.test.py:594 wait() |
| 7 | read_line: drop the p.kill() on timeout |
red: test_read_line_fails_instead_of_hanging |
| 8 | give_marks: keep an outer HEAVY_MARKS |
red: test_the_command_gets_heavy_marks_only_from_its_own_heavy |
| 8 | labelled: read the first folder only |
red: the marks-folder test |
| 8 | forget: clear the first folder only |
red: the marks-folder test |
| 8 | marks_dirs: leave the state folder out |
red: the marks-folder test |
| 8 | state_marks_dir: make_base=False |
red: the marks-folder test |
| 8 | note_label: no check against HEAVY_MARKS |
red: test_the_note_goes_where_heavy_reads_it |
| 2 | owner_value: old refusal text |
red: test_a_process_that_left_heavys_scope_under_a_shell_is_told_to_name_its_owner |
| 7 (gap) | add p.stdout.readlines() and p.communicate('x') to queue.test.py |
stays green (minor 1) |
Items 1 and 6 are README-only. I checked their text against the code (below).
Is each item fixed at the root?
-
cgroup.kill also kills sudo/setuid children. The README now says so and gives the reason. True to
kill_cgroup. -
A refused
docker-label. I checked it with Docker 29.1.3:docker run --label ""fails flag parsing ("invalid label '': empty name") before it contacts the daemon, so no container starts.--label "fork-kit.heavy.owner="is accepted, which is what the README's--valuewarning is about. The refusal prints nothing on stdout (tested), and the new message names--owner-pid. The README is true. -
Pid reuse.
signal_innow returns at once withoutpidfd_open, and skips a pid whosepidfd_openfails.os.killinbin/heavynow only reaches heavy's own unreaped child or its probe, never a pid read fromcgroup.procs. No reuse window is left. The cost: on Linux < 5.3 or Python < 3.9 no TERM is sent by hand, and the KILL needscgroup.kill. The README says so. -
done()'s wait is now pinned by a test. Removing the wait goes red (above). -
The install note. Fixed. The test now checks both folders.
-
README. The command refuses to start, not the guard. Now correct.
-
Timeouts. I grepped all four files: every
wait,communicate,subprocess.runand stdout read has a timeout or goes throughread_line. The Hygiene test catches a missing one with no false alarms today. Gaps are in minor 1. -
A note that never reaches heavy. heavy reads both folders, passes
HEAVY_MARKS(device:inode), anddocker-labelwrites only into a folder heavy reads. Otherwise it removes its stray note and warns. Every case fails safe: at worst a leak to the sweep, never a wider removal. Removal is still by exact label (remove_containers). On the state question:- Runs again: the same note is written again.
- Old heavy: no
HEAVY_MARKS, so the note goes to/run/useronly, as before. - Empty state: heavy makes the missing state folder.
- Bad folder permissions: that folder is skipped.
- Neither folder: heavy asks Docker after every run.
All of these are tested.
HOME=""resolves to/, so/.local/statecannot be made and the folder is skipped (checked).
README vs code
--owner-pid, the--valueexit code (label_mainreturns 1 with empty stdout),HEAVY_MARKSas device:inode, and the fallback folder~/.local/state/heavy/labelled/all matchbin/heavyandlib/heavy_sweep.py. One wording nit is in minor 3.
#569: closing with no code change is right
- I checked the failed attempt-1 run of
Fork kit testson cleaner: kit list and example machine file show every rule (#491) #564 (run 44654650190). - It checked out
Merge 5a88292 into 772fcaf, and772fcafdoes not containc09ed55(fork-kit/heavy: the queue tests' own look waits for the lock in real time (#551) #560). - Its traceback is
live()→with self.q(the fake-clock queue) →LockBusy ... stayed taken. That is exactly the path fork-kit/heavy: the queue tests' own look waits for the lock in real time (#551) #560 replaced with a real-clock queue. - The only fake-clock lock user left near real processes is
decide()intest_a_crashed_job_frees_its_reservation. It runs after the caller printedadmitted, andenter()drops the lock before it returns, so it never meets a held lock.
General vs project
No personal names, paths, hosts, VM ids or project names in the diff (grepped). Everything is machine-wide heavy behaviour.
Flakiness under load
Nothing new looks flaky. The new guard test's p.wait(timeout=2) expects a timeout while the guard is stopped, so it cannot pass early. One race is possible (minor 2).
Minor
fork-kit/heavy/tests/heavy.test.py:1070-1074: the Hygiene check has gaps.communicate(x)with a positional argument passes as if it had a timeout, but forcommunicatethe first positional argument isinput.stdout.readlines(), any read ofstderr,for line in p.stdout,from subprocess import run, andaddCleanup(subprocess.run, ...)are not checked.- I added
p.stdout.readlines(); p.communicate('x')and the test stayed green. - None of these forms is in the files today, so nothing hangs now. Adding them would make "new ones cannot creep in" true. Suggested changes:
- for
communicate, require thetimeout=keyword or a second positional argument; - add
readlinesandstderr; - flag
Forloops over*.stdout.
- for
heavy.test.py:360(new) and:429(old):[guard] = self.guards()right after theupline.- The guard renames itself to
scope-guard(prctl,bin/heavy:556) after its double fork, and heavy does not wait for that before it starts the command. - On a starved CPU the
upline can arrive first. Thenguards()returns[]and the unpack errors. - It passed every time here (6 runs).
wait_for(lambda: len(self.guards()) == 1, what='the guard')would close it.
- The guard renames itself to
README.md:350: "the sweep only reports such a container" is true only while the container runs.lib/heavy_sweep.py:828skips a stopped container with an empty or bad owner label without a word. Suggested: "the sweep only reports it while it runs".lib/heavy_sweep.py:1214: "Without HEAVY_MARKS (an older heavy ...) heavy asks Docker after every run anyway" is not true of main's heavy (heavy: guard tests and hardening from the #687 reviews #727). That version asks only when its/run/usernote exists. The behaviour is unchanged from main, so only the docstring is off.- Notes in
~/.local/statesurvive reboot. Unlike/run/user, nothing ever prunes them. In the both-killed case they pile up as 0-byte files (harmless, as the PR body says). The leftover sweep could delete notes whose scope no longer exists. bin/heavy:404, nit: withHOMEunset and a uid with no passwd entry,expanduser('~')returns'~'.make_base=Truewould then make a relative./~/.local/statein the command's working folder. Anos.path.isabs(base)check would close it. It is very unlikely under a systemd user manager.- Nit: the real
heavy.test.pyruns use the tester's realHOME, so they make~/.local/state/heavy/labelledthere. Only the end-to-end test uses a tempHOME. That is harmless, because the installed new heavy makes the folder anyway.
🤖 Generated with Claude Code
- The fallback note folder (~/.local/state/heavy) is used only in a home the effective user owns ($HOME, else the passwd home). As root with a user's HOME (sudo -E) it never makes a root-owned folder there. With no usable home it refuses instead of writing into the working dir. - stop_scope waits the grace time only after a step that sent a signal. - The leftover sweep removes old empty docker-label notes of scopes that are gone (not listed when it began, minAgeSeconds old). A live run's note stays. - Tests: the hygiene check finds every untimed read form; the real tests wait for the guard's rename and use a temp HOME. README/docstring wording fixed. 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>
- The fallback note folder (~/.local/state/heavy) is used only in a home the effective user owns ($HOME, else the passwd home). As root with a user's HOME (sudo -E) it never makes a root-owned folder there. With no usable home it refuses instead of writing into the working dir. - stop_scope waits the grace time only after a step that sent a signal. - The leftover sweep removes old empty docker-label notes of scopes that are gone (not listed when it began, minAgeSeconds old). A live run's note stays. - Tests: the hygiene check finds every untimed read form; the real tests wait for the guard's rename and use a temp HOME. README/docstring wording fixed. 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>
- The fallback note folder (~/.local/state/heavy) is used only in a home the effective user owns ($HOME, else the passwd home). As root with a user's HOME (sudo -E) it never makes a root-owned folder there. With no usable home it refuses instead of writing into the working dir. - stop_scope waits the grace time only after a step that sent a signal. - The leftover sweep removes old empty docker-label notes of scopes that are gone (not listed when it began, minAgeSeconds old). A live run's note stays. - Tests: the hygiene check finds every untimed read form; the real tests wait for the guard's rename and use a temp HOME. README/docstring wording fixed. 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>
- The fallback note folder (~/.local/state/heavy) is used only in a home the effective user owns ($HOME, else the passwd home). As root with a user's HOME (sudo -E) it never makes a root-owned folder there. With no usable home it refuses instead of writing into the working dir. - stop_scope waits the grace time only after a step that sent a signal. - The leftover sweep removes old empty docker-label notes of scopes that are gone (not listed when it began, minAgeSeconds old). A live run's note stays. - Tests: the hygiene check finds every untimed read form; the real tests wait for the guard's rename and use a temp HOME. README/docstring wording fixed. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What and why
#569: the queue test that left the lock taken
Root cause: the failing CI run did not test current main. It tested a merge onto an older base, from before #560.
On that base, the test's
live()look used the queue built on the fake clock. The queue retries its non-blockingflockevery 0.05 s for up to 30 s, but on the fake clock those 30 s pass with no real time spent. So whenever a realprocess (the killed waiter's sibling, or the second caller) held the lock for a few milliseconds, the look raised
LockBusy("stayed taken"). The lock itself was released correctly: the kernel drops aflockwhile the killedprocess closes its files, before its parent is told it ended, so the lock is free once
wait()returns. #560 alreadyfixed this at the root:
live()now uses a queue on the real clock.Reproduced: 50 runs each of
test_a_waiter_killed_with_9_frees_its_placeandtest_two_callers_at_the_same_instant,with 8 CPU hogs on 12 cores:
Main already has deterministic tests of the release path:
test_a_lock_holder_killed_with_9_frees_the_lock_at_oncetest_a_look_waits_in_real_time_for_a_process_holding_the_lockSo the queue code needs no change for #569. This PR closes the issue with that evidence.
#744: the 8 minors from the #727 reviews
cgroup.killalso kills asudoor setuid process thecommand started in its scope. The README now says so on purpose: the scope is the job's own.
docker-labelunder a shell. The refusal prints nothing, so--label "$(heavy docker-label)"becomes--label "". Docker rejects an empty label, so no container starts: this form fails closed. The refusal message nownames the real cause when the process left heavy's scope (
... so heavy would remove the container under it: pass --owner-pid PID ...). The README tells--valuecallers to check the exit code, since Docker accepts an emptylabel value (the sweep only reports such a container).
signal_innow sends signals only through a pidfd, after checking that the process is stillin the scope. It never falls back to
os.kill(pid). Without pidfds (before Linux 5.3) no TERM is sent; the KILL iscgroup.kill. So there is no window left where a reused pid gets hit.done()'s wait.test_heavy_ends_only_after_its_guardstops the guard with SIGSTOP and checks thatheavy does not exit until the guard ends.
install.test.pyleaves a note behind. The test now uses--owner-pid(a process owner writes no note) andchecks that no note of its scope appeared in either folder.
The README now says so. Two over-long prose lines are rewrapped too.
read_line(p, timeout=60)helper that killsthe process and fails instead of hanging. Every
wait(),communicate()andsubprocess.run()in the four heavy testfiles now has a timeout. A new
Hygienetest parses the four files and fails on any read or wait without a timeout,so new ones cannot creep in.
/run/user/<uid>/heavy/labelled/, as before~/.local/state/heavy/labelled/, which heavy makes when it is missingheavy passes the device:inode of each folder it reads to the command as
HEAVY_MARKS.docker-labelwrites its notein the first folder that is one of those, so a note in another mount namespace's
/run/user(a sandbox), or in a/run/userthat is full, is never counted as delivered: the note goes to the state folder instead. Only whenneither folder reaches heavy does
docker-labelwarn. heavy then cannot tell the run labelled a container, and theleftover sweep removes the container later. Each folder, and the folders above it up to the base, must be a
directory owned by the user, with no group or other write permission, or heavy does not use it. So a
group-writable
~/.local/stateleaves only/run/user, as before this PR.State question (runs again, stopped half-way, old/empty/missing state)
docker-labelin the same scope rewrites the same note. heavy deletes the note in bothfolders after asking Docker. Tested.
kill -9, a 0-byte note can stay in~/.local/state. That is harmless: a later scope with the same random 32-bit name would only ask Docker once more.The leftover sweep still finds the container.
HEAVY_MARKS),docker-labelwrites only to/run/user, as before. Tested.folder at all heavy asks Docker after every run, as before. Tested.
Tests
All run locally, each gated on
t3-capacity:queue.test.py: 70 tests OKsweep.test.py: 78 tests OK (1 skipped, as on main: it is skipped when run inside a heavy scope)install.test.py: 16 tests OKheavy.test.pywithHEAVY_REAL_TESTS=1(real systemd user manager): 59 tests OKNew tests:
Parts.test_without_pidfds_nothing_is_signalled_by_pid(item 3;pidfd_openmissing, and failing with ENOSYS)Heavy.test_heavy_ends_only_after_its_guard(item 4)Heavy.test_a_note_that_cannot_reach_heavy_in_run_user_goes_to_the_state_folder(item 8, end to end with fakedocker)
Parts.test_marks_folder_the_same_for_heavy_and_docker_label_and_only_this_users, rewritten for two folders(item 8: missing, unusable and old state)
Parts.test_the_command_gets_heavy_marks_only_from_its_own_heavy(item 8)Label.test_the_note_goes_where_heavy_reads_it(item 8: the normal case, running again, another namespace, anunusable folder, neither folder, an older heavy)
Label.test_a_process_that_left_heavys_scope_under_a_shell_is_told_to_name_its_owner(item 2)Hygiene.test_every_wait_for_a_test_process_has_a_timeoutandHygiene.test_read_line_fails_instead_of_hanging(item 7)
Red on the old code
New tests run against origin/main's code (main's
bin/heavyandlib/, with this PR's test files): red aretest_without_pidfds_nothing_is_signalled_by_pid(both cases)test_a_note_that_cannot_reach_heavy_in_run_user_goes_to_the_state_foldertest_marks_folder_the_same_for_heavy_and_docker_label_and_only_this_userstest_the_command_gets_heavy_marks_only_from_its_own_heavytest_the_note_goes_where_heavy_reads_ittest_a_process_that_left_heavys_scope_under_a_shell_is_told_to_name_its_ownerSome fixes were already on main or are test fixes, so their tests pass on main. Items 4, 5 and 7 are like that: the
wait in
done()came with #727, and items 5 and 7 change the tests themselves. For those, and for each new line ofitem 8, the spot checks below remove one fix line at a time. Each goes red:
done()'s wait for the guardtest_heavy_ends_only_after_its_guard("heavy ended while its guard still ran")give_marksdropping an outerHEAVY_MARKStest_the_command_gets_heavy_marks_only_from_its_own_heavylabelledlooking in every folderforgetclearing every folderdocker-label's check againstHEAVY_MARKStest_the_note_goes_where_heavy_reads_it--owner-pidin the install test (run under heavy)test_installed_version_runs_the_sweep_from_its_own_copy_of_commonwait(timeout=60)inqueue.test.pytest_every_wait_for_a_test_process_has_a_timeoutread_lineon timeouttest_read_line_fails_instead_of_hangingGeneral vs project
Everything here is general: fork-kit/heavy is a machine-wide tool with no project facts in it. No upstream files are
changed (
fork-seam-checkpasses).Closes #569
Closes #744
🤖 Generated with Claude Code