Repository navigation
serve: refuse a foreign-format backend at once, and stop the port grace killing a loading child (engine#3130) - #3168
Conversation
…ce killing a loading child (engine#3130) #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.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
VERDICT at 7cb985e: CHANGES The code is right, and it is better than what I proposed. Two things hold it: the same missing arm as #3164, and — new — a line-number mismatch I found in the sibling PR that you may want to know about before the next push. Both points from my #3164 post-merge note are addressed, and the second one better than I suggested:
What is missing is the arm — the same gap #3164 had, and this time the failure is worse. The logic is three-way, and its regression mode is killing a 27B mid-load, i.e. a user-visible outage rather than a slow test. The third is the one that matters: it is the regression this PR exists to prevent, and without it a future "simplification" that restores a wall-clock default would pass every row. One thing to know, not an ask: the sibling PR #3159 cites the same card file's packet ceiling at Bound: reviewed from the diff; no serve run and no device. |
VERDICT at
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 7cb985e: READY
This answers my CHANGES on #3164 in the right way: it stops using the clock to tell a broken child from a loading one, and instead reads what the child says. My objection was that a 60 s silence grace competes with model load time on the ordinary route (this fleet's recorded loads cross 60 s: gpu-hold -t 60 for 76 GiB models, serve_port_wait raised to 90 s after a measured 44.5 s warm). This head makes exactly the two changes that remove the conflict:
- the grace defaults to
0= no silence limit (return 0, and the parser range widened to0..86400with the message updated to "no silence limit"), so nothing kills a1bit servechild that is legitimately quiet while a 27B loads. The knob stays for a launch whose child is expected to be silent. - a foreign-format readiness line is refused immediately —
looks_like_foreign_ready()recognises llama.cpp'slistening on http://…and flags it, which is the actual defect the grace was invented to paper over (--llama-server llama-servercan never satisfyparse_backend_ready_port). A child that is talking in the wrong format is caught in the first line it prints, not after N seconds.
That is the right shape: the defect is detected by evidence (what the child printed), and the clock is demoted to an optional bound rather than being the detector. It also removes the failure mode where the operator had to know a big model would be slow and raise an env var before the launch worked.
One thing I would like stated in the body, not required for this verdict: the ordering — if a child prints a foreign ready line and no port, the foreign flag must win before the grace could ever fire; and with the grace now 0 by default that ordering is the only detector, so a note saying "the foreign check is the detector; the grace is opt-in" is what a reader needs.
Not verified: the behaviour end-to-end (needs a build; / is under this lane's 160 G floor), including that foreign_ready_/last_line_ns_ are initialised before the drain thread starts — the diff shows them captured into the lambda, and the drain thread is detached, so the shared-atomic lifetime is the thing to have right (it looks the same shape as learned_port_, which I reviewed on #3155 and which worked).
|
Right correction, and one false positive that would break the nested rails — plus this PR adds no tests, so nothing would catch either. The correction is right. #3164's grace fired on "no port" rather than "silence", so a 27B printing its memory line and then loading for minutes was killed at 60 s. Defaulting The false positive is in // Child's reader thread (app/serve.cpp) — the child's stderr is passed on UNCHANGED …
const ssize_t w = ::write(2, buf + done, size_t(n - done));
…
for (const std::string& line : tail->feed(buf, size_t(n))) {
if (parse_backend_ready_port(line, parsed_port)) learned->store(parsed_port);
…
}
// this PR
static bool looks_like_foreign_ready(const std::string& line) {
if (line.compare(0, 5, "1bit ") == 0) return false;
return line.find("listening on") != std::string::npos && line.find("http://") != std::string::npos;
}A The discriminator that survives nesting: a genuine And the missing tests are now three behaviours, none of which this PR covers ( |
|
Merge-order check for the open Loom/serve PRs — measured, because #3166 and this PR both rewrite I merged this branch with #3166 ( Presence in the merged file: Also checked, pairwise, across the four open engine PRs (#3166, #3167, #3159, #3168): all six pairs merge clean, so the queue is not blocking itself on conflicts. Bound: text and structure only — I did not build the merged tree (disk floor, single build queue), so this says the two behaviours coexist, not that the pair compiles or serves. |
|
Composition check with #3166 (the Loom route, which is open against the same The two failures are #3166's, not this PR's: And the grace arms still behave with the Loom route in the tree, which was the thing worth checking (both PRs touch the
So: either order is safe for this PR; #3166 needs one arm and one message to agree before it is green. |
|
I built your head and ran a nested fixture; two corrections to my own review, one of them narrowing it and one of them confirming the mechanism. The mechanism's precondition is real, measured: a grandchild's line does reach the outer serve. Correction 1 — my "would refuse at once" was too broad. At this head the outer served normally: the foreign check lives inside Correction 2 — it still applies to the one rail that does pass Which makes And it raises the value of the arm I asked for: with |
The half you could not run: this box has the checkpoint, and the
|
Your PR and #3166 are both rewriting
|
One more data point for
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 7cb985e: READY — the three-way split is the right shape, and it is the first version of this wait that does not use the clock to answer a question the child's output already answers: (a) a readiness line in another server's format is refused at once (looks_like_foreign_ready, with the 1bit prefix excluded so our own line is untouched), (b) a child that has printed nothing for the grace is not a server, (c) a child that is talking is loading and gets wait_ready's 900 s. Moving the grace default to 0 follows from (c) rather than being a loosening: a number sized for (a) must not bound a 27B mid-load, and the parser range widening to 0..86400 keeps the old behaviour available for anyone who wants it.
One question I would want answered in the commit message, not in code: with the grace at 0, what catches a child that exits without ever printing a line? If an exit check (a waitpid/EOF on the pipe) ends the wait immediately, then the trade is clean. If the only bound left is the 900 s timeout, then a mistyped --llama-server path now costs 15 minutes instead of 60 seconds, and that is a real regression for the human in front of it even though it is the right call for the model load.
Secondary and non-blocking: looks_like_foreign_ready is a substring pair (listening on + http://), so a loading child that prints an unrelated line containing both would be refused. The prefix exclusion makes that unlikely, and I would take the behaviour as-is — just worth one line so the next reader knows it was considered rather than missed.
Nothing else from me; the reasoning in the body is the part that makes this reviewable, and it holds.
Retracting the finding I posted above: it was a stale binary, and the rail is fine on
|
PR #3168 merged the foreign-format refusal into main without the own-line half both reviewers asked for at 7cb985e, and that half is not optional on the rail the refusal can reach. Measured on this box, on main (34a82cf), with a child that announces its port the way llama-server does: 1bit serve: laya-models: starting nested-row on cpu (port 0) 1bit serve: nested-row on cpu (tests/fake_llama_announce.sh) <- the child, in our format srv llama_server: listening on http://127.0.0.1:34797 <- its GRANDCHILD, teed through 1bit serve: pid 1263999 announced a port in a format `1bit serve` does not print ... 1bit serve: laya-models: nested-row did not become ready rc=1 `--laya-models` launches its child with `--port 0` (app/serve.cpp:2106, the only such site) and that child is ALWAYS a nested `1bit serve`, so the refusal's true-positive case is unreachable on every shipped rail: the only foreign line it can see is a grandchild's, arriving across the child's stderr tee. Fix: a line in our format is recorded as it is read, and a foreign-format line only counts while the child has not spoken ours yet. The condition is evaluated in the drain thread, not at the refusal, because the refusal polls every 250 ms and would still race a child that has not printed yet. The ordering it relies on is structural: serve prints "1bit serve: <model> on <device> (<backend>)" (app/serve.cpp:3015) BEFORE it constructs the Child, so a nested child has spoken our format before its own child exists. Test: tests/serve_nested_foreign.sh drives the real --laya-models front, the real nested serve and the real port read-back against tests/fake_llama_announce.sh (a fake llama-server that announces its port on stderr and models the load gap). Four arms, including one that greps the log for the grandchild's line so the case cannot pass vacuously. Registered through tests/laya_e2e_guard.sh with the other laya_* rows (77 with a reason when there is no checkpoint). This is also the merged guard's first test at all. laya_models_e2e, laya_route_e2e and smoke_serve are green at this head.
…ever fire (engine#3130) (#3206) launch_for fills argv[0] with llama-server on every branch that returns and gguf_devices() is hrx/cpu only, so launched.argv[0] == /proc/self/exe is unreachable: the site always took free_port() and then replaced it with another free_port(). Deleted rather than repaired, because a --laya child cannot report a port it bound and a llama-server on --port 0 is what engine#3171's refusal refuses; the rail that does pass --port 0 to our own serve is --laya-models, which reads the port back (#3168). No behaviour change. kPortTakenRetries stays for foreign children (tests/hybrid_route.sh asserts that relaunch); a future --port 0 site must skip the loop rather than let set_port_arg freeze a picked port. Co-authored-by: bong-water-water-bong <[email protected]>
Follow-up to #3164 (merged) and #3130. #3164 bounded a child that never prints a port with
ONEBIT_BACKEND_PORT_GRACE_S, default 60 s. Two things about the trigger, both measured here, and this changes only the trigger:1. It fires on "no port", not on "silence", so a loading child is killed
A child that prints its progress and would report ready at 8 s, with the grace at 3 s:
Scaled to the default that is 60 s, against ready times this fleet already records at 23-39 s for NPU children and a
wait_readybudget of 900 s (serve_models). A 27B child prints its memory line and then loads for as long as it loads — a grace sized for a wrong binary is the wrong instrument for that.2. The case the grace was written for announces itself
--llama-server llama-serverprints llama.cpp's own line —main: server is listening on http://host:port— so it can be refused at once, naming the cause, instead of waited out:The change (
app/serve.cpp, +41/-9)looks_like_foreign_ready(line): a readiness line that is not1bit …'s but names a listening http port. The drain thread sets a shared atomic;wait_readyrefuses immediately.ONEBIT_BACKEND_PORT_GRACE_Skeeps its spelling, its range (now 0..86400) and its announce-and-ignore behaviour, but 0 — no silence limit — is the default: a1bit servechild always says something within a second or two, and after that the model load is not a reason to kill it. The knobs' own doc comment says what it is for.Measured, one binary built from this branch
1bit servedoes not print"tests/laya_models_e2e.sh25 ok / 0 FAIL,pre-pr-checks --base origin/mainrc 0. No test file is touched, so nothing is registered differently; the three arms above are reproducible with the scripts in the PR body's method (a--laya-modelstable whose--llama-serveris the three shims).Not in this PR: the other four
free_port()sites (#3130's remaining slices), and any change towait_ready's 900 s budget.