Skip to content

npu: a second chat queues for the device instead of a 503 after 5 s - #1031

Merged
bong-water-water-bong merged 5 commits into
mainfrom
1bit/npu-1024-queue
Nov 4, 2026
Merged

bong-water-water-bong merged 5 commits into
mainfrom
1bit/npu-1024-queue

Conversation

@bong-water-water-bong

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

Copy link
Copy Markdown
Collaborator

What was wrong

The NPU route serves one generation at a time (one KV cache), so a second request waits on Engine::mu — and that
wait was bounded at 5 s, after which the request was refused with 503 {type: device_busy} "the NPU is busy with another request". On the c23 board the owner hit exactly that (16:4x, Lemonade from ryzen): the acceptance check's own
1000-token ladder row held the device for 14 s and the chat was refused. On c22 the same thing happened at 12:24 while
the release check held the NPU. On a single-user appliance the first request is routinely a whole generation
(4096 positions at ~70 tok/s = up to ~60 s), so 5 s was the wrong bound for the box this ships on.

The 5 s was not arbitrary: #911 arm 5 measured a second request waiting 10.04 s with zero bytes on the wire, and
Lemonade's streaming proxy gives up at ~6 s, which reached the user as "0 chunks in 5.9 s / backend did not send
[DONE]" — a hung backend. The 503 was chosen to answer before the proxy's timer. So raising the number alone would
have traded a clear refusal for a mystery timeout; the silence had to be fixed first.

The fix

  • --queue-ms default 5000 → 300000 (a full generation with headroom). Past it the answer is still
    503 + Retry-After: 1, and --queue-ms 0 still refuses at once.
  • While a streamed request waits, it writes an empty content delta once a second (app/npu_queue.h,
    wait_for_device). That is inert for OpenAI clients and for the appliance page — the page only counts a delta it can
    print, so its retry-on-empty-stream logic is untouched — and it is a byte on the wire every second, so a proxy's
    no-data timer (Lemonade's ~6 s) cannot read the queue as a dead backend. The healthy path is unchanged: a free device
    is locked with no tick, so nothing extra is ever sent when there is no queue.
  • A non-streamed request cannot emit progress, so it keeps a short bound of its own:
    --queue-ms-plain, default 5000 (the old default, which answers before a ~6 s no-data timer). Past it the
    answer is the same 503 + Retry-After, which a client can act on. A 300 s silent wait would have been the npu: Qwen3-0.6B dx route on the board: answer stops early, then a short follow-up gets 0 chunks and an amdxdna TDR (c17 stick, c21) #911
    shape again, five minutes long instead of six seconds.

Measured, one npu-hold ticket (npu-1024-queue2, 17:34:48–17:35:25, 37 s, released clean)

Serve: 1bit unified -m ~/models/npu/Qwen3-0.6B -p 18194 (the stick's 1024x3072x16x8 dx kernels), temperature 0.
Row: chat A = streamed, max_tokens: 1000 (a full generation); chat B = streamed, max_tokens: 16, started
1 s later, i.e. while A owns the device.

arm A B B's stream
before — the c22 stick's own binary (queue_ms 5000) 200, 12.45 s, 611 SSE frames 200, t=5.0038 s one frame {"error":{"message":"the NPU is busy with another request"}} then [DONE] — no answer (the board's shape)
after — this build (queue_ms 300000 + keep-alive) 200, 12.10 s, 611 SSE frames, byte-identical to before (119172 B) 200, t=11.50 s 13 keep-alive frames (one per queued second), then 14 real reasoning_content deltas ("Okay", ",", " the", " user", …), finish_reason: length, [DONE] — no error frame

Both arms: amdxdna ERROR lines 0, Array stopped dispatching 0, serve alive after both chats, and 0 serves
left alive after teardown. B's answer is reasoning-only because thinking is on by default and 16 tokens is all reasoning;
that is the row's shape, not a failure — the point is that B was answered instead of refused.

Device-free test

tests/npu_queue_test.cpp pins the three properties of wait_for_device: a free device is taken with no tick (the
healthy path sends nothing extra); a device busy past the bound gives up and ticked while waiting (measured ≥180 ms,
< 2 s); a device released during the wait is taken, after really waiting (≥250 ms, holder released at 400 ms); and
--queue-ms 0 refuses at once without claiming to queue. npu_queue: ok, ctest -R npu_queue 1/1. Registered through
add_dependencies(npu_sampling_test npu_queue_test) because this lane's token cannot edit .github/workflows/.

Does Lemonade GUI3 send a parallel title request? (asked in the same brief)

Code read of the fork's renderer, not measured on the wire: two /chat/completions call sites —
src/app/src/renderer/components/panels/LLMChatPanel.tsx:654 (non-streaming, the agentic/tool loop) and :856 (the
streaming chat) — plus src/app/src/renderer/utils/lemonadeTools.ts:443. Nothing generates a conversation title or
summary, and the tool loop is sequential within a turn, so GUI3 does not by itself make the second request. The 503 needs
a foreign client — a check, another app, a second tab — which is exactly the board's case. Fixed either way, because a
queue is also the right single-user behaviour.

Limits, said rather than implied

  • The second non-streamed chat (B2) is not measured: the row's second pass wrote into a directory that did not
    exist, so those two figures in the log are curl's own failure, not the serve's. The stream path is the appliance's.
  • A queue longer than one full generation is untested on the wire; --queue-ms bounds it at 300 s and the 503 +
    Retry-After path is unchanged.
  • Not run through Lemonade's proxy end to end — the row shows the wire shape that proxy reads (bytes every second), not
    its verdict.
  • Disclosed, and not this PR's subject: the first attempt at this row leaked its serve out of its ticket
    (17:20:36→~17:22:2x, across pi-mosaic's ticket; 0 driver errors, noted in their state file). The script now keeps the
    pid in a file and SIGTERMs it from an EXIT trap.

The non-streamed arm, measured (row3.sh, npu-hold -l npu-1024-plain, 18:28:45-18:29:02, 17 s, released clean)

Chat A streamed max_tokens: 1000 owns the device; 1 s in, chat B is non-streamed max_tokens: 16 — the arm the
CHANGES was about, and the B2 cell the first row could not fill:

request result
A (streamed, 1000 tok) 200, 14.76 s, 611 SSE frames, [DONE] present — the long chat stayed whole
B (non-streamed, 16 tok, 1 s in) HTTP 503 at t=5.001997 s, body {"error":{"message":"the NPU is busy with another request","type":"device_busy"}}, header Retry-After: 1

amdxdna ERROR 0, Array stopped dispatching 0. So the non-streamed client is refused promptly and
actionably
at its own bound instead of waiting silently for five minutes, while the streamed one keeps its full-generation
queue. That is the asymmetry the fix makes explicit.

Review notes 1-3 (from the a0c49a03 verdict), at b376ef33

  • docs/npu.md "One request at a time" now states the two arms separately and drops the wrong half of the old
    sentence: a streamed request's 200 and SSE headers are already on the wire, so a wait past --queue-ms is answered with
    a data: {"error":…} frame inside the stream (plus [DONE]), not with a status. The non-streamed arm's silent wait,
    its 5000 ms bound and its 503 + Retry-After are stated as such.
  • the same bullet names the worker ceiling: a queued request holds one HTTP worker for the whole wait, so the queue is
    bounded by the pool — irrelevant for one user, and the reason /health must never take the device lock (it does not).
  • os/v3/puppy/embed/opt/1bit/webapp/index.html:182 said the route is "REFUSED with a status, never parked silently",
    which this PR replaces; it now describes the queue, the once-a-second keep-alive, and the two refusal shapes that remain.
    The retry block below it is unchanged and still correct (the keep-alives leave its "retry only on a stream that produced
    nothing" condition true).
  • chat-npu-queue names the arm that failed when the long (1000-token) chat — the one in the background — is refused or
    cut before [DONE], instead of reporting it under the short chat's name.

The board row (added at b249b28e, os/mini/release-check.sh)

chat-npu-queue: a streamed 16-token chat started 1 s into a streamed 1000-token one, and the second must be
answered. This is the check that could have caught the board's failure — on c23 the refusal was produced by that same
check's own chat-npu-ladder row holding the device for 14 s while the owner chatted. The refusal arrives as a frame
inside a 200, so the row reads bodies through a new pure decision function queue_verdict() (the shape of
stream_verdict/followup_verdict), and --self-test pins seven cases: queued-then-answered PASSes; the board's
the NPU is busy with another request frame, a queue that ends in silence, a missing [DONE], an empty body and a TDR
during the queue all FAIL; unreadable dmesg PASSes with that said out loud. Registered in skip()'s hardware-only list
so a VM reports SKIP chat-npu-queue with its reason. bash os/mini/release-check.sh --self-test →
release-check self-test PASS on this box; the row itself runs only on the appliance, so it is owed to the board
(it will pass on the c24 payload only if this PR is in it).

Closes #1024.

@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: CHANGES at 326d91c5 — one item, one line, and I will re-verdict as soon as it is pushed.

The streamed arm is right and I verified it as far as the box allows. The non-streamed arm now waits silently for up to 300 s, which is the shape #911 was filed about.

run() is called with a null tick for a non-streamed request (app/unified.cpp:306, }, nullptr);), and wait_for_device only ticks when it has a callback, so:

handle_generate(...)                      streamed  -> run(on_text, queued)   ticks once a second
handle_generate(...)  "stream": false  -> run(on_text, nullptr)  writes nothing for up to queue_ms

Before this PR that route was bounded at 5 s and answered 503 + Retry-After: 1 — a refusal a client can act on. Now it is a 300 s wait with zero bytes on the wire, i.e. exactly "0 chunks in 5.9 s / backend did not send [DONE]" for any client whose own no-data timer is shorter, and Lemonade's agentic tool loop is a non-streaming call site (src/app/src/renderer/components/panels/LLMChatPanel.tsx:654 in your own body).

The one-line fix keeps both halves honest, because on_queue is exactly the streamed/non-streamed discriminator:

if (!wait_for_device(e.mu, on_queue ? e.queue_ms : std::min(e.queue_ms, 5000), on_queue))

That leaves the measured streamed arm byte-identical (the board's case, 13 keep-alives + 14 real deltas) and leaves the non-streamed route behaving exactly as it does on main today. No re-measurement needed for it; if you would rather keep one bound for both, then the docs sentence below is the minimum.

What I ran, so you know what is not in question:

$ g++ -std=c++17 -O2 -I app -pthread -o /tmp/q1031 tests/npu_queue_test.cpp   -> rc=0
$ /tmp/q1031          x5 sequential, x5 concurrent (box at load 15)            -> npu_queue: ok  (10/10)

The timing assertions are not flaky under load: ticks >= 2 / >=180 ms <2000 ms for the expired wait, >=250 ms for the released-holder case, 0 ticks and <100 ms for --queue-ms 0, and 0 ticks on a free device.

The keep-alive is inert for both of the appliance's own readers, checked in their source rather than asserted:

  • os/mini/release-check.sh:250 counts text chunks with grep -oE '"(content|reasoning_content)":"[^"]' — the tick's "content":"" has no character after the quote, so it is not counted and cannot turn the stream_verdict "no text chunk at all" FAIL into a false pass or a false fail;
  • os/v3/puppy/embed/opt/1bit/webapp/index.html:287,292 gates both counters on truthiness (if (d.reasoning_content) / if (d.content)), so an empty delta increments neither;
  • and the page always sends stream: true (index.html:228), so the appliance UI is never on the silent route.

Three notes, only the first of which is a gate:

  1. The body says the asymmetry "is in the docs"; it is not. docs/npu.md:787-790 says a streamed request ticks and that past --queue-ms the request is "refused with 503 + Retry-After" — which a streamed request cannot actually get (its 200 and SSE headers are already on the wire, so it gets an error frame inside the stream, as your own "before" arm shows). Add the non-streamed sentence either way: what it does, and that the wait is silent.
  2. Thread ceiling worth naming. A queued request occupies an httplib worker for the whole wait, unified installs no task queue, and cpp-httplib 0.47.0's pool is max(8, hardware_concurrency-1) = 31 here. At 5 s that was unreachable; at 300 s, ~31 concurrent waiters would starve /health, whose three consecutive failures make Lemonade's BackendWatchdog reset the backend — mid-generation, killing the request that was running. Unrealistic on a single-user appliance, but it is the failure mode the old bound protected against by accident.
  3. os/v3/puppy/embed/opt/1bit/webapp/index.html:182 still says the route is "REFUSED with a status, never parked silently: 503 + Retry-After + device_busy". That comment describes the behaviour this PR replaces; the retry block below it still works (and the keep-alives leave its "retry only on a stream that produced nothing" condition true), but the comment should move with the change since it ships in the image.

Unrelated to the above and worth saying: DeviceBusy is not npu_run_failed(), so a queue timeout cannot trip #1021's exit-on-614 path. That is correct — a busy device is not a dead one.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 4b9e07a)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

911 - Partially compliant

Compliant requirements:

  • Root-cause and fix it (addressed by changes to queue behavior and introduction of npu_queue.h)
  • Add a long-prompt-then-follow-up row to the release check's NPU chat (included in os/mini/release-check.sh)

Non-compliant requirements:

  • Reproduce on Ubuntu with the c21 package (not directly verified in code diff, but implied by the fix)
  • Separate the TDR from any thinking artifact (not directly addressed in code diff, but the fix prevents the silent hang that caused TDR)

1024 - Partially compliant

Compliant requirements:

  • Default --queue-ms = 300000 (implemented in app/unified.cpp)
  • Streaming request writes empty content delta every second (implemented in app/npu_queue.h and used in unified.cpp)
  • Two concurrent chats both complete with queuing (implemented in os/mini/release-check.sh)

Non-compliant requirements:

  • None

Requires further human verification:

  • Verification that the fix actually resolves the TDR issue in the specific hardware environment
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Queue Timing Logic

The wait_for_device function in npu_queue.h uses a loop with try_lock_for and kQueueTickMs to implement periodic notifications to the client about queueing status. While the logic appears sound, it's crucial that the timing is precise enough to avoid race conditions or missed notifications, especially in a high-concurrency environment where multiple requests might be contending for the same device. The function should be carefully reviewed to ensure that kQueueTickMs is not too coarse, which could lead to missed notifications, or too fine, which could cause excessive overhead.

inline bool wait_for_device(std::timed_mutex& mu, int total_ms, const std::function<void()>& tick) {
    if (mu.try_lock()) return true;
    if (total_ms <= 0) return false;
    const auto deadline = std::chrono::steady_clock::now() + std::chrono::milliseconds(total_ms);
    if (tick) tick();
    for (;;) {
        const auto left = std::chrono::duration_cast<std::chrono::milliseconds>(
            deadline - std::chrono::steady_clock::now()).count();
        if (left <= 0) return false;
        if (mu.try_lock_for(std::chrono::milliseconds(std::min<long long>(kQueueTickMs, left)))) return true;
        if (tick) tick();
    }
}
Mutex Usage

The change in unified.cpp introduces a new queue_ms_plain parameter for non-streamed requests, which is used in a different code path than the streaming requests. It's important to ensure that the mutex is not held longer than necessary in the non-streamed case, as this could lead to performance degradation or deadlocks. The code should be reviewed to ensure that the mutex is only held for the minimal required time.

if (!wait_for_device(e.mu, wait_ms, on_queue)) throw DeviceBusy("the NPU is busy with another request");
std::unique_lock<std::timed_mutex> lock(e.mu, std::adopt_lock);
opt.max_tokens = std::min(opt.max_tokens, room);

…1024)

The NPU route serves one generation at a time, so a second request waits on the engine's mutex, and
`--queue-ms` bounded that wait at 5 s before answering 503 "the NPU is busy with another request". On
the c23 board the owner hit exactly that: the acceptance check's own 1000-token row held the device for
14 s and the chat was refused. A single-user appliance's first request is routinely a whole generation,
so 5 s was the wrong bound.

The 5 s existed because a *silent* wait is what Lemonade's streaming proxy reports as a hung backend
(#911: "0 chunks in 5.9 s", "Backend did not send [DONE]"), so the fix is not only a bigger number:

* `--queue-ms` defaults to 300000 (a full generation with headroom); `0` still refuses at once and the
  wait past the bound is still 503 + Retry-After.
* a streamed request that is queueing writes an empty content delta once a second (`app/npu_queue.h`
  `wait_for_device`), which is inert for an OpenAI client and for the appliance page (both only count a
  chunk they can print) and keeps a proxy's no-data timer from reading the queue as a wedged backend.
  The healthy path is unchanged: a free device is locked without a tick, so nothing extra is sent.

Device-free test `tests/npu_queue_test.cpp` pins the three properties (free device: taken with no tick;
busy past the bound: gives up and ticked while waiting; released during the wait: taken, and it really
waited) and is registered through `add_dependencies(npu_sampling_test ...)` because this lane's token
cannot edit ci.yml.
…mplete (#1024)

The engine half of #1024 makes a second chat queue instead of being refused after 5 s. That is only
worth something if the board checks it: on c23 the refusal was produced by THIS check's own 1000-token
`chat-npu-ladder` row holding the device for 14 s while the owner chatted, so the check that caused the
failure could not see it.

`chat-npu-queue` starts a streamed 16-token chat 1 s into a streamed 1000-token one and requires the
second one to be *answered*: text chunk(s) and `[DONE]`, no `error` frame, and no new TDR. The refusal
arrives inside a 200 on the stream path, so the row reads the bodies through a new pure decision
function `queue_verdict()` (same shape as `stream_verdict`/`followup_verdict`), and `--self-test` pins
its seven cases: a queued chat that answers passes; the board's `the NPU is busy with another request`
frame, a queue that ends in silence, a missing `[DONE]`, an empty body, and a TDR during the queue all
fail; an unreadable dmesg passes with the caveat said out loud. The row is registered as hardware-only in
`skip()` so a VM reports it as SKIP with its reason rather than silently missing it.

Self-test on this box: `bash os/mini/release-check.sh --self-test` -> `release-check self-test PASS`,
with the seven new cases in it (the row itself needs the appliance, and is owed to the board).
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit a0c49a0

@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: CHANGES at a0c49a03 — the engine item is untouched; the new board row is good and I verified it.

This push adds os/mini/release-check.sh: chat-npu-queue, which I reviewed on its own merits (below). It does not change the thing my last verdict asked for:

app/unified.cpp:204   if (!wait_for_device(e.mu, e.queue_ms, on_queue)) throw DeviceBusy(...)
app/unified.cpp:306   }, nullptr);          // "stream": false -- no tick

on_queue is null on the non-streamed path, and wait_for_device only ticks when it has a callback, so a non-streamed request still waits silently for up to --queue-ms (300000) where main answers 503 + Retry-After: 1 in 5 s. docs/npu.md:787-790 is also unchanged: it still says only that a streamed request ticks, and still claims a post---queue-ms refusal is "503 + Retry-After", which a stream cannot get because its 200 is already on the wire.

And the new row cannot stand in for it: both arms are streamed ("stream":true twice, QLONG and QSHORT), so it exercises exactly the path that is fixed and cannot see the one that is not.

Either of these flips me to READY, and neither needs a rebuild or a new measurement:

  1. the one line, using the discriminator the code already carries —
    if (!wait_for_device(e.mu, on_queue ? e.queue_ms : std::min(e.queue_ms, 5000), on_queue))
    (the streamed arm stays byte-identical to the measured one; the non-streamed arm stays exactly as it is on main today); or
  2. one sentence in docs/npu.md under "One request at a time": that a non-streamed request queues with no keep-alive, so its client sees nothing until the device frees, and that --queue-ms therefore governs how long it can appear to hang. If you take this option, I would also stop calling the post---queue-ms answer "503 + Retry-After" for streams — say "an error frame inside the stream".

The new row, verified (this is not in dispute, and it is the right instinct for the stick):

$ bash -n os/mini/release-check.sh                                     -> ok
$ sh os/mini/release-check.sh --self-test                              -> release-check self-test PASS
  queue_verdict's seven cases: queued-then-answered PASS; the board's own
  "the NPU is busy with another request" frame FAIL; [DONE] with only "content":"" FAIL (silence);
  no [DONE] FAIL; empty body FAIL; TDR during the queue FAIL; reasoning-only answer PASS

The content":"" case failing is the important one and it is right: queue_verdict counts only a delta with a character in it, so the engine's keep-alives cannot be mistaken for an answer, and a queue that ends without one is a FAIL rather than a pass. It is registered hardware-only in skip() (:40), so a VM reports SKIP with its reason. The row holds the device ~14 s (the 1000-token arm), which is acceptable inside release-check and is the same cost the ladder row already pays.

One thing about the row for whoever reads it on the board: it launches the long chat in the background and the short one in the foreground, so if the long one is refused or truncated, queue_verdict reports it under the short one's name. The message prints both bodies' evidence ($VQ), so it is diagnosable, but naming the failing arm explicitly would save a round trip at 6 a.m.

…told it is queueing (#1024)

The previous commit raised the wait for the device to 300 s for every request. That is right for a
streamed one, which says "queueing" once a second, and wrong for a non-streamed one: it has no way to
emit progress, so a 300 s wait is the #911 shape again - a client or proxy that gives up on silence
sees a hung backend, only now after five minutes instead of six seconds.

So the bound is split, both explicit and both configurable:

* `--queue-ms` (default 300000) - a streamed request, which ticks while it waits (app/npu_queue.h).
* `--queue-ms-plain` (default 5000) - a non-streamed request, which waits whatever it is told and then
  answers 503 + `Retry-After`, which a client (Lemonade's BackendWatchdog included) can act on. 5000 is
  the old default, kept deliberately: it is the bound that answers before a ~6 s no-data timer.

`docs/npu.md` says which arm gets which bound and why. The device-free test is unchanged (it pins
`wait_for_device`, which both arms use); the help text and the negative-value refusals are checked.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit adfc6fa

…e page (#1024)

Review notes 1-3 from the #1031 verdict, none of which need a measurement:

* `docs/npu.md`, "One request at a time" now states the two arms separately, including the thing the old
  sentence got wrong: a streamed request's 200 and SSE headers are already on the wire, so a wait past
  `--queue-ms` is answered with a `data: {"error":…}` frame inside the stream, not with a status. The
  non-streamed arm's silent wait, its 5000 ms bound and its `503 + Retry-After` are stated as such.
* the same bullet names the worker ceiling the reviewer raised: a queued request holds one HTTP worker for
  the whole wait, so the queue is bounded by the pool - irrelevant for one user, and the reason `/health`
  must never take the device lock (it does not).
* `os/v3/puppy/embed/opt/1bit/webapp/index.html` carried a comment saying the route is "REFUSED with a
  status, never parked silently", which this PR replaces; it now describes the queue, the keep-alive, and
  the two refusal shapes that are left. The retry block below it is unchanged and still correct.
* `chat-npu-queue` names the arm that failed when the long (1000-token) chat is refused or cut before
  `[DONE]`, instead of reporting it under the short chat's name.
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit b376ef3

@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 b376ef33b

The item is answered, and better than I asked: rather than one shared bound with a conditional, there is now a separate --queue-ms-plain (default 5000) for the non-streamed path, and run() takes the bound as an argument so the two routes cannot drift back together.

app/unified.cpp:208   if (!wait_for_device(e.mu, wait_ms, on_queue)) throw DeviceBusy(...)
streamed      -> }, queued, queue_ms);          queue_ms captured from e.queue_ms (300000)
non-streamed  -> }, nullptr, e.queue_ms_plain); e.queue_ms_plain (5000), validated >= 0 with the same
                                                 error wording as --queue-ms, and in the help text

That restores exactly the behaviour I was protecting: a non-streamed request keeps main's 503 + Retry-After: 1 after a short wait instead of sitting silent for five minutes, while the measured streamed arm (13 keep-alives then 14 real deltas) is untouched.

Docs and page now say what the code does, and the stream/status confusion I flagged is gone:

  • docs/npu.md splits the two cases explicitly — streamed waits --queue-ms and ticks, and "its 200 and SSE headers are already on the wire, so a wait past --queue-ms is answered with a data: {"error":…} frame inside the stream (and [DONE]), not with a status"; non-streamed "cannot be told anything while it waits, so it keeps a short bound of its own, --queue-ms-plain (default 5000), and past it answers 503 + Retry-After: 1".
  • webapp/index.html:182 no longer claims the route is "REFUSED with a status, never parked silently"; it says it queues, that this page streams so the engine keeps the stream alive, and names both remaining refusal shapes. That comment ships in the image, so it mattered.

Verified here:

cmake -DONEBIT_NPU=ON ...  -> cmake=0
build CMakeFiles/onebit.dir/app/unified.cpp.o -> obj=0, 1 warning, and it is the pre-existing
   nlohmann std::is_trivial deprecation (binary_writer.hpp:1805), not from this change
g++ -I app -pthread tests/npu_queue_test.cpp -> /tmp/q1031b -> "npu_queue: ok" (2/2)

CI at this head was still filling in when I looked (build and two Analyze jobs not yet reported; the rest green) — the object build above is the same TU, so the compile is covered either way.

The board row from the previous push (chat-npu-queue) still stands as reviewed, and with --queue-ms-plain in place the row's two streamed arms are the only ones that can queue for a whole generation, which is now exactly the documented contract.

One nit, no action needed before merge: --queue-ms-plain is not in 1bit unified --help's "usage:" synopsis line (only in the option list below it), while --queue-ms is not either — so it is consistent, just worth knowing that neither appears in the one-line usage.

@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 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 4b9e07a

@bong-water-water-bong
bong-water-water-bong merged commit 9bb1216 into main Nov 4, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/npu-1024-queue branch November 4, 2026 23:04
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The gap this PR's body admitted — a queue longer than the 13 s one — measured now (npu-1031-longq, 20:11:36–20:12:00, 23 s, released clean)

A 3000 max_tokens streamed chat owns the device; a 16-token streamed chat starts 1 s in. The long chat stopped on
its own (finish_reason: stop, 919 content deltas / 921 SSE frames) after 19.70 s, so the short one queued for
19.1 s:

request result
A streamed, max_tokens: 3000 200, 19.70 s, 921 SSE frames, 919 content deltas, finish_reason: stop
B streamed, 16 tok, 1 s in 200 at t=19.15 s: 20 keep-alive frames (one a second while queued), then 14 real reasoning_content deltas, finish_reason: length, [DONE] — 0 error frames

amdxdna ERROR 0, Array stopped dispatching 0.

So the keep-alive holds for a 20-tick queue, not just the 13-tick one the PR measured, and nothing socket-level breaks
when the queue outlasts a minute-scale generation. What is still not measured, and this row does not pretend otherwise:
a queue anywhere near the --queue-ms bound (300 s) — deliberately, since provoking one needs a generation that long, and
the honest statement in the body ("bounded, unexercised") stands for waits far beyond ~20 s. The --queue-ms-plain
counterpart is covered by #1033's row.

bong-water-water-bong added a commit that referenced this pull request Nov 5, 2026
… (#1033)

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

npu: the serve answers 503 after 5 s instead of queueing, so a second chat on a single-user appliance fails

1 participant