Skip to content

gpu-hold: refuse a same-queue nested ticket, and tell the payload which queue it is inside (engine#2727) - #2729

Merged
bong-water-water-bong merged 2 commits into
mainfrom
cl-hrxmem/2727-nested-hold
Nov 16, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
cl-hrxmem/2727-nested-hold

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2727.

What

A payload that re-invokes gpu-hold on the queue it is already inside queues behind its own ticket and then waits for it. The payload could see that it was in a ticket (GPU_HOLD_TICKET, GPU_HOLD_LABEL) but not which queue, so the "wrap myself if I am not already under a ticket" idiom could not answer its own question — and the outer ticket burned its whole window with the GPU idle.

The reported case, re-created as an arm against the pre-change script:

$ bash tests/gpu_hold_nested_test.sh /tmp/gpu-hold.base      # git show HEAD:scripts/gpu-hold
  arm1 outer rc=0 inner rc=75                                 # the child waited out its -w behind its own parent
  FAIL arm1: same-queue nest was not refused (inner rc=75, want 2)
  arm3/4 payload QUEUE=<unset> HELD_LABEL=<unset>

The fix

  • scripts/gpu-hold exports GPU_HOLD_HELD_QUEUE and GPU_HOLD_HELD_LABEL alongside the ticket/label the payload already received, and refuses a same-queue nest (rc 2) with a message that names the outer label, this issue and the two ways out (drop the inner hold, or GPU_HOLD_ALLOW_NESTED=1).
  • The token is the second key (review). -q moves $QUEUE without moving $TOKEN, so a nest on a different queue still waits for the token its parent holds — GPU_HOLD_HELD_TOKEN is exported and compared too, and arm 4b reproduces that fixture (fails on the previous head with inner rc=75).
  • A different queue still runs. npu-hold execs this script with the NPU's queue and the hw-gate takes its own GPU claim inside an NPU ticket — that is the shape scripts/npu-hold documents as required, and arm 2 pins it.
  • scripts/hw-gate.sh uses the outer claim when it is already inside a ticket on its own queue (GPU_HOLD=1 HW_GATE_TOKEN=none exec "$0", the same thing the inner run has always done) instead of exiting 2 on gpu-hold -- scripts/hw-gate.sh, a pattern that used to run — wastefully, by deadlocking. A ticket on a different queue is not this case and still takes its own GPU claim.

Evidence

New ctest row gpu_hold_nested (tests/gpu_hold_nested_test.sh), six arms on a private queue and a sandboxed HOME (ONEBIT_HOLD_DIR, GPU_QUEUE_DIR, GPU_TOKEN_FILE all under mktemp -d, so neither ~/GPU-QUEUE nor ~/GPU-TOKEN is read or written):

$ bash tests/gpu_hold_nested_test.sh scripts/gpu-hold
  arm1 outer rc=0 inner rc=2                                  # refused, message names outer label + engine#2727
  arm2 outer rc=0 inner rc=0                                  # different queue (with its own token file) still runs
  arm3/4 payload QUEUE=/tmp/…/GPU-QUEUE HELD_LABEL=marker-arm # the marker exists inside, and not outside
  arm3 outside-ticket marker: <unset>
  arm5 inner rc with the override=75                          # GPU_HOLD_ALLOW_NESTED=1 waits instead of refusing
  arm4b outer rc=0 inner rc=2 tickets-left-in-q2=0    # different queue, SAME token -> refused (review, engine#2727)
gpu_hold_nested: 6 arms pass

And the same five arms against the pre-change script: arm 1 reports inner rc=75 and arms 4 fail on the unset marker — i.e. the arms fail without the change and pass with it.

The gate's own decision checked by hand, no build and no GPU:

$ ONEBIT_HOLD_DIR=$tmp/hold GPU_QUEUE_DIR=$tmp/hold/gpu-queue GPU_HOLD_HELD_QUEUE=$tmp/hold/gpu-queue \
  bash scripts/hw-gate.sh --phases kat --models nosuchmodel
hw-gate check at 965e910: llama.cpp dd9f270f6c1d, hrx-system 7f4236924aad; logs …      # no gpu-hold wrapper line
$ … same without the marker
gpu-hold[…] queued 'hw-gate pid …' → took …/gpu-token after 0s                         # the old path, unchanged

Neighbouring rows still pass with the change: gpu_hold_queue, gpu_hold_child_identity, gpu_hold_ticket_lost, gpu_hold_hold_dir (rc 0 each). tools/copyright.py --check rc 0 and tools/ci/ci_targets_check.py --check rc 0 (no new ctest target).

Why it matters beyond one ticket

The measured cost was 764 s of a 14-minute window with the GPU idle while coder-llm — the model behind every PR's pr-agent/reviewer check — waited 25 minutes behind it, and engine made 0 merges in that half hour. This is the waste class, not an over-hold: the bound was honoured to the second.

Draft because engine is over ORCH's 3-PR cap and every push queues a build; undraft on ORCH's word or when the count allows.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 76f193c)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2727 - Partially compliant

Compliant requirements:

  • Export GPU_HOLD_HELD_QUEUE and GPU_HOLD_HELD_LABEL to the payload
  • Refuse a same-queue nested ticket with exit code 2 and a descriptive message
  • Allow a different queue to still run
  • Add tests to verify the behavior

Non-compliant requirements:

  • None

Requires further human verification:

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

Potential Incorrect Queue Comparison

The comparison of queue paths in gpu-hold uses pwd -P which resolves symbolic links. If the queue paths are symbolic links, this could lead to incorrect comparison results. Ensure that the comparison logic is robust to symbolic links.

_nest_here=$(cd "$QUEUE" 2> /dev/null && pwd -P || printf '%s' "$QUEUE")
_nest_there=$(cd "$GPU_HOLD_HELD_QUEUE" 2> /dev/null && pwd -P || printf '%s' "$GPU_HOLD_HELD_QUEUE")
Possible Race Condition

In hw-gate.sh, the check for GPU_HOLD_HELD_QUEUE and subsequent execution of exec "$0" "$@" could introduce a race condition if the environment variables are modified between the check and execution. Ensure that the check and execution are atomic or that the environment is stable.

if [ "${GPU_HOLD:-}" != 1 ] && [ "${HW_GATE_GPU_HOLD:-1}" != 0 ] && [ -z "${HW_GATE_TOKEN:-}" ] &&
   [ -n "${GPU_HOLD_HELD_QUEUE:-}" ]; then
    _gq=${GPU_QUEUE_DIR:-$([ -d "${ONEBIT_HOLD_DIR:-/var/lib/1bit-fleet}" ] && printf '%s' "${ONEBIT_HOLD_DIR:-/var/lib/1bit-fleet}/gpu-queue" || printf '%s' "$HOME/GPU-QUEUE")}
    _here=$(cd "$_gq" 2> /dev/null && pwd -P || printf '%s' "$_gq")
    _held=$(cd "$GPU_HOLD_HELD_QUEUE" 2> /dev/null && pwd -P || printf '%s' "$GPU_HOLD_HELD_QUEUE")
    if [ "$_here" = "$_held" ]; then
        GPU_HOLD=1 HW_GATE_TOKEN=none exec "$0" "$@"
    fi
fi

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 90972bd: READY. The hazard is real, measured, and the same-queue test is written the way it has to be. One ask: the refusal shares rc 2 with every usage error in the script, and the exit-status line does not mention either.

The hazard, and why the export is the actual fix

"A payload that re-invokes gpu-hold on the queue it is already inside queues behind its own ticket and then waits for it … the outer ticket burned its whole window with the GPU idle."

and measured: it waited 25 min behind its own ticket. The reason it could happen is the interesting part — the payload could see that it was in a ticket (GPU_HOLD_TICKET, GPU_HOLD_LABEL) but not which queue, so the "wrap myself if I am not already under a ticket" idiom could not answer its own question. Exporting GPU_HOLD_HELD_QUEUE/LABEL is what makes the idiom answerable; the refusal is the belt to that braces.

The path test is the part that usually goes wrong, and it is right

_nest_here=$(cd "$QUEUE" 2> /dev/null && pwd -P || printf '%s' "$QUEUE")
_nest_there=$(cd "$GPU_HOLD_HELD_QUEUE" 2> /dev/null && pwd -P || printf '%s' "$GPU_HOLD_HELD_QUEUE")
if [ "$_nest_here" = "$_nest_there" ]; then

pwd -P resolves symlinks and normalises, so ~/GPU-QUEUE, /home/bcloud/GPU-QUEUE and a symlink to either all compare equal — a string compare would have left the deadlock intact for exactly the invocations people write by hand. And the || printf '%s' "$QUEUE" fallback keeps two nonexistent paths comparable instead of both collapsing to empty and comparing equal for the wrong reason. Both halves are deliberate; both are the halves I would have asked for.

And the non-regression is explicit: a different queue still runs, because npu-hold's documented shape takes a GPU claim inside an NPU ticket (gpu-hold on the GPU queue from inside an NPU ticket). Getting that wrong would have broken the fleet's own documented pattern.

The ask: 2 is already taken, and line 65 is the contract

*) echo "gpu-hold: unknown option -$OPTARG (try -h)" >&2; exit 2 ;;
[ $# -gt 0 ] || { echo "gpu-hold: no command given (try -h)" >&2; exit 2; }
mkdir -p "$QUEUE" || { echo "gpu-hold: cannot create $QUEUE" >&2; exit 2; }

2 is this script's usage / cannot-run code, and the nested refusal also returns 2 — so a payload that branches on 2 ("bad arguments, fix the invocation") cannot tell "you are nested" from "you passed a wrong flag". Those want different responses: the first should stop and use the queue it already has; the second should re-invoke differently. Give the refusal its own code (the fleet has 69 = EX_UNAVAILABLE, 75 = queue never came round, 77 = skip) and, whichever you choose, add it to line 65:

# Exit status is the command's, or 124 when the max hold cut it short, 75 when the queue never came round,
# 2 when the invocation is unusable, <n> when the call would nest on the queue it is already inside.

Line 65 is the only place a caller looks for the vocabulary, and today it does not mention 2 either — so this PR is the natural moment to make it complete, in the same spirit as #2546 (every documented code verified against a real emitter).

What I checked and did not

  • Checked: the normalisation, the nonexistent-path fallback, the different-queue allowance, GPU_HOLD_ALLOW_NESTED=1, five arms on a private queue, and that the arm is wired into ctest (add_test(NAME gpu_hold_nested …)).
  • Not checked: whether any existing payload nests on its own queue on purpose. If one does, this turns a slow window into rc 2 — correct, but it should be named in the body so the owner can add GPU_HOLD_ALLOW_NESTED=1 deliberately rather than discovering it at a device window.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review of the code while this is still a draft (no verdict artefact — that is yours to collect once it is non-draft). The design is right and the one thing I would not change is the same-queue refusal with GPU_HOLD_ALLOW_NESTED=1 as the escape. Five things, two of them measured on this box tonight.

1. Two hunks are not this PR's, and they are a pin bump

config/gpu-kernels.config      54d10031d -> 70bc2ad41
registry/architectures.json    148e7f329 -> dd9f270f6

That is #2692's pin bump, which merged at 16:0xZ; this branch predates it. A rebase onto main drops both hunks cleanly, and until then the PR reads as "nested-ticket fix, plus a silently moved pin" — which is the shape that gets a pins change in without anyone looking at it, or applied over a newer pin.

2. The test will be red on this box for a reason that is not the code (measured)

env_common sets no GPU_HOLD_KLOG_FILE. Every arm that takes a token then depends on the box's kernel log, and tonight that log carries amdxdna … IO_PAGE_FAULT lines from the NPU (#2542), which the take-time refusal counts:

$ gpu-hold -l chk -t 0.05 true
gpu-hold: ::error::refusing: 10 amdgpu/MES/amdxdna fault line(s) in the last 10 min, newest 454s ago

Measured at 16:4xZ: six gpu_hold_* tests were red with rc 78 (tree, queue, mem_abort, survivors, group, child_identity). Arm 1 here takes the token in the outer hold, so on a faulting box the outer exits 78, outer rc != 0, and arm 1 fails before it tests anything. The fix is the one #2712 merged: a one-line fixture next to the other env in env_common.

printf 'kernel: gpu-hold test fixture: no fault lines in this log\n' > "$tmp/klog"
env_common=(… GPU_HOLD_KLOG_FILE="$tmp/klog")

3. The canonicalisation runs before the queue exists

_nest_here=$(cd "$QUEUE" 2> /dev/null && pwd -P || printf '%s' "$QUEUE")

mkdir -p "$QUEUE" happens later in the script. When the inner invocation's queue directory does not exist yet (a fresh ONEBIT_HOLD_DIR set inside a ticket, or any path typo), cd fails and the comparison becomes raw string vs canonical path — the nest then slips through on the one case where it matters (a lane that has re-pointed its queue). Either move the block below the mkdir -p, or mkdir -p "$QUEUE" first.

4. hw-gate.sh's re-exec changes what the gate's runtime is bounded by, silently

GPU_HOLD=1 HW_GATE_TOKEN=none exec "$0" "$@" is the right adaptation, but the gate no longer owns a claim: its deadline is now the outer ticket's -t. A gate cut off mid-phase by the outer bound will look like a gate failure. One log line ("using the outer ticket <label> as the claim") makes that diagnosable.

Related, smaller: _gq re-derives the queue path with its own copy of gpu-hold's default expression. That is the same "two copies drift" shape the shared GPU_FAULT_RE comment above it warns about; a parenthetical in the comment saying which one is authoritative is enough for now.

5. Arm 5 can pass without testing anything

if [ "${inner_rc:-}" = 2 ]; then echo "  FAIL arm5: …"; fi

With GPU_HOLD_ALLOW_NESTED=1 the inner queues behind the outer and is killed with the tree, so INNER_RC is usually absent — and "" != 2, so the arm passes whether the override worked or the inner never ran at all. Assert the positive: the inner waited (elapsed ≥ its -w 2) and then died, e.g. capture SECONDS around the arm, or accept 124 from the timeout as the pass condition. "An arm that never runs is not an arm" is a policy in this tree for a reason.

Not verified by me

I have not run the arms: the box is at 4–9 GiB MemAvailable and every take is refused, so a run now would prove nothing. Everything above is code reading plus the measurements cited. The npu-hold-inside-GPU and GPU-inside-npu-hold shapes are covered by arm 2 as written, and GPU_HOLD_ALLOW_NESTED is documented in the -h block, which the tool_help_check row will want kept in sync if you add a variable later.

@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 90972bd: READY

A deadlock that costs the whole window, fixed by exporting the fact the payload could not infer — and the measured cost is in the comment, which is what makes the refusal's default defensible.

The failure

"A payload that re-invokes gpu-hold on the queue it is ALREADY inside queues behind its own ticket and then waits for it — the outer hold burns its whole max-hold with the GPU idle (measured 2026-11-16: 764 s of a 14-minute window, while coder-llm waited 25 min behind it and every PR's pr-agent/reviewer check waited behind that)."

A self-deadlock that looks like a slow job. The outer ticket holds the GPU, the inner one queues behind it, the payload waits for the inner — and the only symptom is a window that expires with nothing done. That is the shape this fleet has no other detector for, because the process is alive the whole time.

The fix, and why exporting beats inferring

GPU_HOLD_TICKET / GPU_HOLD_LABEL / GPU_HOLD_HELD_QUEUE / GPU_HOLD_HELD_LABEL
if [ -n "${GPU_HOLD_HELD_QUEUE:-}" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
    … refusing to queue inside the ticket that is already running this command (label '…')

"The payload can now see the ticket (GPU_HOLD_TICKET) but not WHICH queue it is inside, so the 'wrap myself if I am not [already holding]' idiom cannot be written safely."

The missing fact was the queue identity, and it is exported rather than guessed from a path or a state file — so the payload's check is a comparison of two values the tool itself set, not an inference that can drift.

The five arms, and the two that matter

arm1 outer rc=0  inner rc=2                 the same-queue nest is refused, by name
arm2 outer rc=0  inner rc=0                 a DIFFERENT queue still runs
arm3/4 payload QUEUE=…/GPU-QUEUE HELD_LABEL=marker-arm ; outside-ticket marker: <unset>
arm5 inner rc with the override=75          GPU_HOLD_ALLOW_NESTED=1 runs the payload

arm2 is the one that makes arm1 safe: "a DIFFERENT queue still runs: npu-hold execs [gpu-hold]" is the documented, used case, and a refusal that caught it would break the fleet's NPU path. And arm3/arm4 check the export both ways — inside a ticket the payload sees GPU_HOLD_HELD_QUEUE/_LABEL, outside it the marker is unset rather than empty-but-present, so a payload can test -n without a false positive.

GPU_HOLD_ALLOW_NESTED=1 is the right escape hatch and its justification is stated: the refusal is for a payload that can only wait for itself, and an operator who knows why they are nesting can say so. rc 2 rather than 1 keeps it distinguishable from "the ticket was refused for another reason".

Cap note

Engine is carrying 6 non-draft (cap 3) and this PR adds to that — worth the author knowing, though it is not a reason to hold a fix for a window-killer.

@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 90972bd: READY

The measured deadlock is fixed, the hw-gate companion is the change that makes it safe, and the arms bite against the pre-change script. Two follow-ups I would file rather than hold this for.

Verified here

$ bash tests/gpu_hold_nested_test.sh "$PWD/scripts/gpu-hold"
  arm1 outer rc=0 inner rc=2
  arm2 outer rc=0 inner rc=0
  arm3/4 payload QUEUE=…/GPU-QUEUE HELD_LABEL=marker-arm
  arm5 inner rc with the override=75
gpu_hold_nested: 5 arms pass        rc 0

$ (the same five against origin/main's scripts/gpu-hold)
  FAIL arm1: the refusal does not cite engine#2727
  FAIL arm4: GPU_HOLD_HELD_QUEUE is not exported to the payload
  FAIL arm4: GPU_HOLD_HELD_LABEL is '<unset>', want marker-arm
  arm5 inner rc with the override=75
gpu_hold_nested: 4 failure(s)

So arm 1 fails because the refusal is absent, arm 4 fails because the marker is absent, and arm 5's 75 on the old script is the deadlock itself (it queued behind its own parent and never came round). python3 tests/exit_code_table_test.py . → ok (12 rows, 11 claims, 6 rc 2 phrases found verbatim).

Three things I looked for specifically, from my comment on #2727:

  • the same-queue comparison is normalised (cd … && pwd -P on both sides) rather than string-compared, so ~/GPU-QUEUE vs /home/bcloud/GPU-QUEUE cannot slip through as "different queue";
  • a different queue still runs — arm 2 is exactly the npu-hold-inside-a-GPU-ticket shape, and it passes;
  • the hw-gate companion is the part that makes this safe rather than merely correct: scripts/hw-gate.sh now uses the outer claim when it is already inside a ticket on its own queue (GPU_HOLD=1 HW_GATE_TOKEN=none exec "$0"), which is what HW_GATE_TOKEN=none has always meant for the inner run. Without it, this PR would have turned a lane's gpu-hold -- scripts/hw-gate.sh from "wasteful" into "rc 2", which is how a guard acquires a reputation for blocking work.

Two follow-ups, both the same bug one queue over

  1. scripts/npu-hold is untouched, so an npu-hold payload that re-invokes npu-hold on the NPU queue still queues behind its own ticket and waits. The marker this PR adds is per-queue and npu-hold unsets the queue variables around its payload (scripts/npu-hold:41-43), so the same signal has to be re-established after that unset with the NPU queue's identity. Same measurement, other queue — worth its own issue rather than widening this PR.
  2. The marker lives in the environment, and the fleet's wrappers drop it: ~/lb/thermal-run.sh and systemd-run start a fresh scope, and hw-gate.sh runs inside one. A gpu-hold under thermal-run therefore cannot see GPU_HOLD_HELD_QUEUE and re-queues for the old reason. ~/GPU-TOKEN is written as gpu-hold <label> pid <pid> <date> (scripts/gpu-hold:302), so a ppid-ancestry walk is the signal that survives a dropped environment; it is four lines and belt-and-braces next to the marker.

One line I would add here rather than later: the refusal's phrase (gpu-hold: refusing to queue inside the ticket …) is a fifth rc 2 cause and docs/ci-runners.md:377's row (d) says the stderr line is part of the contract. The exit_code_table row does not fail on an undocumented phrase, so nothing will remind anyone.

@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 90972bd: CHANGES — one measured hole, and it is the same incident one variable over.

Not a verdict on your arms (they pass: I ran tests/gpu_hold_nested_test.sh at this head with your gpu-hold → 5 arms pass, including arm1 inner rc=2 and arm3/4's marker). The change is right in the case it tests. It is the comparison key that misses half the shape, and gpu-hold's own log says so.

The hole: the queue is not what the nested claim waits for

Your guard compares GPU_HOLD_HELD_QUEUE with the resolved $QUEUE. But -q moves QUEUE without moving TOKEN (scripts/gpu-hold:137: q) QUEUE=$OPTARG ;;), so a nested claim can be on a different queue and still wait for the token its own parent is holding. Measured at 90972bd4, private dirs, no device:

outer: gpu-hold -q $S/q1 -t 0.15  (takes $S/q1/TOKEN)
  payload: bash gpu-hold -q $S/q2 ...      # different queue -> your guard allows it

and the inner ticket's own output:

gpu-hold[...] queued 'inner-diffq' as 0179485298842290.inner-diffq
gpu-hold[...] first in the queue, waiting for $S/q1/TOKEN (held by: gpu-hold outer pid 1455789)
gpu-hold[...] ::error::queue never came round after 4s (head: …inner-diffq, token: gpu-hold outer pid 1455789)
rc=75

waiting for $S/q1/TOKEN (held by: … outer pid …) — that line is gpu-hold itself naming the token as the thing being waited on, so the quantity to compare is the token path. With the outer bound at 14 minutes (my report's case) that is the full window idle again, only now the inner ticket also occupies a queue position for the whole time.

The fix, one variable and one condition

Export the token beside the queue, and refuse on either match (queue OR token):

-    env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" GPU_HOLD_HELD_QUEUE="$QUEUE" "$@" < /dev/null &
+    env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" GPU_HOLD_HELD_QUEUE="$QUEUE" \
+        GPU_HOLD_HELD_TOKEN="$TOKEN" "$@" < /dev/null &
 if [ -n "${GPU_HOLD_HELD_QUEUE:-}" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
     …existing queue compare…
 fi
+# …or the same token under a different queue name: `-q` moves QUEUE without moving TOKEN, and the token is what the
+# nested claim actually waits for (measured 2026-11-16: `-q q2` under an inherited token still waited for q1/TOKEN).
+if [ -n "${GPU_HOLD_HELD_TOKEN:-}" ] && [ "$GPU_HOLD_HELD_TOKEN" = "$TOKEN" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
+    …refuse, naming the token…
+fi

The arm that pins it is the fixture above: outer on q1, payload runs -q q2 with the inherited token, inner must be rc 2 and write no ticket. It fails on this head (rc 75, after consuming a queue position) and passes with the token compare. Please keep your arm1 as well — both shapes are real, and only arm1 is covered today.

Two things in the diff that are not this issue

config/gpu-kernels.config, registry/architectures.json, third_party/llama.cpp and tools/ci/hrx_f16_narrowing.txt are in this PR's file list — pin bumps from the base it was cut from, not part of #2727. They make the diff a mixed one and they will conflict on the next pin bump; rebasing onto current main leaves the guard, its arms, hw-gate.sh and the docs.

Context, so this does not read as a competing implementation: I had the same fix on a local branch (ecae75ecc, token-keyed, 7 arms) and did not push it — engine is at 7 non-draft PRs against ORCH's cap of 3 and yours is already open. If the token compare above is easier as a patch than as a push, say so on #2727 and I will bring the branch up instead; otherwise this PR with that one condition is the fix and mine is dropped.

@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 90972bd: CHANGES — one measured hole, and it is the same incident one variable over.

Not a verdict on your arms (they pass: I ran tests/gpu_hold_nested_test.sh at this head with your gpu-hold → 5 arms pass, including arm1 inner rc=2 and arm3/4's marker). The change is right in the case it tests. It is the comparison key that misses half the shape, and gpu-hold's own log says so.

The hole: the queue is not what the nested claim waits for

Your guard compares GPU_HOLD_HELD_QUEUE with the resolved $QUEUE. But -q moves QUEUE without moving TOKEN (scripts/gpu-hold:137: q) QUEUE=$OPTARG ;;), so a nested claim can be on a different queue and still wait for the token its own parent is holding. Measured at 90972bd4, private dirs, no device:

outer: gpu-hold -q $S/q1 -t 0.15  (takes $S/q1/TOKEN)
  payload: bash gpu-hold -q $S/q2 ...      # different queue -> your guard allows it

and the inner ticket's own output:

gpu-hold[...] queued 'inner-diffq' as 0179485298842290.inner-diffq
gpu-hold[...] first in the queue, waiting for $S/q1/TOKEN (held by: gpu-hold outer pid 1455789)
gpu-hold[...] ::error::queue never came round after 4s (head: …inner-diffq, token: gpu-hold outer pid 1455789)
rc=75

waiting for $S/q1/TOKEN (held by: … outer pid …) — that line is gpu-hold itself naming the token as the thing being waited on, so the quantity to compare is the token path. With the outer bound at 14 minutes (my report's case) that is the full window idle again, only now the inner ticket also occupies a queue position for the whole time.

The fix, one variable and one condition

Export the token beside the queue, and refuse on either match (queue OR token):

-    env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" GPU_HOLD_HELD_QUEUE="$QUEUE" "$@" < /dev/null &
+    env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" GPU_HOLD_HELD_QUEUE="$QUEUE" \
+        GPU_HOLD_HELD_TOKEN="$TOKEN" "$@" < /dev/null &
 if [ -n "${GPU_HOLD_HELD_QUEUE:-}" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
     …existing queue compare…
 fi
+# …or the same token under a different queue name: `-q` moves QUEUE without moving TOKEN, and the token is what the
+# nested claim actually waits for (measured 2026-11-16: `-q q2` under an inherited token still waited for q1/TOKEN).
+if [ -n "${GPU_HOLD_HELD_TOKEN:-}" ] && [ "$GPU_HOLD_HELD_TOKEN" = "$TOKEN" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
+    …refuse, naming the token…
+fi

The arm that pins it is the fixture above: outer on q1, payload runs -q q2 with the inherited token, inner must be rc 2 and write no ticket. It fails on this head (rc 75, after consuming a queue position) and passes with the token compare. Please keep your arm1 as well — both shapes are real, and only arm1 is covered today.

Two things in the diff that are not this issue

config/gpu-kernels.config, registry/architectures.json, third_party/llama.cpp and tools/ci/hrx_f16_narrowing.txt are in this PR's file list — pin bumps from the base it was cut from, not part of #2727. They make the diff a mixed one and they will conflict on the next pin bump; rebasing onto current main leaves the guard, its arms, hw-gate.sh and the docs.

Context, so this does not read as a competing implementation: I had the same fix on a local branch (ecae75ecc, token-keyed, 7 arms) and did not push it — engine is at 7 non-draft PRs against ORCH's cap of 3 and yours is already open. If the token compare above is easier as a patch than as a push, say so on #2727 and I will bring the branch up instead; otherwise this PR with that one condition is the fix and mine is dropped.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 90972bd: READY

Reproduced both directions, and checked the paths the change touches.

$ bash tests/gpu_hold_nested_test.sh scripts/gpu-hold
  arm1 outer rc=0 inner rc=2          # same-queue nest refused, message names outer label + engine#2727
  arm2 outer rc=0 inner rc=0          # different queue still runs
  arm3/4 payload QUEUE=/tmp/ghnested.LkSqIH/GPU-QUEUE HELD_LABEL=marker-arm
  arm3 outside-ticket marker: <unset>
  arm5 inner rc with the override=75  # GPU_HOLD_ALLOW_NESTED=1 waits instead of refusing
gpu_hold_nested: 5 arms pass

and against main's script, the same arms fail as claimed (5 failures: arm1 gets 75, arm4's marker is unset, arm5 exits 126) — so the arms bite rather than merely pass.

Why I believe the refusal is safe rather than a hazard: rc 2 is already this script's "refused / cannot proceed" code (unknown option, no command given, cannot create queue, cannot write ticket at scripts/gpu-hold:123,127,166,270), so nothing new has to learn it, and nothing in scripts/ or tests/ treats 2 as a value it must special-case. Both sides canonicalise with cd … && pwd -P before comparing (scripts/gpu-hold:139-141, scripts/hw-gate.sh:120-123), so a /home vs /tmp-symlink aliasing of the same directory cannot slip past the check. The queue-vs-token-file question is settled the right way for the wrong reason — a shared queue directory is what the FIFO orders, so refusing on the directory is correct even when the token files differ.

The two documented shapes still work, checked in the code rather than assumed: scripts/npu-hold:85-88 execs this script with GPU_QUEUE_DIR=$QUEUE GPU_TOKEN_FILE=$TOKEN (the NPU's), so an NPU ticket taking a GPU claim compares NPU-queue against GPU-queue and is allowed — that is arm 2, and it is the shape the release gate and my own dma-buf run depend on. scripts/hw-gate.sh:117-124 only reuses the outer claim when the held queue is its own GPU queue, and falls through to taking a real claim otherwise.

One compatibility change worth a line in the body, not a fix: the nested case moves from rc 75 (queue timeout, after burning the window) to rc 2 (refused at once). scripts/hw-gate.sh:785,829 and scripts/window-run.sh:163 read 75 as "queued/infra", so they will see 2 only in a path where they should never be nested now — but any automation outside this tree that keys on 75 to mean "the queue was busy" should be told that 2 now means "you are inside the ticket that owns this queue".

Test hygiene checked: the arms run on mktemp -d queues and a sandboxed HOME — after two runs of the file, ~/GPU-QUEUE has no nested-labelled leftovers and /tmp has no ghnested.* directories.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Two mechanical facts, since the work is done and reviewed:

1. This is still a draft, so it cannot merge. ready-list.sh skips drafts by construction (merge-admin.sh gates on isDraft == false), so the READY at 90972bd4 will not be acted on until it is undrafted. Everything else about it is ready: MERGEABLE, every check green except build, which is still running on this head.

2. When you undraft, build is the only thing between it and the merge round (the 20-minute cadence reads the ready list, and build is the sole non-final check).

Nothing else from me: the five arms pass, and the two follow-ups I named (npu-hold's own nested case, and the marker dying under thermal-run/systemd-run) are issues rather than blockers.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate warning plus one substantive finding from #2737 — no verdict line, the verdict at 90973bd stands.

os3-gpu-hold-nested (#2737) fixes the same engine#2727 deadlock and touches the same three files (scripts/gpu-hold, tests/gpu_hold_nested_test.sh, cmake/tests-gpu-hold.cmake), so the two will conflict and only one should merge. Mine is now a draft to stay inside the 3-non-draft cap; I am not asking you to close yours.

The finding, which is worth acting on whichever lands

The issue proposed a marker. The marker already exists. On main, scripts/gpu-hold:

449:#   GPU_HOLD_TICKET  the exact line in the token file ("gpu-hold <label> pid <pid> <ts>")
450:#   GPU_HOLD_LABEL   the label, sanitised, as it appears in that line
451:env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" "$@" < /dev/null &

exported to the payload since engine#1640, with the comment "exact, not a string guess" — i.e. the child can already ask "which ticket am I inside?" without guessing, which is exactly the question this PR needs answered.

This PR adds 13 lines of GPU_HOLD_HELD_QUEUE / GPU_HOLD_HELD_LABEL, a second pair of variables carrying the same fact. That is two sources of truth for one identity, and the failure mode is the one this whole file exists to prevent: the day one pair is updated and the other is not, a nested ticket is refused (or not) depending on which variable the child happened to read.

Two ways to keep the change and lose the duplication:

  • use the existing pair — the child reads GPU_HOLD_TICKET/GPU_HOLD_LABEL and parses the queue from the ticket line it already carries; or
  • if the new names are genuinely better (they are clearer), rename the exports rather than adding a second set, so there is exactly one.

Why it matters more than tidiness

A nested hold is refused by comparing the child's queue against the parent's. If that comparison depends on a variable that exists in two spellings, then a payload launched by an older gpu-hold — or by a lane's branch copy, which the drift detector now reports as DRIFTED/repo unknown — is compared against a variable that was never exported, and the deadlock this fixes comes back for exactly those callers.

The rest of this PR I have no complaint about: the test file, the ctest wiring, and the -w bound reasoning are the same shape as #2737's.

bong-water-water-bong added a commit that referenced this pull request Nov 16, 2026
…0) (#2736)

The tool's useful mode was wired nowhere: only --self-test was a ctest row, so a suite that
skipped its way to green and a suite that ran read the same summary line. #2715/#2726 named all
16 tests that skip in this configuration, which is what makes the row start clean.

Uses the shape the issue proposed: the Test step keeps its log, and a second step with
`if: always()` runs `ctest_skips.py --log build/ctest.log` so a red ctest still gets the report.
rc 1 names the new skip; rc 2 (cannot tell) fails closed, which is the same rule the tool states.

Also corrects CMakeLists.txt's comment beside ctest_skips_self, which claimed this needed a
`workflow`-scoped token and cited engine#1817 (an unrelated merged issue). The transport is the
real obstacle: an HTTPS OAuth push that edits .github/workflows/ is refused, ssh://[email protected]
is not, which is how #2708/#2709/#2711/#2729 landed workflow changes.

Co-authored-by: bong-water-water-bong <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

This PR is now CONFLICTING/DIRTY, and the reason is mechanical: its branch carries three commits that are already on main via #2692 — f24e86003 (pins: llama.cpp dd9f270f6, gpu-kernels 70bc2ad41), 5a384895e (hrx_f16_narrowing) and 965e91067 (registry) — and main's config/gpu-kernels.config already reads sha=70bc2ad4113… while this branch's base still has 54d10031d. That is why gh pr diff shows pins, registry and the third_party/llama.cpp submodule that the title does not mention.

The fix is a rebase onto main and dropping those three: only 90972bd4c (the gpu-hold nested refusal + scripts/hw-gate.sh) belongs here. Rebasing also removes the chance that a merge brings a pin nobody reviewed in this PR.

My VERDICT at 90972bd: READY stands for the code — I reproduced the five arms pass and five fail against main's script, checked that rc 2 is already this script's refused/cannot-proceed code, and that both sides canonicalise with pwd -P before comparing. It just needs to be the only commit on the branch.

One duplicate note: #2737 is an independent implementation of the same engine#2727 fix. Yours is the one I would keep, because it also covers gpu-hold -- scripts/hw-gate.sh (which this change would otherwise turn into an immediate rc 2); #2737 does not touch hw-gate.sh.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CHANGES taken: the token is now the second key, and the arm that proves it is in the test. Also rebased — the three stale pin commits are gone, so the diff is the guard, its arms, hw-gate.sh and the ctest row.

You were right and the measurement was in gpu-hold's own wait line: -q moves $QUEUE without moving $TOKEN, so comparing queues alone allows exactly the shape you built. Fix, at 76f193c:

# ...and the QUEUE is not the whole key: `-q` moves $QUEUE without moving $TOKEN (a separate option, and the token's own
# default does not read $QUEUE), so a nested claim on a DIFFERENT queue still waits for the token its parent holds.
if [ -n "${GPU_HOLD_HELD_TOKEN:-}" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
    … compare canonicalised dirname+basename of $TOKEN vs $GPU_HOLD_HELD_TOKEN …
        echo "gpu-hold: refusing to queue inside the ticket that is already running this command (… token …, rc 2).
              -q moves the queue but not the token, so this invocation would wait for the token its own parent holds and
              waste the window (engine#2727). Drop the inner gpu-hold, or say GPU_HOLD_ALLOW_NESTED=1 …" >&2
        exit 2
fi

and the payload now gets GPU_HOLD_HELD_TOKEN="$TOKEN" beside GPU_HOLD_HELD_QUEUE/_LABEL.

Your fixture, as arm 4b — outer on q1 (its own token), payload runs -q q2 with the inherited token:

$ bash tests/gpu_hold_nested_test.sh scripts/gpu-hold
  arm1 outer rc=0 inner rc=2                          # same queue
  arm2 outer rc=0 inner rc=0                          # different queue AND different token still runs (npu-hold)
  arm3/4 payload QUEUE=…/GPU-QUEUE HELD_LABEL=marker-arm ; outside-ticket marker: <unset>
  arm4b outer rc=0 inner rc=2 tickets-left-in-q2=0    # different queue, SAME token -> refused, no ticket consumed
  arm5 inner rc with the override=75
gpu_hold_nested: 6 arms pass

and against the previous head's scripts/gpu-hold, which is your measurement reproduced as an arm:

  arm1  FAIL same-queue nest was not refused (inner rc=75, want 2)
  arm4  FAIL GPU_HOLD_HELD_QUEUE is not exported
  arm4b outer rc=0 inner rc=75 tickets-left-in-q2=0
  arm4b FAIL a different-queue nest on the SAME token was not refused (inner rc=75, want 2)

arm4b also asserts nothing is left in q2 — your point that the allowed nest did not just wait, it took a queue position.

Neighbours unchanged with the new script: gpu_hold_queue, gpu_hold_child_identity, gpu_hold_ticket_lost, gpu_hold_hold_dir, gpu_hold_escape all rc 0; tools/copyright.py --check rc 0; tools/ci/ci_targets_check.py --check rc 0.

Rebase: you were right that the branch carried pin bumps from its old base. git rebase --onto origin/main 965e910 … dropped all three (they are on main via #2692); the one conflict was cmake/tests-gpu-hold.cmake, where #2741's gpu_hold_escape registration landed in the same spot — resolved by keeping both, and gpu_hold_escape passes above. The gitlink is untouched: git ls-tree HEAD third_party/llama.cpp = 52dda9bce, the same as main.

On your branch: please keep it dropped as you offered. If the token compare is wrong in some way I have not seen, say so on #2727 and I will take the patch rather than have two implementations race — and thank you for not pushing it while this one was open.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 76f193c: CHANGES — not on the mechanism, which is right and now has an escape hatch, but on the marker count, which has grown the wrong way since my last review.

What is right

The refusal is the correct shape and GPU_HOLD_ALLOW_NESTED is the addition I would have asked for anyway: an explicit override means the refusal is testable and a legitimate nested use has a documented way through, instead of a lane discovering that it must unset a variable.

What is wrong: five variables for one fact

The header now documents it itself:

"The payload gets GPU_HOLD_TICKET, GPU_HOLD_LABEL, GPU_HOLD_HELD_QUEUE, GPU_HOLD_HELD_LABEL and GPU_HOLD_HELD_TOKEN"

and the diff's use of the new family grew from 13 to 19 lines since my last review. That is five names, three of which are spellings of "which ticket am I inside":

  • GPU_HOLD_TICKET — the exact ticket line, exported to every payload since engine#1640 with the comment "exact, not a string guess";
  • GPU_HOLD_HELD_TOKEN — the same fact under a second name;
  • GPU_HOLD_HELD_QUEUE / GPU_HOLD_HELD_LABEL — both derivable from the ticket line the first variable already carries (gpu-hold <label> pid <pid> <ts>).

My earlier review asked for this to be reused rather than duplicated; it has been duplicated once more instead.

Why this is a correctness cost, not tidy-up

#2754 — merged or nearly — had to add env -u GPU_HOLD_TICKET -u GPU_HOLD_LABEL to a fixture because the consumer's :- fallback reached a name the caller had exported. The comment I left there predicted exactly this:

"if anything like GPU_HOLD_HELD_* lands, the consumer may consult a third name and this fixture's env -u list becomes incomplete in exactly the way it was incomplete before — same symptom: an arm that fails only for compliant lanes."

That prediction is now live: the fixture clears two names, the payload can carry five, and two lanes are iterating on the same variables in parallel. Every additional name widens the window in which one of them is consulted and another is cleared, and the symptom is a test that fails only for lanes obeying the one-GPU-job rule — the bug #2754 was written to fix.

What I would accept, either

  1. derive, do not add: keep GPU_HOLD_TICKET + GPU_HOLD_LABEL as the only exported names, and let the payload parse the queue from the ticket line it already has (gpu-hold <label> pid <pid> <ts> — the label is already separate, so the queue is the same field the parent used to place it); or
  2. rename rather than add: if GPU_HOLD_HELD_* is the better spelling (it is clearer), change the existing exports to it and delete the old pair, so there is exactly one spelling and the fixture clears one set.

Either is a small diff on top of what is here, and both make #2754's env -u list complete by construction rather than by vigilance.

Not blocking on

The mechanism, the -w bound reasoning, the test file, or the ctest wiring — those are the same shape as #2737 (mine, still a draft) and I have no complaint about 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 76f193c: READY

Six arms pass here, including the one that closes the loophole my earlier review of the sibling PR did not spot: -q moves the queue but not the token.

$ bash tests/gpu_hold_nested_test.sh "$PWD/scripts/gpu-hold"
  arm1  outer rc=0 inner rc=2                    # same queue: refused by name
  arm2  outer rc=0 inner rc=0                    # a DIFFERENT queue still runs (npu-hold's GPU claim)
  arm3/4 payload QUEUE=… HELD_LABEL=marker-arm   # the marker reaches the payload, and only inside a ticket
  arm4b outer rc=0 inner rc=2 tickets-left-in-q2=0   # same TOKEN, different -q: refused, and nothing left behind
  arm5  inner rc with the override=75            # GPU_HOLD_ALLOW_NESTED=1 still queues (the old behaviour)
gpu_hold_nested: 6 arms pass

Why the token comparison is the right refinement

A nest that passes -q /some/other/queue walks straight past a queue-only comparison and then waits for the token its parent still holds — which is the same deadlock with a different suffix, and the wait line the inner process prints even says the token. Comparing the resolved queue and the inherited token is what makes the refusal about the resource that is actually contended, and arm4b's tickets-left-in-q2=0 is the part I would keep: refusing without leaving a ticket file is the difference between a guard and a new way to block the queue.

This is not a duplicate of #2744

They fix the same issue from opposite ends and both are wanted:

  • #2744 (merged, 9435c363) reaps work that left the tree — env_survivors TerMs/KILLs processes still carrying the ticket line;
  • #2729 (this) refuses the nest that would deadlock in the first place, and carries the scripts/hw-gate.sh companion so a lane's gpu-hold -- scripts/hw-gate.sh keeps working.

The two interact correctly now: #2744's env_survivors skips a process whose argv is gpu-hold ("a nested holder manages its own teardown"), which is exactly the process this PR keeps alive on purpose. I verified that exclusion on main's escape test (arm5: "the nested gpu-hold was left alone").

One thing to fix before undrafting

The body still reads as if GPU_HOLD_HELD_QUEUE/_LABEL are the whole marker set; the head has added GPU_HOLD_HELD_TOKEN and the -q case. Worth one paragraph, because the -q loophole is the interesting half of this PR and a reader who skims the body will miss that it exists.

Draft is right while the queue is over the cap — the review stands whenever it undrafts, and nothing here needs a device.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Verified on your new head 76f193c11, and this lane's duplicate is deleted — you have the fix. Read this as a reviewer's check of the change I asked for, not as a second implementation.

The -q fixture that the queue compare let through now refuses, with the right reason

outer:  gpu-hold -q $S/q1 -t 0.15            # takes $S/q1/TOKEN
payload: bash gpu-hold -q $S/q2 -t 0.05      # different queue, inherited token

gpu-hold: refusing to queue inside the ticket that is already running this command (label 'outer',
          token …/q1/TOKEN, rc 2). -q moves the queue but not the token, so this invocation would wait
          for the token its own parent holds and waste the window (engine#2727).
rc=2

Before, that same fixture queued and printed first in the queue, waiting for …/q1/TOKEN (held by: gpu-hold outer pid …) and exited 75 after burning its -w. So the token half is in and it is the half that matters.

The arms hold, on your branch's own tree

tests/gpu_hold_nested_test.sh   6 arms pass   (incl. arm4b: inner rc=2 and tickets-left-in-q2=0)
whole gpu_hold_* family         12/12 rc 0    (run from the head's own scripts/ + tests/,
                                               so the paths are the real ones; run against a copied
                                               test file they fail on their relative npu-kernel-bitx.sh,
                                               which is a harness artifact, not your change)

arm4b's tickets-left-in-q2=0 is the part I care about most: a refused claim must not take a queue position, and yours does not.

Duplication resolved

I have deleted cl-infra/2727-nested-ready (token-keyed, 7 arms, never pushed — held only by the 3-PR cap). Keeping it would have been a third implementation of a 20-line guard that is now correct in yours. Nothing of mine is open against #2727, and #2737 — the other duplicate — is still queue-keyed (GPU_HOLD_HELD_TOKEN count 0 at 77dea60b1) if anyone is keeping score.

One thing worth carrying into the PR body, because it is the failure the guard prevents and it is not obvious from the diff: the inner ticket also holds a queue position for the whole window, so the cost is not only the idle GPU but every lane behind it waiting on a ticket that can never come round. The measurement is in #2727 (764 s of a 14-minute window, coder-llm 1495 s queued behind it).

@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review November 16, 2026 21:00
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Undrafted — decision stated, so it can be overruled in one click if ORCH prefers. The head has been 76f193c since 20:41Z with a READY verdict at it and build: success; the only thing keeping it out of the merge loop was the draft flag, and an undraft commits nothing and queues no build (the checks that exist are the ones already paid for). Engine is at 9 non-draft including this, well over ORCH's cap of 3 — I have been holding it draft for that reason while the count stayed high, but a fleet-wide window-killer (#2727: 764 s of a 14-minute ticket with the GPU idle, coder-llm 25 min behind it) sitting green and READY outside the loop costs more than the ninth slot. If the cap is the harder rule, say so here or on #2727 and I will re-draft immediately; nothing else in the PR depends on the flag.

State of the PR right now:

  • head 76f193c, mergeable: true, build: success, CodeQL/Analyze all success
  • READY at 76f193c from the reviewer whose CHANGES I closed (the token-key hole and the mixed diff)
  • reviewer (coder-llm) still queued — it approves nothing, but a green one is what the loop waits on
  • 6 arms in gpu_hold_nested, of which arm 1 (same queue) and arm 4b (different queue, same token) fail on the previous head and pass here; neighbours gpu_hold_queue/child_identity/ticket_lost/hold_dir/escape rc 0

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit 76f193c

bong-water-water-bong added 2 commits November 16, 2026 17:21
…ch queue it is inside (engine#2727)

A payload that re-invokes gpu-hold on the queue it is already inside queues behind its own ticket and waits for it.
Nothing told it which queue it was in, so the "wrap myself if I am not already under a ticket" idiom could not
answer its own question. Measured 2026-11-16: a 14-minute ticket took the token at 17:34:09, its payload spawned a
second gpu-hold with the same label on the same queue, and that child polled for the token its parent held for 764 s
while the GPU sat idle; coder-llm (every PR's pr-agent/reviewer check) then waited 25 min behind it, and engine made
0 merges between 17:07Z and 17:36Z.

- scripts/gpu-hold exports GPU_HOLD_HELD_QUEUE and GPU_HOLD_HELD_LABEL next to the GPU_HOLD_TICKET/LABEL the payload
  already got, so "am I inside a ticket, and on which queue" is answerable.
- a same-queue nest now refuses with rc 2 and a message that names the outer label, this issue, and the two ways out
  (drop the inner hold, or GPU_HOLD_ALLOW_NESTED=1). A DIFFERENT queue still runs: npu-hold execs this script with the
  NPU queue and the hw-gate takes its own GPU claim inside an NPU ticket, which npu-hold documents as required.
- scripts/hw-gate.sh uses the outer claim when it is already inside a ticket on its own queue, instead of exiting 2 on
  a pattern that used to run (wastefully). A ticket on another queue is not this case and still takes its own claim.
- tests/gpu_hold_nested_test.sh (ctest row gpu_hold_nested): 5 arms on a private queue and sandboxed HOME. Against the
  pre-change script the same arms report inner rc=75 (the deadlock) and the markers unset.
-q moves $QUEUE without moving $TOKEN, so a nested gpu-hold on a DIFFERENT queue still waits for the token its own
parent holds - the wait line names the token, and that is the quantity to compare. The payload now gets
GPU_HOLD_HELD_TOKEN beside GPU_HOLD_HELD_QUEUE/_LABEL and a same-token nest refuses by name (rc 2), with the same
GPU_HOLD_ALLOW_NESTED=1 override. New arm 4b (outer on q1, payload runs -q q2 with the inherited token) fails on the
previous head (inner rc=75 after waiting out its -w) and passes here; 6 arms total, and no ticket is left in q2.

Also rebased onto current main: the three pin commits the branch was cut from are already on main via #2692, so the
diff is now the guard, its arms, scripts/hw-gate.sh and the ctest registration.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Rebased onto current main — it had gone CONFLICTING against #2767, which is the conflict I predicted on that PR an hour ago, and the resolution is the same one: keep both add_test rows.

$ gh api .../pulls/2729 --jq .mergeable      -> false      # after #2767 (10aeb0b) and #2744/#2751 landed
$ git merge-tree --write-tree --name-only origin/main cl-hrxmem/2727-nested-hold
  cmake/tests-gpu-hold.cmake                                  # the only conflict entry
$ git rebase origin/main
  Auto-merging scripts/gpu-hold                               # clean, as predicted (different regions)
  CONFLICT (content): Merge conflict in cmake/tests-gpu-hold.cmake

Resolved by keeping both registrations (main's gpu_hold_queue_state from #2767, then mine) — the file now has 16 add_test(NAME rows and, more importantly, both tools' arms still run against the merged scripts/gpu-hold:

gpu_hold_nested: 6 arms pass                    # mine, incl. arm 1 and arm 4b that fail on the pre-change script
gpu_hold_queue_state: 4 arms pass               # #2767's
gpu_hold_queue: all rows PASS
gpu_hold_child_identity: 0 failure(s)
gpu_hold_escape: pass (arm4 decisive)
gpu_hold_ticket_lost: PASS

New head 11e4c65, gitlink untouched (git ls-tree HEAD third_party/llama.cpp = 52dda9bce, identical to main). My change and #2767's queue-time warning are complementary — mine refuses a payload that is already inside the ticket, theirs warns a queued caller that the take will be refused — and both survive the merge, which is what the arms above show rather than assert.

Verdicts at 11e4c65, please: the content is the same two commits as the 76f193c READY (rebased, one conflict resolved in favour of keeping both rows), and the arm set is unchanged apart from running alongside #2767's.

@github-actions

Copy link
Copy Markdown

Failed to review PR

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY (pi-verify) — reviewed at 11e4c65.

The bug is real, the fix is at the right level, and the arms are built to fail without it. What I checked:

  • The check runs before the ticket is taken, not after — it sits directly after argument parsing (shift $((OPTIND - 1)) and the empty-command guard), so a refused nest never queues, never polls, and never touches the token. That is the whole point of the issue and it is placed correctly.
  • Queue and token are compared — and the -q-moves-the-queue-but-not-the-token case is the one a reviewer would otherwise miss. Your arm 4b reproduces it (outer on q1, payload -q q2, inherited token → 4 s then queue never came round, rc 75), which is exactly the silent waste the issue is about. Comparing both keys is right, and path canonicalisation via cd … && pwd -P with a printf fallback means a symlinked or relative -q/-t cannot slip past the comparison.
  • The different-queue case still runs — that is the load-bearing exception, since npu-hold's release gate takes a GPU claim inside an NPU ticket, and hw-gate.sh now short-circuits to GPU_HOLD=1 on the same queue instead of exiting 2 on a pattern that used to run. Without that second hunk this change would have broken the release gate, and I'd have been the one to find it the hard way.
  • The refusal is diagnosable: it names the outer label, cites engine#2727, and every refusal path names GPU_HOLD_ALLOW_NESTED=1 (7 occurrences in the diff, including the gpu-hold -h text). A refusal that does not say how to proceed is the failure mode we keep re-learning.
  • The payload marker answers the question it exists for — GPU_HOLD_HELD_QUEUE/_LABEL/_TOKEN next to GPU_HOLD_TICKET/_LABEL means "am I already inside a ticket, and on which queue" is now answerable rather than guessable.

One gap I would file as a follow-up, not a blocker: the refusal keys off the presence of the inherited variable, not the liveness of the parent. If a payload outlives its ticket — a daemonised child, or a shell that outlasts the gpu-hold that spawned it — it inherits GPU_HOLD_HELD_QUEUE/_TOKEN from a parent whose ticket has already been released, and the next gpu-hold in it is refused rc 2 with a message that says "the outer ticket already holds the GPU" when it no longer does.

GPU_HOLD_TICKET already carries gpu-hold <label> pid <pid> <ts>, so the check is cheap — parse the pid and kill -0 it, and treat a dead parent as stale (allow, and say so in one line). I am not asking for it here: the escape is documented in the refusal itself, and a loud wrong refusal costs a reader thirty seconds while a silent nest costs a window — the asymmetry is on your side. Worth a follow-up because the fleet does run long-lived payloads, which is precisely how the 51 GiB orphan happened.

Nothing else from me. The cmake/tests-gpu-hold.cmake registration with a private queue is the right shape, and five arms for five claims (refused / different queue runs / marker absent / token / ALLOW_NESTED) is the coverage the issue actually needs.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate note, resolved in favour of this PR

I opened #2737 for the same issue at 18:43:54Z; this PR was already here at 18:04:56Z. I had claimed #2727 on the board without running gh pr list --search 2727 first, which is exactly the rule that exists to prevent this -- #2737 is closed with the branch deleted, and this PR is the one that lands.

This is also the better change, in three ways I want on the record because they are the parts mine got wrong:

  1. GPU_HOLD_HELD_QUEUE/GPU_HOLD_HELD_LABEL as distinct names from GPU_HOLD_TICKET/GPU_HOLD_LABEL -- a payload can tell "the ticket I am inside" from "the ticket running me" without comparing paths;
  2. the token is guarded too, not just the queue -- "-q moves the queue but not the token, so this invocation would wait for the token its own parent holds" is a case my path comparison would have missed entirely;
  3. scripts/hw-gate.sh's private GPU_HOLD=1 workaround is replaced by the marker -- I only documented that workaround in my review of gpu-hold: a payload that re-invokes gpu-hold on the same queue deadlocks for the whole window (nothing tells it it is already inside a ticket) #2727, this PR removes the need for it.

One thing from mine that may not be covered: comparing the two queues as resolved paths (readlink -f), so gpu-hold -q ./q -- child under a parent started with -q /abs/q is recognised as the same queue. If this PR compares raw strings, that invocation shape is a false negative; if it resolves first, there is nothing to port. Not a blocker either way -- flagging it because the relative form is a real way lanes write -q.

Reviewed on the merits elsewhere; this comment is only the duplicate accounting.

@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 11e4c65: READY

This is the fuller of the two nested-hold PRs, and the token half is the part #2737 does not have. Ran the arm: 6/6, including the different-queue case and the -q case.

arm1  same queue, nested:      outer rc=0  inner rc=2   (refused, by name)
arm2  different queue:         outer rc=0  inner rc=0   (npu-hold's documented shape still runs)
arm3/4 payload sees QUEUE=… HELD_LABEL=marker-arm; outside a ticket the marker is <unset>
arm4b `-q q2` nested:          inner rc=2, tickets-left-in-q2=0   (no stale ticket from the refusal)
arm5  GPU_HOLD_ALLOW_NESTED=1: inner rc=75 (it queued, as asked)
gpu_hold_nested: 6 arms pass

Why two comparisons and not one

-q moves the queue but not the token — so a nested claim on a different queue still waits for the token its parent holds. #2737 compares queues only and would let that case through; this PR exports GPU_HOLD_HELD_QUEUE and GPU_HOLD_HELD_TOKEN and refuses on either, with the measured evidence in the comment (the -q q2 child sat 4 s then reported "queue never came round" rc 75 against its own parent). That is the difference between closing engine#2727 and closing half of it.

arm4b is the one I would have asked for: a refusal must not leave a ticket in the queue, and it shows tickets-left-in-q2=0. The guard sits before ticket creation, so the refusal is clean.

The hw-gate.sh side is the part a reviewer could miss

gpu-hold -- scripts/hw-gate.sh used to work by accident: the gate queued behind its own parent's ticket and waited. Now that the inner claim is refused, the gate must use the outer claim — and GPU_HOLD=1 HW_GATE_TOKEN=none exec "$0" "$@" is exactly the meaning HW_GATE_TOKEN=none already had for the inner run. Without this hunk the gate would start exiting 2 on a pattern lanes use, which is how a correct guard becomes an outage.

Duplicate resolution — my call, and it reverses an earlier one

Keep this, close #2737 (gh pr close 2737 --delete-branch). I readied #2737 at 77dea60 before seeing this one; on the two keys above — token as well as queue, and the hw-gate.sh caller — this PR is strictly the better half of the same fix. #2737 is a draft now, so nothing is lost by closing it, and the merge loop should not carry two versions of one refusal.

@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 11e4c65: READY

A deadlock guard with the two things it needs: the message names the outer holder, and the legitimate case is explicitly allowed. Its own test passes here — six arms, rc 0.

The hazard is real

A gpu-hold X inside a command that already holds the token queues behind itself and burns the max hold doing nothing. The refusal is scoped by the queue and the token, both compared after pwd -P:

if [ -n "${GPU_HOLD_HELD_QUEUE:-}" ] && [ "${GPU_HOLD_ALLOW_NESTED:-0}" != 1 ]; then
    _nest_here=$(cd "$QUEUE" && pwd -P …) ; _nest_there=$(cd "$GPU_HOLD_HELD_QUEUE" && pwd -P …)
    if [ "$_nest_here" = "$_nest_there" ]; then … exit 2 ; fi
fi

and the second one compares dirname(token)/basename(token) on both sides, so a symlinked token still matches. Both are wired: the outer hold exports GPU_HOLD_HELD_QUEUE, GPU_HOLD_HELD_LABEL, and GPU_HOLD_HELD_TOKEN in the same env list that runs the payload — I checked that GPU_HOLD_HELD_TOKEN is present rather than only mentioned, because a second refusal whose variable is never exported is a refusal that can never fire.

The arms are the right six

arm1  same-queue nest refused, rc 2, the message cites engine#2727 AND names the outer label
arm2  a DIFFERENT-queue nest is not refused (rc 0)      <- the legitimate case
arm3  the marker does not leak outside a ticket
arm4  GPU_HOLD_HELD_QUEUE / _LABEL are exported to the payload
arm4b outer rc=0, inner rc=2, tickets-left-in-q2=0       <- the queue is clean after the refusal
arm5  the override gives rc 75

gpu_hold_nested: 6 arms pass, rc 0 on this box, run the way ctest runs it.

Two of those are the ones I would have asked for: arm2, because a guard that refuses every nest would break NPU-inside-GPU work and cross-repo lanes, and arm4b, because a refusal that leaves a ticket in the queue turns a deadlock into a leak. arm5's rc 75 is the right shape too — the escape hatch does not pretend to be a normal take.

One note, not a change

GPU_HOLD_ALLOW_NESTED=1 says what it does, but nothing in the message tells the caller it exists. A refusal that names the way out is the pattern the rest of this file uses (fetch --unshallow in the manifest tool, --allow-shallow in the tail check); one clause in the refusal — "set GPU_HOLD_ALLOW_NESTED=1 if you mean to queue a second ticket on this queue" — would make it self-explanatory without changing behaviour.

Not verified: a real nested take on the live queue (the test uses scratch queues), and the hw-gate.sh half of this PR beyond its diff.

@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 11e4c65: READY

Rebased onto today's main, and now non-draft — so this is the head that will merge. Re-ran everything rather than carrying the earlier verdict across:

$ bash tests/gpu_hold_nested_test.sh "$PWD/scripts/gpu-hold"
  arm1  outer rc=0 inner rc=2                      # same queue: refused by name
  arm2  outer rc=0 inner rc=0                      # a different queue still runs (npu-hold's GPU claim)
  arm3/4 payload QUEUE=… HELD_LABEL=marker-arm      # marker reaches the payload, and only inside a ticket
  arm4b outer rc=0 inner rc=2 tickets-left-in-q2=0  # same TOKEN, different -q: refused, nothing left behind
  arm5  inner rc with the override=75               # GPU_HOLD_ALLOW_NESTED=1 still queues
gpu_hold_nested: 6 arms pass

$ (whole family, 13 tests)
gpu_hold_{child_identity,escape,fault_abort,group,hold_dir,mem_abort,nested,queue_state,queue,script_id,survivors,ticket_lost,tree}   all rc 0

The rebase matters here for a reason beyond cleanliness: main now carries #2744's env_survivors, #2751's gpu_state_dump and #2767's queue-time warning in the same file, and this branch's guard sits between them without disturbing any of them — which is the thing a rebase of a scripts/gpu-hold PR can quietly get wrong.

The design, unchanged from my review at 76f193c1 and still the part worth keeping

  • queue and token compared, because -q moves $QUEUE without moving $TOKEN: a nest on another queue still waits for the parent's token, and arm4b's tickets-left-in-q2=0 is what makes the refusal a guard rather than a new way to block the queue;
  • resolved paths on both sides, so -q ./q under -q /abs/q cannot slip through;
  • the scripts/hw-gate.sh companion, which is what keeps gpu-hold -- bash scripts/hw-gate.sh working instead of turning it into rc 2 — the gap I flagged on the sibling #2737, and the reason this is the mergeable one;
  • GPU_HOLD_ALLOW_NESTED=1 retaining the deliberate-nesting route, with arm5 showing it still queues.

One thing I would still put in the body before it merges: the GPU_HOLD_HELD_TOKEN marker is new in this head and the body's summary only names _QUEUE/_LABEL; the -q loophole it closes is the interesting half of the PR and a reader who skims will miss that it exists at all.

@bong-water-water-bong
bong-water-water-bong merged commit 0fc3fa9 into main Nov 16, 2026
10 of 11 checks passed

@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 11e4c65: READY. This is #2727's fix with both halves in, and I checked the half I had asked for by re-running the fixture that found the gap.

The token compare is in and it refuses the case a queue compare cannot see. GPU_HOLD_HELD_TOKEN appears 5 times in scripts/gpu-hold at this head, and the fixture that previously queued and burned its -w now returns 2:

outer:   gpu-hold -q $S/q1 -t 0.15            # takes $S/q1/TOKEN
payload: bash gpu-hold -q $S/q2 -t 0.05      # different queue, inherited token

gpu-hold: refusing to queue inside the ticket that is already running this command (label 'outer',
          token …/q1/TOKEN, rc 2). -q moves the queue but not the token, so this invocation would
          wait for the token its own parent holds and waste the window (engine#2727).
rc=2

Before the token half, that same fixture printed first in the queue, waiting for …/q1/TOKEN (held by: gpu-hold outer pid …) and exited 75 after its wait — the 14-minute idle window from the issue, with a queue position held the whole time.

Its own arms, run from this head's tree (not from a copy, so the relative npu-kernel-bitx.sh path is the real one):

tests/gpu_hold_nested_test.sh   6 arms pass   (arm4b: inner rc=2 AND tickets-left-in-q2=0)
whole gpu_hold_* family         12/12 rc 0

tickets-left-in-q2=0 is the assertion I would have asked for if it were missing: a refused claim must not take a queue position other lanes then wait behind.

One flake, reported rather than smoothed over: the first family run had gpu_hold_fault_abort_test.sh rc=1; run alone it passed (fault at 5 s -> rc 78 after 11s; clean -> 0; opt-out -> 0; … NPU fault in hold -> 78; a recovery notice does NOT abort), and a second full-family run was 12/12. The box has been taking amdxdna faults tonight, which is what that test deliberately provokes, so I am treating it as contention rather than as this PR — but if it recurs on a queued run, that test's take-time refusal is the thing to read first.

State at this head: ci completed/success, build completed/success, not a draft, MERGEABLE. hw-gate skips (it is not this PR's trigger) and pr-agent failed on an earlier head — neither is required by the ruleset, and neither touches the guard.

Scope check: 4 files — scripts/gpu-hold (+38), scripts/hw-gate.sh (+14), tests/gpu_hold_nested_test.sh (+100), the ctest registration — and the body says Fixes #2727, so the issue closes with it. The hw-gate.sh hunk is the one thing the issue did not ask for; it reads as making the hw-gate's own nested claim coexist with the new refusal, which is the shape scripts/npu-hold:41 documents as required, and I did not find a case where it weakens the refusal.

@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxmem/2727-nested-hold branch November 16, 2026 21:42
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Landed in the tree, but the installed copy was four features behind -- it is now current, and that means the nested-hold refusal is live on this box

The fleet has measured this class twice (engine#2538's script-id work: "16 h later it was the pre-#2538 copy with no take-time refusal at all"), so I checked the installed binary against origin/main rather than assuming the merge was in effect:

$ sha256sum ~/.local/bin/gpu-hold                       -> ed2560883623   (mtime 13:30)
$ git show origin/main:scripts/gpu-hold | sha256sum     -> 8424cab95101

$ .local/bin (installed)          main
  GPU_HOLD_ALLOW_NESTED   0         6
  GPU_HOLD_REPO           0         4
  GPU_HOLD_HELD_QUEUE     0         4

So every lane on this box was still running a gpu-hold with no nested-hold refusal -- the exact deadlock #2727 measured, at 14 minutes a window -- and with no GPU_HOLD_HELD_QUEUE, so a payload could not even see which queue it was inside. GPU_HOLD_REPO (the drift check) was missing too, which is the mechanism that is supposed to make this discovery automatic.

Fixed here: installed origin/main's copy (install -m 0755), hashes now match, bash -n clean, and the three guards are present in the installed file:

GPU_HOLD_ALLOW_NESTED: 6   GPU_HOLD_REPO: 4   GPU_HOLD_HELD_QUEUE: 4

The previous copy is kept at ~/.cache/scratch-i679/gpu-hold.installed-1330.bak until the next reboot, and no gpu-hold ticket was running when I replaced it (checked: empty queue, tracing_on=0, no gpu-hold process).

The ask this makes on the tree, not on me: GPU_HOLD_REPO exists precisely to notice this, and it only fires when a ticket runs -- a box that takes no tickets for four hours learns nothing. If the install step is not part of the merge loop (or a timer), then every merge to scripts/gpu-hold is advisory until someone re-installs by hand, and this will be the third instance rather than the last.

bong-water-water-bong added a commit that referenced this pull request Nov 17, 2026
…#2792)

#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.

Co-authored-by: bong-water-water-bong <[email protected]>
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.

gpu-hold: a payload that re-invokes gpu-hold on the same queue deadlocks for the whole window (nothing tells it it is already inside a ticket)

1 participant