Repository navigation
feat(compress): reject truncated summaries; optional proportional summary floor - #521
miaomiaozii wants to merge 4 commits into
Conversation
…mary floor - rejectTruncatedSummary (default true): reject summaries ending in an ellipsis or with an unclosed ``` fence. A cut-off summary becomes the only record of the range and is silently lossy. - minSummaryRatio (default 0 = off): min summary chars per token of the range's direct messages. Consumed blocks are excluded so tier-2/3 distillation is unaffected; floor is capped at maxSummaryLength/2.
The PR was committed with two lines over the 80-col print width, so format:check was red. Rewrap only; no logic change. Verified: 7/7 summary-integrity tests pass, tsc --noEmit clean, format:check green.
applyRefolds only called validateSummaryLength, so a truncated summary could still replace a block's summary via decompress-inline -> refold. Extract validateSummaryNotTruncated and call it from both fresh compression and refold. The proportional floor stays fresh-only: a refold has no new direct messages. Addresses review finding F1 on ranxianglei#520.
- Add a regression test: the minSummaryRatio floor must be computed from the range's direct messages only. A mixed range (5 consumed-block messages + 5 new direct messages) with a 300-char summary passes the direct-only floor (250) and would be rejected if the consumed block's summary tokens were counted (450). Verified the test fails when the validateSummaryProportion call is moved after the consumed-block loop. - Drop the dead 'merge' key from the test config helper: Config has no merge field (hidden by the 'as Config' cast, read by nothing).
[bot] 🏷 Duplicate check: no duplicate. Related: closed predecessor PR #520 (same author, superseded by this PR for the branch-name check). No other open PR or issue targets the same mechanism (summary truncation / undersized validation). Review verdict: mergeable, with two test-quality fixes I pushed to the PR branch as commit What I verified
Fixes I pushed (
|
Supersedes #520, reopened only to satisfy the
YYYY-MM-DD_short-titlebranch-name check (GitHub can't change a PR's head branch).Same commits as #520 (including the maintainer's prettier fix
fef29fe), plus one new commit:79f9491fix(compress): run the truncation check on the refold path too. Addresses review finding F1:applyRefoldsonly calledvalidateSummaryLength, so a truncated summary could still land via decompress-inline → refold. ExtractedvalidateSummaryNotTruncatedand call it from both paths; the proportional floor stays fresh-compression-only. Two new tests intests/refold.test.ts(reject…/ unclosed fence on refold and leave the block untouched; opt-out still works). The reject test fails without the fix.Local:
tsc --noEmitclean;refold+summary-integritytests 29/29; prettier clean.Fixes ranxianglei/billion-context#6927.
Change
rejectTruncatedSummary(defaulttrue):detectTruncatedSummary()rejects a summary ending in…/...or with an odd number of ``` fences. The error tells the model to finish the sentence/fence and resubmit.minSummaryRatio(default0, off): min summary chars per token of the range's direct messages. Checked aftercompressedTokensis computed and before consumed blocks are added, so tier-2/3 distillation is not penalized. Floor capped atmaxSummaryLength / 2(orsummaryMaxChars / 2).Both live in
CompressValidationConfigas optional fields, so existing configs and adapters compile unchanged.Tests
tests/summary-integrity.test.ts(7 tests): detector true/false cases, default rejection, opt-out, ratio reject/pass, ceiling cap, ratio off by default.node --import tsx --test tests/summary-integrity.test.ts→ 7 passnpm test→ 1238 pass / 2 fail. The 2 failures (applyRetrieve exports large originals to a file,default builders are byte-stable against checked-in fixtures) fail identically on unmodifiedmasteron this Windows machine (verified withgit stash), so they are environment-related, not from this change.tsc --noEmitclean.