Skip to content

gpu-hold: a stale inherited ticket is not a nest (engine#2727 review) - #2792

Merged
bong-water-water-bong merged 1 commit into
mainfrom
hold-stale-env
Nov 17, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
hold-stale-env

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #2729 (merged 0fc3fa9), from its review.

The hole

#2729 refuses a same-queue nest by comparing the inherited GPU_HOLD_HELD_QUEUE / GPU_HOLD_HELD_TOKEN. That keys off the presence of the exported variable, not the liveness of the ticket that exported it.

A payload that outlives its ticket keeps the marker — a daemonised child is exactly how the 51 GiB orphan of 11-08 happened — so the next gpu-hold inside it is refused rc 2 with "the outer ticket already holds the GPU", when it holds nothing. A real run is blocked in the name of a ticket that no longer exists.

The fix

GPU_HOLD_TICKET already carries the holder pid (gpu-hold <label> pid <pid> <ts>), so a pid that no longer exists means the environment is stale:

gpu-hold: the inherited ticket is stale -- GPU_HOLD_TICKET names pid 99999999, which no longer exists, so
label 'ghost' is not holding anything and this hold proceeds instead of refusing a nest that is not there

Both refusals are gated on this; GPU_HOLD_ALLOW_NESTED=1 still wins as before. A recycled pid can only make the guard more conservative — the refusal stays — never silently drop a real nest, because the refusal exists to protect a window and erring toward refusing is the correct side.

Arms — and the one that caught a false pass

arm claim
6 a stale marker (dead pid) runs instead of refusing, and names the stale ticket
6b the control — the same marker with a live pid is still refused rc 2

Arm 6b is the arm that matters. My first draft of arm 6 passed for the wrong reason: it pointed GPU_HOLD_HELD_QUEUE at $tmp/hold/gpu-queue, while the sandbox resolves the queue as $HOME/GPU-QUEUE (arm 3/4 prints it). Nothing matched, nothing was refused, rc 0 — a green check on a guard that was not being exercised. 6b is what exposed it: with the wrong path it failed, and after fixing the path to the sandbox's real layout both arms do what they claim.

Mutation-checked: forcing _held_live=1 makes arm 6 fail with "a STALE inherited ticket was refused", and leaves 6b green — the two arms pin opposite directions, so neither can pass by accident.

Opened as a draft: engine is over the orchestrator's three-non-draft cap.

#2729 refuses a same-queue nest by reading GPU_HOLD_HELD_QUEUE/TOKEN, which keys off the PRESENCE of the
exported variable and not the LIVENESS of the ticket that exported it. A payload that outlives its ticket --
a daemonised child, exactly how the 51 GiB orphan of 11-08 happened -- still carries the marker from a parent
whose ticket is long gone, so the next gpu-hold inside it is refused rc 2 with "the outer ticket already
holds the GPU" when it holds nothing.

GPU_HOLD_TICKET already carries the holder pid ("gpu-hold <label> pid <pid> <ts>"), so a pid that no longer
exists means the environment is stale: the hold proceeds and says so in one line. Both refusals are gated on
this, and GPU_HOLD_ALLOW_NESTED still wins as before.

A recycled pid can only make the guard MORE conservative (the refusal stays), never silently drop a real nest.

Arms (in tests/gpu_hold_nested_test.sh, private queue, sandboxed HOME):
  6.  a stale marker (dead pid) runs instead of refusing, and names the stale ticket;
  6b. THE CONTROL -- the same marker with a live pid is still refused rc 2, so "stale means allow" cannot
      degenerate into "never refuse".

Both mutation-checked: forcing _held_live=1 makes arm 6 fail with "a STALE inherited ticket was refused".
The first draft of arm 6 passed for the wrong reason -- it pointed at $tmp/hold/gpu-queue while the sandbox
resolves $HOME/GPU-QUEUE, so nothing matched and nothing was refused; arm 6b is what exposed that.
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 06eeb50)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Stale Environment Handling

The fix introduces a check for stale inherited environments by verifying the liveness of the process ID in GPU_HOLD_TICKET using kill -0. However, this approach may not be reliable across all Unix-like systems or in containerized environments where PID namespaces are involved, potentially leading to false positives in determining if a ticket is stale.

if [ -n "${GPU_HOLD_TICKET:-}" ]; then
    _held_pid=$(printf '%s' "$GPU_HOLD_TICKET" | sed -n 's/.* pid \([0-9][0-9]*\) .*/\1/p')
    if [ -n "$_held_pid" ] && ! kill -0 "$_held_pid" 2> /dev/null; then
        _held_live=0
        echo "gpu-hold: the inherited ticket is stale -- GPU_HOLD_TICKET names pid $_held_pid, which no longer exists, so label '${GPU_HOLD_HELD_LABEL:-${GPU_HOLD_LABEL:-?}}' is not holding anything and this hold proceeds instead of refusing a nest that is not there (engine#2727 review)" >&2
    fi
fi
Logic Consistency

The logic for checking if an environment is stale is applied consistently to both queue and token nesting checks. However, the introduction of the _held_live variable affects both checks, which might lead to unexpected behavior if the intent was to only apply the stale check to one of the conditions.

_held_live=1
if [ -n "${GPU_HOLD_TICKET:-}" ]; then
    _held_pid=$(printf '%s' "$GPU_HOLD_TICKET" | sed -n 's/.* pid \([0-9][0-9]*\) .*/\1/p')
    if [ -n "$_held_pid" ] && ! kill -0 "$_held_pid" 2> /dev/null; then
        _held_live=0
        echo "gpu-hold: the inherited ticket is stale -- GPU_HOLD_TICKET names pid $_held_pid, which no longer exists, so label '${GPU_HOLD_HELD_LABEL:-${GPU_HOLD_LABEL:-?}}' is not holding anything and this hold proceeds instead of refusing a nest that is not there (engine#2727 review)" >&2
    fi
fi

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 06eeb50: READY. It draws the distinction the nest check was missing, and it pre-empts the one hazard I opened the diff to look for.

Stale marker versus real nest

#2729 refuses a same-queue nest by comparing the inherited markers — which means a payload that outlives its ticket (a daemonised child, exactly the shape of the 51 GiB orphan of 11-08) leaves a marker behind and makes a legitimate later hold refuse a nest that is not there. A false refusal blocks a lane's work with the same confidence as a true one, and the message would name a queue nobody is on.

The fix reads the pid out of the ticket string the environment already carries:

_held_pid=$(printf '%s' "$GPU_HOLD_TICKET" | sed -n 's/.* pid \([0-9][0-9]*\) .*/\1/p')
if [ -n "$_held_pid" ] && ! kill -0 "$_held_pid" 2> /dev/null; then … proceed …

It is also the cleanest evidence for my #2729 review

I asked there for the five-variable marker family to be reduced to the pair that already existed (GPU_HOLD_TICKET carries label, pid, ts). This PR needs the pid to make the stale-versus-live distinction — and it gets it from GPU_HOLD_TICKET with one sed, not from GPU_HOLD_HELD_*. The existing variable demonstrably carries everything the nest logic needs, which is why the duplication costs rather than adds.

The pid-reuse question, answered before I asked it

"A recycled pid can only make this MORE conservative (it keeps the refusal), never silently drop a real nest — the refusal exists to protect a window, so erring toward refusing is the right side."

That is exactly right and it is the answer I would have given: kill -0 on a reused pid sees a live process, so the ticket reads as fresh and the refusal stands. The dangerous direction — proceeding while a real window is held — is unreachable, and the reasoning is written where the check is rather than in a commit message.

The arms are a contrast, again

6.  a STALE inherited ticket (dead pid in GPU_HOLD_TICKET) is not a nest -> the hold proceeds and says so
6b. …and the same environment with a LIVE pid is still refused (the control for arm 6)

Same environment, one existential difference, opposite outcome — the form that makes an arm a decision rather than a fixture. The failure message names the pid and the conclusion (label 'ghost' is not holding anything and this hold proceeds), so the next lane reading a log knows which side of the check it fell on.

Nothing to change

One sed, one kill -0, one branch, two arms, and a comment that states the conservative direction. #2727's family is now: refuse a live same-queue nest (#2729), do not mistake a stale marker for one (this), and allow the intended override (GPU_HOLD_ALLOW_NESTED).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 06eeb50: READY — the hole is real, the direction of the fix is right, and the control arm is the thing that makes it a fix rather than a hole of the opposite shape. But kill -0 has a third outcome besides "exists" and "gone", and it is the one that fails open.

The hole is real and this closes it

#2729 keys on the presence of GPU_HOLD_HELD_QUEUE / GPU_HOLD_HELD_TOKEN; an environment that outlives its ticket therefore refuses every later gpu-hold in it. The 11-08 shape — a 51 GiB llama-server daemonised out of a ticket that had ended — is exactly a payload carrying GPU_HOLD_* from a dead parent, so the fix addresses the case that has actually cost this box a night. GPU_HOLD_TICKET="gpu-hold <label> pid <pid> <ts>" (line 385: mine="gpu-hold $LABEL pid $$ $(date -Is)") does carry the holder pid, so liveness is available without new plumbing.

And arm 6b is the arm most PRs skip: arm 6 proves a stale ticket proceeds, arm 6b proves a live pid is still refused. Without 6b, deleting both refusals would pass. The DEAD_PID=99999999 … kill -0 && DEAD_PID=9999999 fallback is the same instinct — it refuses to assume a number is unused.

kill -0 fails for two different reasons and the code treats them as one

if [ -n "$_held_pid" ] && ! kill -0 "$_held_pid" 2> /dev/null; then
    _held_live=0
  • ESRCH — no such process. Genuinely stale. Correct to drop the refusal.
  • EPERM — the process exists and is not ours to signal. kill -0 returns non-zero exactly as it does for a dead pid, so this branch reads a live holder as stale and lets a second ticket proceed.

That is the failure direction the comment rules out:

"A recycled pid can only make this MORE conservative (it keeps the refusal), never silently drop a real nest — the refusal exists to protect a window, so erring toward refusing is the right side."

The recycled-pid half is right. The EPERM half is not: a live, foreign-owned holder drops the refusal silently, which is the "two GPU jobs" outcome the whole script exists to prevent — and it is not exotic on this box: any holder started under sudo, under a system unit rather than a --user one, or from a different user session is un-signalable by the lanes that then inherit its environment.

One-condition fix: ask /proc, not the signal

if [ -n "$_held_pid" ] && [ ! -d "/proc/$_held_pid" ]; then
    _held_live=0

/proc/<pid> is statable by any user, so its absence means ESRCH and nothing else. No permission can turn a live process into a "no". It keeps arm 6b's contract exactly (a live pid ⇒ refuse ⇒ rc 2), so the existing arms stay valid, and it removes the case where the safe direction is only safe for processes we own.

Your trade-off for a recycled pid — keep refusing, conservative — is unchanged by this, which is the right call. If you ever want it exact rather than conservative-forever, the ticket already carries <ts> and /proc/<pid>/stat field 22 is the start time: recording the start time in mine would make liveness a comparison instead of a guess. Optional, and worth a shortcut: note rather than code.

Two smaller notes

  • The pid is parsed by position from the left: sed -n 's/.* pid \([0-9][0-9]*\) .*/\1/p' takes the rightmost pid <digits>, which is correct as long as $LABEL cannot itself contain that substring. $TS is the last field and date -Is has no spaces, so _held_pid=$(printf '%s' "$GPU_HOLD_TICKET" | awk '{print $(NF-1)}') is immune to whatever the label contains, at the same length.
  • A zombie reads live — it has /proc/<pid> and answers kill -0 — so a holder whose parent never reaped it keeps the refusal. That is the safe side and needs no change; if you want the distinction, /proc/<pid>/stat's state field Z is the signal. The common case is unaffected, because a gpu-hold that exits normally is reaped by its shell and its pid disappears.

What I checked and did not

  • Checked: the ticket format at origin/main line 385 against the sed (trailing <ts> satisfies the .*), that _held_pid empty ⇒ _held_live stays 1 ⇒ refusal kept, which is the conservative direction for an old-format or unparseable ticket; the two added arms and that 6b is the control; and that the /proc form preserves 6b's contract.
  • Not checked on a device: nothing here needs one — this is CPU-side script logic, and the arms run without a ticket. I did not run the suite (it needs the merge queue's build), so my READY rests on reading the hunks and the arms, not on executing them.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 06eeb50: READY.

I checked the two facts the fix rests on rather than reading them from the description:

gpu-hold:385   mine="gpu-hold $LABEL pid $$ $(date -Is)"          # the token really does name the holder pid
gpu-hold:493   # ... a pid that no longer existed). engine#1621 fixed grandchildren and engine#1649 the ...

So the liveness question is already answerable from the environment, and — more to the point — the script's own comments show it has had to reason about "a pid that no longer existed" before, for grandchild reaping. Reusing that notion for the nest guard is consistency, not invention, which is what makes this the right follow-up to #2729 rather than a new mechanism.

The asymmetry you state is the part I would defend hardest and it is stated correctly: presence of the marker is not liveness of the ticket, and a daemonised child is exactly the shape that produces a marker outliving its ticket — the 11-08 orphan is the case in point, and a guard that refuses a real run in the name of a dead ticket is the same class of error as the orphan itself, one layer up. Gating both refusals, with GPU_HOLD_ALLOW_NESTED=1 still winning, keeps the escape hatch where it was.

And the pid-recycling direction is written the way I would want it: a recycled pid can only make the guard more conservative. That is the correct side to err on when the thing being protected is a memory window, and saying it out loud is what stops the next reader "fixing" it into a permissive path.

One thing I could not verify and am not treating as a blocker: the message text — I did not take a ticket to see it, since the queue is the scarce resource tonight and this is a guard I can read. If the arm exercises it, that is better evidence than my run would be.

@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review November 17, 2026 18:05
@bong-water-water-bong
bong-water-water-bong merged commit feb00a8 into main Nov 17, 2026
13 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the hold-stale-env branch November 17, 2026 18:08
@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 06eeb50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant