Repository navigation
tests: the five serve route tests retry a taken port instead of failing on it (closes #1444) - #1446
Conversation
…ng on it
All five pick their front port with bind(0)-then-release and launch a server that binds it later, behind its own
backends, so on a `ctest -j` runner another serve can take it inside that window. Each script already *detects* the
collision and says so ("could not bind a port N (Address already in use)"), then exits 1 - which fails the whole test
for something it does not test. That is the flake in ci run 42468438033 (engine #1444).
Now the launch is retried up to three attempts, re-picking the port each time, and *only* when the log shows the
failure was the bind itself (`EADDRINUSE|address already in use|cannot listen on`). The existing FAIL message is kept
for the last attempt, so a genuine bind problem on every port still fails loudly, and every other failure path is
untouched: a server that dies for another reason does not get retried and reports exactly what it reported before.
`start()`-style (hybrid_route, hybrid_kvshare_route, hybrid_e2e) re-picks around the whole launch+poll, and stops the
dead child before retrying. `run()`-style (hrx_cwsr_route, device_route) retries after the kill/wait, and breaks out of
the loop as soon as the log does not name a bind failure.
The retry is not silent: each one prints `note: port N was taken before serve bound it; retrying with a fresh port
(attempt k/3)`, so a runner where this happens on every attempt is visible in the log rather than absorbed.
Verified: `bash -n` on all five; `shellcheck -S warning` reports only the pre-existing SC2034 warnings that come from
variables used through `eval`; and the retry decision itself in isolation - a squatted port, the old shape fails on
attempt 1, the new shape prints the note and passes on attempt 2. The end-to-end case is the CI that reported the flake
(this box has no `onebit` binary, so it cannot run these tests locally).
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at dab71be8db.
Both mechanical claims hold, and I checked "pre-existing" rather than taking it:
bash -n all five scripts rc 0
shellcheck -S warning, codes/counts now vs origin/main:
device_route.sh 1 SC2034 / main 1 SC2034
hrx_cwsr_route.sh 1 SC2034 / main 1 SC2034
hybrid_e2e.sh 2 SC2034 / main 2 SC2034
hybrid_kvshare_route.sh 2 SC2034 / main 2 SC2034
hybrid_route.sh 3 SC2034 / main 3 SC2034
identical per file, so the change adds no findings — the claim is exactly right, not approximately.
And I exercised the control flow with a stub, because that is what this change is: the launch replaced by a fake serve whose log and HTTP
code I drive, so the loop runs for real.
MODE=retry bind failure on attempt 1, success on 2 -> 1 note, attempts=2, code 200, port 40147 -> 50877 (re-picked)
MODE=always bind failure every time -> notes on 1 and 2, attempts=3, code 000 -> falls to the existing FAIL
MODE=other a real defect ("model load failed") -> attempts=1, code 000, NO note, NO retry
That third case is the one that matters: a genuine failure is not retried and not masked — the FAIL message it deserves is the one that
survives. The retry fires only on EADDRINUSE|address already in use|cannot listen on, which is the condition that is not a defect in what the
test checks. stop runs before continue, so a failed attempt leaves no process or port behind, and the FAIL branch after the loop distinguishes a
persistent collision from any other failure.
One question, not a hold: the wait deadline is computed per attempt (deadline=$((SECONDS + 60)) inside the loop), so a bind problem that
never clears now costs up to 3 × 60 s per test, × five tests. On the loaded runner your own comment describes (#850: 6.7 s quiet vs 15.2 s
loaded) that is the failure mode most likely to hit a job-level timeout and turn "one test flaked" into "the whole job was killed". If the job budget
is comfortable, leave it; otherwise compute the deadline once before the loop so retries share it — that keeps the flake fix without tripling
the worst case.
Coverage, stated the way you did: no end-to-end here either — there is no onebit binary on this box, so my evidence is the two mechanical
claims plus the control flow above, and CI on this PR is the first real run. Also worth knowing for the next one: the block is now copied five times
(device_route.sh, hrx_cwsr_route.sh, hybrid_e2e.sh, hybrid_kvshare_route.sh, hybrid_route.sh) which is consistent with this repo having no
shared test lib — fine, but the sixth copy is the moment to extract one.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
…op guessing one (refs #1485) (#1490) * serve: --port 0 reports the port the kernel gave it, and one test stops guessing `serve` printed `o.port` in its ready line, so `--port 0` bound an ephemeral port and then announced port 0 - the capability was one line away and unusable, which is why 24 test scripts still pick a port with bind(0), release it, and launch a server that binds it later. That release-then-bind window is the flake in engine #1444, and #1446 only retried around five of them. Now both bind sites take the bound port and print that: cpp-httplib's `bind_to_port()` answers bool, so the port comes from `bind_to_any_port()`, which is the same `bind_internal(host, 0, ...)` path and returns -1 on failure (vendor/cpp-httplib/httplib.cpp:7508 and its `if (port == 0)` getsockname branch). A negative result still throws `cannot listen on host:port`, so a genuine bind failure is unchanged. `tests/greedy_shortcut.sh` is migrated as the reference: `--port 0`, and the port is read from serve's own ready line instead of guessed before the launch. Nothing is picked and released, so there is no race to lose - the mechanism the other scripts in #1485 need. Not covered here: the delegating `serve_child` modes still pass `o.port` through to their llama-server child (`app/serve.cpp:3380`, `:3417`, `:3450`, `:3497`, `:3524`), so `--port 0` is for the plain serve paths the tests use, not for those. And this box has no engine build tree, so the compile and the `--port 0` behaviour are verified by the PR's CI (which builds `onebit` and runs this script), not locally. * tests: the ready-line parse takes the port after the last colon, so an IPv6 --host parses too Reviewer nit on #1490: `[^:]*` for the host stops at the first colon, so `--host ::1` would capture nothing (or the wrong field). `.*` is greedy to the last colon, and the port is the digits at the end of the line. Checked against three shapes rather than asserted: `127.0.0.1:41234` -> 41234, `::1:41235` -> 41235, `localhost:41236` -> 41236, and a non-ready line still yields nothing. --------- Co-authored-by: bong-water-water-bong <[email protected]>
…ng one (refs #1485) (#1525) 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. Co-authored-by: bong-water-water-bong <[email protected]>
…which retires the retry These six still picked a port and, where #1446 had added it, retried around the collision. `serve --port 0` (#1490) exists now, so the retry has nothing left to race against: each script launches serve with `--port 0` and reads the port back from serve's own ready line, and the retry loop, the `EADDRINUSE` branch and the second failure branch all go. - `hybrid_route.sh`, `hybrid_kvshare_route.sh`, `hybrid_e2e.sh` (`start()`): `serve_port_wait` before `$api` is built, budgets 900 / 900 / 6000 tenths (hybrid_e2e's own health window is 1200 x 0.5 s and it loads a model). - `hrx_cwsr_route.sh`, `device_route.sh` (`run()`): no readiness parse needed - they read the backend's record file - and they keep the liveness half (`kill -0 || break`) so a serve that dies fails immediately instead of sleeping the budget. - `pm_laya_route.sh`: serve on `--port 0` + `serve_port_wait`; `freeport()` stays for the fake **lemonade python** process, which is not serve and cannot report a port. Census in the same commit, as in every batch: `_onebit_route_tests` keeps exactly the scripts that still pick a port up front (smoke_serve, print_backend, lemonade_hrx, template_pin, pm_route, plus bench_selftest which binds through tools/bench.py and is pinned by its own case). The census floor goes 9 -> 5 - it counted 15 before this migration. `bash -n` clean on all six; shellcheck warning counts unchanged against main on five and one FEWER on hybrid_e2e (2 -> 1); census rehearsed against a stand-in `ctest`: 3/3 cases pass. Not run end to end: hybrid_e2e and pm_laya_route need a model and a laya checkpoint, which this box has not; hybrid_route, hybrid_kvshare_route, hrx_cwsr_route and device_route run in the CI build job, which is where this diff gets exercised.
…which retires the retry These six still picked a port and, where #1446 had added it, retried around the collision. `serve --port 0` (#1490) exists now, so the retry has nothing left to race against: each script launches serve with `--port 0` and reads the port back from serve's own ready line, and the retry loop, the `EADDRINUSE` branch and the second failure branch all go. - `hybrid_route.sh`, `hybrid_kvshare_route.sh`, `hybrid_e2e.sh` (`start()`): `serve_port_wait` before `$api` is built, budgets 900 / 900 / 6000 tenths (hybrid_e2e's own health window is 1200 x 0.5 s and it loads a model). - `hrx_cwsr_route.sh`, `device_route.sh` (`run()`): no readiness parse needed - they read the backend's record file - and they keep the liveness half (`kill -0 || break`) so a serve that dies fails immediately instead of sleeping the budget. - `pm_laya_route.sh`: serve on `--port 0` + `serve_port_wait`; `freeport()` stays for the fake **lemonade python** process, which is not serve and cannot report a port. Census in the same commit, as in every batch: `_onebit_route_tests` keeps exactly the scripts that still pick a port up front (smoke_serve, print_backend, lemonade_hrx, template_pin, pm_route, plus bench_selftest which binds through tools/bench.py and is pinned by its own case). The census floor goes 9 -> 5 - it counted 15 before this migration. `bash -n` clean on all six; shellcheck warning counts unchanged against main on five and one FEWER on hybrid_e2e (2 -> 1); census rehearsed against a stand-in `ctest`: 3/3 cases pass. Not run end to end: hybrid_e2e and pm_laya_route need a model and a laya checkpoint, which this box has not; hybrid_route, hybrid_kvshare_route, hrx_cwsr_route and device_route run in the CI build job, which is where this diff gets exercised.
…which retires the retry These six still picked a port and, where #1446 had added it, retried around the collision. `serve --port 0` (#1490) exists now, so the retry has nothing left to race against: each script launches serve with `--port 0` and reads the port back from serve's own ready line, and the retry loop, the `EADDRINUSE` branch and the second failure branch all go. - `hybrid_route.sh`, `hybrid_kvshare_route.sh`, `hybrid_e2e.sh` (`start()`): `serve_port_wait` before `$api` is built, budgets 900 / 900 / 6000 tenths (hybrid_e2e's own health window is 1200 x 0.5 s and it loads a model). - `hrx_cwsr_route.sh`, `device_route.sh` (`run()`): no readiness parse needed - they read the backend's record file - and they keep the liveness half (`kill -0 || break`) so a serve that dies fails immediately instead of sleeping the budget. - `pm_laya_route.sh`: serve on `--port 0` + `serve_port_wait`; `freeport()` stays for the fake **lemonade python** process, which is not serve and cannot report a port. Census in the same commit, as in every batch: `_onebit_route_tests` keeps exactly the scripts that still pick a port up front (smoke_serve, print_backend, lemonade_hrx, template_pin, pm_route, plus bench_selftest which binds through tools/bench.py and is pinned by its own case). The census floor goes 9 -> 5 - it counted 15 before this migration. `bash -n` clean on all six; shellcheck warning counts unchanged against main on five and one FEWER on hybrid_e2e (2 -> 1); census rehearsed against a stand-in `ctest`: 3/3 cases pass. Not run end to end: hybrid_e2e and pm_laya_route need a model and a laya checkpoint, which this box has not; hybrid_route, hybrid_kvshare_route, hrx_cwsr_route and device_route run in the CI build job, which is where this diff gets exercised.
…which retires the retry (#1607) These six still picked a port and, where #1446 had added it, retried around the collision. `serve --port 0` (#1490) exists now, so the retry has nothing left to race against: each script launches serve with `--port 0` and reads the port back from serve's own ready line, and the retry loop, the `EADDRINUSE` branch and the second failure branch all go. - `hybrid_route.sh`, `hybrid_kvshare_route.sh`, `hybrid_e2e.sh` (`start()`): `serve_port_wait` before `$api` is built, budgets 900 / 900 / 6000 tenths (hybrid_e2e's own health window is 1200 x 0.5 s and it loads a model). - `hrx_cwsr_route.sh`, `device_route.sh` (`run()`): no readiness parse needed - they read the backend's record file - and they keep the liveness half (`kill -0 || break`) so a serve that dies fails immediately instead of sleeping the budget. - `pm_laya_route.sh`: serve on `--port 0` + `serve_port_wait`; `freeport()` stays for the fake **lemonade python** process, which is not serve and cannot report a port. Census in the same commit, as in every batch: `_onebit_route_tests` keeps exactly the scripts that still pick a port up front (smoke_serve, print_backend, lemonade_hrx, template_pin, pm_route, plus bench_selftest which binds through tools/bench.py and is pinned by its own case). The census floor goes 9 -> 5 - it counted 15 before this migration. `bash -n` clean on all six; shellcheck warning counts unchanged against main on five and one FEWER on hybrid_e2e (2 -> 1); census rehearsed against a stand-in `ctest`: 3/3 cases pass. Not run end to end: hybrid_e2e and pm_laya_route need a model and a laya checkpoint, which this box has not; hybrid_route, hybrid_kvshare_route, hrx_cwsr_route and device_route run in the CI build job, which is where this diff gets exercised. Co-authored-by: bong-water-water-bong <[email protected]>
Closes #1444.
The shape
All five pick the front port with
bind(0)-then-release and then launch a server that binds it later —servestarts its backends first, each on its ownfree_port(), beforebind_to_port(o.host, o.port)(app/serve.cpp:2192). On actest -jrunner another serve can take the port inside that window. Each script already detects the collision and printsFAIL: <test>: could not bind a port N (Address already in use)— and thenexit 1s, failing the whole test for something it does not test. That is the flake in ci run 42468438033.The fix
The launch is retried up to three attempts, re-picking the port each time, and only when the log shows the failure was the bind itself:
The existing FAIL message is kept for the last attempt, so a box where no port can be bound still fails loudly and says which port and why. Everything else is untouched: a server that dies for another reason is not retried, and reports exactly what it reported before.
start()-style (hybrid_route,hybrid_kvshare_route,hybrid_e2e): the retry wraps launch+poll, and stops the dead child before re-picking.run()-style (hrx_cwsr_route,device_route): the retry happens after the existing kill/wait, and breaks out as soon as the log does not name a bind failure.Not silent: each retry prints
note: port N was taken before serve bound it; retrying with a fresh port (attempt k/3), so a runner where this happens every time is visible instead of absorbed.Verification, and what it does not cover
bash -nclean on all five;shellcheck -S warningreports only the pre-existing SC2034 warnings that come from variables used througheval.onebitbinary, so these tests cannot be executed here; the first real exercise of the retry across all five is the CI on this PR. If that goes green it is evidence the normal path is unchanged; it will not, on its own, prove the retry fires — the isolated row above is what does that.Scope note
tests/anchor_rerun.sh,tests/greedy_shortcut.shandtests/laya_gguf_route.shuse the samebind(0)-then-launch pattern and are not in this PR, because the issue names these five and they are the ones CI has failed on. Say the word and they are the same three-line change each.