Repository navigation
fix(tier2): review large repeated-content clusters within the prompt budget - #338
Merged
Merged
Conversation
…budget Context deduplication marked any candidate cluster with more than 64 members as incomplete (llm_cluster_member_limit), even when its review request fit the 64,000-character per-call budget. Skills with many repeated sections therefore never finished Tier 2. - Set the cluster member limit to the 512-chunk ceiling, so the per-cluster prompt, total prompt and cluster-count limits decide. - When SYSTEM_PROMPT plus the full user prompt would exceed the per-call budget, build_user_prompt lists each exactly repeated chunk text once as SHARED CONTENT n. Every occurrence keeps its own CHUNK entry with file, section and lines plus a reference. Distinct text is never dropped, so a cluster still over budget stays incomplete. - The per-call budget now lives in llm_analyzer (MAX_PROMPT_CHARS) and the validator's CONTENT_DEDUP_MAX_LLM_PROMPT_CHARS refers to it, so the prompt that is measured is the prompt that is sent. - Duplicate and llm_refused finding messages name at most 64 member locations and source files and count the rest, so a 512-member cluster does not produce a ~40 KB message. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe how a cluster review request lists exactly repeated text once, add the LLM review clusters, cluster members, per-cluster prompt and total prompt limits to the defaults table, and add the CHANGELOG entry. The earlier Unreleased work-limit entry now names the 512-member limit. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
commented
Nov 4, 2026
rng1995
left a comment
Collaborator
Author
There was a problem hiding this comment.
Automated review: 2 findings (0 P1, 0 P2, 2 P3); 2 posted inline.
rng1995
commented
Nov 4, 2026
rng1995
left a comment
Collaborator
Author
There was a problem hiding this comment.
Automated review: 1 findings (0 P1, 1 P2, 0 P3); 1 posted inline.
A Markdown section chunk's text opens with its own heading line, so the same boilerplate body under different headings was never byte-identical and never shared. 500 "## Step i" sections with one body, or 30 "## Tool i" sections with one 2.8k-character body, still stopped the scan with llm_prompt_size_limit. When sharing applies, build_user_prompt now compares the text after a chunk's own heading line (when the text opens with it). Each occurrence keeps its heading line followed by a [SHARED CONTENT n] reference, so the heading line plus the shared block is exactly the chunk text. Text that does not open with its heading line is compared whole, and a chunk whose whole text equals another chunk's body shares that block. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The member limit equals the 512-chunk ceiling, and the chunk-count check runs first with an effective limit of at most 512, so a cluster can never exceed it in a real scan. The docs defaults table now says it never stops a scan on its own, and the user-facing lists of LLM-review limits in the docs and the earlier Unreleased work-limit CHANGELOG entry no longer name "members in one cluster". The check itself stays as a defensive guard. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
The validator copied llm_analyzer.MAX_PROMPT_CHARS into CONTENT_DEDUP_MAX_LLM_PROMPT_CHARS at import time, while build_user_prompt read llm_analyzer.MAX_PROMPT_CHARS. Patching one moved the refusal threshold without the sharing threshold, or the reverse. The validator now compares each cluster's request against llm_analyzer.MAX_PROMPT_CHARS at call time and the copy is removed, so a single value sets both when repeated text is shared and when a request is refused. The limit tests patch llm_analyzer.MAX_PROMPT_CHARS, and a new test lowers it to show that a shared prompt fits and a distinct one is refused under the same budget. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
marked this pull request as ready for review
November 5, 2026 17:49
rng1995
requested review from
chrisknvidia,
mosheabr and
rmalani-nv
as code owners
November 5, 2026 17:49
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CONTENT_DEDUP_MAX_CLUSTER_MEMBERS) to the 512-chunk ceiling instead of 64. The chunk check runs first with an effective ceiling of at most 512, so the member check is now a guard that never stops a scan on its own. The per-cluster prompt (64,000 characters), total prompt (1,000,000 characters) and cluster-count (50) limits decide whether a cluster is reviewed.build_user_promptstill renders every member in full when the request fits. WhenSYSTEM_PROMPTplus the full user prompt would exceed 64,000 characters, each exactly repeated text is listed once asSHARED CONTENT nif its block and[SHARED CONTENT n]references are shorter than its inline copies. A short body repeated under long headings therefore stays inline, where sharing it would make the request longer. The compact form is used only when it is shorter, with its notice line counted.CHUNKentry with file, section and line range, then its own heading line and[SHARED CONTENT n]in place of the body, so the heading line plus the shared block is exactly the chunk text. Text that does not open with its heading line is compared whole.llm_prompt_size_limit.llm_analyzer.pyasMAX_PROMPT_CHARS. The validator readsllm_analyzer.MAX_PROMPT_CHARSwhen it checks each cluster, and its import-time copyCONTENT_DEDUP_MAX_LLM_PROMPT_CHARSis removed, so one value decides both when text is shared and when a request is refused. Sharing uses the same measure as the validator (system prompt plus user prompt), so there is no band where a 63,000 to 64,000-character user prompt is left unshared and then refused.analyze_clustersends exactly the prompt the validator measured.llm_refusedfinding messages name at most 64 member locations and 64 source files, then count the rest (and 436 more locations (500 in total),and 36 more files). Without this, a 512-member cluster would produce a message of about 40 KB in BENCHMARK.md, HTML and JSON reports. Clusters of up to 64 members keep the same message as before, and the JSONsource_filesmetadata still lists every file.docs/tier2-deduplication.mdxand adds rows for the LLM review clusters, cluster members, per-cluster prompt and total prompt limits to the defaults table. The cluster-members row says the limit never stops a scan on its own, and the lists of LLM-review limits in the docs no longer name it. Adds a CHANGELOG entry under Unreleased > Fixed, and the earlier Unreleased work-limit entry no longer lists "more than 64 members in one cluster" among the limits a user can hit.Why
A skill with many repeated sections (for example the same boilerplate block under several hundred headings) forms one large candidate cluster. Public main marked every cluster over 64 members as incomplete before any LLM call, even when its full prompt was far below the 64,000-character budget. With the default
--block-on-dedup, Tier 2 then failedvalidateand the skill could never finish deduplication.Through real chunking and clustering on
main:llm_cluster_member_limit, whether they share one heading or have 500 different headings (## Step 0to## Step 499).## Tool 0to## Tool 29with the same three-paragraph body of about 2,800 characters stop withllm_prompt_size_limit(an 86,513-character request).llm_cluster_member_limit.On this branch each of these completes with one LLM call. The two 500-section cases send 55,236 and 55,016-character requests, and the 30-section case sends 7,172 characters.
Kept from public
IntraSkillValidator.validateis unchanged: member count, then per-cluster prompt, then total prompt, all before the first LLM call. The validator still measureslen(SYSTEM_PROMPT) + len(build_user_prompt(cluster)), so it picks up sharing without a new code path. The member check stays as a defensive guard._mark_work_limit_incompletereporting, thework_limitJSON record and the incomplete-scan error text are unchanged.split_grouphandling are unchanged.analyze_cluster(client, cluster)keeps its signature, so the existing side-effect mocks in the validator tests still apply.tests/deduplication/plugin/test_private_dedup.pynow patchllm_analyzer.MAX_PROMPT_CHARS. The plugin test usedraising=Falsebefore; it now fails if the attribute is missing.llm_prompt_size_limit.docs/tier2-deduplication.mdxandCHANGELOG.md, and feat(plugin): Add Plugin evaluation support across all tiers #28 also editsintra_skill/llm_analyzer.pyandintra_skill_validator.py, including the per-call prompt constant. Whichever lands second needs a rebase that keeps a single per-call budget.Tests
tests/deduplication/intra_skill/test_intra_llm_analyzer.py:CHUNKentries keeps its file, section and lines, and the request fitsSee guide.plus 25 sections with a shared 920-character body: the short bodies stay inline and the request fits, while sending everything in full or sharing both bodies is over budget[SHARED CONTENT 1]analyze_clustersends the shared prompt that the validator measurestests/deduplication/intra_skill/test_intra_skill_validator.py:llm_analyzer.MAX_PROMPT_CHARS(64,000), and the validator keeps no copy of itSee guide.plus 14 sections with a 920-character body complete with one LLM call. The short bodies stay inline, and sharing both bodies would be over budgetDUPLICATEandRELATED_BUT_DISTINCTllm_cluster_member_limit(limit 512), and 500 distinct members still hitllm_prompt_size_limitllm_analyzer.MAX_PROMPT_CHARSlowered to 8,000, a repeated cluster is shared and reviewed, and a distinct cluster is refused at that same limittest_llm_review_limits_are_incomplete_before_llm_analysisandtest_context_prompt_limit_refuses_llm_before_external_workpatchllm_analyzer.MAX_PROMPT_CHARS. The three case IDs of the first test now name the module that holds each limit.mainsrc, 34 of the 158 cases in these three test files fail: 32 of the 35 new cases and the 2 adjusted ones. The 3 new cases that pass are guards for unchanged behavior: the 64-member message (duplicate and refusal) and the within-budget prompt.tests/deduplication/intra_skill/test_intra_llm_analyzer.pyandtest_intra_skill_validator.py: 113 passed.tests/deduplication: 288 passed, 1 skipped.tests/deduplication,tests/inference/test_llm_client.py,tests/reporting/test_mixed_execution_errors.py,tests/reporting/test_reporters.py,tests/reporting/test_tier3_validate_cases.py,tests/test_publication_evidence.py,tests/test_tier2_command_failures.py,tests/validators/test_similarity.py,tests/embedding/test_client.py,tests/test_cli.py,tests/test_ci_workflows.py,tests/ci/test_image_build.py, and the docs and CHANGELOG readers (test_oss_packaging.py,test_accuracy_arithmetic.py,test_benchmark_rollout_docs.py,test_ci_change_classifier.py,test_tier3_public_runtime.py): 1363 passed, 1 skipped.ruff checkandruff format --checkare clean on the 5 changed Python files.scripts/check_oss_boundary.pypassed.🤖 Generated with Claude Code