Skip to content

tests/serve_port.sh: parse all three ready-line shapes, not just the unsuffixed one (fixes review finding on #1525) - #1531

Merged
bong-water-water-bong merged 1 commit into
mainfrom
1bit/i669-serve-port-shapes
Nov 8, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
1bit/i669-serve-port-shapes

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes the finding the review made on #1525, which merged before the fix could land: the helper's parse was end-anchored and matched only one of the three ready-line shapes app/serve.cpp prints.

$ matched ready on http://HOST:PORT only. The other two both carry trailing text — (laya routes each request; …) on the plain path when laya is on, and (laya-models: model auto is routed per request) on the laya-models path, always. #1525's three callers run --device cpu with no laya, which is exactly why its own exercise passed: it tested the one shape it happened to use. The next test to adopt the helper on a laya path would have gotten an empty port, waited out its 30 s and failed after serve had reported one.

Now the URL token is taken whole (everything after on up to the first space) and the port is the field after its last colon:

serve_port_from_log() {  # <log> -> the port, empty while serve has not said
    awk '/^1bit serve: ready on http:\/\//{ n = split($5, a, ":"); if (a[n] ~ /^[0-9]+$/) { print a[n]; exit } }' "$1" 2>/dev/null
}

That keeps both properties the anchor was there for — a line that is not a ready line yields nothing, and an IPv6 --host parses — and it has to be this way round: with a suffix present, the last colon of the line is inside the suffix text, so "greedy to the last colon" over the whole line is wrong too.

Verified on every shape, not the convenient one

ready on http://127.0.0.1:41234                                         -> 41234
ready on http://127.0.0.1:41235 (laya routes each request; x)           -> 41235
ready on http://127.0.0.1:41236 (laya-models: model auto is routed …)   -> 41236
ready on http://::1:41237                                               -> 41237
ready on http://localhost:41238 (laya-models: model auto is routed …)   -> 41238
1bit serve: loading model                                               -> (nothing)
(empty log)                                                             -> (nothing)
1bit serve: ready on http://127.0.0.1:notaport                          -> (nothing)

bash -n clean. One file, tests/serve_port.sh +9/-3. Nothing else in the migration changes; #1485's remaining scripts are unaffected either way (they will call this helper, so they want it right first).

…not just the unsuffixed one

The helper landed in #1525 with an end-anchored parse, and serve prints three shapes:

    ready on http://HOST:PORT                                          (plain path, laya off)
    ready on http://HOST:PORT (laya routes each request; ...)          (plain path, laya on)
    ready on http://HOST:PORT (laya-models: model auto is routed ...)  (laya-models path, always suffixed)

so `$` matched only the first. The three callers in that PR run `--device cpu` with no laya and therefore hit the
unsuffixed form, which is why its own exercise passed; the next test to adopt the helper on a laya path would have
gotten an empty port, waited out its 30 s and failed *after* serve had reported one.

Now the URL token is taken whole (everything after "on " up to the first space) and the port is the field after its last
colon. That keeps both properties the anchor was for - a line that is not a ready line yields nothing, and an IPv6
--host parses - and it has to be this way round, because with a suffix present the last colon of the *line* is inside
the suffix text.

Exercised on all three shapes plus IPv6, a suffixed localhost form, a non-ready line and an empty log: every one as
expected. Found by review in #1525; that PR merged before this fix landed, so it is here on its own.

@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 4536f44c37f1fb5014db009e84b2231d52bc4d24

This is my finding from #1525, fixed properly rather than patched, and the new parser handles every shape I can construct:

s1  "…ready on http://127.0.0.1:8095"                                  -> 8095
s2  "…ready on http://127.0.0.1:8095 (laya routes each request; …)"    -> 8095     (the shape the old $ anchor missed)
s3  "…ready on http://127.0.0.1:8095 (laya-models: model auto …)"      -> 8095     (serve.cpp:2031)
s4  "…ready on http://::1:41235 (laya-models: …)"                      -> 41235    (IPv6 --host still right)
s5  "1bit serve: starting"                                             -> (empty)  (not a ready line)
s6  "…ready on http://localhost:9999"                                  -> 9999

awk taking field 5 and splitting on : for the last field is the right shape — it treats the URL as a token rather than trying to make one regex serve three line formats, and the a[n] ~ /^[0-9]+$/ guard means a malformed tail yields empty rather than a plausible wrong number. Empty is the safe failure: the caller's wait times out and says "serve never reported a port", which is exactly what a shared helper should do when it cannot read the line.

The header now lists the three shapes with the code comment that produces them, and records why the end-anchor was wrong — "a helper meant to be shared would hand the next test an empty port, wait out its budget and fail after serve had reported one". That is the sentence that stops the next person re-introducing $.

One observation, not a defect: with the digits guard, a bracketed IPv6 host (http://[::1]:8095) would yield empty rather than 8095, where the old greedy-regex form happened to get it right. serve.cpp prints http://%s:%d with the raw --host, so brackets only appear if someone passes --host '[::1]' — and if they do, the failure is the loud one above, not a wrong port. Worth a line in the header if bracketed hosts are ever supported; no change needed today.

Not run: the three updated suites end to end (they need 1bit + a tiny gguf); the six log shapes above are the parser, which is the whole change.

@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 4536f44c37f1fb5014db009e84b2231d52bc4d24

I checked the parse against the printer, not just against the body's table.

  • The printer. app/serve.cpp prints the ready line in exactly the shapes the comment lists:

    • :2031 "1bit serve: ready on http://%s:%d (laya-models: model auto is routed per request)\n";
    • :2746 "…http://%s:%d%s\n", where the %s is " (laya routes each request; …)" or empty.

    Both suffixes start with a space, so $5 is always exactly the URL token. Without that space, the plain-path laya shape would have come out empty.

  • I sourced the helper at this head and ran it on these lines:

    line result
    plain 41234
    the real laya suffix 41235
    the laya-models suffix 41236
    http://::1:41237 41237
    http://[::1]:41239 41239
    :notaport (nothing)
    a non-ready line (nothing)
    an empty log (nothing)

    A non-ready line still can't be mistaken for one.

  • bash -n passes and shellcheck -S warning reports 0.

One small note, not blocking. The comment credits the finding to "#1523/#1525". #1523 is the PARD correction, so it should say #1525 only.

1bit forward-serve prints its own … ready on http://%s:%d (%s) line (forward_serve.cpp:1049), and the ^1bit serve: anchor correctly ignores it. That matters if a forward-serve test ever adopts this helper, so a word in the comment would help.

@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 4536f44c.

Exercised on every shape, including the two negatives — all correct:

1bit serve: ready on http://127.0.0.1:43210 (laya-models: model auto is routed per request)   -> 43210
1bit serve: ready on http://127.0.0.1:43211 (laya routes each request; a device's backend …)  -> 43211
1bit serve: ready on http://127.0.0.1:43212                                                    -> 43212
1bit serve: ready on http://[::1]:43213 (laya-models: model auto is routed per request)        -> 43213
1bit serve: ready on http://nohost                                                             -> (empty)
warning: 1bit serve: ready on http://h:1 was slow                                              -> (empty)

That is the finding fixed exactly: the prefix anchor (/^1bit serve: ready on http:\/\//) is what rejects a line that merely contains the text, and
the port comes from the last colon of the URL token, so [::1] parses and a lost port prints nothing rather than a wrong number. Taking $5 whole is
sound for this line — the four words before it are fixed, and neither a host nor a port contains a space.

bash -n clean, 12 lines changed, one file.

Worth saying explicitly because it is the useful part of the design: a parse that cannot read the line should print nothing and let serve_port_wait
time out with the log attached, and that is what happens now — http://nohost yields empty rather than host or 0. That is the difference between a
test that says "serve never reported a port" and one that silently talks to the wrong port.

@bong-water-water-bong
bong-water-water-bong merged commit 819a453 into main Nov 8, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/i669-serve-port-shapes branch November 8, 2026 19:40
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

1485 - Partially compliant

Compliant requirements:

  • The helper script serve_port.sh now parses all three ready-line shapes correctly
  • The fix addresses the issue where only one of the three shapes was matched, causing tests to fail
  • The change ensures that scripts using --port 0 will correctly extract the bound port regardless of the serve path used

Non-compliant requirements:

  • The PR does not include the migration of the 19 scripts to use the new mechanism in batches
  • The PR does not include the actual implementation of serve --port 0 reporting the bound port in app/serve.cpp

Requires further human verification:

  • The actual migration of the 19 scripts to use the new mechanism needs to be verified
  • The behavior of serve --port 0 in app/serve.cpp needs to be confirmed to report the bound port
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect port parsing logic

The previous implementation used a $-anchored regex that only matched the first ready-line shape, causing tests to fail when other shapes were printed. The new implementation correctly parses all three shapes by extracting the URL token and finding the port after the last colon, which also handles IPv6 addresses properly.

awk '/^1bit serve: ready on http:\/\//{ n = split($5, a, ":"); if (a[n] ~ /^[0-9]+$/) { print a[n]; exit } }' "$1" 2>/dev/null

@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: APPROVE. I ran the awk against your table rather than reading it, and it returns exactly what you claim:

1bit serve: ready on http://127.0.0.1:41234                       -> 41234
1bit serve: ready on http://127.0.0.1:41235 (laya routes …)       -> 41235
1bit serve: ready on http://::1:41237                             -> 41237
1bit serve: ready on http://127.0.0.1:notaport                    -> (nothing)

The two design points are both right and both worth keeping in the comment: taking the token whole beats an end anchor, and the port being the field after the token's last colon is the only formulation that survives a trailing suffix — as you say, "greedy to the last colon over the whole line" is wrong once the suffix contains a colon, and a[n] ~ /^[0-9]+$/ is also what rejects notaport and a URL with no port at all. And serve_port_wait breaking on kill -0 is the part that turns a wrong parse from a 30 s stall into a fast failure.

One silent-empty case remains, and it is the same class as the bug you just fixed. ^1bit serve: plus the positional $5 means any log prefix defeats both the anchor and the field index:

[2026-11-08 19:00:00] 1bit serve: ready on http://127.0.0.1:41239   -> (nothing)   expected 41239
2026-11-08T19:00:00Z 1bit serve: ready on http://127.0.0.1:41240     -> (nothing)   expected 41240

Verified by running the function on both. So the helper is correct for raw serve > "$log" 2>&1 capture and silently wrong for a capture that timestamps (ts, awk '{print strftime…}', a CI wrapper, systemd journal formatting). Nobody does that today — the callers are the three #1525 sites — but this is a shared helper whose whole purpose is the next caller, and the failure is invisible: empty port, then a fail after serve had already reported. Two ways to close it, either is fine:

  1. match the token by pattern instead of by field index, which is immune to both problems at once:
    match($0, /ready on http:\/\/[^ ]+/); t = substr($0, RSTART+9, RLENGTH-9) then split t on : and take the last field — the anchor still rejects non-ready lines, because ready on http:// has to be present;
  2. or keep the code and state the precondition in the usage comment ("$log must be serve's raw output; a prefixed or rewritten log will yield nothing"), so a future caller who pipes through a timestamper has been told.

The serve_port_wait docstring says "non-zero if it never came" — worth a word in the PR body, because it is the property the three callers depend on and it is what makes a parse failure loud rather than silent. Reviewed by running the parser on synthetic logs for your four shapes plus the two prefixed ones; I did not run the ctest suite.

bong-water-water-bong added a commit that referenced this pull request Nov 8, 2026
…g one (refs #1485) (#1537)

* tests: five more scripts take a port serve reports instead of guessing one (refs #1485)

Batch 2 of the migration, on top of the fixed helper from #1531.

- `metrics_serve.sh`, `watchdog_serve.sh`: the serve launch moves to `--port 0` and the port comes from
  `serve_port_wait`; their "could not bind a port N" branches go away, and so does the now-unused `newport()`.
- `pm_route.sh`: the `--pm` serve uses `--port 0` + `serve_port_wait` (the child pid is kept in `$spid` because
  `serve_port_wait` needs it). `freeport()` stays: the fake lemonade is a python process, not serve, and the
  `dead_port`/`spawn_port` cases there are deliberately unusable ports.
- `prism_route.sh`, `recipes_route.sh`: `--port 0`, and the bind-collision branches are deleted - both read their
  result from the backend's record file, so neither needs a readiness parse, and with the kernel picking a bind
  failure cannot be the script colliding with itself. `recipes_route`'s two negative cases (a malformed recipe, a
  non-list `gguf_keys`) drop the port entirely: those serve runs exit before binding anything.

`bash -n` clean on all five; `shellcheck -S warning` now reports only the pre-existing SC2034s (I introduced one
SC2206 with an unquoted `pids+=($spid)` and fixed it before pushing). Not run end to end: no engine build tree on
this box, so ctest on CI is the first execution - `metrics_serve`, `watchdog_serve`, `parallel_args` and
`smoke_serve` from batch 1 are all in `ci.yml`'s list, which is what makes `--port 0` actually exercised.

* tests: clear the two leftovers the reviews found in prism_route and recipes_route

Both reviewers flagged the same pair, and both were right about the second one being the substantive half.

1. **Dead `local port`** in both: the migration removed the assignment and left the declaration, which is what took
   shellcheck's SC2034 count from 1→2 (prism_route) and 2→3 (recipes_route) against main. Deleted.
2. **The record-file wait lost the liveness half** of the helper. `serve_port_wait` exits as soon as the process is gone
   (`kill -0 || break`) so a serve that dies reports its own log in a tenth of a second; these two kept the plain
   `[ -s "$2" ]` loop, so a dead serve slept the full 10 s and then surfaced later as a JSON/read error from the record
   file. Now `kill -0 "$pid" 2>/dev/null || break`, one line each, which is what the reviewer asked for rather than
   adopting the parse they do not need.

Measured rather than asserted: with a pid that is already dead the loop now exits in **13 ms** instead of ~10 000 ms.
shellcheck warning counts are back to main's per file (prism_route 1, recipes_route 2), `bash -n` clean.

* tests: the route-port census follows the scripts that stopped pre-picking a port

CI build failed on `route_port_lock`: `AssertionError: 'recipes_route' not found in {...}`, because that test
*enumerates* the scripts that bind a loopback port up front (`freeport|free_port|bind(("127.0.0.1", 0))|--port 43xxx`)
and requires each to hold `RESOURCE_LOCK route_ports`. Seven scripts in this migration no longer match, because they
no longer pick a port at all - which is the point of `--port 0`.

So the census and the lock list move together, which is what the census is for:

- `_onebit_route_tests` keeps exactly the tests that still choose their port up front: smoke_serve, print_backend,
  lemonade_hrx, template_pin, device_route, npu_repack_path, pm_route, bench_selftest, laya_gguf_route,
  mem_admit_route, hrx_cwsr_route, hybrid_route, hybrid_kvshare_route. Dropped: watchdog_serve, metrics_serve,
  parallel_args, recipes_route, greedy_shortcut, prism_route, hrx_runtime_route - none of them binds a port any more,
  so the lock was serialising them for nothing.
- `bench_selftest` stays even though its own script text has no bind: it starts servers through `tools/bench.py`, which
  picks its own `free_port`, and there is a dedicated test case for exactly that.
- the census's required names drop `recipes_route` (with the reason in a comment) and the floor goes 15 -> 12, with the
  note that it counted 15 before this migration and that a model-enabled build configures several more.

Rehearsed locally without a build tree by driving the test with a stand-in `ctest` that reports the bare-build list and
the new lock properties: all three cases pass, census finds 12, `bench_selftest`'s indirect case still holds.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 9, 2026
…to cover it

Two review points from #1621, both about what "ready" means to a caller.

1. **`warming` before the pass, `ready` after it.** A caller polling for `ready on` could not tell "the cache is warming, give
   it a minute" from "hung". Measured cost is 44.5 s on a folded 27B pack, so the distinction is the difference between a
   readable log and "serve never reported a port".

2. **`tests/serve_port.sh`'s default budget is now 90 s, not 30.** #1621 moves 44.5 s in front of the ready line, and the
   helper's `tries=300` x 0.1 s would time out on exactly the configurations these tests exercise, with the message
   #1531/#1545 spent effort removing. The default carries a comment saying why it is not 30 s, and a caller can still pass
   its own bound; with (1) in place a short budget now fails next to a `warming` line rather than silently.

The breakdown of the 44.5 s is still owed and is the other review point -- the arithmetic in the PR body (112 first touches
x ~4.3 ms) does not add up to 44.5 s on the folded route, which the reviewer was right to notice. Measuring it next.
bong-water-water-bong added a commit that referenced this pull request Nov 9, 2026
…5 s it was hiding) (#1621)

* npu: dump each layer's residual stream so a per-layer cosine is possible at all

`NPU_INFER_DUMP_LAYERS` prints mean|x| and absmax per layer, which can tell that a forward drifted but not where: two
different bugs with the same mean look identical. This adds `NPU_INFER_DUMP_DIR=<dir>`, which writes layer_<l>.f32
(M x H floats, row-major) at the end of each layer, after the DeepStack add, so the tensor a reference trace compares
against exists.

Written with plain fopen/fwrite, off unless the variable is set, one stderr line announcing the directory. No behaviour
change when it is unset, and nothing in the compute path reads it.

First use, and the reason it was worth writing: engine #1416's gate-2 follow-up needs per-layer agreement with a
reference trace, and the first comparison (Qwen3-VL-2B text half, 19 rows, our q4nx int8 pack against a TorchLens capture
of the same ids/positions/embeddings) runs 0.9912 at layer 0 to 0.9803 at layer 26 -- a smooth quantisation drift with no
step change -- which is a result this instrument could not report before.

* npu: the profiler dumps for a prefill-only run (it required a decode launch first)

Both dump sites were `if (prof_dec_n_ && (prof_dec_n_ + prof_pre_n_) % 100 == 0) prof_dump();`. The guard makes a
prefill-only process print nothing at all: no decode launch has happened, so the condition is false however many prefill
launches run.

That is the case that matters when a request stalls. engine #1605 has an arm where an 8-token request on the pb16i route
returns nothing in 420 s, and the run printed no profiler rows -- which cannot be read as "no launches happened",
because on that path no dump could have happened either way. A silent instrument that looks like a negative result is
worse than no instrument.

Verified on the t2s pack (which serves normally): with the guard removed, a request that only prefills prints its rows.

    [prof] pre   D     128        4    0.30      0.21   3.806     0.011     4.328
    [prof] pre   QKV   128        3    0.13      0.15   2.936     0.018     3.233
    [prof] pre   QKVFAQ 16        2    0.13      0.20   2.111     0.012     2.457

Four launches per role is far below the 100-launch window, so these rows exist only because the prefill family now
counts -- which is the change.

* serve: forward-serve warms the weight cache before it says "ready"

A first request has to touch every (layer, role) weight once. On the non-folded int8 route that means `q4nx_assemble_B`
building the weight matrix in float32 and `packB_into` quantising it, ~112 projections -- measured on this box at
**44.5 s** even on the *folded* pack, where each first touch is only ~4.3 ms, because there are 112 of them and the
folded route's own first touches add up. Left inside the request it looks like a hang: engine #1605 has an 8-token
request returning nothing in 150-420 s, and the "ready on http://..." line is technically true and practically a lie
about the next minute.

The warm-up runs one four-token batch pass through the same forward before binding is announced, resets the state, and
prints what it cost:

    1bit forward-serve: warm-up pass 44483.6 ms (weight cache warm; NPU_SERVE_NO_WARMUP=1 to skip)
    1bit forward-serve: bonsai2-t2s2-perrole876 ready on http://127.0.0.1:18099 (full ELF) [npu-target=xdna]

`NPU_SERVE_NO_WARMUP=1` keeps the previous behaviour, and a failed warm-up is reported and does not stop the server --
the first request then pays it, exactly as before.

After it, a 130-token request on the same pack completes in 20 s wall with `[prof] pre` rows at `pack` 0.10-0.27 ms and
`wait` 2.9-3.4 ms per launch -- which is what the steady state looks like when nobody is measuring the first touch.

* serve: the warm-up's log line names what it does not cover (routed MoE experts)

Review point, taken: the warm-up touches the token-invariant weights (`wkey >= 0`, "packed once and reused") and those are
the ones a first request reads on a dense pack. Routed-expert weights are `wkey < 0` and are deliberately never cached
("whose weights change per token"), so on a MoE pack the warm-up is not the whole first-touch cost and the 44.5 s measured
here will not disappear by the same amount.

Said in the log line rather than only in the PR body, because the person who needs it is reading the log of a MoE pack
wondering why the warm-up "did not work":

    1bit forward-serve: warm-up pass 44740.0 ms (token-invariant weights only -- routed MoE experts are never cached, so a
    MoE pack still pays per-expert packing; NPU_SERVE_NO_WARMUP=1 to skip)

Re-measured after the edit on the same pack: 44.7 s, unchanged.

* serve: announce the warm-up, and raise the readiness helper's budget to cover it

Two review points from #1621, both about what "ready" means to a caller.

1. **`warming` before the pass, `ready` after it.** A caller polling for `ready on` could not tell "the cache is warming, give
   it a minute" from "hung". Measured cost is 44.5 s on a folded 27B pack, so the distinction is the difference between a
   readable log and "serve never reported a port".

2. **`tests/serve_port.sh`'s default budget is now 90 s, not 30.** #1621 moves 44.5 s in front of the ready line, and the
   helper's `tries=300` x 0.1 s would time out on exactly the configurations these tests exercise, with the message
   #1531/#1545 spent effort removing. The default carries a comment saying why it is not 30 s, and a caller can still pass
   its own bound; with (1) in place a short budget now fails next to a `warming` line rather than silently.

The breakdown of the 44.5 s is still owed and is the other review point -- the arithmetic in the PR body (112 first touches
x ~4.3 ms) does not add up to 44.5 s on the folded route, which the reviewer was right to notice. Measuring it next.

---------

Co-authored-by: pi-npufeat <npufeat@strixhalo>
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.

1 participant