Skip to content

fix(tier2): reject out-of-range or non-string dedup LLM verdict fields - #412

Merged
rng1995 merged 10 commits into
mainfrom
naren/port-tier2-intra-llm-limits
Nov 12, 2026
Merged

rng1995 merged 10 commits into
mainfrom
naren/port-tier2-intra-llm-limits

Conversation

@rng1995

@rng1995 rng1995 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Context deduplication now checks each chat-LLM verdict before it becomes a finding.

  • New parse_bounded_llm_verdict in skillevaluator.inference (with require_bounded_llm_string). It requires:
    • a JSON object;
    • a verdict string from the allowed set;
    • when present, a confidence that is a JSON number (not a bool or a string), finite and within [0, 1];
    • when present, rationale (or the legacy reasoning) and suggestion strings of at most 8,192 characters (TIER2_LLM_MAX_RESPONSE_SCALAR_CHARS).
  • A missing confidence still reads as 0 (a MEDIUM finding for a DUPLICATE verdict) and a missing text field as empty, as before.
  • analyze_cluster uses it, so a bad reply raises LLMClientError. The validator already turns that into a failed cluster analysis with the bounded "LLM configuration or response was invalid" diagnostic, so the scan is reported as incomplete.
  • The checks apply to every verdict, not only DUPLICATE. So some scans that passed on main are now incomplete, which is a blocking error. Examples are an INTENTIONAL_DETAIL or RELATED_BUT_DISTINCT reply with a null suggestion or a "0.9" string confidence. Those verdicts never become findings, so main ignored their fields. A DUPLICATE reply with a "0.9" confidence, a null suggestion or a 9,000-character rationale also turns from a HIGH finding into an incomplete scan.
  • Docs: the verdict paragraph and the limits table in docs/tier2-deduplication.mdx. CHANGELOG entry under Unreleased > Fixed, which also states the passed-to-incomplete change.

The closed plugin-evaluation PR #28 carried a version of this fix inside its larger change; this PR lands the generic part on its own.

Why

analyze_cluster built the verdict with float(data.get("confidence", 0.0)) and passed rationale and suggestion through as they came. The verdict schema says number and string, but it sets no range, and endpoints without structured output (Bedrock, or after a schema downgrade) are not held to it. On current main:

  • A confidence of 85 (a percentage) or true makes a HIGH, blocking finding.
  • The string "NaN" becomes a NaN confidence. The skill passes with a MEDIUM finding, and the JSON and SARIF reports then fail with ValueError: Out of range float values are not JSON compliant. "inf" gives a HIGH finding and the same report failure.
  • A list or object in rationale or suggestion reaches the finding metadata and suggestion unchanged, and a 200,000-character rationale is kept whole.

The new checks fail closed whatever the verdict. A reply that breaks them is malformed whether or not it would become a finding, so it now fails the analysis instead of passing on a guess. The cost is the behavior change in the Summary: a non-finding verdict with a null text field or a string confidence now leaves Tier 2 incomplete.

Kept from public

  • The work limits added on main stay as they are: the 64,000-character per-request budget (system prompt included), the 1,000,000-character total, the cluster member cap equal to the chunk ceiling, and the cluster count limit. All are checked before the first chat-LLM call and reported as an incomplete scan under work_limit, not as CRITICAL findings.
  • The shared-content prompt compaction, the VERDICT_JSON_SCHEMA request, the strict JSON decoding in extract_json_from_response and the llm_refused advisory are unchanged.
  • The validator's failure handling (llm_failure_diagnostic, mark_scan_incomplete, the llm_analysis metadata) is unchanged; a rejected reply follows the same path as any other malformed reply.
  • main already has a generic require_bounded_string in skillevaluator/utils/structured_data.py, and the plugin analyzer in deduplication/plugin/llm_analyzer.py has its own verdict checks with its own 8,192-character MAX_RESPONSE_SCALAR_CHARS. Both stay as they are. The new helper, require_bounded_llm_string, raises LLMClientError, the error analyze_cluster documents and the analyzer tests pin. The validator would report a ValueError from require_bounded_string with the same diagnostic, so the helper does not change what users see. Plugin code is out of scope here.
  • Not ported, because main has no gap there: passing the pre-rendered prompt into analyze_cluster (rendering is deterministic and the validator already measures the same prompt), the batch prompt helpers (the validator does these checks), the recommendation field check (not in this schema) and the answering-model field on LLMVerdict.
  • Overlap with other PRs:
  • The companion Tier 2 ports (bounded frontmatter YAML, fix(tier2): parse skill frontmatter with bounded YAML #422, and shell chunker performance, fix(tier2): chunk shell scripts in one pass instead of once per function header #423) also edit CHANGELOG.md and docs/tier2-deduplication.mdx, and the bounded YAML port adds a test near line 181 of test_intra_skill_validator.py. This entry sits above the SHARED CONTENT n entry, and the new limits row sits above the "Intra-skill review prompts in total" row, so each pair merges without conflicts in either order (checked with git merge-tree).

Tests

  • tests/deduplication/intra_skill/test_intra_llm_analyzer.py, 29 new tests:
    • confidence rejected: NaN, inf, -0.1, 1.1, 85, true, "0.5", "NaN", null and 10**400 (10)
    • confidence bounds 0, 1, 0.0 and 1.0 accepted as floats (4)
    • non-string verdict, rationale and suggestion, and a rationale or suggestion of 8,193 characters, rejected (8); a non-string legacy reasoning rejected (1)
    • a rationale and suggestion of exactly 8,192 characters kept whole (1); a reply with only a verdict keeps the defaults (1)
    • a reply that is a list, string, number or null rejected (4)
  • tests/deduplication/intra_skill/test_intra_skill_validator.py, 8 new tests, all through the real analyze_cluster:
    • a "NaN", "Infinity", 85 or true confidence leaves the scan incomplete with no finding, and the JSON report still renders (4)
    • an INTENTIONAL_DETAIL reply with a null suggestion, and a RELATED_BUT_DISTINCT or DUPLICATE reply with a "0.9" confidence, leave the scan incomplete with no finding (3)
    • a DUPLICATE reply without a confidence still gives a MEDIUM advisory finding with confidence 0, and the skill passes (1)
  • Fail-before: with src/ from main at d717f22cf and this PR's tests, 30 of the 37 new tests fail.
    • 22 fail because main accepted the reply: 15 analyzer tests, plus the 7 incomplete-scan validator tests. On main those validator scans end passed for "NaN" and for the two non-duplicate replies, and failed (a HIGH finding) for the other four.
    • 8 analyzer tests (a null or 10**400 confidence, a list or null verdict, and the 4 replies that are not objects) also failed on main, but with a TypeError, OverflowError, AttributeError or a different LLMClientError message. The scan was incomplete on main too, with the same diagnostic except for 10**400, which got "Unexpected LLM request error". These tests pin the documented LLMClientError contract, not a change in what users see.
    • 7 pass on main: the bounds (4), the 8,192-character limit (1), the defaults (1) and the MEDIUM finding for a missing confidence (1).
  • tests/deduplication/intra_skill: 174 passed (test_intra_llm_analyzer.py 66, test_intra_skill_validator.py 91).
  • tests/deduplication, tests/inference, tests/embedding, tests/validators/test_similarity.py, tests/validators/test_hygiene.py, tests/test_ci_workflows.py and the docs and CHANGELOG readers (tests/ci/test_image_build.py, tests/test_harbor_claude_refusal_fallback.py, tests/test_oss_packaging.py, tests/test_ci_change_classifier.py, tests/tier3/test_private_loose_source.py, tests/test_accuracy_arithmetic.py, tests/test_tier3_public_runtime.py, tests/test_benchmark_rollout_docs.py): 1627 passed, 2 skipped.
  • tests/reporting/test_reporters.py, tests/test_publication_evidence.py, tests/test_tier2_command_failures.py and tests/test_cli.py: 351 passed.
  • ruff check and ruff format --check are clean on the changed Python files, and scripts/check_oss_boundary.py passed.
  • main at d717f22cf is merged into the branch with no conflicts, and git merge-tree against it is clean. Since this branch started, main has changed CHANGELOG.md, constants.py (fix(reporting): explain each dimension, its evidence and baseline in reports #376 and feat(plugin): recognize native OpenClaw manifests in the private plugin helpers #391, from line 635 on), docs/tier2-deduplication.mdx (feat(ci): add three-tier onboarding and private report feedback #349 and docs: simplify repository CI onboarding #443, a section near the top; fix(tier2): expose collection coverage and transactional rebuilds #436, the collection coverage text and a scale benchmark section) and test_intra_skill_validator.py (fix(tier2): retain trailing shell comments in deduplication #357, one test near line 114) among the files this PR edits.

🤖 Generated with Claude Code

rng1995 and others added 5 commits November 7, 2026 01:33
Context deduplication turned the chat-LLM reply into a finding with
float(confidence) and the raw rationale and suggestion values. A
confidence of 85 or true made a HIGH finding, the string "NaN" made a
MEDIUM finding whose NaN confidence broke the strict JSON and SARIF
reports, and a list or object in a text field reached the finding
unchanged.

Add parse_bounded_llm_verdict to the inference types. It requires a JSON
object, a known verdict string, a finite numeric confidence within
[0, 1] (not a bool or a string), and rationale and suggestion strings of
at most 8,192 characters. analyze_cluster uses it, so a bad reply raises
LLMClientError and the validator reports the cluster as a failed
analysis, which leaves the scan incomplete.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Describe the confidence range and text-length checks on chat-LLM
verdicts in the Tier 2 page and its limits table, and add a Fixed entry
under Unreleased.

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

The Fixed entry implied that only DUPLICATE verdicts were affected. The
checks apply to every verdict, so an INTENTIONAL_DETAIL or
RELATED_BUT_DISTINCT reply with a null suggestion or a "0.9" string
confidence, which passed on 0.8.0, now leaves Tier 2 incomplete, and so
does a DUPLICATE reply with a "0.9" confidence. Say that the field rules
apply when a field is present, since a missing confidence still reads as
0. Move the entry above the SHARED CONTENT entry so it no longer touches
the hunk a sibling change adds below that entry.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A reply that breaks the confidence or text-field rules now fails the
cluster's analysis whatever its verdict. Pin that an INTENTIONAL_DETAIL
reply with a null suggestion and a RELATED_BUT_DISTINCT reply with a
"0.9" confidence, which both passed before, and a DUPLICATE reply with a
"0.9" confidence, which made a HIGH finding, now leave the scan
incomplete with no finding. Also pin that a DUPLICATE reply without a
confidence still reads it as 0 and gives a MEDIUM advisory finding.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A missing confidence still reads as 0, so a DUPLICATE verdict without
one is MEDIUM, and a missing rationale or suggestion reads as empty. Say
so, and say that a reply that breaks the rules fails the analysis
whatever its verdict, including a null suggestion. Move the verdict text
row above the total prompt row in the limits table, so it no longer
touches rows a sibling change adds after that row.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
No file conflicted. Four files changed on both sides and merged
automatically:

- CHANGELOG.md: main's new Unreleased entries are kept. This branch's
  dedup verdict entry stays under Fixed, between the PII
  evidence_sha256 entry and the SHARED CONTENT numbering entry, as
  before. Each Unreleased subsection still has one heading.
- docs/tier2-deduplication.mdx: main's CI, collection coverage and
  scale benchmark sections are kept next to this branch's verdict
  field rules and the verdict text row in the limits table.
- src/skillevaluator/constants.py: main's SIGNAL_EVIDENCE_SOURCES and
  OpenClaw manifest constants are kept next to
  TIER2_LLM_MAX_RESPONSE_SCALAR_CHARS.
- tests/deduplication/intra_skill/test_intra_skill_validator.py:
  main's end-of-file shell comment test is kept next to this branch's
  verdict validation tests. It mocks analyze_cluster, so the verdict
  checks do not affect it.

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.

Reviewed the complete production diff and regression coverage; checked typed verdict fields, finite unit-interval confidence, scalar limits, analyzer/schema behavior and incomplete-analysis propagation. No actionable findings.

Verification at unchanged head 7402aded5279cb1f3ef97824e2bc11c77f577f39: 20 existing CI checks succeeded and 2 were intentionally skipped, including the supported Python tests, lint/package and security/platform gates where applicable. Fresh git merge-tree --write-tree is clean against the frozen main commit ce52a09. No new local test run is claimed for this unchanged code.

Signed-off-by: Narendran Raghavan <[email protected]>

# Conflicts:
#	CHANGELOG.md

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

Integration review at 440a66e2adb04b64d66d98c92d2419724e17feff: resolved the actual CHANGELOG conflict while merging main a0b65a91d512fdc2254d2559900b6c30404218b8, retaining both independent entries. No additional production edit was made beyond the reviewed integration. Focused verification: 37 passed in 9.71s; make lint passed; pinned Fern 5.121.0 check passed with 0 errors and only the existing authenticated-redirect warning.

The candidate is merge-clean against explicitly audited main a0b65a91d512fdc2254d2559900b6c30404218b8; subsequent main checks are recorded where main advanced during external merges. The merge commit has DCO sign-off and was pushed normally after fresh open-PR and live-head checks. Fresh hosted CI is pending. No PR was merged by this review.

@rng1995
rng1995 enabled auto-merge (squash) November 12, 2026 19:50
rng1995 and others added 2 commits November 12, 2026 11:54
* fix(tier2): raise the intra-skill chunk ceiling to 1,024

A valid skill with 513 to 1,024 content chunks stopped context
deduplication as incomplete, and with 2,048-dimensional embeddings the
scalar budget allowed only 512 chunks. Raise CONTENT_DEDUP_MAX_CHUNKS to
1,024 and size the scalar-comparison budget for 1,024-dimensional vectors
at that ceiling (536,346,624). Effective chunk limits become 1,024 up to
1,024 dimensions, 836 at 1,536, 724 at 2,048, 591 at 3,072 and 512 at
4,096, each at or above the old limit. The cluster member cap follows the
chunk ceiling as before.

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

* docs(tier2): document the 1,024-chunk intra-skill ceiling

Update the limits table: 1,024 content chunks, a 536,346,624 scalar
comparison budget with its effective chunk limit per embedding width, and
1,024 cluster members.

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

* docs(changelog): note the 1,024-chunk intra-skill ceiling

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

* test(tier2): pin where a 2,048-dimensional skill at the ceiling stops

A skill with 1,024 chunks and 2,048-dimensional embeddings passes the
chunk ceiling, sends one 64-chunk embedding batch and then stops with
scalar_comparison_limit (effective limit 724). Before the ceiling rose it
stopped before any embedding request with chunk_count_limit. The existing
width test covers the low end of that band (725 chunks); this covers the
top, which the CHANGELOG now describes.

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

* docs(tier2): give the chunk limit of each default embedding model

The limits table listed the effective chunk limit per embedding width but
did not say which width the default models return. OpenAI's
text-embedding-3-small returns 1,536 dimensions (836 chunks) and NVIDIA
Build's nvidia/nemotron-3-embed-1b returns 2,048 (724 chunks), so a user
on the defaults could read 1,024 as their limit. The row now names both,
and the paragraph below it says that a default-width skill with 725 to
1,024 chunks stops after the first embedding batch.

A test resolves each provider's default model, looks up its width and
checks that the row gives that width's limit next to the model name.

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

* docs(changelog): lead with the default models' chunk limits

The entry opened with 1,024 chunks, which neither default embedding model
reaches. It now gives 724 for NVIDIA Build's 2,048-dimensional default and
836 for OpenAI's 1,536-dimensional default, and says that a skill above
its width's limit but within 1,024 chunks now stops after the first
embedding batch with scalar_comparison_limit instead of before any
embedding request with chunk_count_limit, with the same exit code.

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

* test(tier2): check the default-model docs entry without a new import

The docs check used a regular expression, and its module-level import of
re sat where the open plugin-evaluation PR adds its own imports, which
added a conflict region between the two. Plain string checks on the
comma-separated entry that names the model do the same job.

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

* docs(tier2): name the OpenAI-compatible default's chunk limit

The comparison-work row named the limits of the OpenAI and NVIDIA Build
default embedding models but not the OpenAI-compatible default,
nvidia/nvidia/nemotron-3-embed-1b. That is the same 2,048-dimensional
model, so its limit is also 724, and a gateway user on the default could
read 1,024 as their limit. The row and the paragraph below the table now
name it.

The docs check gains an openai-compatible case, which failed before this
change because the row did not name the model.

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

* docs(changelog): name the OpenAI-compatible default and embedding volume

The entry gave the new limits for the OpenAI and NVIDIA Build default
embedding models. It now also names the OpenAI-compatible default, the
same 2,048-dimensional model with the same 724-chunk limit, and says that
the most embedding input one skill can send doubles with the ceiling,
from 512 to 1,024 texts (724 with either 2,048-dimensional default).

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

---------

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

# Conflicts:
#	docs/tier2-deduplication.mdx

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

Concurrent-merge integration review at 14362c8297e14e7a8e3c0375a761110768423616: The actual Tier 2 docs conflict preserves both main’s frontmatter/name-description limits and the 1,024-chunk/scalar budget from externally merged #426. The external main merge and #426 squash remain in history. No production conflict required manual edits. Focused contracts: 55 passed in 8.30s. Lint passes; pinned Fern validation reports 0 errors and only the existing authenticated-redirect warning.

The signed-off fix was pushed normally after live open/head/base guards and clean merge checks against captured main b38b71be01f7fdf332e37efbfec49714f3939161 and actual base main at b38b71be01f7fdf332e37efbfec49714f3939161. Fresh exact-head hosted CI is pending. No PR was merged by this review.

@rng1995
rng1995 merged commit 3cf34ec into main Nov 12, 2026
27 checks passed
@rng1995
rng1995 deleted the naren/port-tier2-intra-llm-limits branch November 12, 2026 20:55
rng1995 added a commit that referenced this pull request Nov 12, 2026
Brings in #410, #412, #413, #419, #421, #425, #430 and #444. Conflicts: CHANGELOG.md (kept both Unreleased Fixed entries) and evaluation/options.py (kept main's tolerate_baseline_timeouts field and this PR's backend field).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[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.

1 participant