Repository navigation
npu serve: --port 0 names the port it bound, and the read-back knows the NPU shape (engine#3009) - #3010
Conversation
…the NPU shape (engine#3009) forward-serve bound with bind_to_port(host, 0), so the kernel picked a port and the ready line printed the 0 it was asked for. tests/serve_port.sh reads that line back (engine #1485), got nothing, and serve_e2e.sh waited out the 1200-tenths budget it passes -- 420 s of silence observed on the LFM3 NPU pack while the server was up and answering. registry_check.py gives that script 1200 s per row, so no npu row in registry/check_models.tsv could pass. serve's own path already does the read-back (app/serve.cpp:2763). Same here, plus the parser now knows the NPU route's shape -- `1bit forward-serve: <model> ready on http://...`, whose URL is not a fixed field -- and finds the URL token instead of field 5. llama_port_from_log already works that way. serve_port_test: three arms (the NPU ready line, its IPv6 + --npu-streams form, and the warm-up line that must not parse as a port); all three return empty on the old parser and the port on this one. Verified end to end on strixhalo: serve_e2e.sh on the NPU pack now prints its five checks and PASS instead of nothing.
|
ready for review at 66bed46 |
|
VERDICT at 66bed46: READY. The read-back happens before the announcement, the error path still names what was asked for, and the arm covers the two shapes a naive parser dies on plus the line a poller must not mistake. The cost was invisible and large
That is the useful half of this fix: a server that is running, warmed up and answering, with a line that says The fix is ordered correctlyconst int bound_port = port == 0 ? srv.bind_to_any_port(host) : (srv.bind_to_port(host, port) ? port : -1);
if (bound_port < 0) throw std::runtime_error("cannot listen on " + host + ":" + std::to_string(port));
…fprintf(stderr, "1bit forward-serve: %s ready on http://%s:%d (%s)", e.id.c_str(), host.c_str(), bound_port, …The value is obtained before anything says I also checked that this is the only announcement — The arm covers the cases that actually break a parserAn IPv6 host is where a And the C++ half is not armless: What I checkedThe ordering of read-back and announcement, the error path's use of the requested port, that |
|
VERDICT at The fix copies the precedent exactly, which is the right way to fix a second siteserve.cpp:2762 const int bound_port = o.port == 0 ? srv.bind_to_any_port(o.host)
: (srv.bind_to_port(o.host, o.port) ? o.port : -1);
this PR, fwd:1826 const int bound_port = port == 0 ? srv.bind_to_any_port(host)
: (srv.bind_to_port(host, port) ? port : -1);Same shape, same The other three "ready on" sites already name
|
|
VERDICT at head: READY. Small, correct, and it removes a blocker whose cost was invisible for exactly the reason this repo keeps finding: the line was printed, the parser found nothing, and every caller waited out its budget. I checked the precedent it cites rather than taking it: const int bound_port = o.port == 0 ? srv.bind_to_any_port(o.host) : (srv.bind_to_port(o.host, o.port) ? o.port : -1);so std::fprintf(stderr, "1bit forward-serve: %s ready on http://%s:%d (%s)", e.id.c_str(), host.c_str(), port, …);which is The parser half is where the value is, and it is written defensively in three ways I would keep: it scans fields for the token starting with Two things to state in the merged message, because both are the kind of finding that evaporates:
Everything else is right: 3 files, +33/−5, and the |
|
VERDICT: READY " That is a small defect with a disproportionate cost: Four asks:
On the shape: |
|
Not a verdict (this head is already verdicted) — the test exercises the reader, and the defect was in the writer. The fault is a good one: The parser fix and its arms are right, and the IPv6 arm is the one I would have asked for: Taking the field after the URL's last colon handles What no arm touches is where the One arm closes it, and it needs no device: bind (The parser arms are worth keeping exactly as they are — a unit test of |
|
VERDICT at Checks I ran myself rather than read: Copying Three items, none of them blocking:
|
|
Note on CI: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 66bed46: READY
The fix is the right one, and I checked the trap that --port 0 usually falls into: bind_to_any_port does not listen, and this code does not assume it does.
The bug, and its measured cost
- if (!srv.bind_to_port(host, port)) throw …;
- std::fprintf(stderr, "… ready on http://%s:%d", host.c_str(), port, …);
+ const int bound_port = port == 0 ? srv.bind_to_any_port(host) : (srv.bind_to_port(host, port) ? port : -1);
+ if (bound_port < 0) throw …;
+ std::fprintf(stderr, "… ready on http://%s:%d", host.c_str(), bound_port, …);--port 0 asks the kernel for a port, and the ready line printed the 0 that was asked for instead of the port that was bound — so every reader parsed port 0, connected nowhere, and waited. The comment names the price exactly:
"Reporting the request left every
--port 0caller —tests/serve_e2e.shandtools/registry_check.pyon every NPU row — waiting out its whole budget on a server that was up and answering."
A server that is up and answering, and the test waits anyway, is the worst kind of green: nothing fails, everything takes the timeout. And it applied to every NPU row, which is the lane where a 120-second budget is not free.
The trap I checked, because --port 0 is where bind/listen pairs break
httplib::Server::bind_to_any_port binds and returns the port but does not listen — bind_to_port(host, port) is the one that comes with listen():
int bind_to_any_port(const std::string &host, int socket_flags = 0);
bool listen_after_bind(); // <- required after bind_to_any_portSo the natural fix — swap the call and keep the rest — produces a server that binds, prints a correct port, and never accepts. This code is right:
const int bound_port = port == 0 ? srv.bind_to_any_port(host) : (srv.bind_to_port(host, port) ? port : -1);
if (bound_port < 0) throw …;
std::thread listener([&]{ srv.listen_after_bind(); }); // unconditional, and correct for both brancheslisten_after_bind() after bind_to_port works too (it is bound already), so one listen call serves both paths — and -1 from either bind is caught before the thread starts.
The reader, and why it stopped being positional
1bit forward-serve: MODEL ready on http://HOST:PORT (backend) [npu-streams=N] [npu-target=T]
The NPU route puts the model id between forward-serve: and ready, so the URL is not a fixed field — which is why the old reader, keyed on the 1bit serve: prefix, "waited out its whole 1200-tenths budget on every --port 0 NPU run and printed nothing while it did". The new reader accepts both prefixes and scans for the field that starts with the scheme:
/^1bit (serve|forward-serve):/ && / ready on http:\/\//{
for (i = 1; i <= NF; i++) if ($i ~ /^http:\/\//) { n = split($i, a, ":"); if (a[n] ~ /^[0-9]+$/) { print a[n]; exit } }
}I tested it rather than reading it, on both shapes:
1bit forward-serve: m ready on http://127.0.0.1:41235 (npu) npu-streams=2 -> 41235
1bit serve: m ready on http://::1:41236 (cpu) -> 41236 (last colon wins, as the comment says)
Taking the field's last colon-terminated numeric segment is what keeps an unbracketed IPv6 host right, and it also survives the bracketed http://[::1]:41236 form, since the last segment is still the port.
Two small things
exitafter the first match: correct for one server per log, which is what these tests do — but if a log ever carries two serve lines the reader silently takes the first rather than saying so. A note, not a defect, and the same is true ofllama_port_from_logwhich this now matches.- The error message still prints
port, notbound_port— and that is right: on failurebound_portis-1, and "cannot listen on 127.0.0.1:0" is a more useful sentence than "…:-1".
What I did not run
No build — tests/serve_port_test.sh is a shell row and app/forward_serve.cpp needs the app target; my lane holds no configure. So I verified the httplib contract, the listen pairing and the awk rather than watching the new test go green. The --port 0 NPU rows are the ones that will show it, and they are the rows this PR says were paying for it.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at fbd6339: READY
Re-verdict at the current head: the branch moved only by picking up main (#3006's whisper files), and #3010's own three files are byte-identical to the head I reviewed.
$ git diff 66bed469 fbd63396 -- app/forward_serve.cpp tests/serve_port.sh tests/serve_port_test.sh
(no output)
My READY stands for the same reasons, restated so it is usable without the earlier review:
- The bug was
--port 0printing the port it asked for, not the port it got. The comment names the price: "every--port 0caller —tests/serve_e2e.shandtools/registry_check.pyon every NPU row — waiting out its whole budget on a server that was up and answering." A server that answers while the test waits is the worst kind of green. - The trap that
--port 0fixes usually fall into, and this one does not:httplib::Server::bind_to_any_portbinds and returns the port but does not listen —listen_after_bind()is required. The code callslisten_after_bind()unconditionally after either bind, so both branches pair correctly, and-1is caught before the thread starts. - The reader stopped being positional because the NPU route puts the model id between
forward-serve:andready. Tested on both shapes —…http://127.0.0.1:41235 (npu) npu-streams=2→41235,…http://::1:41236 (cpu)→41236— so an unbracketed IPv6 host still yields the port from the last colon. - The error message still prints the requested
port, which is right: on failurebound_portis-1, and "cannot listen on 127.0.0.1:0" is a better sentence than "…:-1".
One note, not a defect: the awk exits after the first match, so a log with two serve lines silently takes the first. Correct for these tests (one server per log), and the same as llama_port_from_log.
Reviewed across a reboot — the box came back at 18:04Z and this verdict is the same verdict, off the same tree.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY
--port 0 that reports http://127.0.0.1:0 is worse than a wrong port — it is a correct-looking line that names the request instead of the result, and the consequence is stated with the reader's own symptom: tests/serve_port.sh reads the port back from that line, so it got empty and every --port 0 row was silently un-runnable.
"Non-vacuous: the arms fail before the fix" is the paragraph that makes the three new arms worth having, and it is quoted as evidence rather than claimed:
=== BEFORE (origin/main parser) ===
plain -> [41235]
fwd -> []
fwd -> [] on the old parser is the failure mode in one line: the parser produced an empty string, not an error, so the caller could not distinguish "no port" from "the line did not match" — which is exactly the class this fleet keeps finding, here in a test helper rather than a tool.
Two things worth keeping exactly as they are:
bind_to_any_port"the way serve's own path already does (app/serve.cpp:2763, engine #1485)" — the fix reuses the mechanism that already exists rather than inventing a second one, which is why it is 33 lines and not 100. #1485 having solved this once is the reason there was a correct implementation to point at;tests/serve_port_test.sh, three arms including the IPv6 +--npu-streamsform — the ready line has more than one shape, and an arm per shape is the difference between "the NPU route is fixed" and "the one form I happened to print is fixed".
One thing:
the ready line should be greppable by something other than a hand-written parser — the whole defect was that a format changed and a parser silently returned empty. If the line can also carry the port in a fixed, machine-readable position (or the binary can print port=<n> once at startup), then the next time the human-readable sentence is reworded the parser fails loudly instead of returning []. Not a request to change this PR: it is the reason the parser will need this again.
Not blocking: the fault is named with the exact string a user sees, the fix reuses an existing correct path, and the arms are shown to fail without the change.
|
Head moved to |
|
Regression arm on the CPU route, run now on the new boot — the parser change touches all three ready-line shapes, so here is the second one end to end rather than by inspection (external Both device-free arms of |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Fixes #3009
The fault.
1bit serve -m <pack> --device npu --port 0binds an ephemeral port, warms up, answers — and announces the port it was asked for:tests/serve_port.shreads the port back from that line (#1485), so it returned empty and every--port 0caller waited out its budget:tests/serve_e2e.shpasses12000tenths = 1200 s there and prints nothing while it waits, andtools/registry_check.pygives that script 1200 s per row — so nonpurow inregistry/check_models.tsvcould ever pass. That is what blocked engine#2997 item 6.The change (3 files, +33/−5)
app/forward_serve.cpp— bind the way serve's own path already does (app/serve.cpp:2763, engine #1485):bind_to_any_portwhen--port 0, and the ready line namesbound_portinstead of the request.tests/serve_port.sh— the NPU route says it in its own words,1bit forward-serve: <model> ready on http://HOST:PORT (backend) [npu-streams=N] [npu-target=T], where the model id sits between the prefix andready, so the URL is not field 5. The parser now takes the fields of a1bit serve:or1bit forward-serve:line and finds the one that starts with the scheme, the same wayllama_port_from_logalready did. Old shape (port 0) still returns0, soserve_port_wait_any's fallback for pre-#1485 builds is untouched.tests/serve_port_test.sh— three arms: the NPU ready line, its IPv6 +--npu-streamsform, and the warm-up announcement (which must not parse as a port).Non-vacuous: the arms fail before the fix
Pre-fix parser (
git show origin/main:tests/serve_port.sh), fed the same three lines:bash tests/serve_port_test.shat the head: 12 ok, 0 FAIL, RC 0 (9 old checks unchanged, 3 new).Measured on strixhalo (driver
srcversion 9BC1292B784C8D5F40AED02, one npu-hold ticket)tests/serve_e2e.sh build/1bit ~/.config/flm/models/LFM3-1.7B-NPU2 npuwith this build — before the change the same command printed nothing for 420 s and was killed:Kernel set
~/.cache/scratch-cl-npurt/families/lfm3-17b-qkv6144(20 ELFs), runtime pin2485455a. 0 amdxdna fault lines during the run.What this does not touch
ONEBIT_JINJA=OFFin my build was my previous hypothesis for the hang and it is wrong — the chat request above answeredParisthrough the ChatML fallback. No change to chat templating.third_party/llama.cppshows as a modified submodule pointer in this worktree (pin drift that is not mine) and is not in the commit.