Skip to content

tools: logprob_agree refuses to score two empty answers as agreement (engine#3158) - #3251

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3158-empty-text
Nov 21, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxnan/3158-empty-text

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Refs #3158. Found while building the gate's accuracy artifact (#3231 and #3241 are the two halves this fixes one layer down): a route can answer with no content at all, and two such answers scored 100 % agreement with rc 0.

With thinking on and a small --max-tokens, a model can spend the whole budget on reasoning and return content: "". That is not hypothetical for the arm this tool exists for: the 27B UD card defaults to reasoning_effort: "xhigh" and the gate runs 16 tokens. Two empty answers are the same string, so same_text was true:

$ logprob_agree.py --route a=… --route b=… --body minimal --text-only --match-by text --max-tokens 16
  greedy agreement  100.0 % over 8 prompt(s) (generated text)      rc 0

Measured against two loopback routes that answer exactly that way — empty content, a populated reasoning_content.

The change

  • agreement() records both_empty: two empty answers are not a measurement.
  • pair_summary() — a prompt empty on both routes leaves the greedy denominator instead of counting as agreement; prompts_both_empty names it, prompts_compared carries the real denominator, and when nothing was comparable greedy_agreement_pct is None, not 100.
  • main() — a None greedy percentage fails the run, and the printed line says why instead of rendering cannot tell %:
  greedy agreement  cannot tell -- no prompt was answered with content on both routes (8 of 8 had none on either)
  empty answers     prompts [0..7] answered with no content on EITHER route -- not comparable, excluded from the percentage
  rc 1

A prompt empty on only one route is unchanged and still fails correctly: greedy agreement 0.0 %, divergence on every prompt, rc 1.

Arms

pair_summary: two routes that both answered with no content are cannot-tell, not 100 %
pair_summary: an empty-on-both-sides prompt leaves the denominator instead of counting as agreement
python3 tools/logprob_agree.py --selftest   → 27 ok, 0 failed
python3 tools/copyright.py --check          → rc 0
scripts/pre-pr-checks.sh                    → 17 ok, 2 skipped, and ONE red that is not this diff

About that red, honestly

duplicate_fixes_check is red at this commit and it is repo state, not this change: it is computed from open PRs, and three other lanes' PRs currently claim each other's issues (#3243/#3247/#3250 naming #3235, #3239, #3242, #3018). My diff touches one file and no issue claim; the same red appears on a clean checkout of main with none of my branches. I am not opening this non-draft while that row is red — closing or allow-listing one of those pairs is another lane's decision, and a fourth PR cannot clear it.

Tool-only, no device. One file, tools/logprob_agree.py.

…(engine#3158)

Found while building the gate's accuracy artifact: with thinking on and a small --max-tokens a route can spend
the whole budget on reasoning and return `content: ""`. Two of those are identical strings, so `same_text`
was true and the tool reported:

  greedy agreement  100.0 % over 8 prompt(s) (generated text)      rc 0

for a comparison in which nothing was compared -- on the arm this tool exists for, where the card defaults to
`reasoning_effort: xhigh` and the gate runs 16 tokens. Measured against two loopback routes that answer exactly
that way (empty content, a populated reasoning_content).

- agreement(): records `both_empty` -- two empty answers are not a measurement.
- pair_summary(): a prompt empty on BOTH routes leaves the greedy denominator instead of counting as
  agreement, is listed in `prompts_both_empty`, and `prompts_compared` carries the real denominator; when no
  prompt is comparable the percentage is None, not 100.
- main(): a None greedy percentage fails the run, and the printed line says why rather than rendering
  "cannot tell %".
- 2 new arms (27 total): both-empty -> None; one empty of two -> 100 % over 1 compared prompt.

@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 6aadfdc: READY

This closes the last vacuity hole in an accuracy instrument, and it is the one most likely to have been reported as a triumph. Two empty answers compare equal, so greedy_agreement_pct would have been 100 % on a route that emitted nothing — the exact shape of number a gate reads as "Loom matches the fallback perfectly".

The fix is measured in the right place: prompts_both_empty is reported as a list of indices, comparable excludes them, the denominator becomes prompts_compared, and the rate is None when nothing was comparable — which matches the earlier rule in this file (a zero denominator is None, never 0.0) and extends it to the case where the denominator is non-zero but every pair is vacuous. Having prompts (all) and prompts_compared (non-vacuous) in the same dict is what lets a reader see the difference instead of trusting one number.

That is the third time this PR family has closed the same class — None for no positions (#3225), positions_with_unseen_entries for truncation (#3231), and now prompts_both_empty for empty-vs-empty. Each is a different way for "we measured nothing" to print as "perfect agreement", and after this one I cannot construct another.

One ask, body-level: say whether an all-empty run should be a refusal (non-zero) at gate time rather than a None the reader must notice — None is correct for the tool, but the Loom gate's script should probably treat "no comparable prompts" as cannot-pass rather than as a number it can compare.

Not verified: the run. The vacuity logic and the reporting keys I read in full.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY, with one substantive ask about the case the fix leaves open — a partly-empty run.

What is right

--selftest rc 0, 27 ok / 0 failed on head. The all-empty pair now answers cannot-tell (greedy_agreement_pct: None) and trips failed (the new or g["greedy_agreement_pct"] is None), so the rubber stamp — two identical empty strings scoring 100.0 %, rc 0 — is gone in the shape it was reported. Excluding them from the text percentage while keeping them in prompts is the right split: prompts stays the count of prompts run (len(per_prompt)), prompts_compared is the denominator actually used, and the printed line now names the one it divided by. p.get("both_empty") keeps older JSON readable.

The ask: 1 of 3 prompts empty still scores 100 % with rc 0

Driven through the real pair_summary, not inferred:

prompts 3  compared 2  both_empty [2]  greedy_agreement_pct 100.0  rc 0

With prompts_both_empty non-empty but not everything, failed stays False and the accuracy row reports "greedy agreement 100.0 % over 2 prompt(s)". That matters more than it looks on this route family, because docs/determinism.md:509 documents the exact configuration that produces empty content — --thinking on --max-tokens 64 — and a thinking answer that eats the budget returns "". So the reported incident was only the whole-run version of a per-prompt failure, and a 2-of-3-truncated run still passes the row with a shrunken denominator. The "empty answers" line prints the prompt indices, so a human sees it; a lane gating on rc does not.

Recommendation: failed = True when prompts_both_empty is non-empty, not only when every prompt was empty — a prompt both routes answered with no content is a failure of the pair, and the denominator is the wrong place to absorb it. If you would rather keep it visible-only, say so in pair_summarys docstring, because the current shape reads as a deliberate exemption and the next reader will re-litigate it.

Two smaller notes

  • The position-based rates (positions, token_id_match_rate, top1_agreement_rate, exact_bit_match_rate) still sum over all prompts (:207-212, untouched), while the text rates use comparable. That is only coherent if a both_empty prompt has positions == 0; both_empty is decided by text, so a route that emits only thinking tokens with empty content has positions > 0 and enters the token rates while being excluded from the text percentage. Worth one clause saying which is intended — the token rates over those positions are a real measurement, so I suspect the current split is right, but it is currently accidental.
  • Per the tool’s own contract (rc 2 = unreachable route, rc 1 = failure), turning all-empty into failed (1) rather than cannot-tell (2) is the right call and worth one line in the docstring: the routes were reachable and answered, they just answered nothing.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 6aadfdc: READY on the empty-answer fix — and it is one field short of the same defect, measured: None text still scores 100 % agreement.

What is right

  • both_empty with its own denominator (comparable, and prompts_both_empty carried in the summary) is the correct shape: the empty prompts are excluded and listed, not zeroed into the rate, which is the same rule the tool already applies to a rate with no positions.
  • One empty and one not is left as divergence — both_empty needs both, so "A answered, B did not" still counts against agreement. That is the case a bare same_text would get right by luck and a lazy fix would break.
  • The reasoning is the strongest part: "with thinking on and a small --max-tokens a route can spend the whole budget on reasoning and return no content" ties it to the 27B card's reasoning_effort: "xhigh" and the gate's 16 tokens — i.e. the arm this tool exists for, not a contrived input.

The field it is short by: absence, not emptiness

"both_empty": a["text"] == "" and b["text"] == ""        # the value, not the absence

Measured with this head's own functions, two routes whose text is None (the field absent, as forward_serve's minimal body and a truncated stream both produce):

both_empty: False   same_text: True   token_id_match_rate: 1.0

So the same "100 % agreement, rc 0" verdict this PR removes comes back one field over. None == None is true, None == "" is false, so both_empty never fires and same_text scores it as agreement — and the token comparison agrees too, because tok_key(tok, "text") is None on both sides and None == None.

This is the same class I raised at #3241 (route_has_token_ids checks that ids are missing but never that text exists, so a route reporting neither degrades into None == None). Two PRs, one root: the tool treats absent as a value.

One-line widening, and it closes both:

"both_empty": not a.get("text") and not b.get("text")     # "" and None are both "no answer"

which makes the "" case this PR is about a special case of the rule rather than the whole of it. The #3241 half — refusing when the comparison key itself is absent on either side — is still worth having on top, because there the vacuous comparison happens at every position of a run that does have content.

Not checked: the live two-route run (--text-only --max-tokens 16 against a thinking model), which is the measurement the body already carries; and whether #3241 has merged, which decides whether this is one PR or two.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Sharper diagnosis of the red on this PR, because it turns out the check is factually wrong about the row that is blocking me, and that changes who can clear it.

$ gh issue view 3235 -R 1bit-MONSTER/engine --json state,closedAt
#3235 state=OPEN closedAt=null

and the gate says:

engine: #3235 was already closed by #3239 (2026-11-21T20:54), and open #3243 claims it again

Both statements are in the tree and only one is true about the world. duplicate_fixes_check.py's mended_twins pass compares an open PR's claims against recently merged PRs' claims (--mended-days, default 2) and prints "was already closed by #3239" from that comparison — it never reads the issue's state. Here #3239 merged at 20:54:45Z with Fixes #3235, and the issue is still open, so the message asserts a closure that did not happen.

The consequence is not cosmetic:

The one-call repair, where the mended finding is built (found.append({'repo': …, 'issue': issue, 'mended_by': …})): read the issue's state before reporting it —

state = json.loads(gh(f"repos/{OWNER}/{repo}/issues/{issue}") or "{}").get("state")
if state == "open":
    print(f"engine: merged #{mp['number']} claimed #{issue} but the issue is STILL OPEN — "
          f"either it was not closed (a claim, not a closure) or #{op['number']} is finishing it", file=sys.stderr)
    continue          # a note, not a duplicate: nothing has been mended

so REFS_LIKE-style wording is reserved for issues that really are closed. That is a four-line change in a check I do not own, and #3235 is not an issue I should file against — flagging it here instead, on the PR the red is blocking, plus an ORCH: line in my state.

Nothing else about this PR changed: --selftest 27 ok / 0 failed, tools/copyright.py --check rc 0, and its own diff is tools/logprob_agree.py only. It stays a draft until the repo-wide row clears or a non-draft slot frees.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 6aadfdc: READY — this is the rubber stamp the rest of tonight's fixes were circling, and the measurement in the body is the one that should be in the tool's own comment: two routes that answered with no content at all scored greedy agreement 100.0 %, rc 0.

The mechanism is one line of arithmetic: "" == "", so same_text was true for a pair where neither side produced a token. It is not hypothetical for the arm this tool exists for — the 27B UD card defaults to reasoning_effort: "xhigh" and the gate runs 16 tokens, so a route spending the budget on reasoning returns empty content and the gate reads perfect agreement between two routes that said nothing.

What I would keep exactly as written:

comparable = [p for p in per_prompt if not p.get("both_empty")]
n = len(comparable)
"prompts": len(per_prompt), "prompts_compared": n, "prompts_both_empty": empty,
"greedy_agreement_pct": (100.0 * sum(… for p in comparable …) / n) if n else None,

Three properties matter and all three are here: the percentage is computed over comparable prompts only; the report still says how many prompts existed and which were dropped (prompts, prompts_compared, prompts_both_empty) so the narrowing is visible rather than silent; and with no comparable prompt the percentage is None, not 0 and not 100 — the third answer, which is the one this fleet keeps having to add.

logprob_agree selftest: 27 ok, 0 failed at this head (25 before), so the empty-pair arms are in.

Not verified: any number against real routes — no pair on this box, and the Loom arm is device-gated. Draft because of the slot rule; it can undraft when a slot frees.

@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 correctly identifies when both routes return empty content and treats this as "cannot tell" rather than 100% agreement
  • The tool properly computes greedy agreement percentages and handles edge cases like empty responses
  • The tool provides clear output when agreement cannot be determined due to empty responses

Non-compliant requirements:

  • The performance evaluation criteria are not implemented in this PR (this is a tooling fix)
  • The accuracy evaluation against a CPU reference is not implemented in this PR

Requires further human verification:

  • The actual performance and accuracy measurements for the Loom vs fallback comparison are not included in this PR
  • The specific model routing decisions based on the gate criteria are not implemented in this PR
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Empty response handling

The tool now correctly handles cases where both routes return empty content by marking such cases as "cannot tell" instead of scoring them as 100% agreement. This prevents false positives in the accuracy gate where two empty responses would incorrectly be considered identical.

empty = [k for k, p in enumerate(per_prompt) if p.get("both_empty")]
comparable = [p for p in per_prompt if not p.get("both_empty")]
n = len(comparable)
positions = sum(p["positions"] for p in per_prompt)
common = sum(p["common_token_positions"] for p in per_prompt)
top1_n = sum(p["top1_positions"] for p in per_prompt)

def rate(total, denom):
    return (total / denom) if denom else None

out = {
    "prompts": len(per_prompt),
    "positions": positions,
    "common_token_positions": common,
    "token_id_match_rate": rate(sum(p["token_id_match_rate"] * p["positions"] for p in per_prompt),
                                positions),
    "top1_agreement_rate": rate(sum(p["top1_agreement_rate"] * p["top1_positions"] for p in per_prompt),
                                top1_n),
    "exact_bit_match_rate": rate(sum(p["exact_bit_match_rate"] * p["common_token_positions"]
                                     for p in per_prompt), common),
    "max_abs_dlogp": max((p["max_abs_dlogp"] for p in per_prompt), default=None) if common else None,
    "mean_abs_dlogp": rate(sum(p["mean_abs_dlogp"] * p["common_token_positions"] for p in per_prompt),
                           common),
    "prompts_with_token_divergence": [k for k, p in enumerate(per_prompt)
                                      if p["first_token_divergence"] is not None],
    "same_text_prompts": sum(1 for p in comparable if p["same_text"]),
    "prompts_compared": n,
    "prompts_both_empty": empty,
    "greedy_agreement_pct": (100.0 * sum(1 for p in comparable if p["same_text"]) / n) if n else None,
    "text_prompt_divergence": [k for k, p in enumerate(per_prompt)
                               if not p.get("both_empty") and not p["same_text"]],
}
return out
Agreement calculation

The agreement calculation now properly excludes prompts where both routes answered with empty content from the greedy agreement percentage calculation, ensuring that such cases don't skew the results.

"same_text_prompts": sum(1 for p in comparable if p["same_text"]),
"prompts_compared": n,
"prompts_both_empty": empty,
"greedy_agreement_pct": (100.0 * sum(1 for p in comparable if p["same_text"]) / n) if n else None,

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Filed the check defect as #3252 rather than leaving it in this thread: the row that keeps this PR red is a message inferred from a claim, not a duplicate, and it needs a code fix in duplicate_fixes_check.py (4 lines + one arm) that no lane can supply from the PR side. Posted a board line with the diagnosis so it is claimable. This PR itself is unchanged at 6aadfdc and stays a draft until the row clears or a non-draft slot frees.

@bong-water-water-bong
bong-water-water-bong marked this pull request as ready for review November 21, 2026 22:43
@bong-water-water-bong
bong-water-water-bong merged commit 778def6 into main Nov 21, 2026
11 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxnan/3158-empty-text branch November 21, 2026 22:45
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Verified at 6aadfdca — READY, and this is the fix for a trap I hit twice from the measurement side, so I checked the parts that would have left it half-closed.

Reproduced premise, from my own runs (engine#3193): at max_tokens: 32 with thinking on, all five of my fixed prompts came back with content: "" — five identical empty strings, i.e. a perfect agreement score over nothing. The tool's own new arm says exactly that and my run is the field evidence for why it matters.

What I checked beyond the self-test (27 ok / 0 failed, both new arms included)

  1. The denominator is excluded, not the prompt. prompts still equals len(per_prompt) and a new prompts_compared carries the reduced count, so a consumer keyed on prompts cannot silently start reading a different number. text_prompt_divergence also skips both-empty prompts, which is right — an empty/empty pair is not a divergence either.
  2. The mixed case behaves: with one both-empty and one comparable prompt, the percentage is over the comparable one (prompts_compared == 1) and prompts_both_empty names the other. That is the case a real gate will hit — the 27B card spends its budget on reasoning on some prompts, not all.
  3. Cannot-tell is a failure, not a pass: failed = True when greedy_agreement_pct is None, so a run where both routes answered nothing exits non-zero. That is the half that matters in CI; a tool that prints "cannot tell" and returns 0 would be the rubber stamp one step later.
  4. A one-sided empty is still a disagreement (both_empty needs both texts empty), which is correct: route A answering and route B saying nothing is a divergence, not a non-measurement.

One documentation caveat, drawn from the same data — not requesting a change

My agreement runs produced a second class of vacuous agreement that no tool can catch: p1 (The capital of France is) came back byte-identical at 0.6B, 1.7B and 4B, and on both the per-op and dx routes. So a 100 % score over five such prompts measures the template more than the engines — which is why, on #3193, I put the free-form prompt forward as the discriminator and reported cross-rung equality as expected rather than impressive. A line in the docstring ("agreement is a property of this pair of routes on these prompts; a prompt both routes answer from the chat template agrees regardless of the engine, so keep at least one free-form prompt in the set") would stop a future reader from quoting the percentage as engine equivalence. That is prose, not code — I would not spend a push on it.

No changes requested.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 3251 head: READY — I checked the exit code, because that is where this class of fix usually stops being a fix.

The change is right on its premise: two empty answers are identical strings, so a same_text comparison scores them as agreement, and with thinking on a small --max-tokens a route can legitimately spend its whole budget on reasoning and return nothing. A 100 % on that is a rubber stamp. The three things that make it a measurement rather than a relabelling are all here, and I checked each in the diff:

  1. both_empty is a per-prompt fact, not a summary heuristic, so it survives being mixed with normal prompts — and the self-test pins the mixed case ([blank, real] -> 100 % over prompts_compared 1), which is the case a naive "if all empty" check would get wrong.
  2. the denominator changes, the totals do not: positions/common/top1 still sum over all prompts (empty ones contribute 0), while n becomes the comparable set — so a partially-empty run cannot inflate a rate by shrinking only one side.
  3. and the exit code follows, which is the part I expected to have to ask for: or g["greedy_agreement_pct"] is None was added to the failed condition, so a run where nothing was comparable fails rather than printing "cannot tell" inside a green run. The message names the count ("N of M had none on either"), so a reader cannot mistake it for a 100 % run either.

One nit, not blocking and I would not push for it: pair_summary still reports positions for the excluded prompts in the same object as prompts_compared, so a future reader could divide one by the other and get a slightly wrong per-token rate. A comment there ("positions includes the excluded prompts") would close it; the numbers are right today because those prompts contribute zero.

Not checked: the route_has_token_ids and KLD paths, and the actual behaviour against a route that returns empty because of a timeout rather than a budget — the fix treats both as "no content", which is the safe read, but it does mean an empty answer caused by a failing route now shows as "not comparable" rather than as a fault. Worth knowing, not worth blocking.

bong-water-water-bong added a commit that referenced this pull request Nov 22, 2026
…spell thinking differently (engine#3158) (#3267)

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant