Skip to content

tests: the five serve route tests retry a taken port instead of failing on it (closes #1444) - #1446

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

bong-water-water-bong merged 1 commit into
mainfrom
1bit/i669-port-collision-retry

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #1444.

The shape

All five pick the front port with bind(0)-then-release and then launch a server that binds it later — serve starts its backends first, each on its own free_port(), before bind_to_port(o.host, o.port) (app/serve.cpp:2192). On a ctest -j runner another serve can take the port inside that window. Each script already detects the collision and prints FAIL: <test>: could not bind a port N (Address already in use) — and then exit 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:

EADDRINUSE|address already in use|cannot listen on

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 -n clean on all five; shellcheck -S warning reports only the pre-existing SC2034 warnings that come from variables used through eval.
  • The retry decision in isolation, deterministically (the race only happens sometimes on CI, so here the port is squatted before the launch):
# held port 36817 is squatted before either arm starts
before (no retry): FAIL after 1 attempt(s) (port 36817)
after  (3 tries) :      note: port 36817 was taken before server bound it; retrying with a fresh port (attempt 2/4)
PASS on attempt 2 (port 54633)
  • Not covered: the end-to-end run. This box has no onebit binary, 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.sh and tests/laya_gguf_route.sh use the same bind(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.

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

@bong-water-water-bong
bong-water-water-bong merged commit fb0cda3 into main Nov 8, 2026
9 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/i669-port-collision-retry branch November 8, 2026 11:16
@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 🔶

1444 - Partially compliant

Compliant requirements:

  • All five test scripts now retry on port collision up to 3 times
  • The retry mechanism correctly identifies bind failures using regex patterns
  • Note messages are printed for each retry attempt
  • The final failure message is preserved for persistent collisions
  • No changes to serve's startup order or behavior

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Port collision retry logic

The retry logic for port collisions in device_route.sh correctly handles the case where a port is taken before serve binds it, but the check for EADDRINUSE is done after killing the process. This could potentially miss a race condition where the port is taken between the process start and the check.

run() {  # <record> <model> [serve args]
    local attempt port
    for attempt in 1 2 3; do
        port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')
        RECORD="$1" "$bin" serve -m "$scratch/$2.gguf" --port "$port" --llama-server "$scratch/backend.py" "${@:3}" >"$1.log" 2>&1 &
        pid=$!
        for _ in $(seq 1 100); do [ -s "$1" ] && break; sleep 0.1; done
        kill -9 "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
        if ! grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$1.log"; then break; fi
        if [ "$attempt" -ge 3 ]; then break; fi
            # A server that never came up because it could not bind is a port collision, not a defect in what
            # this test checks: serve picks the port, releases it, and launches its backends before it binds, so on
            # a -j runner another serve can take it inside that window. Re-pick a bounded number of times; the FAIL
            # message below stays for a collision that will not go away (engine #1444).
        echo "     note: port $port was taken before serve bound it; retrying with a fresh port (attempt $((attempt + 1))/3)"
    done
    if grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$1.log"; then
        echo "FAIL: device_route: could not bind a port $port ($(grep -m1 -oiE 'EADDRINUSE|address already in use|cannot listen on [^ ]*' "$1.log" | head -1))"
        exit 1
    fi
}
Port collision retry logic

Similar to device_route.sh, the retry logic in hrx_cwsr_route.sh checks for EADDRINUSE after killing the process, which may not be robust against race conditions.

run() {  # <record> [serve args]: the backend's three variables, as JSON, in <record>; serve's log in <record>.log
    local attempt port
    for attempt in 1 2 3; do
        port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')
        RECORD="$1" "$bin" serve -m "$scratch/plain.gguf" --port "$port" --llama-server "$scratch/backend.py" \
            --no-mem-check "${@:2}" >"$1.log" 2>&1 &
        pid=$!
        for _ in $(seq 1 100); do [ -s "$1" ] && break; kill -0 "$pid" 2>/dev/null || break; sleep 0.1; done
        kill -9 "$pid" 2>/dev/null; wait "$pid" 2>/dev/null
        if ! grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$1.log"; then break; fi
        if [ "$attempt" -ge 3 ]; then break; fi
            # A server that never came up because it could not bind is a port collision, not a defect in what
            # this test checks: serve picks the port, releases it, and launches its backends before it binds, so on
            # a -j runner another serve can take it inside that window. Re-pick a bounded number of times; the FAIL
            # message below stays for a collision that will not go away (engine #1444).
        echo "     note: port $port was taken before serve bound it; retrying with a fresh port (attempt $((attempt + 1))/3)"
    done
    if grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$1.log"; then
        echo "FAIL: hrx_cwsr_route: could not bind a port $port ($(grep -m1 -oiE 'EADDRINUSE|address already in use|cannot listen on [^ ]*' "$1.log" | head -1))"
        exit 1
    fi
}
Port collision retry logic

The retry logic in hybrid_e2e.sh checks for EADDRINUSE after stopping the process, which may not be sufficient to catch all race conditions where the port is taken between process start and the check.

start() {   # start <device> <log> [env...]
    local device=$1 log=$2; shift 2
    local attempt port code
    for attempt in 1 2 3; do
        port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')
        env "$@" "$bin" serve -m "$model" --device "$device" --port "$port" --alias e2e-model --ctx-size 2048 \
            --no-mem-check "${server_arg[@]}" >"$log" 2>&1 &
        pid=$!
        api="http://127.0.0.1:$port"
        code=000
        for _ in $(seq 1 1200); do
            code=$(curl -s -o /dev/null -w '%{http_code}' "$api/health"); [ "$code" = 200 ] && break
            kill -0 "$pid" 2>/dev/null || break; sleep 0.5
        done
        if [ "$code" != 200 ] && grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$log" && [ "$attempt" -lt 3 ]; then
            # A server that never came up because it could not bind is a port collision, not a defect in what
            # this test checks: serve picks the port, releases it, and launches its backends before it binds, so on
            # a -j runner another serve can take it inside that window. Re-pick a bounded number of times; the FAIL
            # message below stays for a collision that will not go away (engine #1444).
            echo "     note: port $port was taken before serve bound it; retrying with a fresh port (attempt $((attempt + 1))/3)"
            stop
            continue
        fi
        break
    done
    if grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$log"; then
        echo "FAIL: hybrid_e2e: could not bind a port $port ($(grep -m1 -oiE 'EADDRINUSE|address already in use|cannot listen on [^ ]*' "$log" | head -1))"
        exit 1
    fi
Port collision retry logic

The retry logic in hybrid_kvshare_route.sh checks for EADDRINUSE after stopping the process, which may not be sufficient to catch all race conditions where the port is taken between process start and the check.

start() {   # start <log> [env...]
    local log=$1; shift
    local attempt port code
    for attempt in 1 2 3; do
        port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')
        env FAKE_KVSHARE_MARKER="$scratch/provider.json" FAKE_SLOT_MARKER="$scratch/slot.json" "$@" "$bin" serve -m "$scratch/tiny.gguf" --device hybrid --port "$port" --alias hybrid-model \
            --llama-server "$here/fake_backend.py" --no-mem-check >"$log" 2>&1 &
        pid=$!
        api="http://127.0.0.1:$port"
        code=000
        for _ in $(seq 1 100); do code=$(curl -s -o /dev/null -w '%{http_code}' "$api/health"); [ "$code" = 200 ] && break; sleep 0.1; done
        if [ "$code" != 200 ] && grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$log" && [ "$attempt" -lt 3 ]; then
            # A server that never came up because it could not bind is a port collision, not a defect in what
            # this test checks: serve picks the port, releases it, and launches its backends before it binds, so on
            # a -j runner another serve can take it inside that window. Re-pick a bounded number of times; the FAIL
            # message below stays for a collision that will not go away (engine #1444).
            echo "     note: port $port was taken before serve bound it; retrying with a fresh port (attempt $((attempt + 1))/3)"
            stop
            continue
        fi
        break
    done
    if grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$log"; then
        echo "FAIL: hybrid_kvshare_route: could not bind a port $port ($(grep -m1 -oiE 'EADDRINUSE|address already in use|cannot listen on [^ ]*' "$log" | head -1))"
        exit 1
    fi
Port collision retry logic

The retry logic in hybrid_route.sh checks for EADDRINUSE after stopping the process, which may not be sufficient to catch all race conditions where the port is taken between process start and the check.

start() {   # start <log> [env...]: serve on a free port with the fake backend, env applied to serve
    local log=$1; shift
    local attempt port code deadline
    for attempt in 1 2 3; do
        port=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1])')
        env FAKE_SLOT_MARKER="$scratch/slot.json" "$@" "$bin" serve -m "$scratch/tiny.gguf" --device hybrid --port "$port" --alias hybrid-model \
            --llama-server "$here/fake_backend.py" --no-mem-check >"$log" 2>&1 &
        pid=$!
        api="http://127.0.0.1:$port"
        # A deadline in seconds, not a try count: the old 100-try loop took 6.7 s on a quiet box and 15.2 s on the
        # same commit on a loaded CI runner, so a slow runner exhausted it and four checks failed as if routing had
        # broken (engine #850).
        code=000 deadline=$((SECONDS + ${HYBRID_ROUTE_START_S:-60}))
        while :; do
            code=$(curl -s -o /dev/null -w '%{http_code}' "$api/health")
            [ "$code" = 200 ] && break
            [ $SECONDS -lt $deadline ] || break
            sleep 0.1
        done
        if [ "$code" != 200 ] && grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$log" && [ "$attempt" -lt 3 ]; then
            # A server that never came up because it could not bind is a port collision, not a defect in what
            # this test checks: serve picks the port, releases it, and launches its backends before it binds, so on
            # a -j runner another serve can take it inside that window. Re-pick a bounded number of times; the FAIL
            # message below stays for a collision that will not go away (engine #1444).
            echo "     note: port $port was taken before serve bound it; retrying with a fresh port (attempt $((attempt + 1))/3)"
            stop
            continue
        fi
        break
    done
    if [ "$code" != 200 ]; then
        if grep -qiE 'EADDRINUSE|address already in use|cannot listen on' "$log"; then
            echo "FAIL: hybrid_route: could not bind a port $port ($(grep -m1 -oiE 'EADDRINUSE|address already in use|cannot listen on [^ ]*' "$log" | head -1))"
            exit 1
        fi

bong-water-water-bong added a commit that referenced this pull request Nov 8, 2026
…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]>
bong-water-water-bong added a commit that referenced this pull request Nov 8, 2026
…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]>
bong-water-water-bong pushed a commit that referenced this pull request Nov 9, 2026
…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.
bong-water-water-bong pushed a commit that referenced this pull request Nov 9, 2026
…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.
bong-water-water-bong pushed a commit that referenced this pull request Nov 9, 2026
…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.
bong-water-water-bong added a commit that referenced this pull request Nov 9, 2026
…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]>
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.

tests: five serve route tests fail on a front-port collision instead of retrying (check-then-use race, CI flake)

1 participant