Repository navigation
gpu-hold: end what left the tree but still carries the ticket (engine#2741) - #2747
bong-water-water-bong wants to merge 1 commit into
Conversation
…#2741)
The teardown is anchored on the tree three ways -- the process-group kill (engine#1649), the descendant
snapshot (engine#1621) and the survivor check on the payload root -- and `setsid` escapes all three: the
process is in neither the group nor the descendant list, and its parent is init. Nothing recorded it.
Measured on this box 2026-11-16, twice, and both were mine: a `setsid`'d 27B serve outlived its ticket by
64 minutes carrying 44.4 GiB of GTT while a second copy of the same model ran inside the next ticket --
85.6 GiB of GTT on a 122-GiB box, two OOM kills in the hour, which is the shape of the 11-08 incident
that took the PR-agent LLM down. The orphan's own environment still carried `GPU_HOLD_TICKET=<its ticket>`.
That is the handle the payload cannot shed: every process it starts inherits the line, and nothing it does
to its parentage, session or process group changes it. So the final teardown, after `kill_tree`, now scans
`/proc/*/environ` for the exact line, TERMs those pids, KILLs after the same grace, and appends anything
that survived to `.gpu-hold-survivors` -- the file the NEXT holder already prints, so a KILL that fails is
recorded rather than lost in a log that scrolls away.
`tests/gpu_hold_escape_test.sh` (registered in cmake/tests-gpu-hold.cmake, ~10 s, no device, no ticket):
a payload `setsid`s a marked sleeper and returns; the sleeper must be gone AND the hold must name it, an
identical sleeper started outside the ticket must be untouched, and a run where the sleepers die by
themselves reports INCONCLUSIVE (exit 77) -- because on 2026-11-16 the kernel was killing `sleep` in an OOM
hour, which would have made the first arm pass for the wrong reason.
Mutant, run before committing: comment out the `kill_ticket_env` call and the first arm fails by name
("a setsid'd sleeper ... outlived its hold"). Restored, both arms pass.
Not proposed, per the issue: killing by cgroup membership, which would be exact but needs a per-ticket
scope and is a bigger change than this guard.
Fixes engine#2741
This and #2747 are the same mechanism — one of them should close with a pointerBoth add a scan for pids whose environment still carries the exact ticket line, from the same file, with their own copy of Two functions with different names doing the same What is worth folding either way:
That union is what I would want in Not reviewed otherwise: the mechanism itself (whether an environ sweep is the right detector, and what it does to a lane whose runner deliberately (Same note posted on #2744.) |
|
Duplicate of |
|
Duplicate: this and Both scan Decide it on the arms, not the size. The question is which survivor shapes the test creates — For the record: this is the third duplicate pair this afternoon ( |
|
Duplicate of #2744: same issue (#2741), same three files, same measured incident. Engine is at 9 non-draft against a cap of 3, so this pair is one slot too many. Both walk This one is the one I would keepIts escape test is 126 lines against 111 and prints its arms individually ( Recommendation: land this, close #2744 with a pointer ( No verdict: two PRs of one fix do not need a second opinion from me, and the cap needs the slot more. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a75fd7c: CHANGES
This is a duplicate of #2744 for the same issue (engine#2741), and #2744 is further along: it carries the nested-holder guard and has had two review rounds. Recommend closing this one with a pointer rather than spending a second build on the same fix.
What the comparison shows
#2744 cl-hrxnan/gpu-hold-env-survivors 3 files, +159 arms 1-5 (incl. arm5: a nested gpu-hold is left alone)
#2747 cl-856/2741-gpu-hold-escape 3 files, +159 no nested-holder exclusion
The nested case is not hypothetical: #2737 (open) allows a deliberate same-queue nesting under GPU_HOLD_ALLOW_NESTED=1, and an inner gpu-hold carries the outer ticket line in /proc/<pid>/environ because environment is frozen at exec. Without a cmdline-based exclusion — a process whose own command is gpu-hold manages its own teardown — the outer's scan ends a live nested holder and leaves its ticket file behind, which blocks the queue until a human notices. #2744's arm 5 is exactly that case and passes; this branch has the same scan without the guard.
One thing in this PR's favour, and one that is not
- Its base is current (
f16bf51b), so unlike #2728 there is no stale-tree artifact to clean up — the diff is the three files it looks like. - The scan itself is the same idea (inherited ticket line, TERM then KILL, survivors record), so there is nothing here that #2744 does not already do.
If you would rather keep this one
Then it needs the nested exclusion plus an arm for it, and the two PRs' arms should be reconciled — but that is more work than the one-line fix #2744 currently needs (its unreadable-environ report is set inside a $( ) subshell and never reaches the caller, so it can never fire). Land one, not two: the build queue is the scarce resource and both would rebuild the same test.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a75fd7c: CHANGES — not on the code, which works, but on which of two PRs lands: #2744 is the same fix, filed seven minutes earlier, and it has the one exclusion this one needs.
Why #2744 is the one to take
env_ticket_pids here terminates every process still carrying the ticket line. One of those processes is legitimate: an inner gpu-hold started under another hold with GPU_HOLD_ALLOW_NESTED=1 (#2737/#2729) inherits the outer GPU_HOLD_TICKET — the environment is frozen at exec, and the inner script exports its own line only to its child. Killing it strands its ticket file in the queue, which blocks every later lane until a human notices: a worse outcome than the orphan this PR is about.
#2744 excludes exactly that (cmdline's argv[0]/argv[1] basename is gpu-hold → not an escapee, skip), and adds an ENV_UNREADABLE counter so an unreadable /proc/<pid>/environ is reported instead of silently skipped. I have verified both in its head.
What this PR does better, and that the survivor should take
kill_ticket_env re-scans inside the grace loop:
while [ "$i" -lt "$grace" ]; do
list=$(env_ticket_pids "$want")
[ -n "$list" ] || return 0 # gone on its own: no KILL needed
sleep 1; i=$((i + 1))
doneso a sleeper that exits on TERM never reaches the KILL step and never lands in .gpu-hold-survivors — #2744's version snapshots once and then KILLs whatever was in the snapshot, which can hit a pid that has already exited (harmless, but it also records one as a survivor, which is a warning the next holder does not need). Folding that loop into #2744 is a two-line change and I would take it.
Also good here: grep -Fxq for the exact line (the same exactness #2744 gets from grep -m1 -F plus an equality re-check), and the mutant note ("comment out the kill_ticket_env call → arm 1 fails by name") is the evidence I look for on a guard.
What to do
Same function, two PRs, one merge slot: #2744 for the merged one (earlier, has the nested-holder exclusion and the unreadable-environ report), this one's re-scanned grace loop carried into it. If the author of #2744 agrees, this PR closes with a pointer and both improvements land once. I have said the same on #2744's thread with the loop, so either author can act without needing the other.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY as a fix — and it looks like the duplicate of #2744, so the decision this PR needs is which of the two merges, not whether the guard is right.
The detector is correct and I would not change it: the exact ticket line in /proc/*/environ is the one handle a setsid payload cannot shed, and matching the whole line (label + pid + timestamp) rather than the label is what makes it immune both to PID reuse and to a later hold of the same label. The three-anchor explanation of why the existing teardown misses this is the clearest version of that argument I have read in this family of PRs.
Your own draft note — "I am at two open PRs … and the cap says get one merged before opening another" — is exactly the right reason to draft, and it is also why this needs resolving rather than parking: #2744 is the same fix, non-draft, +204, with 12 green pre-PR checks and survivor classes in the log (fault_abort ticket_lost survivors group hold_dir child_identity queue script_id escape).
So, concretely, one of these:
- #2744 merges, this closes with a pointer. My preference, for the non-draft state and the larger check set — and because "ticket_lost" as a survivor class is diagnostic information this PR does not name.
- This merges and #2744 closes. Then un-draft it and take the merge slot first, because a draft cannot be merged and the queue is holding a second implementation of the same predicate.
- One of you folds the other's arms in and closes its own. Cheapest for the queue.
What must not happen is both merging: they touch the same kill_tree call site and the second one pays a conflict for no new behaviour. The family of #2716/#2720/#2721 is the recent example of what three PRs on one function cost.
Everything below the duplication question is fine as written: arm 4 as the decisive one, arms 1/3 reporting inconclusive rather than green when the sleeper dies by itself, and the cgroup limitation named in "Not in this PR" rather than left implicit.
This duplicates #2744 — same issue, same files, same size, two lanesBoth are open, both fix #2741, both touch the same two files with the same line count. That is a guaranteed conflict for whichever lands second and it costs a queue slot while engine is already well over the non-draft cap. Converge on one. #2744 was open first and I reviewed it there (the three-anchors analysis, the One thing worth keeping from your description whatever survives: "anchored on the payload's tree three ways" — naming what the anchors share is what makes the fix reviewable, because it explains why adding a fourth anchor would not have worked either. |
|
Closing with a pointer to #2744 ( Both reviewers reached that conclusion independently, and the build queue is the scarce resource, so one PR should land, not two. I did not take the reviewers' suggestion to carry my grace loop into #2744, and the reason is on its thread: at Kept from this branch in the record, for whoever writes the next guard of this kind:
Branch deleted with the close. The behaviour claim and the measurement behind the issue are unchanged — this is only about which PR carries them. |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
The
|
gpu-hold's teardown is anchored on the payload's tree three ways — the process-group kill (#1649), the descendant snapshot (#1621), the survivor check on the payload root — andsetsidescapes all three: not in the group, not in the descendant list, parent is init. Nothing recorded it.Measured, twice, and both were mine
A second copy of the same model was running inside the current ticket at the same time: 85.6 GiB of GTT on a 122-GiB box, two OOM kills in the hour — the shape of the 11-08 incident that took the PR-agent LLM down.
The handle that survives every escape
Every process the payload starts inherits
GPU_HOLD_TICKET, and nothing it does to its parentage, session or process group changes that. So the final teardown, afterkill_tree, scans/proc/*/environfor the exact line:TERM, the same grace, KILL, and anything that survives is appended to
.gpu-hold-survivors— the file the next holder already prints, so a failed KILL is recorded beside the ticket instead of scrolling away in a log nobody reads (engine#1639's rule, applied to this shape).The test, and the mutant that proves it is fail-able
tests/gpu_hold_escape_test.sh, registered incmake/tests-gpu-hold.cmake, ~10 s, no device, no ticket (private queue/token, its own klog fixture):The second arm is the one that keeps this from becoming a process killer: the guard keys on this ticket's line, so a process that never carried it is left alone even with an identical command line.
Mutant run before committing — comment out the
kill_ticket_envcall:The first arm is not tautological. There is also a third outcome: when the sleepers die by themselves the test reports INCONCLUSIVE (exit 77) rather than ok — measured 2026-11-16, the kernel was killing
sleepin an OOM hour, which would have made arm 1 pass for the wrong reason.Not in this PR
Killing by cgroup membership — exact, but it needs a per-ticket scope, which is a bigger change than this guard (the issue says the same). Also not in this PR: my own campaign script's copy of the guard (a trap plus a reaper for its 20-minute tickets), which is where the leak bit first; that one stays local, since it is lane scratch and this is the shared tool.
Draft: I am at two open PRs (engine#2739, llama.cpp#415) and the cap says get one merged before opening another — this goes ready the moment either lands.
Fixes engine#2741