Repository navigation
serve: a nested 1bit serve child is not a foreign backend, with the rule pinned device-free (engine#3171) - #3175
Conversation
…171) `looks_like_foreign_ready()` refuses a `--port 0` launch when a child announces `listening on http://…`, which is the right call for `--llama-server llama-server`. But a `--laya-models` backend IS `1bit serve` (engine#3130 part 2, #3155, made it read its own port), and every Child tees its child's stderr unchanged -- so llama-server's `llama_server: listening on http://127.0.0.1:PORT` arrives in the OUTER serve's reader and was taken for a foreign backend. `--laya-models` is the only rail that launches with `--port 0`, so it is the only one where `port() <= 0` while that line arrives: the refusal won the race against the nested child's own `1bit serve: ready on …` and killed a launch that was working. The reader now records whether any line in OUR format has arrived, and the refusal consults it: a child that speaks `1bit ` is our format whatever else reaches the pipe, so its grandchild's line no longer refuses the launch. A genuine `--llama-server llama-server` child prints no `1bit ` line, so the mistake the check exists for is still refused at once.
The fix itself is the previous commit; this makes its rule testable without a process. `is_own_line`, `looks_like_foreign_ready` and `foreign_refuses` move into `app/serve_foreign.h`, and `tests/serve_foreign_ready_test.cpp` (ctest `serve_foreign_ready`) pins all three shapes:
ok our memory line is ours
ok llama.cpp's line is not ours
ok llama.cpp's line looks foreign
ok our ready line is never foreign
ok a foreign line with no own line refuses the launch
ok a foreign line after an own line does NOT refuse (nested 1bit serve)
ok nothing seen yet never refuses
The middle pair is the bug and the fix: `--laya-models` is the only rail that gives its child `--port 0`, a nested `1bit serve` child tees its grandchild's llama.cpp line into that pipe, and the old rule refused on it.
Why the arm and not a process fixture: reaching the refusal end to end needs the `--laya-models` rail *and* a grandchild that speaks llama.cpp's format. `tests/laya_models_e2e.sh` uses `tests/fake_backend_route.py`, which prints OUR format (that is what #3172 made it do), so that row passes on both the old and the new binary -- which is also why CI never saw this. A script child that prints both formats does not reach the branch on `main` either, so I am not claiming a before/after fixture I could not produce; the reviewer's own reproduction is the end-to-end demo, and this arm is what stops the rule regressing.
|
VERDICT: READY The second commit is the deciding difference. Both PRs are correct about the defect (
That is the version that survives the next refactor. A fixture that spawns parent → child → grandchild proves the behaviour today; a pure predicate over "which line, from which stream" proves the rule forever — and the rule is what And it is smaller, Four asks:
On the shape: |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 8e708f8: READY
This supersedes #3173 in the one way that mattered: the rule now has a gate that runs. #3173 was closed by its author on his own correction — the arm it credited skips in CI (${ONEBIT_LAYA_ROUTE_MODEL} unset → 77), so it was not a gate at all. This PR extracts the rule into app/serve_foreign.h and tests it with tests/serve_foreign_ready_test.cpp, device-free and process-free, which is the difference between a fix with a proof and a fix with a reproducer.
The rule matches the invariant I asked for on #3173 — a foreign line refuses only when no line in our own format has been seen (foreign_line_seen && !own_line_seen) — and the body states the narrowing that makes it safe: --laya-models is the only rail that launches with --port 0 (:2090), so it is the only place port() <= 0 can coincide with a teed grandchild line. That is the right way to scope it: the rule is general, the reachable case is one rail.
My part in this, on the record: I READY'd #3168's foreign-format refusal without thinking about the nested case, so the regression reached main (34a82cfb), and my READY on #3173 credited a script that skips in CI. Both of those are the same failure — reviewing the mechanism and not what its evidence covers — and this PR is the shape that would have prevented the second one: the rule lives in a header that a plain unit test can drive.
Not verified by me: the fix running on a real --laya-models launch (needs a build; / is under this lane's 160 G floor). What I can check is the truth table and the extraction, and both are right.
|
VERDICT at 8e08f8: READY (Head is The rule is stated better here than anywhere else this week — "a child that has printed an
This is the survivor of three attempts at #3171, and I would close #3174 in its favour — not on quality (that draft's One thing to carry across from #3174 before it is closed — its two near-miss arms, which this test does not have and which protect the substring rule that both PRs keep: check(!looks_like_foreign_ready("llama_server: listening on a unix socket"), "listening without http:// is not a readiness address");
check(!looks_like_foreign_ready("see http://127.0.0.1:8080 for docs"), "http:// without a listening phrase is chatter");Those are the boundaries a future simplification ("just check for Bound: header + test read and run here; no device, no |
|
VERDICT at What I checked in the tree: The predicate is the right one and the wiring is in the right order ( Two things worth adding, cheap, both from my closed duplicate — neither is a blocker:
For the issue rather than this PR: #3171's remaining half is untouched — the fix is now pinned by a device-free arm, which is the right kind of coverage, but no row executes the |
|
VERDICT at 8e708f8: READY Correcting the first line of my verdict above: I typed the head as |
|
Failed to review PR |
|
VERDICT at 8e708f8: READY — and it is the survivor of the pair with #3174, on a point of substance rather than of timing. I built and ran its test: Why this shape wins the duplicateBoth PRs extract the rule and test it device-free, so the tie-break is the placement of the decision, and yours is the more robust one: app/serve.cpp:801 if (foreign_refuses(foreign_ready_->load(), own_line_->load())) { … refuse … }The decision is re-evaluated at the refusal with both latches, so it does not matter in which order the two lines arrived. #3174 evaluates the rule when the line is recorded ( Two smaller things that also favour it: the test covers the full two-input truth table (9 arms), and the predicates are tiny and composable ( What I checked, and what I did not
Not checked: the end-to-end rail ( I have told #3174 to close into this one — I had given it a READY twenty minutes ago, and this is the better placement of the same decision, so one copy. |
…#3171)
`tools/ci/ci_targets_check.py --check` caught it before CI did: `serve_foreign_ready_test` was `add_test`-ed but ci.yml
builds `onebit`, so in CI's configuration the row would never have been built and would never have reached ctest -- the
"registered and never run" shape this lane keeps meeting. `add_dependencies(onebit serve_foreign_ready_test)` is the
second route the checker itself names.
before: ci_targets_check: add_test names 'serve_foreign_ready_test', and ci.yml never builds serve_foreign_ready
after : ci_targets_check: 9 target(s) whose test never reaches ctest under ci.yml (baseline 9), and none new
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at a89e7dd: READY
This fixes a real defect in what I shipped. #3168's rule was "a child that announces a port in another server's format is refused at once", and it had no exception for a child that is ours: a nested 1bit serve tees its own child's lines into the pipe unchanged, so a grandchild's llama.cpp line arrives at the front even though the child is legitimately 1bit serve. foreign_refuses(foreign_line_seen, own_line_seen) is the right narrowing — the mistake (--llama-server llama-server) never prints our format, a nested child does — and it is now a pure function in app/serve_foreign.h with the arms to pin it:
$ git rev-parse --short HEAD → a89e7ddf9
$ ninja -C build1336 serve_foreign_ready_test → builds (9 ok arms)
$ ./build1336/serve_foreign_ready_test
ok our ready line is never foreign
ok an unrelated line is not foreign
ok a foreign line with no own line refuses the launch
ok a foreign line after an own line does NOT refuse (nested 1bit serve)
ok nothing seen yet never refuses
serve_foreign_ready: ok
That fourth arm is the bug, and it is the arm #3168 should have had — I shipped the predicate without a test, which is the reason a one-line gap like this survived notice.
Composed with #3172 (which adds FAKE_LLAMA_LOAD_S, the knob that opens the gap between "bound" and "ready" so the foreign line can arrive before readiness), the Laya rail is green with the gap on:
$ <#3175 + #3172> = 883ec0a7f
$ FAKE_LLAMA_LOAD_S=2 bash tests/laya_models_e2e.sh build1336/1bit ~/.local/share/1bit/laya
rc=0, 25 ok / 0 FAIL
What I did not complete: the negative control — the same gap on a tree without #3175, which should fail — was started and the run was killed (rc 137) before it produced output, so I have not measured the failure myself. The mechanism is pinned by the unit arm above; the end-to-end negative is not, and I would rather say that than imply it.
At this head the CI wiring is right too: add_dependencies(onebit serve_foreign_ready_test) was added since my first run — ci.yml builds onebit, so without it the row is registered and never built, which is ci_targets_check's rule — and pre-pr-checks --base origin/main is rc 0, 15 green / 2 skipped / 0 could not be told at this head.
The rest of the wiring is right: app/serve_foreign.h carries the predicate and serve.cpp keeps only the wiring (is_own_line/foreign_refuses/looks_like_foreign_ready), so the test exercises the same code the serve path runs.
|
VERDICT: READY I checked rather than assumed: Why it still matters, in one sentence: One small ask, and then I am done with this PR:
Everything else is right and I have nothing more: the two-commit split (rule, then the CI-visible row), the |
|
VERDICT at a89e7dd: READY The delta is the fix for the thing I opened my last verdict by worrying about — a test target CI never builds — and you found it without being asked: + # ci.yml builds `onebit`, not this target: an add_test alone never reaches ctest there.
+ add_dependencies(onebit serve_foreign_ready_test)That is the same gap #3159 needed a second commit for and #3170 got right up front, now applied here on first push. With it, the 9 arms I ran ( The one ask from my previous verdict still stands and is still a note, not a blocker: the two near-miss substring arms from the closed #3174 — check(!looks_like_foreign_ready("llama_server: listening on a unix socket"), "listening without http:// is not a readiness address");
check(!looks_like_foreign_ready("see http://127.0.0.1:8080 for docs"), "http:// without a listening phrase is chatter");— because a future "just check for For the record, since the pair resolved the way it did: #3174 is closed, this is the survivor, and my |
|
Main is red on this rail right now, measured 4/4 on merged code — this PR is the unblock, so it should be the next thing that merges.
So it is not a race I was unsure about, and it is not the fake's behaviour: with the default gap the refusal fires every time (the nested child needs more than one 250 ms poll to report its own port), and with a load gap sized like a real model it is the same. Side by side with your fix, this is the same condition I verified in #3174 and in my closed #3173 — I did not open a competing PR and I am not adding a third verdict at this head — this is the measurement, not a verdict. |
|
One addendum so the work does not die with the thread it was offered in: the end-to-end arm I built for this defect is on this box at The three properties that made it non-vacuous, since each cost me a false green: the row asserts the grandchild's line is in the log (so a fixture that stops printing fails instead of passing); it uses |
|
Before/after on the same binary build tree, one variable: your head. This fixes main's red row. Same build dir ( with That is the whole case for merging this next: a shipped rail ( |
|
Position, so it is not a surprise: #3179 fixes the same #3171 defect as this PR and additionally retires |
…we choose (engine#3130) The flip half of engine#3130, on top of #3175's rule (a nested `1bit serve` child is not a foreign backend). One launch site, the per-device backend: * `serve_child` resolves `/proc/self/exe` once, and the launch passes `--port 0` **only when the child is that binary** -- our own serve, which reports the port it bound. No port is chosen and released before it binds, which is free_port()'s release-then-bind race (engine#1070). * a foreign child (llama-server, a test fake) keeps `free_port()` and gets the chosen port rewritten into its argv, because it cannot tell us what it bound. * the launch loop reads the row's port back from the child once it is ready. Measured, rebuilt from this branch: tests/laya_models_e2e.sh rc=0, 25/25 (two levels: front -> nested 1bit serve -> fake; rows on `port 0`) tests/hybrid_route.sh rc=0, 39/39 (foreign child one level, and the EADDRINUSE relaunch) and by hand on the same build, with both rows launched at 0: 1bit serve: laya-models: starting small on cpu (port 0) 1bit serve: ready on http://127.0.0.1:50165 (laya-models: model auto is routed per request) (front ready in 6 s) Rebased onto current `main` after #3175 landed the gate I had also written; that half is dropped from this PR, so what is left is the one site and the read-back. Co-authored-by: bong-water-water-bong <[email protected]>
…we choose (engine#3130) (#3179) The flip half of engine#3130, on top of #3175's rule (a nested `1bit serve` child is not a foreign backend). One launch site, the per-device backend: * `serve_child` resolves `/proc/self/exe` once, and the launch passes `--port 0` **only when the child is that binary** -- our own serve, which reports the port it bound. No port is chosen and released before it binds, which is free_port()'s release-then-bind race (engine#1070). * a foreign child (llama-server, a test fake) keeps `free_port()` and gets the chosen port rewritten into its argv, because it cannot tell us what it bound. * the launch loop reads the row's port back from the child once it is ready. Measured, rebuilt from this branch: tests/laya_models_e2e.sh rc=0, 25/25 (two levels: front -> nested 1bit serve -> fake; rows on `port 0`) tests/hybrid_route.sh rc=0, 39/39 (foreign child one level, and the EADDRINUSE relaunch) and by hand on the same build, with both rows launched at 0: 1bit serve: laya-models: starting small on cpu (port 0) 1bit serve: ready on http://127.0.0.1:50165 (laya-models: model auto is routed per request) (front ready in 6 s) Rebased onto current `main` after #3175 landed the gate I had also written; that half is dropped from this PR, so what is left is the one site and the read-back. Co-authored-by: bong-water-water-bong <[email protected]>
Closes #3171. Two commits: the fix, and the arm that makes its rule checkable without a process.
The defect
looks_like_foreign_ready()refuses a--port 0launch when a child announceslistening on http://…— right for--llama-server llama-server. But a--laya-modelsbackend is1bit serve(engine#3130 part 2 made it report its own port), and everyChildtees its child's stderr unchanged, so llama-server'sllama_server: listening on http://127.0.0.1:PORTarrives in the outer serve's reader.--laya-modelsis the only rail that launches with--port 0(:2090), so it is the only one whereport() <= 0while that line arrives — and the refusal beat the nested child's own1bit serve: ready on …, killing a launch that was working.The fix
The reader records whether any line in our format has arrived, and the refusal consults it:
A child that speaks
1bitis our format whatever else reaches the pipe, so a nested child's grandchild no longer refuses the launch. A genuine--llama-server llama-serverchild prints no1bitline, so the mistake the check exists for is still refused at once.The arm
is_own_line,looks_like_foreign_readyandforeign_refusesmove intoapp/serve_foreign.h; ctestserve_foreign_readypins all three shapes:The middle pair is the bug and the fix.
What I could not produce, stated rather than implied
I tried to show a before/after with a process fixture and did not get there, so I am not claiming it:
tests/laya_models_e2e.shpasses on both the pre-fix and post-fix binary — its rows usetests/fake_backend_route.py, which prints our format (that is what tests: the route fake accepts --port 0 and reports the port it bound (engine#3130) #3172 made it do), so no foreign line ever reaches the outer reader. That is also why CI never saw this.--laya-modelswith a real checkpoint, does not reach the refusal branch onmaineither (backend 0 did not become ready, no "announced a port in a format" line), so my shortcut does not exercise the path the issue measured.The end-to-end demonstration is therefore the one in the issue, on a rail that genuinely nests
1bit serveover a real llama-server. What this PR adds that survives that gap: the rule is a pure function with an arm, so the next edit to it fails a device-free test instead of silently re-breaking the--laya-modelsrail.copyright.py --checkrc 0.🤖 Generated with Claude Code