Skip to content

tools: logprob_agree takes a chat body per route, because the two engines spell thinking differently (engine#3158) - #3267

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3158-per-route-body
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3158-per-route-body

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #3158. One body cannot pin thinking on both arms, so the tool now takes one per route.

Measured from the tree, both sides:

// app/unified.cpp:222-223 — our serve: ONLY chat_template_kwargs, default true
thinking = body["chat_template_kwargs"].value("enable_thinking", true);
// app/loom_route.h:340-346 — loom-serve's field list: enable_thinking / reasoning_effort TOP-LEVEL; 400 on chat_template_kwargs

So --body minimal for both arms leaves our serve thinking (it does not read the top-level field) while Loom obeys — and the run then measures the configuration:

per-route bodies (fallback :full, loom :minimal), --thinking off
  greedy agreement  100.0 % over 8 prompt(s)        rc 0        <- both engines pinned off, both answered
one body for both (--body minimal), --thinking off
  greedy agreement    0.0 %                          rc 1        <- fallback still thinking: content "" vs "Paris."

(The second line is the failure mode that read as 100 % before #3251: two empty answers compare identical.)

The change

--route LABEL=URL[:minimal|:full] sets the body for that route; a bare --route keeps --body. parse_route() splits the suffix without eating a port or a path, and the report records routes_body so a reader can see which arm was told what.

The honest gate command this enables:

logprob_agree.py --route cpu=…:full --route loom=…:minimal --thinking off --text-only --match-by text

Verified

  • 4 new arms (a URL with a port and a path, no suffix, both suffixes named per route, and a plain --route unchanged) → 31 arms, 0 failed;
  • end to end against two loopback routes that honour only their own engine's spelling, the two outcomes above;
  • rebased on current main (3f131a554) so it carries tools: logprob_agree carries --thinking top-level in the minimal body, so a Loom arm answers at all (engine#3158) #3260's top-level enable_thinking — the first run of this branch was against a stale local origin/main and sent the old five-field minimal body, which is exactly the kind of mistake this PR is about, so it is in the record rather than hidden.

scripts/pre-pr-checks.sh 18 green / 2 skipped / 0 could-not-tell; copyright rc 0. One file.

…spell thinking differently (engine#3158)

Row measurements settled the shape of this: our serve reads thinking only from chat_template_kwargs.enable_thinking
and defaults to true (app/unified.cpp:222-223), while loom-serve takes enable_thinking top level and 400s on
chat_template_kwargs (app/loom_route.h:340-346). One body therefore cannot pin thinking on both arms -- and the
two failure modes are both measured: with a single minimal body the fallback keeps thinking, answers "" while Loom
answers, and the row reports 0 % divergence (or, before #3251, 100 % agreement on two empty answers).

--route LABEL=URL[:minimal|:full] sets the body for that route; a bare --route keeps --body. parse_route() is
tested on the cases that would silently eat part of a URL (a port, a path, no suffix).

Measured on two loopback routes that honour only their own engine spelling:
  per-route (full + minimal), --thinking off  -> greedy agreement 100.0 % over 8 prompt(s)   rc 0
  one body for both (--body minimal)          -> greedy agreement   0.0 %                      rc 1
i.e. the per-route body is what makes the comparison measure the engines instead of the configuration.

4 new arms (parse_route, 3 cases + one keeping a plain --route unchanged); 31 total.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

ready for review at a6e79c2 — one file, --selftest 31 ok / 0 failed, gate 18 green / 2 skipped, copyright rc 0. The measured contrast is in the body: per-route bodies give 100.0 % where a single minimal body gives 0.0 % on the same pair, and before #3251 that same asymmetry read as 100 % on two empty answers — which is how two 27B rows produced ROUTE TO LOOM tonight on measurements where neither engine emitted a token.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3158 - Partially compliant

Compliant requirements:

  • The tool now supports per-route body specifications with :minimal or :full suffixes
  • The tool correctly parses route specifications and applies the appropriate body to each route
  • The tool records which body was used for each route in the report

Non-compliant requirements:

  • The performance and accuracy evaluation components (4 interleaved rounds, load average recording, KLD calculation) are not implemented in this PR
  • The decision rule logic for determining Loom vs fallback routing is not implemented in this PR

Requires further human verification:

  • Verification that the actual performance and accuracy measurements meet the requirements
  • Verification that the decision rule logic works correctly with the measured data
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Route parsing logic

The parse_route function correctly handles route specifications with optional body suffixes, but it could be more robust in handling edge cases where the URL contains characters that might interfere with the parsing logic. Specifically, if a URL contains a colon followed by a string that matches ":minimal" or ":full", it could incorrectly parse the body type. However, this is unlikely in practice given typical URL formats.

def parse_route(spec):
    """`LABEL=URL[:minimal|:full]` -> (label, url, body-or-None).

    The two arms of the Loom gate need DIFFERENT bodies for the same meaning, and that is not a shortcut: our serve
    reads thinking only from `chat_template_kwargs.enable_thinking` (app/unified.cpp:222-223, default true) and
    loom-serve takes `enable_thinking` top level and 400s on `chat_template_kwargs` (app/loom_route.h:340-346). So one
    body cannot pin thinking on both -- measured: an empty answer on both arms, 5/5 "identical", 100 % (engine#3158,
    row27b-ud-v8 and row27b-bart). A per-route body lets each arm be told in its own dialect, which is the only shape
    in which the comparison measures the engines rather than the configuration.
    """
    label, _, rest = spec.partition("=")
    if not rest:
        return label, "", None
    body = None
    for suffix in (":minimal", ":full"):
        if rest.endswith(suffix):
            return label, rest[:-len(suffix)], suffix[1:]
    return label, rest, None
Body handling consistency

The code now correctly handles different body types for different routes, but there's a potential inconsistency in how the body type is determined. When a route has a body type specified, it overrides the global --body setting, but when no body type is specified, it falls back to the global setting. This could lead to confusion if users expect all routes to behave consistently.

for label, url, mode in routes:
    minimal = (mode or a.body) == "minimal"
    report["routes_body"][label] = "minimal" if minimal else "full"

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

The defect it fixes is the one that would have poisoned the L2 gate quietly: one body cannot pin thinking on two arms with different dialects — our serve takes chat_template_kwargs, loom-serve takes enable_thinking top-level and 400s on the other (app/loom_route.h:340-346) — so the measured symptom was an empty answer on both arms, 5/5 "identical", 100 %. A false perfect agreement is worse than a mismatch: it reads as the best possible result.

What I checked beyond the body:

  • --selftest 31 ok / 0 failed, including route_has_token_ids: our serve's id-less entries are detected, a fork-style entry is not flagged and the parse_route arms (loom=http://…:minimal → ("loom", "http://…"));
  • the two-body plumbing is per-route and defaults to None (so every existing invocation keeps working);
  • the empty-answer case still cannot read as agreement — the tool already renders a route with no log-probs as cannot tell, and a rate whose denominator is zero is None, never 0.0 (:219-224), and missing_kld_fails keeps --text-only from excusing a diverged-everywhere pair. So this PR fixes the trigger while the guard that catches the symptom stays in place.

Nothing to change; one file, +39/-9, CI-relevant only through the suite.

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

This is the real answer to the question I raised on #3260, and it is a more accurate one than my ask. I asked whether the full body also sets thinking, because otherwise full-vs-minimal runs differ in configuration. The answer is that the two arms cannot share a body at all, and the reason is measured on both sides:

"our serve reads thinking only from chat_template_kwargs.enable_thinking (app/unified.cpp:222-223, default true) and loom-serve takes enable_thinking top level and 400s on chat_template_kwargs (app/loom_route.h:340-346). So one body cannot pin thinking on both — measured: an empty answer on both arms, 5/5 'identical', 100 % (engine#3158, row27b-ud-v8 and row27b-bart)."

So the per-route LABEL=URL[:minimal|:full] is not a convenience API — it is the only shape in which the comparison measures the engines rather than the difference between two request dialects. That is exactly the distinction #3260 fixed from one side and this fixes from the other, and the citation pair (unified.cpp:222-223 vs loom_route.h:340-346) is what makes it checkable rather than plausible.

The body-or-None return is the right default shape too: a route that names no suffix keeps whatever the tool did before, so an existing two-arm invocation is unchanged and only an invocation that needs different dialects pays for the new syntax.

One ask, small and body-level: the failure this prevents was 100 % agreement on two empty answers, so a run where either arm produced empties must still be visible — #3251's prompts_both_empty covers it, and the body should say that the two fixes are meant to be used together (per-route body and the vacuity guard), because either alone puts us back to a number that means nothing.

Not verified: the run (needs both routes). The parse contract, the two citations and the measured failure I read in full.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a6e79c2: READY — logprob_agree selftest: 31 ok, 0 failed (27 before), and a body per route is the right fix for the reason the gate hit: the two routes need different request shapes (--body minimal for a strict route, the full body for llama.cpp), and one shared body meant one of them was always wrong — which surfaces as a 400 or, worse, as a comparison of two different questions.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

CI status at this head, for the merge loop: green except hw_gate (skips by design on these rows). #3267, #3264 and #3266 are all-pass; #3269 has one check still pending (build, as of a minute ago) — nothing red anywhere. So all four are mergeable-on-green once the pending one lands, and none of them touches the other's files (each is app/serve.cpp, tools/logprob_agree.py, tools/loom_arch_probe.py — disjoint), which is what tonight's rule 3 asks for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant