Skip to content

fix(tier2): number shared review blocks from the most repeated text - #361

Merged
rng1995 merged 4 commits into
mainfrom
naren/followup-346-share-order
Nov 6, 2026
Merged

rng1995 merged 4 commits into
mainfrom
naren/followup-346-share-order

Conversation

@rng1995

@rng1995 rng1995 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #346, which merged before its last review round. #346 shares a repeated text in a Tier 2 review prompt only when its block and references are shorter than its inline copies. It numbers the shared blocks in first-seen order, and a reference to block 10 or later is one character longer than one to blocks 1-9.

That can refuse a cluster that would fit. Example on main: nine different 62-character texts, each repeated twice, come first, then a 40-character body repeated 400 times and one 26,100-character distinct section. The 400-copy body becomes [SHARED CONTENT 10], the request is 64,022 characters, and the scan stops with llm_prompt_size_limit. Sharing the body as block 1 gives 63,630 characters.

  • build_user_prompt now numbers candidate texts in descending repeat count, with ties in first-seen order, and chooses which of them to share exactly (dynamic programming over that order). A greedy pass in count order is not enough: a highly repeated text that saves only a little can push another text past block 9 and cost it more than it saves.
  • A new test pins the extra character of two-digit block numbers. Before it, passing a constant index to the saving check still passed every intra_skill test.
  • The fix(tier2): review large repeated-content clusters within the prompt budget #338/fix(tier2): share a repeated text only when that shortens the review prompt #346 CHANGELOG entry (Unreleased / Fixed), docs/tier2-deduplication.mdx and the build_user_prompt docstring no longer say that a short text "under long headings" stays inline. The heading line stays with every occurrence whether or not the body is shared, so only the body's length and repeat count decide. See guide. under 200 short ## Hn headings stays inline too.

Why

#338 and #346 aim to finish scans of skills with heavily repeated content instead of marking deduplication incomplete. A numbering that makes the most referenced text pay an extra character per reference works against that near the budget. The docs should also give the rule that actually decides sharing, so authors are not led to shorten headings to no effect.

Kept from public

  • The 64,000-character budget (system prompt plus user prompt), the per-text check that sharing must save characters, and the final check that the compact prompt is shorter than the full one are unchanged.
  • Equally repeated texts keep fix(tier2): review large repeated-content clusters within the prompt budget #338's first-seen numbering.
  • Heading-line splitting, per-occurrence entries, and the rule that distinct text is never dropped or shortened are unchanged.

Tests

  • New cases in tests/deduplication/intra_skill/test_intra_llm_analyzer.py:
    • the most repeated text gets block 1, and a request that was 200 characters over the budget is now 200 under it;
    • a highly repeated text that would push another past block 9 stays inline;
    • two-digit block numbers cost one more character: at block 10, a 64-character text repeated twice stays inline and a 65-character one is shared;
    • a short repeated body stays inline under short and long headings alike.
  • On the code before this change, the two numbering cases fail. The two-digit case fails when the saving check is given a constant index.
  • An exhaustive check, with references renumbered in binary so the width boundaries are reachable with six texts, found that the new choice matched the shortest prompt over every ordered subset in 400 random clusters. In 2,000 random clusters, first-seen numbering gave a longer prompt in 955 and greedy count-order numbering in 77. Neither was ever shorter than the new choice.
  • The worst case the validator allows (512 members, 256 repeated texts) builds its prompt in about 20 ms.
  • tests/deduplication/intra_skill/test_intra_llm_analyzer.py: 37 passed. tests/deduplication/intra_skill: 136 passed.
  • tests/deduplication, tests/test_ci_workflows.py and tests/test_accuracy_arithmetic.py on main before feat(tier3): split measured agent time into LLM and tool seconds #344 plus this change: 371 passed, 1 skipped. feat(tier3): split measured agent time into LLM and tool seconds #344 touches only Tier 3 and its own CHANGELOG lines, and the branch merges cleanly with current main.
  • ruff check and ruff format --check are clean on the changed files, and scripts/check_oss_boundary.py passes.

🤖 Generated with Claude Code

rng1995 and others added 3 commits November 5, 2026 20:03
A reference to shared block 10 or later is one character longer than one
to blocks 1-9, and its header is too. No test covered that part of the
cost model: passing a constant index to the saving check still passed
every intra_skill test, and then shared a 64-character text repeated
twice as block 10 although that made the prompt no shorter.

Add a case with nine texts worth sharing and a tenth text repeated twice
on the two-digit boundary: 64 characters stays inline, 65 is shared.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…text inline

The CHANGELOG, the Tier 2 deduplication guide and the build_user_prompt
docstring said a short text repeated under long headings stays inline.
The heading line stays with every occurrence whether or not the body is
shared, so only the body's length and repeat count decide: "See guide."
under 200 short "## Hn" headings stays inline too. Long headings only
explain why such a cluster was over budget.

State the actual rule, and add a test that a short repeated body stays
inline under short and long headings alike.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
build_user_prompt numbered shared blocks in first-seen order, and a
reference to block 10 or later is one character longer than one to
blocks 1-9. Nine rarely repeated texts seen first could push a body
repeated 400 times to block 10: the request came to 64,022 characters
and the scan stopped with llm_prompt_size_limit, while sharing the body
as block 1 gave 63,630.

For any set of shared texts the prompt is shortest when the most
repeated texts get the lowest numbers, so candidates are now numbered
in descending repeat count, ties in first-seen order. Choosing them
greedily in that order is still not enough: a highly repeated text
that saves only a little can push another past block 9 and cost it
more than it saves. Which candidates to share is now chosen exactly by
dynamic programming over that order. It runs in about 20 ms for the
512-member worst case and matched an exhaustive search over every
ordered subset in 400 random clusters.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the shared-text selection. The dynamic program prices the extra character for block 10 and above correctly, and the three tests cover the two-digit overhead, the shortest reference going to the most-repeated text, and the marginal text that would push another past block 9. Non-blocking: the table is quadratic in the number of repeated texts. I measured 4.8 s for 2,000 distinct texts and 31 s for 5,000 by calling build_user_prompt directly. Those sizes are far above the 512-member cluster cap, so normal runs are unaffected, but a short comment noting that the cap bounds this cost would help whoever changes the cap. I merged main into the branch to clear the conflict.

@rng1995
rng1995 marked this pull request as ready for review November 6, 2026 12:20
@rng1995
rng1995 merged commit 164e5fc into main Nov 6, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/followup-346-share-order branch November 6, 2026 12:20
rng1995 added a commit that referenced this pull request Nov 6, 2026
…Unreleased

Nine PRs merged after the v0.8.0 tag (8149356). Four of them rewrote
bullets inside the 0.8.0 section and one added a new bullet there, so
main's 0.8.0 notes described behavior that 0.8.0 does not have. Two
fixes to 0.8.0 features added no entry.

- Restore the 0.8.0 section and everything below it to the tagged text,
  byte for byte.
- Move the agent skill entry (#366) to Unreleased, Added.
- Add Documentation entries for the 0.8.0 wording that #360, #361 and
  #363 corrected (refusal coverage error, inline short texts, capitalized
  HTTP prose that still warns).
- Add Fixed entries for #361, #365, #359, #364 and #363 that describe
  only what changed after 0.8.0. The #364 entry states that path masking
  skips text after a non-file: URL up to the next whitespace, which is
  how main behaves today.
- Move the #348 entry to Fixed and say what 0.8.0 did: a CI-redacted PII
  finding kept the digest of its unmasked value.
- The refusal docs test now reads the Documentation correction, which
  matches the docs, and still requires the switch's entry in 0.8.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
rng1995 added a commit that referenced this pull request Nov 6, 2026
…Unreleased

Nine PRs merged after the v0.8.0 tag (8149356). Four of them rewrote
bullets inside the 0.8.0 section and one added a new bullet there, so
main's 0.8.0 notes described behavior that 0.8.0 does not have. Two
fixes to 0.8.0 features added no entry.

- Restore the 0.8.0 section and everything below it to the tagged text,
  byte for byte.
- Move the agent skill entry (#366) to Unreleased, Added.
- Add Documentation entries for the 0.8.0 wording that #360, #361 and
  #363 corrected (refusal coverage error, inline short texts, capitalized
  HTTP prose that still warns).
- Add Fixed entries for #361, #365, #359, #364 and #363 that describe
  only what changed after 0.8.0. The #364 entry states that path masking
  skips text after a non-file: URL up to the next whitespace, which is
  how main behaves today.
- Move the #348 entry to Fixed and say what 0.8.0 did: a CI-redacted PII
  finding kept the digest of its unmasked value.
- The refusal docs test now reads the Documentation correction, which
  matches the docs, and still requires the switch's entry in 0.8.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
rng1995 added a commit that referenced this pull request Nov 6, 2026
…Unreleased (#371)

Nine PRs merged after the v0.8.0 tag (8149356). Four of them rewrote
bullets inside the 0.8.0 section and one added a new bullet there, so
main's 0.8.0 notes described behavior that 0.8.0 does not have. Two
fixes to 0.8.0 features added no entry.

- Restore the 0.8.0 section and everything below it to the tagged text,
  byte for byte.
- Move the agent skill entry (#366) to Unreleased, Added.
- Add Documentation entries for the 0.8.0 wording that #360, #361 and
  #363 corrected (refusal coverage error, inline short texts, capitalized
  HTTP prose that still warns).
- Add Fixed entries for #361, #365, #359, #364 and #363 that describe
  only what changed after 0.8.0. The #364 entry states that path masking
  skips text after a non-file: URL up to the next whitespace, which is
  how main behaves today.
- Move the #348 entry to Fixed and say what 0.8.0 did: a CI-redacted PII
  finding kept the digest of its unmasked value.
- The refusal docs test now reads the Documentation correction, which
  matches the docs, and still requires the switch's entry in 0.8.0.

Signed-off-by: Narendran Raghavan <[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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants