Skip to content

os/v3/puppy: the NPU busy row also covers a non-streamed client, which must be refused at its short bound - #1033

Merged
bong-water-water-bong merged 2 commits into
mainfrom
1bit/npu-1024-plain-row
Nov 5, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
1bit/npu-1024-plain-row

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Why

chat-npu-queue (merged in #1031) starts a 16-token streamed chat 1 s into a 1000-token streamed one and requires the
second to be answered. Both arms stream, so the row cannot see the other half of the same fix — the reviewer of #1031
said so explicitly. A non-streamed request has no way to say "queueing" (no chunk, no comment, no header), so the serve
keeps a short bound for it, --queue-ms-plain (5000 ms), and answers 503 + Retry-After: 1 with type: device_busy.
Lemonade's agentic tool loop is exactly such a call site (src/app/src/renderer/components/panels/LLMChatPanel.tsx:654),
which is how the inconsistency was found.

What

  • chat-npu-queue-plain — the same long streamed chat owns the device; 1 s in, a non-streamed 16-token chat is
    sent. Pass requires: 503, a body that names the device as busy, a numeric Retry-After, the long chat still ending with
    [DONE], and no new TDR.
  • plain_queue_verdict() — the pure decision function, with eight --self-test cases: the refusal shape PASSes;
    being answered while the device is busy FAILs (that would mean the bound did not apply), as do a missing
    device_busy marker, a missing or non-numeric Retry-After, no status at all, a long chat cut before [DONE], and a
    TDR during the arm. bash os/mini/release-check.sh --self-test → release-check self-test PASS.
  • auth_post_watch() — a POST whose status, headers and body are all evidence. The existing got/got_slow
    helpers collapse a status into "did it answer", which is why a refusal was invisible to a row before this.
  • registered hardware-only in skip(), so a VM reports SKIP chat-npu-queue-plain with its reason.

Measured before writing it (one npu-hold ticket, npu-1024-plain, 2026-11-04 18:28:45–18:29:02, 17 s)

request result
A streamed, max_tokens: 1000 200, 14.76 s, 611 SSE frames, [DONE]
B non-streamed, max_tokens: 16, 1 s in HTTP 503 at t=5.001997 s, {"error":{"message":"the NPU is busy with another request","type":"device_busy"}}, Retry-After: 1

amdxdna ERROR 0, Array stopped dispatching 0.

What it can and cannot catch, said rather than implied

The non-streamed bound is unchanged by #1031 (it is main's 5 s bound, kept deliberately), so this row passes on a
pre-#1031 payload as well. Its job is to keep it that way — if someone later points the plain arm at the long queue, this
row goes red instead of a tool-loop call hanging silently — and to make the asymmetry visible in the shipped check rather
than only in docs/npu.md. It holds the device for the same ~14 s the streamed row already costs.

Refs #1024.

`chat-npu-queue` (merged in #1031) starts a 16-token streamed chat 1 s into a 1000-token one and
requires the second to be ANSWERED. Both of its arms stream, so it cannot see the other half of the
same fix: a **non-streamed** request has no way to say "queueing" - no chunk, no comment, no header - so
the serve keeps a short bound for it (`--queue-ms-plain`, 5000 ms) and answers
`503 + Retry-After: 1` with `type: device_busy`, which a client can act on. Lemonade's agentic tool loop
is exactly such a call site (`LLMChatPanel.tsx:654`), which is how this was found.

* `chat-npu-queue-plain`: the same long streamed chat owns the device; 1 s in, a NON-streamed 16-token
  chat is sent. It must come back 503, naming the device as busy, with a numeric `Retry-After` - and the
  long chat must still finish with `[DONE]`, with no new TDR.
* `plain_queue_verdict()`: the pure decision function, and `--self-test` pins its eight cases - the
  refusal shape PASSes; being *answered* while the device is busy FAILs (that would mean the bound did
  not apply), as do a missing `device_busy` marker, a missing or non-numeric `Retry-After`, no status,
  a long chat cut before `[DONE]`, and a TDR during the arm.
* `auth_post_watch()`: a POST whose status, headers and body are all evidence (the `got`/`got_slow`
  helpers collapse a status into "did it answer", which is why the refusal was invisible before).

Measured on this box before writing it (`npu-hold -l npu-1024-plain`, 2026-11-04 18:28:45-18:29:02):
A streamed 1000 tok = 200, 14.76 s, 611 SSE frames; B non-streamed 16 tok started 1 s in = **HTTP 503 at
t=5.001997 s** with `{"error":{"message":"the NPU is busy with another request","type":"device_busy"}}`
and `Retry-After: 1`; 0 driver errors, 0 TDR.

Honest about what it can and cannot catch: the non-streamed bound is unchanged by #1031 (it is main's 5 s
bound, kept deliberately), so this row passes on a pre-#1031 payload too. Its job is to keep it that way -
if someone later points the plain arm at the long queue, this row goes red instead of a tool-loop call
silently hanging - and to make the asymmetry visible in the shipped check rather than only in the docs.
`bash os/mini/release-check.sh --self-test` -> `release-check self-test PASS`.
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit bc76a63)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1024 - Partially compliant

Compliant requirements:

  • The NPU serve now refuses a second chat with 503 the NPU is busy with another request instead of queueing it
  • The fix includes a default --queue-ms of 300000 (5 minutes) for streamed requests
  • The fix includes a --queue-ms-plain of 5000 (5 seconds) for non-streamed requests
  • The fix ensures that while a streaming request waits, it writes an empty content delta once a second to prevent silent timeouts
  • The fix ensures that non-streamed requests are refused promptly at their own bound instead of waiting silently
  • The release check includes a test for both streamed and non-streamed arms

Non-compliant requirements:

  • None

Requires further human verification:

  • None

1031 - Partially compliant

Compliant requirements:

  • The NPU route serves one generation at a time (one KV cache)
  • A second request waits on Engine::mu with a 5s bound that was too short for single-user appliances
  • The 5s bound was chosen to prevent silent timeouts before the proxy's timer
  • The fix increases the default --queue-ms to 300000 (5 minutes) with a keep-alive mechanism
  • The fix adds a --queue-ms-plain default of 5000 (5 seconds) for non-streamed requests
  • The fix ensures that while a streamed request waits, it writes an empty content delta once a second
  • The fix ensures that non-streamed requests are refused at their own bound with 503 + Retry-After

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

Missing Test Coverage for TDR Detection

The plain_queue_verdict function includes checks for TDRs but the test cases do not cover all possible TDR scenarios. Specifically, the test cases for TDR detection could be more comprehensive to ensure that all failure modes are properly tested.

    if [ -z "$_t0" ] || [ -z "$_t1" ]; then
        printf 'PASS the non-streamed chat was refused at its short bound (503, Retry-After %s) instead of waiting silently; the kernel log was not readable, so no TDR was ruled out' "$_pr"
        return 0
    fi
    [ "$_t1" -gt "$_t0" ] && { printf 'FAIL the NPU logged a TDR during the non-streamed arm (%s -> %s): see dmesg' "$_t0" "$_t1"
                               return 0; }
    printf 'PASS the non-streamed chat was refused at its short bound (503, Retry-After %s) instead of waiting silently, no TDR (still %s)' "$_pr" "$_t1"
}
Potential Race Condition in Test Execution

The test execution in chat-npu-queue-plain uses background processes and sleep 1 to simulate concurrent requests. This approach could introduce race conditions or timing issues that might not be reliably reproducible in all environments.

( auth_post "$PLONG" "$API/api/v1/chat/completions" slow > "$PDIR/long.sse" 2>&1 ) &
PPID=$!
sleep 1
PW=$(auth_post_watch "$PSHORT" "$API/api/v1/chat/completions" "$PDIR/short.json")
wait "$PPID" 2>/dev/null
PLONG_BODY=$(cat "$PDIR/long.sse" 2>/dev/null)
PSHORT_BODY=$(cat "$PDIR/short.json" 2>/dev/null)
TDRP1=$(tdr_count)
VP=$(plain_queue_verdict "$PLONG_BODY" "${PW%% *}" "$PSHORT_BODY" "${PW#* }" "$TDRP0" "$TDRP1")
rm -rf "$PDIR"

@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: READY at a399b3494

This is the arm I asked for in the #1031 review — the one chat-npu-queue cannot see — and it is built the right way round: the pass is a refusal at the short bound, and being answered while the device is busy is the failure.

$ bash -n os/mini/release-check.sh                              -> ok
$ sh os/mini/release-check.sh --self-test                       -> release-check self-test PASS
  plain_queue_verdict's 8 cases: 503+Retry-After+device_busy PASS; 200-while-busy FAIL; no Retry-After FAIL;
  a 503 that says something else FAIL; status 000/empty FAIL; the long chat cut FAIL; a TDR during the arm FAIL;
  unreadable dmesg PASS with the caveat said out loud

The row is PSHORT with no "stream" field (so the engine takes the --queue-ms-plain path) behind a 1000-token
streamed PLONG, and auth_post_watch() captures status + Retry-After from headers rather than from the body, with a
wget -S fallback that says what it cannot see. Registered hardware-only (:26, :40), and it reuses the same
tdr_count() bracketing as its streamed sibling.

One nit, and it is the only reason this is not a clean sweep — read it before someone runs the check under bash:
PPID=$! at :1085 uses a name bash owns. Verified on this box:

dash           rc=0  waited 3s  assignment took: yes
busybox ash    rc=0  waited 3s  assignment took: yes      <- this is what the appliance's /bin/sh is
bash           rc=127 waited 0s assignment took: no   ("PPID: readonly variable")

So on the board (shebang #!/bin/sh → busybox) the row works, and in a VM the row is skipped because there is no
/dev/accel — the failure is only reachable by running the script with bash on a machine that has an NPU, where the
wait would return 127, PLONG_BODY would be read before [DONE], and the row would FAIL falsely. Rename it
(LPID=$!, as the streamed row's QPID already does) and that whole class is gone; it is worth the one word because
the appliance's shell is not the only one that will ever run this file.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit bc76a63

@bong-water-water-bong
bong-water-water-bong merged commit ec2a810 into main Nov 5, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/npu-1024-plain-row branch November 5, 2026 00:28

@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: READY at bc76a630

Rebase-only: own contribution hashes to e738073a5161 at this head and at a399b3494 — 101 lines, +101/−2, identical. My review stands as posted, including the one nit: PPID=$! at release-check.sh:1085 is a name bash makes readonly, so wait "$PPID" returns 127 and the row reads the long body before [DONE]; dash and busybox ash (the appliance's /bin/sh) take the assignment fine, which is why the shipped path works, but the one-word rename (LPID=$!, as the streamed row's own QPID does) removes the class.

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

Labels

Review effort 3/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant