Skip to content

fix(tier2): derive the intra-skill scalar budget from the chunk ceiling - #270

Merged
rng1995 merged 4 commits into
mainfrom
naren/port-tier2-dedup-capacity
Nov 3, 2026
Merged

rng1995 merged 4 commits into
mainfrom
naren/port-tier2-dedup-capacity

Conversation

@rng1995

@rng1995 rng1995 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Tier 2 context deduplication has two limits on the all-pairs clustering work for one skill. The first is a 512-chunk ceiling, checked before any embedding request. The second is a scalar-comparison budget, defined as pair count times embedding width. The second was hard-coded to 25,000,000, in both the validator and the clustering guard in build_clusters. That is far below what the chunk ceiling implies, so valid skills were rejected long before they reached 512 chunks.

This PR:

  • Moves the budget into constants.py and derives it from the chunk ceiling: CONTENT_DEDUP_MAX_PAIR_COMPARISONS (512 × 511 / 2) × CONTENT_DEDUP_SCALAR_BUDGET_DIMENSION (2,048) = 267,911,168. Embeddings of up to 2,048 dimensions can now use all 512 chunks.
  • Makes IntraSkillValidator (its default budget) and build_clusters (its defensive guard) both read that one constant, so the clustering step accepts every workload the validator allows.
  • Adds effective_chunk_limit(vector_dimension, max_scalar_comparisons=None), an exact integer (math.isqrt) bound that gives the largest chunk count allowed for a given width and budget. With the default budget: 511 at 2,049 dimensions, 418 at 3,072, 362 at 4,096.
  • Adds the effective chunk limit to the scalar_comparison_limit finding's message and to its metadata (effective_chunk_limit), so an author knows how far to shrink the skill. The finding uses the validator's actual budget, so a smaller private per-skill budget reports its own limit.
  • Documents both limits in the "Defaults and safety limits" table of docs/tier2-deduplication.mdx and adds a CHANGELOG.md entry under Unreleased → Fixed.

The chunk ceiling, the LLM-cluster limit, the cluster-member and prompt-size guards, the collection limits and the other Tier 2 guards are unchanged.

Scope notes:

  • Main already embeds batch by batch and checks the budget after the first validated batch, normalizes each vector once in build_clusters, and bounds cluster members and LLM prompt sizes. This PR keeps all of that and only changes the budget value, where it is defined, and the finding's detail.
  • The private bundle path in deduplication/plugin/commands.py keeps its own aggregate MAX_PLUGIN_DEDUP_SCALAR_COMPARISONS budget, split across bundled skills. It has no public dispatch, and this PR does not change it.
  • feat(plugin): Add Plugin evaluation support across all tiers #28 still sets the intra-skill budget to 25,000,000 in constants.py. Whichever lands second resolves a small conflict around that constant and the finding.
  • Raising the chunk ceiling above 512 is left for a follow-up.

Why

Before this PR, a skill failed Tier 2 with a CRITICAL scalar_comparison_limit finding at:

Embedding width Fails at
2,048 157 chunks
1,536 181 chunks
1,024 222 chunks

Both widths of the default embedding setups fail well below the 512-chunk ceiling. The 2,048-dimensional case is the default NVIDIA Build embedding model, and 1,536 is OpenAI text-embedding-3-small. validate runs deduplication by default and Tier 2 gates by default, so these skills got a non-zero exit. A 363-chunk skill, for example, failed at every common width. Main now stops after the first embedding batch, which saves the remaining requests, but the skill still fails.

After this PR, embeddings of up to 2,048 dimensions reach the full 512 chunks. Wider models are still bounded, and the finding names the limit that applies to them.

The cost is runtime: skills that used to fail now run the full all-pairs clustering. With main's normalize-once clustering, a local measurement of build_clusters took about 3 s of CPU for 512 chunks at 2,048 dimensions, 1.4 s for 363 chunks at 2,048, and 2.7 s for 418 chunks at 3,072.

No public issue tracks this bug.

Kept from public

  • The embedding flow is unchanged: per-batch embedding with the budget check after the first validated batch, the provider error contract (embedding-provider incomplete scan, no skill finding), vector validation, and the check order are all kept.
  • The private constructor budgets (_max_scalar_comparisons, _max_total_prompt_chars) and max_llm_clusters are kept. Only the default scalar budget changes.
  • The finding is unchanged apart from the new message text and the extra effective_chunk_limit metadata key. It keeps the privacy-safe file_path (the skill directory name, not a host path), its severity and check name, the existing pair_count, vector_dimension, scalar_work and limit metadata, and its suggestion.
  • build_clusters keeps its normalize-once loop, split-piece handling and both guards. Only its budget now comes from constants.py. The chunker and the similarity-check scalar budget (--max-scalar-comparisons) are not touched.
  • The existing monkeypatch-based limit tests still run. The validator test no longer needs raising=False, because the constant is now a real import, and it asserts the new metadata key.

Tests

  • New regression tests in tests/deduplication/intra_skill/test_intra_skill_validator.py:
    • A 363-chunk skill passes at 1,024, 1,536 and 2,048 dimensions.
    • A 512-chunk skill passes at 2,048 dimensions.
    • At 3,072 and 4,096 dimensions, the effective limit passes and one chunk more fails with the exact metadata and message.
    • A validator built with a smaller private budget (25,000,000) reports that budget's effective limit (156 at 2,048 dimensions) and stops after the first embedding batch.
    • 513 chunks still fail with chunk_count_limit before any embedding request.
  • effective_chunk_limit tests:
    • Known widths return the expected limits.
    • For every width from 1 to 65,536, the result is checked to be the largest chunk count within the budget.
    • An explicit budget is honoured.
    • Invalid widths and invalid budgets are rejected.
    • The budget is checked against the constants it is derived from.
  • New tests in tests/deduplication/intra_skill/test_semantic_clustering.py:
    • build_clusters uses the same budget as the validator.
    • build_clusters accepts 157 chunks at 2,048 dimensions (25,079,808 scalar comparisons), which the former fixed budget rejected.
  • On unmodified main, the 363-chunk, 512-chunk, wide-embedding, explicit-budget and clustering regressions fail and the new helper does not exist. All of them pass with this change.
  • pytest tests/deduplication: 245 passed, 1 skipped.
  • The neighbouring suites passed: 1,953 passed, 1 skipped. They cover tests/embedding, tests/inference/test_llm_client.py, tests/golden, tests/reporting, tests/test_cli.py, tests/test_commands.py, tests/test_publication_evidence.py, tests/test_tier2_command_failures.py and tests/validators/test_similarity.py.
  • ruff check and ruff format --check pass on the changed Python files.
  • scripts/check_oss_boundary.py passes, and git diff --check is clean.

🤖 Generated with Claude Code

Tier 2 context deduplication allows 512 content chunks per skill, but a
separate, fixed scalar-comparison budget of 25,000,000 rejected far
smaller skills. The budget is pair count times embedding width, so
2,048-dimensional embeddings hit it at 157 chunks and 1,536-dimensional
embeddings at 181. A valid skill above that size failed `validate` with
a blocking CRITICAL `scalar_comparison_limit` finding. The clustering
guard in `build_clusters` carried its own copy of the same budget.

Derive the budget from the chunk ceiling instead: 512 chunks times
2,048 dimensions, or 267,911,168 scalar comparisons, defined once in
constants.py and shared by the validator and the clustering guard.
Embeddings of up to 2,048 dimensions now reach all 512 chunks. Wider
embeddings get a lower effective chunk limit (418 at 3,072 dimensions,
362 at 4,096), computed exactly with integer arithmetic. The finding now
reports the effective limit for the validator's actual budget in its
message and metadata, so authors know how far to shrink the skill. The
chunk ceiling, the early stop after the first embedding batch and every
other Tier 2 guard are unchanged.

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.

Review summary: no findings (no P1/P2/P3).

Checked: 512511/22048 = 267,911,168 and effective_chunk_limit (exact isqrt bound; 512/511/418/362 at 2048/2049/3072/4096), that the validator and build_clusters now share the one constant (the only remaining 25,000,000 is the separate plugin-bundle budget, as the description says), the extra finding metadata and message, the docs table, and the CHANGELOG placement.

Local verification (head 1412dff): ruff check clean; pytest tests/deduplication tests/embedding: 489 passed, 2 skipped.

Reviewed with Claude Code.

Conflicts: src/skillevaluator/deduplication/intra_skill/intra_skill_validator.py, tests/deduplication/intra_skill/test_intra_skill_validator.py

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.

The change is correct and I found nothing blocking. The new effective_chunk_limit is an exact integer bound (the largest n with n(n-1)/2 times the width within the budget), the validator and build_clusters now read the same constant, and the plugin path keeps its smaller per-skill budget so it still stays under the clustering guard. I also timed build_clusters at the new ceiling: about 2 s for 512 chunks at 2,048 dimensions. One small suggestion on the error message.

rng1995 and others added 2 commits November 3, 2026 04:16
Conflicts: CHANGELOG.md, tests/deduplication/intra_skill/test_intra_skill_validator.py.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The scalar_comparison_limit incomplete-scan error and its work_limit
record named the effective chunk limit but not how many chunks the skill
has, so an author still had to work out how far over the limit it was.
Add the count to the error text and a chunk_count key to work_limit.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 merged commit 300983a into main Nov 3, 2026
21 checks passed
@rng1995
rng1995 deleted the naren/port-tier2-dedup-capacity branch November 3, 2026 20:08
rng1995 added a commit that referenced this pull request Nov 6, 2026
* docs(changelog): move entries released in 0.7.0-0.7.2 out of Unreleased

0.7.0 (#314) and 0.7.1 (#327) never cut their sections on main, and 0.7.2
(#335) added its section below the whole Unreleased block, so Unreleased
still listed work that had already shipped.

Place each Unreleased entry under the release that shipped the PR that
added it:

- 0.7.0: the published section from the 0.7.0 tag, verbatim. It already
  holds the six entries that main had filed under 0.6.0, so 0.6.0 again
  matches the v0.6.0 tag, including the original run_config.json entry.
- 0.7.1: #264 #271 #274 #281 #284 #289 #293 #299 #316 #317 #318 #323
  #324 #326 #327, plus the #320 wording of the Windows Git-root entry,
  since #320 changed that 0.7.0 fix in 0.7.1.
- 0.7.2: #263 #265 #269 #270 #276 #279 #287 #290 #296 #309 #328 #330
  merged with the existing #335 entries.

Only post-v0.7.2 entries stay under Unreleased, with one heading per
subsection. Entry text is unchanged, apart from the published tag wording
in 0.7.0 and 0.6.0.

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

* chore(release): prepare v0.8.0

Set the package, fallback, lock, citation and developer-guide versions to
0.8.0 and move every entry merged since v0.7.2 under
'## 0.8.0 - 2026-11-05', leaving Unreleased empty.

The refusal-fallback documentation test now reads the release section
that names CLAUDE_CODE_DISABLE_REFUSAL_FALLBACK, requires it to be 0.8.0,
and requires exactly one entry there to name the switch.

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

* chore(release): pin the verified 0.8.0 Tier 1 image and add its CI bundle

Pin onboarding to the Tier 1 image published by the reviewed main revision
55d2d04 in "Build and publish Tier 1 image" run 42158955180:
ghcr.io/nvidia/skillevaluator-tier1@sha256:9d5483243918937be4f2178f74cf7c622a531dee41e3176906994d52fa14950a
(config sha256:d17d6f5105ec5f1bf0cbe4dff0d693aae4ecf01e9c1c6a6ddb7830518acace33).
The workflow and publisher refs both move to 55d2d04.

ci/bundles/0.8.0 mirrors the 0.7.2 bundle. The templates, README and
release.json are the run's github-actions-onboarding artifact and match
ci/render_templates.py output for these pins byte for byte. The scanner
inventory and verification receipt come from the build's runtime-stage
version step, the five-case smoke receipt, the onboarding job's anonymous
pull, and the public manifest, whose config digest equals the smoke-tested
image ID. The ZIP uses the 0.7.2 layout (sorted members, inner checksums,
1980 timestamps, 0644, deflate level 9) and rebuilds to identical bytes.

Point the current-bundle links at 0.8.0 and list 0.7.2 as historical.

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

---------

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