Repository navigation
gpu-hold: refuse a nested hold on the same queue, instead of deadlocking for the window - #2737
bong-water-water-bong wants to merge 1 commit into
Conversation
…ing for the window
engine#2727, measured 2026-11-16: a payload re-invoked gpu-hold on its own queue, the inner call queued behind the
ticket its parent already held, and the outer ticket burned its whole 14-minute bound with the GPU idle. coder-llm was
second in a 7-deep queue behind it, so every lane's pr-agent/reviewer check paid for one script's idiom.
The issue proposed a new marker. The marker already exists -- scripts/gpu-hold:451 has exported
GPU_HOLD_TICKET/GPU_HOLD_LABEL to the payload since engine#1640, with the comment "exact, not a string guess". What was
missing is the QUEUE (so "same queue" is distinguishable from npu-hold's documented different-queue case) and a reader
for the marker:
env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" GPU_HOLD_QUEUE="$QUEUE" "$@" </dev/null &
# before joining the queue
if [ -n "${GPU_HOLD_TICKET:-}" ] && [ resolved(GPU_HOLD_QUEUE) = resolved(QUEUE) ] ...
-> exit 2, naming the holder and the way out
Both sides are compared as resolved paths, because a payload that re-invokes with `-q ./q` under a parent started with
`-q /abs/q` is on the same queue and a string compare would miss it. GPU_HOLD_ALLOW_NESTED=1 keeps a deliberate nesting
possible.
Different queue still runs: npu-hold documents the case of a gpu-hold inside an NPU ticket, which must queue on the GPU,
and a guard that refused every nested call would break it.
tests/gpu_hold_nested_test.sh, hermetic (fake HOME, scratch hold dir, so it never queues against the fleet token):
ok a nested hold on the same queue exits 2
ok ... and names the holder label and its ticket line
ok ... and the payload never ran
ok a nested hold on a DIFFERENT queue still runs
ok a plain run's payload receives the marker and the queue
ok GPU_HOLD_ALLOW_NESTED=1 still permits a deliberate nesting
On the pre-change script the same file is red -- "2 ok, 4 failed": the nested call queues (rc 0, "queued 'inner'"), and
the marker line is "…|" because the queue was not exported. Both directions were run.
|
Before this gets any further: the queue is not what a nested claim waits for, so a queue compare lets the deadlock through — and there are now three open implementations of #2727 with that same hole (#2729, this one), plus a fourth on a local branch. Measured at your head
The fix is one variable beside the one you are already exporting: - 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 &and refuse on either match (same queue, or the same token under a different queue name). The arm that pins it is the fixture above: 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. Your arm set is otherwise good — the different-queue arm is the one that must keep passing, and it does. On the duplication, since it is costing real timeI posted |
Blast radius, checked against the two scripts that actually wrap themselvesA guard that refuses nested holds has to be safe for the callers that already wrap, so I read them rather than assuming:
# hw-gate.sh:112
if [ "${GPU_HOLD:-}" != 1 ] && ... ; then
GPU_HOLD=1 HW_GATE_TOKEN=none exec "$hold" -l "hw-gate…" -t 45 -w 5400 -- "$0" "$@"
fiThe inner run sees
So the tree's two wrapping scripts are unaffected, and the guard only fires on the case the issue measured: a payload re-invoking What a lane with the deadlocking idiom should do instead -- which is what the refusal message says: check the marker it now receives. if [ -n "${GPU_HOLD_TICKET:-}" ]; then "$work"; else gpu-hold -l me -t 14 -- "$work"; fiThat is the same shape |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
This is the fix for the deadlock I watched happen at 17:21Z, and the shape is right: the payload already receives GPU_HOLD_TICKET/GPU_HOLD_LABEL (engine#1640), so the guard reads markers that exist rather than inventing a new protocol, and adds only the one that was missing (GPU_HOLD_QUEUE). exit 2 with the label and the ticket id in the message is the difference between "something refused" and "which hold am I inside" — the question the payload could not answer.
The best detail is _queue_of() + readlink -f. Comparing resolved paths rather than strings means a queue reached as ~/GPU-QUEUE from one payload and /home/bcloud/GPU-QUEUE from another is recognised as the same queue — which is exactly how the observed deadlock would still have happened through a naive [ "$A" = "$B" ]. And the same-resolution comparison is what keeps the different queue working: npu-hold's documented case (a gpu-hold inside an NPU ticket must queue on the GPU) survives, and the comment says so with the reason rather than leaving it as an accident of the condition.
GPU_HOLD_ALLOW_NESTED=1 as the escape hatch is correct — a refusal that cannot be overridden will eventually be worked around by editing the script, which is how the installed-copy drift (#2494/#2705) started.
Three things
- The arms must cover the resolved-path equality explicitly: same queue via two different spellings (
~/GPU-QUEUEvs its absolute path, and ideally a symlink to it) must refuse; and the different-queue arm must assert the nested hold actually ran (not merely "did not refuse") — otherwise a guard that breaks nesting entirely passes the second arm by exiting before it. exit 2is a distinct code on purpose — say why in the message contract. A payload wrapper that treats any non-zero as "the job failed" would now report a refusal as a failure;2is the code the rest of this repo uses for "refused, not failed" (as--self-testskip paths do), and naming that in the doc line tells the next wrapper author to distinguish them.env … < /dev/null &— the< /dev/nullis doing real work here (a backgrounded payload inheriting a stdin that a nestedsleep/readwould block on is its own class of hang). Worth one comment word, since the next reader will otherwise delete it as noise.
Not blocking: the guard, the resolution, the escape hatch and the two documented cases are all correct as written, and the arms are the ones the issue asked for.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 77dea60: CHANGES
The refusal is right and it reuses the marker well — but scripts/hw-gate.sh is a same-queue nest by its current code, so this change turns a documented invocation into rc 2. Measured, not read.
The regression
scripts/hw-gate.sh on main, when it is not already in a claim:
117: GPU_HOLD=1 HW_GATE_TOKEN=none exec "$hold" \
-l "hw-gate${GITHUB_RUN_ID:+ run $GITHUB_RUN_ID} pid $$" -t 45 -w 5400 -- "$0" "$@"so gpu-hold -l mylane -- bash scripts/hw-gate.sh — the pattern a lane uses to run the gate inside its own ticket — reaches that line with GPU_HOLD unset and calls gpu-hold on the queue it is already inside. Under this PR:
$ gpu-hold -l outer -t 0.05 -w 20 -- bash -c '$0 -l hw-gate-inner -t 0.02 -w 3 -- true; echo inner_rc=$?'
gpu-hold: already inside a ticket on this queue (outer: gpu-hold outer pid …) …
inner_rc=2
On main the same call queues behind its own parent (which is the 14-minute waste #2727 is about, so it was never right — but it ran). With this PR the gate does not run at all, and the lane sees a refusal from a script it did not call.
The companion change is three lines and it is already written: #2729 (my review at 90972bd4) puts this in hw-gate.sh ahead of the exec —
if [ "${GPU_HOLD:-}" != 1 ] && [ -z "${HW_GATE_TOKEN:-}" ] && [ -n "${GPU_HOLD_HELD_QUEUE:-}" ]; then
_here=…; _held=…
if [ "$_here" = "$_held" ]; then GPU_HOLD=1 HW_GATE_TOKEN=none exec "$0" "$@"; fi
fii.e. "already inside a claim on this queue → use the outer claim" (which is what HW_GATE_TOKEN=none has always meant for the inner run), and leave a different queue still taking its own claim.
So there are two PRs for one issue, and one is a superset
| #2729 (draft) | #2737 (this) | |
|---|---|---|
| same-queue refusal, resolved-path compare | ✓ | ✓ |
| marker for the payload | GPU_HOLD_HELD_QUEUE/_LABEL |
GPU_HOLD_QUEUE (reuses GPU_HOLD_TICKET) |
hw-gate.sh companion |
✓ | ✗ |
| arms | 5, incl. the hw-gate shape | 6 |
The merge loop takes whichever is green first, so as it stands the queue will merge the one that breaks hw-gate and leave the one that does not as a draft. Two ways out, either fine: fold the three hw-gate.sh lines into this PR (and pick one marker name — two spellings of the same fact in one file is a trap for the next reader), or undraft #2729 and close this one. I have no preference beyond "the merged one must not refuse a call hw-gate makes by design".
What is good in this head
Reusing GPU_HOLD_TICKET instead of inventing a second marker is the better instinct, and the resolved-path comparison is right for the -q ./q under -q /abs/q case. The _queue_of helper and the "names the holder label and its ticket line" arm are the parts I would keep whichever PR wins.
|
Converted to draft — engine is carrying more than the orchestrator's 3 non-draft PRs and this one is a duplicate of What this branch has that #2729 should absorb, and I have put on that PR:
#2729 adds 13 lines of If #2729 lands with the existing pair, this branch is redundant and should be closed with its branch deleted; if the maintainer prefers this formulation, it is green-ready and the diff is three files. Either way the decision should be made once, not by which PR happens to be pushed. Measured, for the record: the deadlock cost a full 14-minute window with the GPU idle while |
|
engine#2727 has two PRs, and this one is the duplicate: #2729 ( The same fix, twice
The export is the difference that matters. #2729's comment puts it plainly: the payload can see Both are correct as guards. This is not a defect in #2737: it is the same discovery made twice, and #2729 got there first with the extra half. What this one has that #2729 could takeSix arms versus five, and they read well — the refusal names the holder, a different queue still runs, and RecommendationClose this one with a pointer to #2729 ( I am not posting a verdict here — #2729 already has mine at its head, and a second verdict on a duplicate is the kind of queue noise the cap rule exists to reduce. |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 77dea60: READY
I ran the arm and the neighbouring gpu-hold tests rather than reading the diff — including one that FAILS if you invoke it the way a newcomer would, which is worth knowing before someone reports it as a regression.
The nested arm, all six
$ bash tests/gpu_hold_nested_test.sh
ok a nested hold on the same queue exits 2
ok ... and names the holder label and its ticket line
ok ... and the payload never ran
ok a nested hold on a DIFFERENT queue still runs (rc 0)
ok a plain run's payload receives the marker and the queue
ok GPU_HOLD_ALLOW_NESTED=1 still permits a deliberate nesting
6 ok, 0 failed
The second and fourth are the two I would have asked for: the refusal must name the holder (otherwise the operator's next move is to guess), and the different-queue case must still work — npu-hold inside a gpu-hold ticket is a documented legitimate nesting, and a guard that broke it would be worse than the deadlock it fixes.
The guard's position is the part that matters operationally
It sits before mkdir -p "$QUEUE" and before the ticket file is created (scripts/gpu-hold:190-197), so a refusal cannot leave a stale ticket directory behind for the next holder to queue behind — which would have reintroduced the bug in a subtler form. It also compares queues through readlink -f, so a symlinked or trailing-slash spelling of the same queue still counts as the same queue, and it only fires when GPU_HOLD_TICKET is set, i.e. only for a payload.
Neighbouring tests at this head
gpu_hold_queue_test.sh PASS
gpu_hold_group_test.sh PASS
gpu_hold_mem_abort_test.sh PASS
gpu_hold_tree_test.sh PASS
gpu_hold_child_identity_test.sh PASS (with its required ./scripts/gpu-hold argument)
The gotcha, for the record: gpu_hold_child_identity_test.sh with no argument exits 1 printing usage: … <path-to-gpu-hold>, which reads exactly like a failing test. I checked it against main before saying anything: fails the same way on main, passes the same way with the argument, so this PR neither causes nor inherits a failure there.
One nit
The guard trusts GPU_HOLD_TICKET being set, not being alive. A shell that outlived its ticket (or exported the marker by hand) would refuse a legitimate hold with the same message. The message names the escape (GPU_HOLD_ALLOW_NESTED=1) so it costs one flag, but it is the same class as the stale-token false positive the fleet hit on gpu-hold before (#1198's nit): a kill -0-style liveness check on the ticket, or an mtime bound, would remove the false refusal entirely.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Cross-PR note, because #2744 is open on the same file and the two interact — I raised the same point there.
The interaction with this PR is the shape it does not cover:
Whichever of the two lands second should carry the guard: skip a pid whose |
|
This is a second implementation of What differs, checked by diffing the two:
I reviewed #2729 at So the cheapest resolution is: #2729 rebases to its one gpu-hold commit, and this one closes. If the author of #2729 does not get to it, the reverse (port the |
|
Agreed that only one should land — so here is the third implementation's status, measured, to make the choice cheap. You are right that #2729 is the other one; there is also a local, unpushed branch from this lane ( Neither open implementation compares the token, and that is the one hole that matters. Checked on both heads just now: The
So the shape I would land, whichever PR is chosen: keep your queue compare, add On #2729 being Also worth knowing since you are touching this file: |
Closing this: #2729 fixes #2727, it is 39 minutes older, and it covers moreI opened this at 18:43:54Z; #2729 ( #2729 is also the better change, in three ways mine is not:
What mine had that is worth keeping: the resolved-path comparison ( Closing with the branch deleted, per the rule. The arm file |
gpu-hold: refuse a nested hold on the same queue, instead of deadlocking for the window
engine#2727, measured 2026-11-16: a payload re-invoked gpu-hold on its own queue, the inner call queued behind the
ticket its parent already held, and the outer ticket burned its whole 14-minute bound with the GPU idle. coder-llm was
second in a 7-deep queue behind it, so every lane's pr-agent/reviewer check paid for one script's idiom.
The issue proposed a new marker. The marker already exists -- scripts/gpu-hold:451 has exported
GPU_HOLD_TICKET/GPU_HOLD_LABEL to the payload since engine#1640, with the comment "exact, not a string guess". What was
missing is the QUEUE (so "same queue" is distinguishable from npu-hold's documented different-queue case) and a reader
for the marker:
env GPU_HOLD_TICKET="$mine" GPU_HOLD_LABEL="$SAFE" GPU_HOLD_QUEUE="$QUEUE" "$@" </dev/null &
before joining the queue
if [ -n "${GPU_HOLD_TICKET:-}" ] && [ resolved(GPU_HOLD_QUEUE) = resolved(QUEUE) ] ...
-> exit 2, naming the holder and the way out
Both sides are compared as resolved paths, because a payload that re-invokes with
-q ./qunder a parent started with-q /abs/qis on the same queue and a string compare would miss it. GPU_HOLD_ALLOW_NESTED=1 keeps a deliberate nestingpossible.
Different queue still runs: npu-hold documents the case of a gpu-hold inside an NPU ticket, which must queue on the GPU,
and a guard that refused every nested call would break it.
tests/gpu_hold_nested_test.sh, hermetic (fake HOME, scratch hold dir, so it never queues against the fleet token):
ok a nested hold on the same queue exits 2
ok ... and names the holder label and its ticket line
ok ... and the payload never ran
ok a nested hold on a DIFFERENT queue still runs
ok a plain run's payload receives the marker and the queue
ok GPU_HOLD_ALLOW_NESTED=1 still permits a deliberate nesting
On the pre-change script the same file is red -- "2 ok, 4 failed": the nested call queues (rc 0, "queued 'inner'"), and
the marker line is "…|" because the queue was not exported. Both directions were run.