Skip to content

fix(tier2): review large repeated-content clusters within the prompt budget - #338

Merged
rng1995 merged 5 commits into
mainfrom
naren/port-tier2-cluster-prompt-budget
Nov 5, 2026
Merged

rng1995 merged 5 commits into
mainfrom
naren/port-tier2-cluster-prompt-budget

Conversation

@rng1995

@rng1995 rng1995 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Set the context-deduplication cluster member limit (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_prompt still renders every member in full when the request fits. When SYSTEM_PROMPT plus the full user prompt would exceed 64,000 characters, each exactly repeated text is listed once as SHARED CONTENT n if 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.
  • A Markdown section chunk's text opens with its own heading line, so the text compared is the body after that line. The same body under different headings is listed once. Every occurrence keeps its own CHUNK entry 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.
  • Distinct text is never dropped, shortened or sampled. A cluster that is still over budget after sharing stays incomplete with llm_prompt_size_limit.
  • The per-call budget moves into llm_analyzer.py as MAX_PROMPT_CHARS. The validator reads llm_analyzer.MAX_PROMPT_CHARS when it checks each cluster, and its import-time copy CONTENT_DEDUP_MAX_LLM_PROMPT_CHARS is 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_cluster sends exactly the prompt the validator measured.
  • Duplicate and llm_refused finding 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 JSON source_files metadata still lists every file.
  • Documents the shared-content prompt in docs/tier2-deduplication.mdx and 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 failed validate and the skill could never finish deduplication.

Through real chunking and clustering on main:

  • 500 sections with the same body stop with llm_cluster_member_limit, whether they share one heading or have 500 different headings (## Step 0 to ## Step 499).
  • 30 sections ## Tool 0 to ## Tool 29 with the same three-paragraph body of about 2,800 characters stop with llm_prompt_size_limit (an 86,513-character request).
  • 65 short identical members (a 10,982-character request) stop with 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

  • The limit order in IntraSkillValidator.validate is unchanged: member count, then per-cluster prompt, then total prompt, all before the first LLM call. The validator still measures len(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_incomplete reporting, the work_limit JSON record and the incomplete-scan error text are unchanged.
  • The 512-chunk ceiling, the 267,911,168 scalar-comparison budget, the 3,000-character chunk cap and split_group handling are unchanged.
  • analyze_cluster(client, cluster) keeps its signature, so the existing side-effect mocks in the validator tests still apply.
  • The existing monkeypatched-limit test keeps its three cases and assertions for the member, per-cluster prompt and total prompt limits. Because the validator's copy of the per-call budget is removed, its per-cluster case and the plugin-path prompt-limit test in tests/deduplication/plugin/test_private_dedup.py now patch llm_analyzer.MAX_PROMPT_CHARS. The plugin test used raising=False before; it now fails if the attribute is missing.
  • Sharing helps only with text that is identical byte for byte (after the heading line for a Markdown section). Near-duplicates with small edits are still sent in full and can still hit llm_prompt_size_limit.
  • Conflict note: open PRs feat(plugin): Add Plugin evaluation support across all tiers #28, fix(tier2): allow contained directory aliases #282 and fix(inference): recover one JSON object wrapped in LLM prose #297 also edit docs/tier2-deduplication.mdx and CHANGELOG.md, and feat(plugin): Add Plugin evaluation support across all tiers #28 also edits intra_skill/llm_analyzer.py and intra_skill_validator.py, including the per-call prompt constant. Whichever lands second needs a rebase that keeps a single per-call budget.

Tests

  • 13 new tests (15 cases) in tests/deduplication/intra_skill/test_intra_llm_analyzer.py:
    • 500 repeated members plus one unique member: the repeated text appears once, each of the 501 CHUNK entries keeps its file, section and lines, and the request fits
    • two repeated texts numbered in first-seen order, each occurrence pointing to the right one
    • a user prompt that fits on its own but not with the system prompt is shared
    • a prompt within budget keeps every occurrence inline
    • 500 distinct members over budget are sent in full with no sharing
    • sharing is skipped when it would not shorten the prompt: a 19-character text whose block and references are longer than its two copies, and a 100-character text whose saving is smaller than the shared-content notice (2 cases)
    • a text repeated twice stays inline at 61 characters, where its block and references cost as much as its copies, and is shared at 62 (2 cases)
    • 270 sections with long headings and the body See 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
    • the same body under 500 different heading lines is listed once, and each entry keeps its heading line followed by [SHARED CONTENT 1]
    • a CRLF heading line is kept with each occurrence
    • a chunk whose whole text equals another chunk's body shares that block
    • text that does not open with its own heading line is compared whole and not shared
    • analyze_cluster sends the shared prompt that the validator measures
  • 20 new test cases in tests/deduplication/intra_skill/test_intra_skill_validator.py:
    • the member limit equals the 512-chunk ceiling, the per-call budget is llm_analyzer.MAX_PROMPT_CHARS (64,000), and the validator keeps no copy of it
    • through real chunking and clustering, with LF and CRLF line endings: 500 sections under one heading, 500 sections under different headings, and 30 sections under different headings with a long body all complete with one LLM call, a HIGH finding and a bounded message (6 cases)
    • through real chunking and clustering, 270 sections with long headings and the body See 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 budget
    • a 500-member cluster is reviewed in full for DUPLICATE and RELATED_BUT_DISTINCT
    • 513 members still hit llm_cluster_member_limit (limit 512), and 500 distinct members still hit llm_prompt_size_limit
    • with llm_analyzer.MAX_PROMPT_CHARS lowered to 8,000, a repeated cluster is shared and reviewed, and a distinct cluster is refused at that same limit
    • finding messages for 64, 65 and 100 members across as many files, for both duplicate and refusal findings
  • 2 existing tests adjusted: the per-cluster prompt case of test_llm_review_limits_are_incomplete_before_llm_analysis and test_context_prompt_limit_refuses_llm_before_external_work patch llm_analyzer.MAX_PROMPT_CHARS. The three case IDs of the first test now name the module that holds each limit.
  • Against main src, 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.py and test_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 check and ruff format --check are clean on the 5 changed Python files.
  • scripts/check_oss_boundary.py passed.

🤖 Generated with Claude Code

rng1995 and others added 2 commits November 4, 2026 04:16
…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 rng1995 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.

Automated review: 2 findings (0 P1, 0 P2, 2 P3); 2 posted inline.

@rng1995 rng1995 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.

Automated review: 1 findings (0 P1, 1 P2, 0 P3); 1 posted inline.

rng1995 and others added 3 commits November 5, 2026 01:01
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
rng1995 marked this pull request as ready for review November 5, 2026 17:49
@rng1995
rng1995 merged commit ed3aad5 into main Nov 5, 2026
22 checks passed
@rng1995
rng1995 deleted the naren/port-tier2-cluster-prompt-budget branch November 5, 2026 17:50
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.

1 participant