Skip to content

serve: a backend that never prints its port fails in seconds, not 900 (engine#3130) - #3164

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-npurt/3130-backend-port-rest
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-npurt/3130-backend-port-rest

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #3130 — the failure mode --port 0 introduced, named and bounded.

#3155 merged the mechanism: a backend launched with --port 0 prints the port it bound and wait_ready polls 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 remaining free_port() sites would do if flipped without a child-side contract — --llama-server llama-server prints its own format, not 1bit serve's (see the scoping comment on #3155).

wait_ready's port-0 branch now fails with a reason after ONEBIT_BACKEND_PORT_GRACE_S (default 60; whole seconds 1..86400, with the usual announcement when a bad value is ignored, matching ONEBIT_BACKEND_STOP_GRACE_S):

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

The failure — a --laya-models row whose --llama-server is a script that ignores its arguments (so it binds nothing and prints nothing), with the knob at 3 s:

rc=1 elapsed=6s
1bit serve: small-npu on cpu (…/silent-probe/silent.sh)
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

Without the change the same launch waits the full wait_ready budget (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.sh with the real fake backend still passes 25/25 (rc 0), because a child that reports its port never enters this branch.

Scope: app/serve.cpp only, +28/−1. Nothing about the remaining free_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.

… (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]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at f86ef1d

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3130 - Partially compliant

Compliant requirements:

  • The PR introduces a grace period (ONEBIT_BACKEND_PORT_GRACE_S) to detect when a backend launched with --port 0 fails to report its port
  • The wait_ready function now fails early when a backend does not report its port within the grace period
  • The fix prevents the system from waiting the full 900s timeout for backends that never print their port

Non-compliant requirements:

  • The PR does not fully address the root cause of the port race condition in free_port() for backends (this is a separate fix)

Requires further human verification:

  • The behavior of the port selection mechanism for backends needs to be verified with the full system to ensure no regressions
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Backend Port Grace Period Not Enforced

The backend port grace period is introduced to detect when a backend launched with --port 0 fails to report its port, but the implementation may not fully enforce this for all cases. Specifically, if a backend process starts and never prints its port, it will be detected after the grace period, but the mechanism may not be robust against edge cases in process startup or logging timing.

if (silent_since.time_since_epoch().count() == 0) silent_since = std::chrono::steady_clock::now();
if (std::chrono::steady_clock::now() - silent_since >= std::chrono::seconds(backend_port_grace_s())) {
    std::fprintf(stderr,
                 "1bit serve: pid %d has printed no listening port after %d s; this launch was given "
                 "`--port 0`, so the child must report the port it bound (ONEBIT_BACKEND_PORT_GRACE_S "
                 "sets this wait)\n", int(pid_), backend_port_grace_s());
    return false;
}

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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

"A child that never prints its readiness line is indistinguishable from a slow one, and the two need different answers: one waits, the other is a launch that asked for a port it will never be told."

That is the residual #3155 left, stated exactly. A 900 s budget is correct for a model load and meaningless for a child that will never print — the wait cannot tell a permanent condition from a transient one by duration alone, so it spends the transient budget on the permanent case and then reports it as a slow load. 60 s is the right resolution for the question actually being asked, and it is a grace rather than a timeout, which is the same shape #3135 gave the foreign-port case.

The message teaches the fix

1bit serve: pid %d has printed no listening port after %d s; this launch was given
`--port 0`, so the child must report the port it bound (ONEBIT_BACKEND_PORT_GRACE_S sets this wait)

pid, elapsed, cause (--port 0 means the child must report), and the knob that sets the wait. A user reading this knows which process, which decision, and how to change the number — which is the difference between a diagnostic and a stack trace.

And the knob itself behaves like #3135's: a mistyped value prints what it ignored, what is valid, and what it used (whole seconds, 1..86400; using 60).

The precondition for the rest, which the body states

"That is precisely what the remaining free_port() sites would do if flipped without a child-side contract — --llama-server llama-server prints its own format, not 1bit serve's."

So flipping a site is two changes, not one: adopt --port 0, and teach the child's line to the reader. Naming that here is what stops the next free_port() site from being flipped optimistically and inheriting the 900 s wait it was supposed to remove.

What I checked

The silent_since tracking and the grace comparison against it; the validating parse with its warning and stated range; the message's four pieces (pid, elapsed, cause, knob); the 60 s default against the 900 s budget it replaces; and the child-side-contract precondition for the remaining sites.

@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 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() == 0 as the "unset" sentinel works because steady_clock is monotonic since boot, but it is one boot-time rounding away from being wrong and it reads as a trick. A bool armed beside the timestamp says the same thing and cannot be misread.
  • The message is good — it names the cause (--port 0 was 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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 it

A --port 0 child is, by construction, always a nested 1bit serve (that is the only binary that prints the format parse_backend_ready_port looks for, and #3155's scoping comment says why). And a nested 1bit serve prints its readiness line after its own backends are ready:

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 parse

So port() <= 0 is true from the first poll until the model is loaded and serving — not until "the child should have said something by now". ONEBIT_BACKEND_PORT_GRACE_S=60 therefore bounds load time: a --port 0 child whose model takes 90 s to load is now killed at 60 s and told "pid N has printed no listening port", which is false in the only way that matters — it is loading, and it will print one.

Your own measurement is the case where the grace is genuinely right: a --llama-server script that ignores its arguments binds nothing and prints nothing, ever. That is a silent child, not a slow one — and the difference is available to the code you already have.

How to keep the bound and lose the regression

The parent already drains the child's stdout/stderr (serve_models builds line = [&metrics](const std::string& l){ metrics.backend_line(l); } and passes it into Child), so "has this child ever said anything" is one bool away from wait_ready:

  • silent (no output at all): the grace applies — that is your failing case, and 60 s is generous for it;
  • talking but no port (progress lines during a load): the grace should not apply, because the child is alive and working; the enclosing wait_ready(600 s) is the right budget, which is exactly what it was chosen for.

Either that, or make the default load-shaped (600 s, matching :2965) and keep the knob for the silent case — but then the original complaint comes back for the silent child unless the silence test above is added anyway. The first shape is one extra bool; the message then means what it says.

The arm this needs, and it is free

files is app/serve.cpp alone, so nothing pins either the bound or its default — and your measurement setup is already the perfect fixture: a fake --llama-server that ignores its arguments is device-free, needs no model, and reproduces in a second. Two arms, in the tests/parallel_args.sh harness that already fakes a backend:

  1. a child that never prints → fails within ONEBIT_BACKEND_PORT_GRACE_S (set it to 2 s so the arm is fast), with the message naming the knob;
  2. a child that prints a progress line and no port → is not failed at that same 2 s (the regression guard for the load case above) — this is the arm that would have caught what I am writing about.

What is right and should stay

The knob's parsing matches ONEBIT_BACKEND_STOP_GRACE_S exactly (whole seconds, 1..86400, announced when a bad value is ignored), the message names both the knob and the cause, and silent_since is set on the first poll rather than per-iteration, so the grace cannot drift. The --port N path is untouched — port() > 0 from the start, so no launch that chose its own port is affected.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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: ONEBIT_BACKEND_PORT_GRACE_S is validated the way stop_grace_s is (whole seconds 1..86400, a warning and 60 otherwise), the clock starts at the first poll with no port, and the refusal names the contract: "this launch was given --port 0, so the child must report the port it bound". That sentence is exactly what a lane needs instead of a 900 s wait followed by "did not become ready".

Do not lose this in the revision. Also worth keeping: silent_since as a sentinel-initialised time_point is safe because wait_ready is a fresh call per launch, so a relaunch gets a fresh grace — the same property I checked in #3135.

The behaviour question: 60 s of silence is not the same as 60 s without a port line. backend_port_grace_s measures wall time from the first poll, and a 1bit serve child prints its ready on http://… line only after the model loads. So for a row whose --bin/model takes longer than 60 s to load — the rack of --laya-models rows takes any r.model, and a custom row can serve a large GGUF on any device — this converts a slow load into a refused launch, while the same call site waits 900 s on purpose (wait_ready(std::chrono::seconds(900))). Those two numbers contradict each other for the slow-load case.

The discriminating signal is not silence, it is the child's own format:

  • a 1bit serve child eventually prints the line we parse → wait;
  • a llama-server (or any other --bin) prints a different listening line and will never match → refuse — and better still, parse it: llama-server says server is listening on http://127.0.0.1:PORT, so learning that format makes --bin/--llama-server children work rather than being refused, which is the real fix for the case that motivated this. tests/serve_port.sh already has the shape for a second pattern.

If that is out of scope tonight, the cheap version is: reset silent_since whenever the child prints any line, and keep a separate "printed something, but never a port" grace. Then "silent for 60 s" means a dead/hung child (worth failing) and "busy for 300 s" means a load in progress (worth waiting for).

And it has no arm. +28/−1 in app/serve.cpp, nothing in tests/. This is new logic (a timer, a sentinel, an env parse with a fallback), so it is exactly the kind of change that gets silently reverted by the next person simplifying wait_ready. tests/serve_port.sh is the natural home: a fake backend that prints a foreign listening line must be refused quickly (and, if you take the parse option, must be learned), and ONEBIT_BACKEND_PORT_GRACE_S=abc must warn and use 60. That arm is also how you would settle the slow-load question above without a device: a fake child that prints its 1bit line after N seconds decides which rule is right.

Bound: reviewed from the diff; no serve, no device, no build.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Cross-reference from #3163 (which makes laya_models_e2e register by default): the arm for this bound belongs there. That row is the only coverage of the --port 0 read-back, and its fake backend can be made to load slowly in two lines — so it is the natural place to pin both halves of what I asked for above: a child that prints nothing fails inside the grace, and a child that prints progress but no port is not failed by it. Filing it under a PR that each of us assumes the other owns is how these end up untested.

@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 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:

  1. 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.
  2. 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.
  3. Detect the foreign format positively — a llama.cpp child prints listening on http://…; on seeing a readiness line that is not 1bit 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 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 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:

  1. 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's serve_port_from_log parses the same line from shell. Two readers of one contract is fine; two contracts would not be.
  2. 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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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.

#3155 made wait_ready poll for a port the child prints. A child that never prints one is indistinguishable from a slow one, so the wait ran to its 900 s timeout and read as a model load. That is exactly what would happen to the remaining free_port() rails if someone flipped them to --port 0 without the child-side contract — --llama-server llama-server prints llama.cpp's format, not 1bit serve: ready on http://…. So this is the guard that makes the next step of #3130 safe rather than the fix for a live failure, and that is the right order.

Checked, not taken on trust:

  • -fsyntax-only on app/serve.cpp with this tree's own compile command (from the CI bench build, paths remapped, generated/ + _deps includes): rc 0.
  • The bound is ONEBIT_BACKEND_PORT_GRACE_S, default 60 s, parsed with the same reject-and-warn shape as stop_grace_s()/foreign_port_grace_s() (>= 1 && <= 86400), so a bad value is loud and cannot disable the guard.
  • silent_since is set once (time_since_epoch().count() == 0 as the sentinel) and the check is measured from that first silence, not from entry — so a child that prints its port at 55 s still passes, which is the behaviour a model load needs.
  • The message names the cause ("this launch was given --port 0, so the child must report the port it bound") and the knob. That is the part that makes the log actionable in a CI failure, and it is the difference between this and a bare timeout.

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. tests/smoke_serve.sh already has the fake-backend machinery to do both — FAKE_BACKEND_PIDFILE/FAKE_BACKEND_SLEEP are exactly the two knobs needed, and a case that omits the readiness line entirely would cover the first. If this PR does not add them, they belong in #3130's list rather than nowhere.

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 (ONEBIT_BACKEND_STOP_GRACE_S, ONEBIT_FOREIGN_PORT_GRACE_S, now this), and the three together are what make the --port 0 migration safe on the rails that have not been flipped yet.

@bong-water-water-bong
bong-water-water-bong merged commit 7436ecb into main Nov 21, 2026
12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-npurt/3130-backend-port-rest branch November 21, 2026 10:06
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Post-merge note on main (7436ecb): this landed with app/serve.cpp only — no arm — and with the timing contradiction I raised still in it. Recording it where the code is, since the PR is closed.

1. The 60 s grace versus the 900 s wait, in one file. backend_port_grace_s() defaults to 60 s of wall time from the first poll, and wait_ready is called with std::chrono::seconds(900) at the call site that uses --port 0. A 1bit serve child prints its ready on http://… line only after the model loads, so a load longer than 60 s is now a refused launch while the same function waits 900 s two lines away. Narrow (the --laya-models rows load small scorers) but real for any row whose --bin/model is large.

The discriminating signal is the child's format, not silence: a llama-server child prints server is listening on http://127.0.0.1:PORT and will never match 1bit , so parsing that form too would make --bin/--llama-server children work instead of being refused — and would remove the need for a wall-clock heuristic entirely. tests/serve_port.sh already has the shape for a second pattern.

2. No arm. The new logic is a timer, a sentinel-initialised time_point, and an env parse with a fallback — exactly what a later "simplification" of wait_ready will quietly break. tests/serve_port.sh is the natural home, and two arms would settle both questions without a device:

  • a fake backend that never prints a port must be refused quickly (and, with the parse added, must instead be learned from its own listening line);
  • ONEBIT_BACKEND_PORT_GRACE_S=abc must warn and fall back to 60;
  • and a fake child that prints its 1bit line after N seconds decides which rule is right for the slow-load case — that arm is the answer to point 1.

Nothing here is a request to revert: the diagnosis message this adds ("this launch was given --port 0, so the child must report the port it bound") is a real improvement over a 900 s hang followed by "did not become ready".

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

1 participant