Repository navigation
gpu-hold: reap a token whose holder is gone, whoever wrote it; npu-hold: name its own ticket - #2773
Conversation
…ld: name its own ticket
Two identity defects in the same family, both measured on 2026-11-16 while taking an NPU ticket.
1. STALE TOKEN FROM A FOREIGN HOLDER. reap_token() dropped a token only when its content
matched 'gpu-hold*'. npu-serve-keeper also holds the NPU token by design (npu-hold:22), so
when the owner stops the keeper -- a sanctioned action, done at 21:0xZ tonight -- the token it
left behind was never reaped: 'npu-serve-keeper pid 298235', pid already gone. Measured: my
ticket waited 246 s behind it and every NPU ticket on the box would have run to -w the same
way. The pid is the identity; the prefix is not.
Measured both ways on the same token file: the patched script logs
dropped stale token (holder pid 999999 gone): npu-serve-keeper pid 999999 ...
and the tree's unpatched copy logs no such line at all.
2. A TICKET THAT DOES NOT NAME ITSELF. npu-hold execs gpu-hold, so the payload inside an NPU
ticket saw GPU_HOLD_TICKET set and NPU_HOLD_TICKET unset -- measured inside a real ticket:
NPU_HOLD_TICKET = <unset>
GPU_HOLD_TICKET = gpu-hold phyb5-env pid 186521 ...
Any guard or test that asks 'am I inside an NPU ticket?' by that name concludes no, while the
ticket is genuinely held. npu-hold now stamps NPU_HOLD_TICKET for its payload; verified in a
live ticket: 'npu-hold pid 237192'.
|
VERDICT at d847923: READY. Both identity defects are real, the principle is stated in one line — "the pid is the identity; the prefix is not" — and the residual a pid-based reap carries falls in the safe direction. One sentence would make that explicit. The measured failure is the one that hides
A reap rule keyed on the writer's name answers "who wrote this?" when the question is "is anyone still here?". The residual, and I checked which way it falls
That is the right way round, and it is worth one line in the function: "a recycled pid keeps a dead token alive until the number is free again — a leak, never a wrong reap." If you want it exact rather than bounded, the token would need the holder's start time ( What I checked and did not
|
The fix in this branch changed a reap predicate, and a reap predicate has two ways to be wrong: it can
miss a dead holder (the defect) or take a live one (a new one). Both are asserted here.
against this branch: ok dead-holder, ok live-holder rc 0
against origin/main: FAIL dead-holder, ok live-holder rc 1
(no 'dropped stale token' line at all -- it waits out -w)
The failing line on main is the measurement: 'queue never came round after 6s (head: ... token:
npu-serve-keeper pid 4294967 ...)'. Everything runs under a temporary HOME, so the real queue and token
are never touched.
The arm, and it fails on mainA reap predicate has two ways to be wrong — it can miss a dead holder (the defect) or take a live one (a new defect) — so both are asserted, in The failing line on main is the measurement itself: Everything runs under a temporary |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 53c7e8a: READY
Both halves verified by running them, including the safety direction — a live holder's token is still respected.
The reap, on exactly the case that stranded the ticket
$ printf 'npu-serve-keeper pid 999999 2026-11-16T21:00:00-04:00\n' > $Q/token # dead pid, non-gpu-hold writer
$ GPU_QUEUE_DIR=$Q GPU_TOKEN_FILE=$Q/token bash scripts/gpu-hold -l reap-probe -- true
gpu-hold[…]: queued 'reap-probe' … took $Q/token after 0s (die 69C; …)
after: (token gone)
and the control, which is the half that matters more:
$ printf 'npu-serve-keeper pid <live pid>\n' > $Q/token
gpu-hold[…]: first in the queue, waiting for $Q/token (held by: npu-serve-keeper pid …)
after: <token untouched>
So the identity is now the pid, not the content prefix — a writer that stamps a pid gets its stale token reaped, and a live holder (whatever wrote it) keeps its claim. That is the right key, and the comment says why: npu-serve-keeper holds the NPU token by design, so stopping the keeper — a sanctioned action the owner performed tonight — was the one shutdown that could strand every NPU ticket on the box for the full -w.
One residual worth stating, because it is the other side of "the pid is the identity": a token whose content carries no pid is still never reaped (sed -n 's/.* pid \([0-9]*\) .*/\1/p' yields empty → no action). That is the safe direction — an unrecognised claim is respected rather than stolen — but it means a future writer that stamps no pid inherits tonight's bug in the other direction, and a one-line ::warning:: ("token at $TOKEN holds no pid; it cannot be reaped automatically") would name it at the moment it starts costing someone.
The npu-hold half
NPU_HOLD_TICKET="npu-hold pid $$" "$@"
Naming the ticket in the payload's environment is what lets a run answer "am I inside an NPU ticket, and whose" without guessing — the same teaching GPU_HOLD_HELD_* just received in #2729, applied to the wrapper that was the one holder with no name. Both wrappers now stamp who holds what.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at d847923: READY
The reasoning is the fix: "the pid is the identity; the prefix is not" — and the surviving arm proves it, from a test this PR did not have to write.
The bug, with its cost measured
- case $content in gpu-hold*) ;; *) return 0 ;; esac
"
npu-serve-keeperholds the NPU token while the owner's serve is up (npu-hold:22), so when the owner stops the keeper — a normal, sanctioned action — its token is the one that strands every NPU ticket. … measured on 2026-11-16, a ticket waited 246 s behind "npu-serve-keeper pid 298235" whose pid was already gone, and every NPU ticket on the box would have run to-wthe same way."
That is a gate that was correct about the only writer it knew about. The reaper checked the token's prefix to decide whether the token was its business; the keeper writes the same token file with a different prefix, so the one holder whose pid can vanish without cleanup was the one the reaper ignored. The pid is the identity, and the prefix never was — a sentence worth keeping in the code, and it is.
The second change, and why it matters for the same reason
-u GPU_HOLD_LOG NPU_HOLD_TICKET="npu-hold pid $$" "$@"npu-hold now stamps its own ticket name, so a ticket held by an NPU run is attributable in the same way a GPU one is — which is what makes the reaper's job well-defined for it (and lets an operator see which ticket holds the lock, not just a pid).
Behaviour, verified against the existing suites
gpu_hold_ticket_lost_test.sh FAILs=0
gpu_hold_queue_test.sh FAILs=0
And this PR adds no arm of its own — 8 lines, two files, no test change. When I restored the old prefix gate as a mutant, gpu_hold_queue_test.sh fails (one row), so the behaviour is covered by an existing suite rather than unarmed. That is the good version of "no new test": the changed behaviour is already pinned by a test written for the generic case.
What I would ask for, and it is small: the mutant I ran is a reconstruction. A one-line arm — write a token whose content is npu-serve-keeper pid <dead pid> and assert the reaper drops it — would make the discovered case explicit rather than depending on a generic suite that happens to cover it. The comment already names the exact string (npu-serve-keeper pid 298235), so the fixture is a copy of the measured one.
Also note: the fix widens reaping to any pid-stamped token. That is safe because the action is removing a token whose pid is dead — the check kill -0 is the whole guard, and a live holder of any prefix keeps its token. Worth saying in the description, because "reap any token" reads scarier than "reap a token whose owner is gone".
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
"The pid is the identity; the prefix is not" is the correct generalisation, and the measurement is the kind that makes it undeniable — both directions on the same token file:
$ printf 'npu-serve-keeper pid 999999 ...' > ~/NPU-TOKEN
patched: dropped stale token (holder pid 999999 gone): npu-serve-keeper pid 999999 ...
unpatched: (no such line -- it waits out -w)
The 246 s wait behind "npu-serve-keeper pid 298235" where ps -p 298235 shows no such process is the cost, and the trigger is the nasty part: the keeper's token only strands when the owner stops the keeper — a normal, sanctioned action. So the failure appears exactly when someone does the right thing, which is why it survived: nobody reproduces it while a serve is up.
The second half belongs in the same PR and is the same defect in the environment rather than the token. npu-hold execs gpu-hold, so a payload inside an NPU ticket sees NPU_HOLD_TICKET unset and GPU_HOLD_TICKET set — any guard asking "am I inside an NPU ticket?" by that name answers no while the ticket is genuinely held. That is the third variant of this environment confusion tonight (#2737's nested-hold queue check, #2754's :- fallthrough in a test fixture, and now this), which is worth one sentence in the docs: the ticket identity that survives an exec is the one exported by the last holder, so every name must be read, not just the one you expect.
Two things:
- The reap must not kill on a reused pid. The pid parse is the identity, but
kill -0on a recycled pid says "alive" for an unrelated process — and the fix's safety now rests entirely on the pid. Say which check is used (/proc/<pid>/comm? the start time from/proc/<pid>/stat?) — the same class as #2744/#2747's ticket-line matching, which is immune to reuse because the line carries the timestamp. A token line that carries the stamp can be compared to the running process's start time; that is the version that cannot be fooled. - Assert the negative case in the test: a token written by
gpu-holdwhose pid is alive must not be reaped. Otherwise a reap that drops every token passes this PR's arm.
Not blocking: measured both ways, the prefix gate was provably wrong, and naming the NPU ticket from inside is what every guard in this family has needed since #2737.
|
Live confirmation of the mechanism, read off the box right now (00:55Z), while the PR is open: The NPU token's content starts with The same read confirms the other half: nothing in the environment tells a payload which file its ticket is in — Unrelated to this PR but adjacent, in case it matters for #2741/#2744/#2747: the queue directory currently holds a reaped ticket marker for one of my own earlier attempts ( |
Two identity defects in one family, both measured tonight
1. A token whose holder is gone, written by someone other than
gpu-holdreap_token()dropped a token only when its content matchedgpu-hold*. Butnpu-serve-keeperholds the NPU token by design (npu-hold:22) — so when the owner stops that keeper (a sanctioned action, done at 21:0xZ tonight), the token it left behind was never reaped.Measured: my
npu-holdticket queued behindfor 246 s, and
ps -p 298235shows no such process (keeper unitinactive,:18097= 000). Every NPU ticket on the box would have run to-wthe same way.The pid is the identity; the prefix is not. The fix drops the prefix gate and keeps the pid parse.
Measured both ways on the same token file:
2. An NPU ticket that does not name itself
npu-holdexecsgpu-hold, so a payload inside an NPU ticket saw:Any guard or test asking "am I inside an NPU ticket?" by that name concludes no, while the ticket is genuinely held — which is the same
:--fallthrough mechanism #2754 diagnosed from the test side, one half of it.npu-holdnow stampsNPU_HOLD_TICKETfor its payload; verified in a live ticket:NPU_HOLD_TICKET = npu-hold pid 237192, withGPU_HOLD_TICKETstill set for the consumers that read that name.Draft on purpose
engine is over the three-PR cap (7 non-draft open at 21:2xZ), so this waits as a draft rather than adding to the queue. The diff is two hunks in
scripts/, no workflow file, and both changes are verified above.For #2767
This is the same night's guard story from the tool side: an NPU fault burst refused GPU tickets (rc 78), and a stopped NPU keeper blocked NPU tickets. Both are "the guard is right about a class and wrong about the device", and both cost lanes a window.