Repository navigation
heavy: count a reservation's work once; machine tier without a user manager; ~/.local checks (#771, #844, #923) - #945
Conversation
…anager; ~/.local checks (#771, #844, #923) - #923: a reservation's owed part is the learned debt of the pieces working in its folder, added to its use, so free counts it once. t3-capacity shows holding without the owed part. - #844: with cgroup v2 and user.slice but no manager of this user's, facts answer at the new machine tier from machine-wide numbers instead of always NOT OK. The answer cache falls back to a private 0700 folder under the temp root when /run/user/<uid> is missing. - #771: heavy and the sweep refuse a ~/.local others can write; HOME is resolved before it is checked; README repair line covers ~/.local; the timeout hygiene check knows more Popen/waitpid forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code · reviewer: lens agent (Opus 5.5) · read at: de3dc1c Detail for the major. Measured with the PR's test machine: two reservations of 1536 MB (folders a and b), one agent scope with pid 4001 (300 MB, cwd in a) and pid 4002 (10 MB, cwd in b), writer cost 768: The same happens with nested reservations (/x and /x/y) and with a heavy job whose processes cross two reserved folders. For a job the debt is its whole kind cost less its use, so the gap can be thousands of MB. It can only happen on a machine with two or more reservations, but that is the case #923 is about. Fix: give each piece's debt to one reservation only. For example, the deepest folder that holds one of its processes, then the first by name. Add a test with one piece in two folders and one in nested folders that checks hold + owed + use equals the reservations' sum. The use part of nested reservations was already credited to both before this PR. That is older behaviour: leave it, or file it. Issue coverage: #923 is covered except the case above, and the display fix (reserved= is now only the debts) is done. #844 is covered: machine tier, note and reason, README, tests, cache fallback. #771 is covered: items 1 to 3 and all three nits, each with a test that fails without it (RedCheck for facts; the PR body's red runs for sweep and heavy). |
|
lens: state · reviewer: lens agent (Opus 5.5) · read at: de3dc1c |
…very reserve.d (#945) Review fixes for #945: - A process counts toward one reservation only (the deepest folder that holds it), and a piece's debt is split over its processes by their use, so two or nested reserved folders never take a debt off twice. - The machine tier reads every person's reserve.d (passwd and user.slice users from UID_MIN to UID_MAX). One it cannot read, or a user with a session but no home it can find, makes it Basic. - A ~/.local others can write (umask 002) is said, not dropped silently, by heavy and the sweep; the README repair line adds chmod go-w ~/.local. - A cache file that is there but cannot be used (another version, other settings, broken, future) starts "elevated", never ok. - No temporary folder this user can write: no cache, never the working folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code r2 · reviewer: lens agent (Opus 5.5) · read at: 90ad533 Probe for the first minor: |
|
lens: state r2 · reviewer: lens agent (Opus 5.5) · read at: 90ad533 |
…ssage; machine tier limits in README (#945) - Two callers of one user with other settings (slice, queue, reservations folder) or another kit version shared one cache file and kept each other "elevated" (NOT OK on a calm machine). Each now has its own heavy-facts-v<version>-<hash>.json, so each one's hold-down steps down on its own. A first call beside another recent cache file of this user's still starts "elevated"; stale ones are removed after the carry window. - bin/heavy and the sweep name chown when another user owns the refused folder, chmod go-w otherwise. - README: the machine tier's limits named plainly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What and why
Three heavy kit fixes in one PR, plus two review rounds (see "Review round" and "Review round 2" below).
#923, a reservation was counted twice. When an agent or a job worked inside a reserved folder, its learned debt was counted as owed work and the reservation still held its full size, so
freedropped twice for the same work. Now each reservation gets anowedMb, from the debt of the pieces whose processes (fromcgroup.procs) have their cwd inside it. The rule getsuseMb + owedMbfor that reservation, so the reservation only holds what is not already counted. The TypeScript and Python capacity rule is unchanged.t3-capacityprintsreserved=from the new number and showsholdingwithout the owed part, plusowed Nwhen there is one.#844, no systemd user manager meant always NOT OK. With cgroup v2 and
user.slicebut no manager for this user (for example a login without lingering, a container, or a cron job), facts fell to thebasictier, which is never free. A newmachinetier answers likefullfrom machine-wide numbers. It counts every user's work and every person's reservations, and leaves out this user's tickets and agent scopes, because it cannot see them. The reason saysmachine-wide numbers: no user manager. With no/run/user/<uid>, the answer cache uses a privateheavy-facts-<uid>folder (mode 0700) under$TMPDIRor/tmp. When that folder is a link, a file, or a folder others can open, or no temp folder can be written, there is no cache and a note says why. The level then starts at "elevated" on every call. The comment on #800 that repeats #844 is covered here. The rest of #800 is left alone.#771, minors from the #770 reviews.
heavyand the sweep's note writing and pruning refuse a~/.localthat others can write. Before, only owner and type were checked.chowns~/.localitself and runschmod go-w ~/.local.~/.localthat is a link stays fail-closed (no second notes folder). This is security code, and an existing test pins the fail-closed behaviour. The README already documents it.bin/heavy.realpathbefore it is checked, so a linked HOME cannot be swapped after the check.with Popen(...)andfrom os import waitpidforms, with cases that prove it.Review round (code lens and state lens, both NOT SAFE on de3dc1c)
MAJOR, a debt counted zero times. A piece with processes in two reserved folders, or in nested ones (
/xand/x/y), had its whole debt taken off each reservation, so the debt was counted zero times. Now:New tests:
test_two_folders_nested_folders_and_work_across_them_count_each_debt_oncechecks that sum for two folders, a nested folder, and one agent and one job spanning both.test_never_looser_than_main_beyond_counting_each_debt_onceworks out main's answer for the same facts. The answer here may be looser than main's only by the debts of the pieces working in reserved folders, each counted once. That is heavy: reservation counted twice for agents under reserve.d #923's point: main counted those twice. With no piece working in a reserved folder, the answer is never looser than main's. On de3dc1c this test fails: free was 7565 MB where the bound was 6829 MB.MAJOR, the machine tier did not see the owner's reservations. A caller with another home (a CI runner, root) read only its own
reserve.d. Now the machine tier reads every person'sreserve.d. "Every person" means the users in/etc/passwdand theuser.sliceusers fromUID_MINtoUID_MAX; root and system users are not read. Another user's files are opened without following links and must be plain files, so a FIFO cannot stop the read, and at most 64 KiB is read. Fail closed: a folder or file it cannot read (a home of mode 750 or 700), or a user with a session but no home it can find, makes the tier Basic, which is never free, with a note. Tested with two users' reserve folders (test_the_machine_tier_sees_every_person_s_reservations), covering a FIFO, a closed folder and a session with no home.minor, ~/.local of mode 775 refused silently.
heavynow says when it refuses the second notes folder, and the sweep adds a note when it leaves old notes. Both messages namechmod go-w <folder>. The README repair line addschmod go-w ~/.local.minor, a cache of another version skipped the hold-down. A cache file that exists but cannot be used now starts "elevated", the same as having no cache folder. That covers another version, other settings, a broken file, a file from the future, and one that is not this user's. Only a missing file, or one older than the carry window, starts with nothing carried. Tested with an old-version cache, an other-settings cache and a broken cache. (Round 2 below gives each version and settings its own file, so callers no longer share one.)
minor, cache in the working folder.
tempfile.gettempdir()fell back to the working folder. Now only$TMPDIR, then/tmp, is used, and it must be an absolute folder this user can write. Otherwise there is no cache and a note says so. Tested.Follow-up only, no code: heavy facts: machine tier misses the caller's own cgroup cap; cache folder squat and TMPDIR nits #951. It covers four things:
/tmp/heavy-facts-<uid>name first (a squat), which makes every call run without a cache;$TMPDIR;Review round 2 (code lens and state lens, both SAFE on 90ad533, with minors)
Fixed in 4674bef:
"Elevated" stall. Two callers of one user with different settings (
HEAVY_SLICE,HEAVY_QUEUE_ROOT,T3_CAPACITY_RESERVE_DIR), or an old and a new kit, shared one cache file. Each read the other's file as unusable, so every call started "elevated" andt3-capacitysaid NOT OK on a calm machine for as long as they took turns. Now:heavy-facts-v<version>-<16 hex of the settings' hash>.json, one per version and settings, so no caller resets another and each one's own hold-down steps down;$HEAVY_FACTS_CACHEstill names one file, as before.New test
test_callers_with_other_settings_taking_turns_each_reach_ok: callers A and B (another reservations folder) take turns every 20 s on a calm machine. B's first call is "elevated", and every call from the seventh on is OK. On 90ad533 it fails: every call after the first stays(75, 'elevated').RedChecktakes out the per-settings name, the "recent other file" check and the stale-file removal one at a time and sees the test fail.Repair message. When the refused
~/.localbelongs to another user (a root-owned one from an older heavy run as root),bin/heavynow sayssudo chown "$USER:" <folder>;chmod go-wonly when it is ours but others can write it; a link or file there: replace it with a real folder. The sweep's note uses the same rule. Tested inheavy.test.pywith a folder another user owns.README, machine tier limits named plainly: it reads only each person's default
reserve.d(not their ownT3_CAPACITY_RESERVE_DIR), only/etc/passwdusers with a UID inUID_MIN..UID_MAXor auser.slicesession (not root or system users, not NSS-only users without a session, not homes that are/or relative);.conffiles must be plain files (a link makes the tier Basic); a non-root caller cannot see other people's working folders, so their reservations hold their whole size (stricter, never looser).heavy facts: machine tier misses the caller's own cgroup cap; cache folder squat and TMPDIR nits #951 got a comment with the two leftovers: NSS users without a session, and the listing of every passwd home on each machine-tier read (autofs).
Tests: each fix fails without it
The new tests were run against unchanged copies of the kit.
Against origin/main (first round):
facts.test.py: 9 failures, 2 errors.sweep.test.py: 2 failures.heavy.test.py: 1 failure.Against de3dc1c (this round), with the new tests:
facts.test.py: 18 failures and 1 error. They come from the two-folder and nested-folder test, the never-looser-than-main test, the every-person reservations test, the old-version cache test, the no-temp-folder test,test_two_callers, the settings-change step of the Holds test, and the in-fileRedCheck.RedChecktakes out each of the 7 new fix lines one at a time and checks that its test fails.sweep.test.py: 1 failure (nochmod go-wnote).heavy.test.py: 1 failure (nochmod go-wmessage).On this branch (4674bef, main merged in), every heavy kit test passes:
facts.test.py: 69 OK.heavy.test.py: 68 OK, run twice (gated, unwrapped on purpose: insideheavy55 of its tests skip; every command it runs gets its ownheavy). The once-flakytest_leftover_that_ignores_term_is_killed_after_the_grace_timepassed both times.sweep.test.py: 84 OK, 1 skip.capacity_rule,queue,installandmeasuretests: OK.Other checks: the seam check (
--config-ref origin/main origin/main HEAD) exits 0, andvp fmt --checkpasses on the README.State question
owedMb, use and other users' reservations are recomputed from livecgroup.procs,/procand eachreserve.d, so a second run gives the same answer for the same machine. The cache folder is created once (mkdirwith mode 0700) and checked each time, and a folder that already exists and is safe is reused.~/.localor state folder that fails the check is refused (and now said) before anymkdirunder it.heavy-facts.jsonis never read; a first call beside one written in the last 5 minutes starts "elevated" once, then its own file carries. An old and a new heavy taking turns no longer keep each other "elevated". Old files past the carry window are removed.t3-capacity, new facts: every field it reads is still there, so it keeps working. Itsreserved=still adds the reservations (reservedMb), so that one line keeps the old double count until the newt3-capacityis installed. The free/OK answer is right with either printer.t3-capacity, old facts (no per-reservationowedMb): it reads that field with.get, soholdingfalls back to size minus use, as before.machinetier (Basic when some person's reservations cannot be read) and the temp cache.owedMbis 0 and the answer is the same as before.basic(never free), as before.General vs project
Everything here is general. It concerns cgroup v2, systemd user managers,
/etc/passwd,/run/userand the temp root. Nothing about a project, host or path is built in. No project config changes.Fixes #771
Part of #844
Fixes #923
🤖 Generated with Claude Code