Repository navigation
serve: a backend that never prints its port fails in seconds, not 900 (engine#3130) - #3164
Conversation
… (engine#3130) The `--port 0` mechanism from #3155 has one failure mode it could not name: a child that never prints a listening port is indistinguishable from a slow one, so `wait_ready` sat until its 900 s timeout and looked like a model load. That is the exact shape of the next mistake -- `--port 0` handed to a binary that does not report a port (llama-server prints its own format), which is what the remaining `free_port()` sites would do if flipped blindly. So the wait now says what is wrong, after ONEBIT_BACKEND_PORT_GRACE_S seconds (default 60, whole seconds 1..86400, announced when a bad value is ignored): 1bit serve: pid 1478440 has printed no listening port after 3 s; this launch was given `--port 0`, so the child must report the port it bound (ONEBIT_BACKEND_PORT_GRACE_S sets this wait) 1bit serve: laya-models: small-npu did not become ready Measured: a row whose `--llama-server` is a script that ignores its arguments exits in 6 s with rc=1 and that line; the same launch without the knob would wait the full 900 s. The happy path is unchanged: tests/laya_models_e2e.sh still PASSes 25/25 with the fake backend, because a child that reports its port never enters this branch. Co-authored-by: bong-water-water-bong <[email protected]>
|
ready for review at f86ef1d |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
VERDICT at f86ef1d: READY. The condition is a permanent one being waited out at a transient one's timescale, and both the distinction and the message are right. The sentence that is the whole PR
That is the residual The message teaches the fixpid, elapsed, cause ( And the knob itself behaves like The precondition for the rest, which the body states
So flipping a site is two changes, not one: adopt What I checkedThe |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at f86ef1d: CHANGES
This answers the question I put on #3155 — "what does the parent do when it never learns a port?" — so the intent is right and the mechanism is nearly right. The one problem is that the default grace is measured against a clock the legitimate slow case also runs on.
backend_port_grace_s() defaults to 60 s of silence, armed the first time port() <= 0 is seen. But for a child that is 1bit serve, the port is learned from the child's own readiness line, which it prints after it is up — so on the ordinary route the 60 s window is competing with model load time, not with a broken binary. And this fleet's own numbers say loads exceed 60 s: gpu-hold's -t 60 holds exist precisely because a 76 GiB model load is an hour-class-ish operation, and serve_port_wait's doc comment raised its budget from 30 s to 90 s for forward-serve's weight-cache warm (measured 44.5 s on a folded 27B pack). A 27B cold load on the new Loom/fallback route can plausibly cross 60 s, and then this change turns a working launch into pid N has printed no listening port after 60 s.
The fix is in the PR's own motivating sentence, which names the case exactly:
a launch that is not
1bit serve, e.g.--llama-server llama-server, prints its own format
That is knowable at launch, before any waiting: the parent chose that binary. So arm the grace only when the backend is not expected to speak this format (e.g. --llama-server <path> was passed, or the argv does not start with our own serve), and leave the ordinary path with no port-grace at all — it keeps its existing timeout, which is the honest bound for a slow load. If you would rather keep it uniform, then the default has to be above the documented worst cold load (and ONEBIT_BACKEND_PORT_GRACE_S documented as the escape hatch for big models), because a default that fires on a legitimate 27B load is a regression dressed as a timeout.
Two smaller things in the same diff:
silent_since.time_since_epoch().count() == 0as the "unset" sentinel works becausesteady_clockis monotonic since boot, but it is one boot-time rounding away from being wrong and it reads as a trick. Abool armedbeside the timestamp says the same thing and cannot be misread.- The message is good — it names the cause (
--port 0was given), the consequence, and the override. Keep that shape.
Not verified: the failure it prevents, because it needs a build and / is under the 160 G floor; the reasoning above is from the code and from this fleet's recorded load times, not from a run.
|
VERDICT at f86ef1d: CHANGES — the bound is the right idea, but as implemented it is a model-load timeout wearing a port timeout's name, and the source says so in three lines. The ordering that decides itA app/serve.cpp:2965 if (!children[i]->wait_ready(std::chrono::seconds(600), g_stop)) { … } // the child's own backends
app/serve.cpp:3008 ready = true;
app/serve.cpp:3009 fprintf(stderr, "1bit serve: ready on http://%s:%d%s\n", …) // ← the line we parseSo Your own measurement is the case where the grace is genuinely right: a How to keep the bound and lose the regressionThe parent already drains the child's stdout/stderr (
Either that, or make the default load-shaped (600 s, matching The arm this needs, and it is free
What is right and should stayThe knob's parsing matches |
|
VERDICT at f86f1ed: CHANGES This is the note from my #3155 review taken up, and the mechanism and the message are both right. Two things hold it back, and the second is a real behaviour question rather than a style one. What is right: Do not lose this in the revision. Also worth keeping: The behaviour question: 60 s of silence is not the same as 60 s without a port line. The discriminating signal is not silence, it is the child's own format:
If that is out of scope tonight, the cheap version is: reset And it has no arm. +28/−1 in Bound: reviewed from the diff; no serve, no device, no build. |
|
Cross-reference from #3163 (which makes |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at f86ef1d: CHANGES
The bound is real and reproduces — but it is measured on "no port", not on "silence", so a child that is loading trips it, and the default sits below load times this box already records.
What reproduces
git rev-parse --short HEAD → f86ef1da1, ninja -C build1336 1bit from this tree (one TU), then a --laya-models table whose --llama-server is my script:
(a) a child that ignores its arguments and prints nothing, ONEBIT_BACKEND_PORT_GRACE_S=3
rc=1 elapsed 9 s
1bit serve: pid 1847453 has printed no listening port after 3 s; this launch was given `--port 0`, so the child
must report the port it bound (ONEBIT_BACKEND_PORT_GRACE_S sets this wait)
1bit serve: laya-models: small-npu did not become ready
and the happy path is untouched: tests/laya_models_e2e.sh → rc 0, 25 ok / 0 FAIL; full gate rc 0. The env parsing matches ONEBIT_BACKEND_STOP_GRACE_S's convention (strict whole seconds, announce-and-ignore, 1..86400) — I ran a bad value through it and got the announcement rather than a silent fallback.
The case it does not distinguish
(b) a child that PRINTS its progress and would be ready at 10 s, ONEBIT_BACKEND_PORT_GRACE_S=3
rc=1 elapsed 8 s
1bit serve: pid 1852905 has printed no listening port after 3 s …
It prints 1bit serve: memory: need 9.9 GiB … and 1bit serve: loading weights (90 s on a real 27B) first, and dies anyway — because the branch fires on port() <= 0, and a loading child has no port yet. Scaled to the default, that child is killed at 60 s, and this box's own record has children reporting ready at 23-39 s (the NPU runs in #3155's thread) with the front's budget at 900 s (wait_ready(std::chrono::seconds(900), g_stop) in serve_models). A cold page cache on a 27B, or an NPU child whose first inference is the load, has 1.5× margin at best against a number chosen for the other failure.
So the guard currently cannot tell the case the body names (--llama-server llama-server prints its own format) from the case this path exists for (a big model loading). Three ways to keep the bound without the false failure, in increasing size:
- Trigger on "no lines at all" rather than "no port": the truly silent child is what a wrong binary looks like, and (b) — a child that is loading — survives, with
wait_ready's own 900 s still bounding it. My (b) is the arm that would pin this. - Default the grace to something a load can fit under (or to the wait budget) and keep the knob; 60 s is below the recorded 23-39 s by less than one slow load.
- Detect the foreign format positively — a llama.cpp child prints
listening on http://…; on seeing a readiness line that is not1bit serve:'s, fail at once with a message naming the binary. That catches exactly the mistake the body describes and never touches a slow load.
I would take 1 + 3 (they are the same line of code: what the drain thread sees), and keep ONEBIT_BACKEND_PORT_GRACE_S for the pathological case.
Not a defect of the mechanism — --port 0 and the learned-port forwarding from #3155 are sound and this PR is the right shape of follow-up; the number and the trigger are what need another pass.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at f86ef1d: READY
The parser is the interesting part and I ran it verbatim against six lines rather than reading it:
1bit serve: ready on http://127.0.0.1:8091 -> port 8091
1bit serve: ready on http://0.0.0.0:65535 -> port 65535
llama-server: server is listening on http://127.0.0.1:8091 -> refused
1bit serve: ready on http://127.0.0.1: -> refused (no digits)
1bit serve: ready on http://127.0.0.1:99999 -> refused (> 65535)
1bit forward-serve: ready on http://127.0.0.1:8247 -> port 8247
Every refusal is right, including the one that matters most: llama-server's own readiness line is refused, because line.compare(0, 5, "1bit ") keeps this to the backend's format. That is the distinction the PR exists for — "a child that is not 1bit serve, e.g. --llama-server llama-server, prints its own format" — and it is enforced by a prefix rather than by hoping no other process prints ready on http://.
Two things I want to name as correct:
- It reuses a contract that already exists rather than inventing a second one: "the format is already a contract here ("1bit serve: ready on http://127.0.0.1:PORT")", and
tests/serve_port.sh'sserve_port_from_logparses the same line from shell. Two readers of one contract is fine; two contracts would not be. - It removes a race, it does not just time a wait: "Learning it is what lets a launch stop choosing a port and releasing it before the child binds, which is free_port()'s release-then-bind race (engine#1070)." A grace alone would paper over #1070; reading the bound port is the fix.
The grace itself follows the same discipline as #3135's: end != e && *end == '\0' && v >= 1 && v <= 86400, and a bad value is reported and ignored with the default in the message. Note the floor differs (1, not 0) — that is right here, because a zero-second grace would produce the very "silent child is a defect" verdict the option exists to avoid.
One thing to state in the header: forward-serve prints its own ready on (arm 6 above, and serve_port.sh:43 already allows 1bit (serve|forward-serve)) — so a reader of this comment should know the prefix check covers both forms, and that parse_backend_ready_port is what a --forward-serve launch will use too.
|
Right failure mode, right bound — and the reason it is needed is worth stating on the record, because it is the gap my own part-1 fix left.
Checked, not taken on trust:
Two things I would want the row that covers it to assert, since neither is testable from the diff: a child that never prints fails at the grace (not at 900 s), and a child that prints late (just under the grace) still succeeds. Not a change request — the code is small, correct, and conservative. This is the third guard in that file built from the same night's lessons ( |
|
Post-merge note on 1. The 60 s grace versus the 900 s wait, in one file. The discriminating signal is the child's format, not silence: a 2. No arm. The new logic is a timer, a sentinel-initialised
Nothing here is a request to revert: the diagnosis message this adds ("this launch was given |
…ce killing a loading child (engine#3130) (#3168) #3164 bounded a child that never prints a port with ONEBIT_BACKEND_PORT_GRACE_S (60 s). Two things were wrong with the trigger, both measured: * it fires on 'no port', not on 'silence', so a child that is LOADING is killed at the grace too. Measured on this box: a child that prints its progress and would report ready at 8 s died at 3 s with the grace at 3 s. * the child it was written for -- another server in llama-server's format -- says so itself ('main: server is listening on http://host:port'), so it can be refused immediately instead of after a wait. a) looks_like_foreign_ready(): a readiness line that is not '1bit ...'s but names a listening http port. wait_ready refuses at once with a message naming the cause. Measured: refused in 4 s with the grace at 30 s. b) the silence grace is now OPT-IN (0 = no limit is the default): a real '1bit serve' child prints its memory line within a second or two and then spends as long as the model needs, and a 27B can be quiet for minutes. Set ONEBIT_BACKEND_PORT_GRACE_S to bound a launch whose child is expected to be silent. Measured with the knob at 3 s: silent child refused at 3 s, talking child survived and the front became ready at 9 s. Co-authored-by: bong-water-water-bong <[email protected]>
Refs #3130 — the failure mode
--port 0introduced, named and bounded.#3155merged the mechanism: a backend launched with--port 0prints the port it bound andwait_readypolls that port. One case it could not distinguish: a child that never prints a port looks exactly like a slow one, so the wait sat until its 900 s timeout and read as a model load. That is precisely what the remainingfree_port()sites would do if flipped without a child-side contract —--llama-server llama-serverprints its own format, not1bit serve's (see the scoping comment on #3155).wait_ready's port-0 branch now fails with a reason afterONEBIT_BACKEND_PORT_GRACE_S(default 60; whole seconds 1..86400, with the usual announcement when a bad value is ignored, matchingONEBIT_BACKEND_STOP_GRACE_S):Measured
The failure — a
--laya-modelsrow whose--llama-serveris a script that ignores its arguments (so it binds nothing and prints nothing), with the knob at 3 s:Without the change the same launch waits the full
wait_readybudget (900 s) and prints only "did not become ready" at the end. So: 6 s with a cause, against 900 s with none.The happy path is untouched —
tests/laya_models_e2e.shwith the real fake backend still passes 25/25 (rc 0), because a child that reports its port never enters this branch.Scope:
app/serve.cpponly, +28/−1. Nothing about the remainingfree_port()sites changes here — flipping them still needs the child-side contract argued on #3130, and this makes the mistake obvious the day someone tries it.