Repository navigation
tests: three more scripts take the port serve reports instead of guessing one (refs #1485) - #1525
Conversation
…ng one (refs #1485) Batch 1 of the migration #1485 tracks, now that `serve --port 0` reports the port it bound (#1490, merged). - `tests/serve_port.sh` (new): two functions, `serve_port_from_log` and `serve_port_wait`. The pattern is greedy to the last colon so an IPv6 `--host` parses, and `$`-anchored so a line that is not a ready line cannot be read as a port; the wait stops early if the process dies instead of sleeping out its budget. - `tests/smoke_serve.sh`: the main serve and the exit-path serve use `--port 0` and read the port back. Its third pick stays: the impostor test holds a port on purpose to check that serve refuses a squatter, which is exactly the case `--port 0` cannot cover. This is the script that gives the new capability its CI coverage, since `smoke_serve` is in `ci.yml`'s target list and runs under ctest. - `tests/parallel_args.sh`, `tests/hrx_runtime_route.sh`: `--port 0`, and their "could not bind a port N" branch goes away - with the kernel picking, a bind failure can no longer be this script colliding with itself, and the branch was added in #1446 only because the port was guessed. They read their result out of the backend's record file, so no readiness parse is needed. `bash -n` clean on all four; `serve_port_from_log`/`serve_port_wait` exercised directly (a log with a ready line, an empty log, and a dead pid). Not run end to end: this box has no engine build tree, so `smoke_serve` under CI is the first real execution of `--port 0` through a script.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: CHANGES at 5d5caf12 — the helper is the right idea and the migration is clean, but its parse is end-anchored and only one of the three
ready-line shapes ends at the port.
What is right, and it is most of the PR:
- One implementation instead of five.
serve_port_waitalso has the early exit I wanted on #1490 —kill -0 "$pid" || breakwith the reason spelled
out ("serve died: no readiness line is ever coming, so stop waiting rather than sleeping out the whole budget"). - The bind-collision branches are gone from
parallel_args/hrx_runtime_route, and that is now correct: with--port 0the kernel picks, so an
EADDRINUSEbranch cannot fire — removing an unreachable guard is better than keeping it "just in case". smoke_servereally is exercised by CI, which I checked rather than taking the phrasing:ci.yml:104runsctest --test-dir build --output-on-failurewith no-Lfilter, andsmoke_serveis registered atCMakeLists.txt:192("Runs everywhere, CI included"). So this is
the first place--port 0is executed rather than compiled ✔.bash -nclean on all four files.
The finding — the parse:
serve_port_from_log() { sed -n 's/^1bit serve: ready on http:\/\/.*:\([0-9][0-9]*\)$/\1/p' "$1" | head -1; }$-anchored, while app/serve.cpp prints three shapes:
:2031 ready on http://%s:%d (laya-models: model auto is routed per request) <- ALWAYS has trailing text
:2746 ready on http://%s:%d%s where %s = laya ? " (laya routes each request; …)" : ""
<- ends at the port only when laya is FALSE
I exercised the helper directly on those lines: the :2031 form and the :2746-with-laya form both return empty, and the plain :2746 form
returns the port. Your three callers run --device cpu / --llama-server with no laya routing, so they hit :2746 with an empty suffix and match today
— which is why your exercise passed.
Why I would still fix it before this lands: the helper exists to be shared, and the next route test that adopts it on a laya-serving path gets
empty → serve_port_wait waits the full 30 s → FAIL serve never reported a port, after serve reported one. That is the failure the $ was
meant to prevent, inverted: the anchor that stops a false positive (a non-ready line matching) also creates a false negative (a ready line not
matching). The prefix ^1bit serve: ready on http:// is what actually prevents mistaking another line; the $ is what makes it miss.
Fix, one expression: anchor the prefix and allow end-of-line or a space after the port —
sed -n 's|^1bit serve: ready on http://.*:\([0-9][0-9]*\)\( .*\)\?$|\1|p'which matches all three shapes and keeps the guard the comment describes. (The greedy .*: you already have is right for an IPv6 host — it takes the
last colon ✔.)
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at 5d5caf1295bef53ccdfadacefffd4461bc1c2036
One helper, three call sites, and the helper is the right shape — it waits on a dead process as well as a timeout ("serve died: no readiness line is ever coming, so stop waiting rather than sleeping out the whole budget"), which is what stops a crashed server from costing 30 s per test.
All four shell files parse, and smoke_serve.sh fails loudly if the port never appears (FAIL serve never reported a port + the log), so a mis-read cannot pass as a green test.
One latent gap, worth one character. The extractor anchors the port at end-of-line:
sed -n 's/^1bit serve: ready on http:\/\/.*:\([0-9][0-9]*\)$/\1/p'
and app/serve.cpp prints two ready lines:
:2031 "1bit serve: ready on http://%s:%d (laya-models: model auto is routed per request)\n" <- has a suffix
:2746 "1bit serve: ready on http://%s:%d%s\n" <- empty suffix in the tests that pass -m
The three updated tests all pass -m <gguf>, so they print the second form and the anchor is fine — that is why the suite is green. But a future test that runs serve with model auto prints the first form, and then:
current=[ ] fixed=[8095] on "http://127.0.0.1:8095 (laya-models: …)"
current=[ ] fixed=[8123] on "http://::1:8123 (x)"
Dropping the $ and letting the tail be consumed — s/^1bit serve: ready on http:\/\/.*:\([0-9][0-9]*\).*$/\1/p — handles both, keeps the greedy .* to the last colon (so an IPv6 --host ::1 still parses), and changes nothing for the three call sites above. It is the difference between a helper that works for the tests that exist and one that works for the next test someone writes.
The refactor itself is the right call: the port-discovery logic now lives once instead of in a copy per script, and parallel_args.sh / smoke_serve.sh / greedy_shortcut.sh all read the port serve reported rather than picking one and releasing it — the release-then-bind race in #1444/#1485 stays fixed everywhere it appears.
Not run: the three suites end to end (they need 1bit and a tiny gguf; I parsed them and drove the helper directly with the four log shapes above).
|
Merged at |
…not just the unsuffixed one (#1531) 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. Co-authored-by: bong-water-water-bong <[email protected]>
…server bound (engine#1485) The driver picked its port with the bind(0)-and-release one-liner, so between closing that socket and llama-server binding it any other test on a busy box could take it -- engine#1485's race, which every other serve test has already migrated away from (#1525, #1545). Its own census lists this file as covered by #1637, which until now was true only of the orphan fix and not of the port. It is now the other shape: `--port 0` and read the bound port back. llama-server handles 0 by binding any port (`tools/server/server-http.cpp`) and prints `listening on http://host:port`, so there is no window to lose. `wait_bound_port()` parses that line and the caller gets None -- with the log tail -- if the server dies or never prints it, rather than guessing. `free_port()` is deleted: nothing else in the file used it. Two details the parser had to get right, both measured: the capture is greedy up to the **last** colon and anchored at end-of-line, because the non-greedy form matched the `1` of `http://[::1]:44444`; and a `unix://` ready line matches nothing, which is the correct answer for a socket curl cannot reach. Checked against four synthetic logs (IPv4, IPv6, unix, no line) plus the orphan test.
…server bound (engine#1485) The driver picked its port with the bind(0)-and-release one-liner, so between closing that socket and llama-server binding it any other test on a busy box could take it -- engine#1485's race, which every other serve test has already migrated away from (#1525, #1545). Its own census lists this file as covered by #1637, which until now was true only of the orphan fix and not of the port. It is now the other shape: `--port 0` and read the bound port back. llama-server handles 0 by binding any port (`tools/server/server-http.cpp`) and prints `listening on http://host:port`, so there is no window to lose. `wait_bound_port()` parses that line and the caller gets None -- with the log tail -- if the server dies or never prints it, rather than guessing. `free_port()` is deleted: nothing else in the file used it. Two details the parser had to get right, both measured: the capture is greedy up to the **last** colon and anchored at end-of-line, because the non-greedy form matched the `1` of `http://[::1]:44444`; and a `unix://` ready line matches nothing, which is the correct answer for a socket curl cannot reach. Checked against four synthetic logs (IPv4, IPv6, unix, no line) plus the orphan test.
…s thread-safe (refs #1624, #698) (#1637) * tests: the handoff driver's provider dies with it too, not just the server #1524 gave the shared-KV driver's *server* PR_SET_PDEATHSIG, so a SIGKILL of the driver cannot leave an HRX decoder holding a context. Its **provider** was still spawned with `subprocess.run(...)` and no such hook -- and that is the one that runs for up to 1800 s on a 16k prompt, so a driver killed inside that window left an orphan with the region mapped. Same class as engine#1624 (kill_tree recomputing descendants after the root died), in this lane's own file. The provider now spawns as `Popen` with `start_new_session=True` and `preexec_fn=die_with_parent`, then `wait(timeout=1800)`; on the deadline it reaps **the group**, which `run()` could not do (it blocks and leaves the child in the driver's process group, which the teardown does not signal). argv, env, `pass_fds` and the redirected log are unchanged, so the provider sees exactly the invocation it saw before. One thing the multi-threaded shape forced: the driver runs a socket-listener thread, so the fork that spawns a child happens in a threaded process, where anything the child does before `exec` that allocates or imports can deadlock on a lock another thread held. `die_with_parent` therefore resolves libc and the signal number once at **import** time and leaves the child a single C call that allocates nothing (it used to `import ctypes` inside the forked child). tests/kvshare_orphan_test.sh gains the source assertion for both spawns -- the functional path needs an HRX server and a model, so a grep is the only device-free way to see that a later edit did not drop one of the two hooks -- and stays at 2.5 s, 4/4 checks. Gate: `kvshare_orphan` 4/4 and `ctest` green (142/142) on this tree at low load; the route-test reds reappear at load 62 and pass in isolation, which is the #1485 contention class and not this diff. The **device** e2e was not re-run: its two inputs (the HRX llama-server and the reference provider) went with the build trees in the 11-08 disk cleanup, and rebuilding them is ~40 minutes of CPU; the invocation is byte-identical apart from the process attributes, so what could differ there is the lifecycle this test already pins. Refs #1624 (the same orphan class), #698 (the gate), #1524 (the server-side half). * tests: the handoff driver stops picking a port and reads the one the server bound (engine#1485) The driver picked its port with the bind(0)-and-release one-liner, so between closing that socket and llama-server binding it any other test on a busy box could take it -- engine#1485's race, which every other serve test has already migrated away from (#1525, #1545). Its own census lists this file as covered by #1637, which until now was true only of the orphan fix and not of the port. It is now the other shape: `--port 0` and read the bound port back. llama-server handles 0 by binding any port (`tools/server/server-http.cpp`) and prints `listening on http://host:port`, so there is no window to lose. `wait_bound_port()` parses that line and the caller gets None -- with the log tail -- if the server dies or never prints it, rather than guessing. `free_port()` is deleted: nothing else in the file used it. Two details the parser had to get right, both measured: the capture is greedy up to the **last** colon and anchored at end-of-line, because the non-greedy form matched the `1` of `http://[::1]:44444`; and a `unix://` ready line matches nothing, which is the correct answer for a socket curl cannot reach. Checked against four synthetic logs (IPv4, IPv6, unix, no line) plus the orphan test. --------- Co-authored-by: t <[email protected]>
…o pickers (engine#1485) tests/serve_port.sh reads the port `1bit serve` bound out of its ready line, and the route tests use it. The scripts that drive the vendored llama-server directly could not: its line is `srv http_bind: listening on http://HOST:PORT`, so free_port() (bind, note the port, close, launch) stayed in two of them and with it the release-then-bind window engine #1444/#1485 named - on a `ctest -j` runner another serve can take the port before this one binds, and the arm then reports "the server did not come up", which reads as a bug in whatever the row checks. llama.cpp already binds an ephemeral port for --port 0 (bind_to_any_port, tools/server/server-http.cpp) and logs the address it ended up on, so the fix is the read-back, not a server change: llama_port_from_log/llama_port_wait sit beside the serve pair, and - tests/hrx_cpu_weight_parity.sh drops free_port() for --port 0 + llama_port_wait - tests/greedy_shortcut.sh drops a local end-anchored sed for the shared serve_port_wait (its pattern matched only serve's plain ready line; the laya shapes carry a suffix after the port, which is the #1523/#1525 finding this test now pins) tests/serve_port_test.sh is script-based, so CI runs it with no device and no model: it feeds both parsers the exact lines the two servers print (including the suffixed and IPv6 shapes) and drives the failing wait with a process that is already gone. Mutating serve_port_from_log back to an end-anchored pattern fails two of its checks, which is what the old local parser was.
…o pickers (engine#1485) (#1663) tests/serve_port.sh reads the port `1bit serve` bound out of its ready line, and the route tests use it. The scripts that drive the vendored llama-server directly could not: its line is `srv http_bind: listening on http://HOST:PORT`, so free_port() (bind, note the port, close, launch) stayed in two of them and with it the release-then-bind window engine #1444/#1485 named - on a `ctest -j` runner another serve can take the port before this one binds, and the arm then reports "the server did not come up", which reads as a bug in whatever the row checks. llama.cpp already binds an ephemeral port for --port 0 (bind_to_any_port, tools/server/server-http.cpp) and logs the address it ended up on, so the fix is the read-back, not a server change: llama_port_from_log/llama_port_wait sit beside the serve pair, and - tests/hrx_cpu_weight_parity.sh drops free_port() for --port 0 + llama_port_wait - tests/greedy_shortcut.sh drops a local end-anchored sed for the shared serve_port_wait (its pattern matched only serve's plain ready line; the laya shapes carry a suffix after the port, which is the #1523/#1525 finding this test now pins) tests/serve_port_test.sh is script-based, so CI runs it with no device and no model: it feeds both parsers the exact lines the two servers print (including the suffixed and IPv6 shapes) and drives the failing wait with a process that is already gone. Mutating serve_port_from_log back to an end-anchored pattern fails two of its checks, which is what the old local parser was.
Refs #1485, batch 1 of the migration. Follows #1446 (five scripts retry) and #1490 (
serve --port 0reports the port it bound, merged).What
tests/serve_port.sh(new, one file, two functions):serve_port_from_logreads the port out of serve's ready line;serve_port_waitpolls it with a budget and stops early if the process died instead of sleeping out the whole wait. The pattern is greedy to the last colon (so--host ::1parses) and$-anchored (so a line that is not a ready line cannot be read as a port — a silent0would send the test at the wrong port).tests/smoke_serve.sh: main serve and the exit-path serve use--port 0and read the port back. Its third pick stays on purpose — the impostor test holds a port to check that serve refuses a squatter, which is precisely the case--port 0cannot cover.tests/parallel_args.sh,tests/hrx_runtime_route.sh:--port 0, and their "could not bind a port N" branch is deleted. With the kernel picking, a bind failure can no longer be this script colliding with itself; that branch only existed because the port was guessed (added in tests: the five serve route tests retry a taken port instead of failing on it (closes #1444) #1446). Both read their result from the backend's record file, so neither needs a readiness parse.Why smoke_serve matters in this batch
smoke_serveis inci.yml's target list and runs under ctest, so this batch is the first place--port 0gets exercised by CI rather than only compiled — which was the open question on #1490. If the ready line and the parse ever disagree, this script fails loudly with the log dumped, not silently against a wrong port.Verification
bash -nclean on all four files.shellcheck -S warning: only the pre-existing SC2034s.smoke_serveunder CI is the first real execution through a script, and it is the point of putting that script in this batch.Remaining in #1485
7 discover-and-exit scripts still to migrate (
metrics_serve,pm_laya_route,pm_route,prism_route,recipes_route×3 picks,watchdog_serve), then the 11 with no detection at all (anchor_rerun,greedy_shortcut— already done —hrx_cpu_weight_parity,kvshare_fd_handoff.py,laya_gguf_route,laya_models_e2e,laya_route_e2e,mem_admit_route,npu_repack_path,serve_e2e).watchdog_serverestarts serve, so it needs the parse per launch rather than once.