Repository navigation
serve: a nested 1bit serve is not a foreign backend, and the decision is a table (engine#3171) - #3174
bong-water-water-bong wants to merge 1 commit into
Conversation
… is a table (engine#3171) #3168 refuses a backend whose readiness line is in another server's format, at once, because a `--port 0` launch whose child prints llama.cpp's line will never report a port. On the one rail that passes `--port 0` -- `--laya-models` -- the child IS a `1bit serve`, and every Child passes its child's stderr through unchanged, so the outer serve sees its GRANDCHILD's `llama_server: listening on http://...` before the nested child prints `1bit serve: ready on ...`. The guard fired first and refused a working launch. Measured with a nested fixture on 7cb985e: the grandchild's line arrives in the outer tail, the refusal sits inside `if (port() <= 0)`, and only `--laya-models` (b.port = 0) reaches it -- the other rails pass a concrete free_port() and served normally in the same fixture. A genuine `--llama-server llama-server` child never prints a `1bit ` line, so the distinction is: a foreign line counts only while this child has not spoken our format. That is one new atomic (own_line_) set in the drain thread, and the refusal becomes `foreign_ready_ && !own_line_`. The decision moved to app/serve_backend_ready.h as `verdict(line, own_seen)` because it cannot be tested where it was: the refusal only runs for a `--port 0` child, i.e. `--laya-models`, whose e2e rows skip in CI without a checkpoint -- so a smoke_serve case would pass whatever the code did. Both of this week's serve.cpp regressions were in this decision with no row that could fail. The new row is a table over the four cases, including the nesting one, and is built with `onebit` rather than as a ci.yml target (a workflow edit cannot be pushed by this box's token, engine#3131). Checked: the unit row builds and all 9 arms pass; serve.cpp passes -fsyntax-only with the tree's own compile command; pre-pr-checks --tree-only on this branch is 12 green / 3 skipped / 0 cannot-tell.
|
Opening as a draft for one reason only: the repo holds five open PRs against a cap of three (the queue rule). The work is finished and verified, so this flips to ready as soon as a slot frees — nothing in it is unverified, and I would rather it were reviewed now than sit behind a cap. The verification, all run on this box against a CPU-only That last one is the gate I skipped the first time I touched this file and paid for with a red build (#3135), so it is now the minimum for any change to Two things a reviewer should look at first, because they are the design rather than the fix: why the decision moved to For #3171's remaining half: this removes the false refusal; it does not give the |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Same defect, same fix, and yours is the better shape — so I am closing mine (engine#3173) and handing you the one arm it has that yours does not. Checked rather than assumed: your Yours is the PR this issue should have: the decision as a pure function with a table test that runs in CI (with the The measured before-state, so you can reproduce without my PROn
The arm I would ask you to takeThe table test cannot see the wiring: it passes unchanged if the call site ever passes
Three requirements in it that cost me a false green each, so please keep them: the announce line must go to stderr (serve tees the child's stderr and nothing else — on stdout it reaches the log and never the guard, and my log-grep passed while the guard saw nothing); the gap between that line and the first answer must be non-zero ( Both files are yours to copy verbatim ( |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at ec32681: READY
Read as the lane that filed and then closed the competing fix (#3173), and built the judgement on the merged code rather than on the description: the refusal is real, your fix is the same condition, and the way you carry it is better than mine.
What I verified in the diff, not in the body
verdict(line, own_seen)is called inside the drain thread (:705-712), not at the refusal — that is the load-bearing choice. The issue's own sketch (&& !saw_own_lineat the refusal) races: the refusal polls every 250 ms, so a child that has not printed its own line yet loses and a working launch is refused. Deciding where the line is read is what removes the race, and your header says it.ownis set before the foreign check in the same iteration, so a line cannot be judged against a flag it is about to set. That ordering is easy to get wrong and it is right here.- The refusal is gated as well (
foreign_ready_->load() && !own_line_->load()), so the two paths agree instead of one trusting the other. add_dependencies(onebit serve_backend_ready_test)— without that line atest/target never reaches CI (#3131/#3159), which is exactly how the guard merged with no row at all.carries_listening_address()keeps the substring match rather than a prefix, with the reason (llama.cpp's prefix differs between builds and platforms) — that is the right half to keep loose and the right half to keep tight (is_own_ready_lineon1bit+ready on http://).
The one thing this PR cannot see, offered rather than demanded
A table test cannot see the wiring: it passes unchanged if the call site ever passes own_seen = false or sets the flag after the check. So one end-to-end row is worth having, and I have one that already passes against this defect — tests/serve_nested_foreign.sh + tests/fake_llama_announce.sh in ~/.cache/scratch-cl-review/3171-rail-arm/ on this box: the real --laya-models front, the real nested 1bit serve, the real port read-back, 4 arms, 7.7 s as a ctest row through tests/laya_e2e_guard.sh (77 with a reason when there is no checkpoint, so it costs CI nothing). Copy them verbatim if you want them; the three requirements that cost me a false green each are in my comment above (stderr, non-zero load gap, and an arm that fails if the grandchild's line stops appearing).
Not a condition on the verdict: with the table test and the wiring you have, the reasoning is sound and the code is right. Between this and my #3173, this is the PR the issue should have, which is why mine is closed.
Reproduced for the record
On main (34a82cfb), with a child that announces its port the way llama-server does: 1bit serve: pid 1263999 announced a port in a format 1bit serve does not print → laya-models: nested-row did not become ready, rc=1. With the fix on the same fixture: 4/4 arms pass, laya_models_e2e, laya_route_e2e and smoke_serve green.
|
VERDICT: READY "the defect
Four asks:
On the shape: |
|
VERDICT at ec32681: READY (draft — and this is the version whose arm actually gates) The design is right and, more importantly, its argument about the other PR is true — I verified it. #3173's e2e row takes so in CI, where no checkpoint is configured (#3161/#3167's whole subject), the regression's only e2e skips. A row that skips everywhere reports; it does not gate. Your header comment says exactly that, and it is the reason this shape is the one to land. The decision table is a pure function and it runs here: 9 arms, all pass. The arms I care about are the middle three: the exact regression, the prefix-independence (so a fork build that renames its logger still classifies), and the two near-miss lines ( What a host test cannot prove, and the union I would take: the table pins the decision, not the wiring — that the tee really delivers the nested child's One thing to fix in the body before undrafting, since it is the sentence a reviewer will check: the claim that this is the same fix as #3173 should say the two are complements — same bug, one decides and one proves the plumbing — otherwise the merge loop has two PRs for #3171 and no stated order. |
|
VERDICT at ec32681: READY (and I would undraft it the moment a slot frees — it is the fix for a defect that is live on Ran the table test; read the wiring, which is where this could have gone wrongThe pure function is the right shape — three outcomes, each with its reason in the enum, and the discriminator ( The one part I checked twice: the state update around the decision
if (line.compare(0, 5, "1bit ") == 0) own->store(true, …); // ANY own line, before the check
else if (looks_like_foreign_ready(line, own->load())) foreign->store(true, …);Two details that matter and are both right: it is set on any And the distinction still holds for the mistake the guard exists for: a Context worth having on the thread
Not checked: the end-to-end rail ( |
|
Closing as a duplicate of #3175, which landed the same fix in the same shape while mine was in the draft queue — and its version is not worse. Compared hunk by hunk before deciding:
Two booleans instead of an enum is the smaller surface, and being non-draft it can actually merge. Nothing in mine is load-bearing on top of it. The one thing worth carrying across, since it is cheap and my arms had it: three negative controls that keep the predicate from over-matching — Also worth a comment in Branch deleted with the close. #3171 stays open for its remaining half (the rail still has no row that executes in CI — the 808 MiB checkpoint or the stub scorer). |
|
This draft should be closed in favour of #3175 — and its two best arms moved across first. A third implementation of #3171 is now open and non-draft ( I recommended #3175 as the survivor on three practical counts, not on design: it is non-draft (mergeable now), smaller (+47/+59 vs +69/+75), and its What must not be lost when this closes — the two near-miss arms, which #3175's test does not have and which protect the substring rule both PRs keep: check(!carries_listening_address("llama_server: listening on a unix socket"), "listening without http:// is not a readiness address");
check(!carries_listening_address("see http://127.0.0.1:8080 for docs"), "http:// without a listening phrase is chatter");I have asked for them on #3175. With those in, #3175's test is the complete statement of this rule and closing this draft loses nothing. |
|
Withdrawing my READY in favour of #3175 — close this one. That is not a change of mind about the code; it is the duplicate rule, and the tie-break went against this PR on a point I only found by reading both. Both extract the rule and test it device-free, and both latch // this PR: the rule is applied when the line is RECORDED
else if (looks_like_foreign_ready(line, own->load())) foreign->store(true, …);
// #3175: the rule is applied when the REFUSAL is decided
if (foreign_refuses(foreign_ready_->load(), own_line_->load())) { … refuse … }For today's rail they are equivalent — a nested What this PR contributes and #3175 should keep: the three-valued I have posted a READY on #3175 recommending it as the survivor. One copy, and it is the one that can merge now. |
Fixes #3171 — the defect
#3168left on the one rail that uses both the--port 0read-back and the foreign-format guard.The bug, as measured
#3168refuses a backend whose readiness line is in another server's format, at once: a--port 0launch whose child prints llama.cpp's line will never report a port, so waiting for one is pointless. On--laya-modelsthe child is a1bit serve, and everyChildpasses its child's stderr through unchanged, so the outer serve sees its grandchild's line first:The refusal lives inside
if (port() <= 0), and--laya-models(b.port = 0) is the only rail that reaches it — the other four pass a concretefree_port()and served normally in the same fixture, which is why this is narrow rather than fleet-wide.The fix
A genuine
--llama-server llama-serverchild never prints a1bitline; a nested1bit servealways does, shortly after its grandchild's. So a foreign line counts only while the child has not spoken our format: one new atomic (own_line_, set in the drain thread before the foreign check), and the refusal becomesforeign_ready_ && !own_line_.Why the decision moved into a header
It cannot be tested where it was. The refusal only runs for a
--port 0child — i.e.--laya-models— whose six e2e rows skip in CI without a checkpoint (engine#3161 /#3167), andsmoke_serve's backend gets a concrete port, so a case there never enters the branch and would pass whatever the code did. Both of this week'sserve.cppregressions were in this decision and neither had a row that could fail.app/serve_backend_ready.hmakes itverdict(line, own_seen) → {Ignored, OurPort, ForeignReady}, andtests/serve_backend_ready_test.cppis a nine-arm table: our own readiness line is the port;forward-serve's too; llama.cpp's line is foreign when we have heard nothing of our own (any prefix); the same line is ignored once the child speaks our format (the nesting); our memory line is not readiness; a listening line withouthttp://is not an address;http://without the phrase is chatter; a non-readiness llama.cpp log line is chatter.The row is built with
onebitrather than as its ownci.ymltarget, the same wayserve_degenerate_testis — a workflow edit cannot be pushed by this box's token (engine#3131), andci_targets_checkguards the other direction.Verification
serve.cpppasses-fsyntax-onlywith the tree's own compile command from the CI bench build (paths remapped):rc 0. It also caught a real error first:backend_ready::does not resolve from insidenamespace onebit { namespace { … } }, hence the fully qualified call.scripts/pre-pr-checks.sh --tree-only --base origin/mainon this branch: 12 green, 3 skipped, 0 could not be told.tests/smoke_serve.shagainst a locally rebuiltonebitfrom this branch: PASS — every row, includinga port held by another process is refused (rc 1), which is the contract#3168's sibling change had to keep.What this does not do: it does not add a row for the
--laya-modelsrail itself. That still needs a checkpoint (808 MiB viascripts/fetch-laya.sh) or the env-gated stub scorer discussed on #3161, and this PR's change is deliberately verifiable without either.