Skip to content

logprob_agree: a reply cut by max_tokens at an agreeing prefix is truncated, not a counted split (#3158) - #3430

Merged
bong-water-water-bong merged 1 commit into
mainfrom
inkling/agree-truncated
Nov 23, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
inkling/agree-truncated

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #3423 / #3429. These merged without the truncation case raised in the cl-inkling review on each; cl-npuconc's points are separate and untouched here.

Defect: near_tie_score() couldn't tell a reply that stopped from one cut by its token budget.

  • What was missing: ask() did not record finish_reason.
  • When it bites: the two texts agree up to the shorter one, and the shorter one hit max_tokens.
    • Reference (CPU) cut, route longer: the CPU has no end-of-turn token at its cut. split_margin finds no route token among its candidates, and the prompt was counted.
    • Route cut, CPU longer: the route was judged against the CPU's next token at the cut, a token it never chose. It was counted whenever that token wasn't the route's (empty) one.
  • Who hits it: Inkling thinking-on rows. A 512-token budget routinely ends inside the thinking; both TML-d24 code replies did on 23 Nov. Arms that count the budget differently, such as a card's think_open prefill, make the cut land at different places.

Change (tools/logprob_agree.py, plus one sentence in docs/loom-route.md):

  • ask() records "finish": ch.get("finish_reason").
  • near_tie_score(): when one text is a prefix of the other and the shorter run's finish == "length", the prompt is truncated.
    • It is reported beside the score and not counted. The split row carries "cut": "route" | "reference".
    • It goes into the score like identical text: the two routes agreed on every token both produced.
  • Unchanged: a run that stopped early (finish: "stop") is still judged at the CPU's token, so an early end of turn is not excused. So is every non-prefix split.
  • Output: the near-tie rule line prints truncated N and marks those prompts cut(route|reference).

Checks:

  • --selftest: 42 ok. Two new cases:
    • a cut reference and a cut route, each at an agreeing prefix, are truncated (with a near-tie split beside them);
    • a route that stopped early is still judged, not excused.
  • Mutation check: with the truncated branch disabled, the first new case FAILs.
  • bash scripts/pre-pr-checks.sh --base origin/main: 18 green, 2 skipped (gpu-kernels audits, no checkout).
  • Saved rows: rows recorded before this PR have no finish field, so they score exactly as before. Nothing re-scored changes.

🤖 Generated with Claude Code

…ncated, not a counted split (#3158)

ask() records finish_reason. near_tie_score() reports a prompt as truncated when one
text is a prefix of the other and the shorter run stopped on its budget (finish
"length"): before, a cut reference gave no readable gap (counted) and a cut route
was judged at a token it never chose. Two self-test cases; docs/loom-route.md names
the kind.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 PR implements the accuracy gate logic for determining whether a model should route to Loom or stay on fallback
  • It correctly handles the case where a reply is truncated due to max_tokens being reached, which should not be counted as a disagreement
  • The toolchain blocker for schema_version: 2 cards is acknowledged and noted as a separate issue

Non-compliant requirements:

  • The performance evaluation requirements (≥ 4 interleaved rounds, client-side streaming measurement, load average and power mode recording) are not implemented in this PR
  • The accuracy evaluation requirements (mean KLD, same-top-token % against CPU reference) are not implemented in this PR
  • The pre-registered decision rule implementation is not fully implemented in this PR
  • The toolchain blocker resolution is not addressed in this PR

Requires further human verification:

  • The performance and accuracy evaluation results for the Qwen3.8-27B model need to be verified once the toolchain blocker is resolved
  • The actual decision rule implementation needs to be validated with real performance and accuracy data
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Truncation Logic

The change correctly identifies when a reply is truncated due to hitting max_tokens (finish_reason: "length") and treats it as a truncated prompt rather than a counted disagreement. This prevents incorrect scoring when one model runs out of tokens while the other continues. The logic correctly checks if one text is a prefix of the other and the shorter one stopped due to token budget, and reports it as "truncated" in the output.

short = c if len(c["text"]) < len(r["text"]) else r
other = r if short is c else c
if other["text"].startswith(short["text"]) and short.get("finish") == "length":
    out["truncated"] += 1
    out["splits"].append({"prompt": p, "char": len(short["text"]), "margin": None, "top2_margin": None,
                          "ref_token": None, "route_token": None, "kind": "truncated",
                          "cut": "route" if short is c else "reference"})
    continue
Score Calculation

The score calculation in near_tie_score() now includes truncated prompts in the total score, which is correct since truncated prompts represent agreement up to the point where one model ran out of tokens. This ensures that the scoring accurately reflects the number of prompts where both models agreed, including those that were truncated due to token budget constraints.

out["score"] = out["identical"] + out["near_tie"] + out["truncated"]

@bong-water-water-bong
bong-water-water-bong merged commit bf85ad6 into main Nov 23, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the inkling/agree-truncated branch November 23, 2026 22:08
bong-water-water-bong added a commit that referenced this pull request Nov 23, 2026
…ts cut inside the thinking (#3158) (#3434)

A reply cut by max_tokens inside its reasoning ends in REASONING_SEP, so its text is
no longer a prefix of the longer reply and #3430's test counted it. The prefix test
now runs on the texts without the separator. One self-test case.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[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