Skip to content

fix(lsp): round diagnostic confidence to the contract's two decimals (#10717) - #11062

Merged
EffortlessSteven merged 4 commits into
mainfrom
claude/project-thread-6sl3rj-laneA2
Oct 30, 2026
Merged

EffortlessSteven merged 4 commits into
mainfrom
claude/project-thread-6sl3rj-laneA2

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Requested by Steven Zimmerman · project thread

Summary

  • LSP diagnostic data.confidence was the f32 widened to f64 (0.4000000059604645). It now goes through one shared helper, domain::contract_confidence, which rounds to the two-decimal contract precision that ripr check prints ({:.2}), so 0.4 reads 0.4.
  • Scope: only the LSP diagnostic payload changes. The two values it builds (data.confidence, data.witness.confidence.value) use the shared helper; other serializers of DiagnosticConfidence (e.g. the context packet JSON) are unchanged.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Governing issue or accepted claim: #10717
Acceptance delta (one sentence): LSP diagnostic data.confidence and witness confidence value equal the two-decimal value ripr check reports for the same finding, pinned by a test.

Candidate Relationships

Candidate branch: claude/project-thread-6sl3rj-laneA2
Stack parent or prerequisite PR (if any): none

Scope

  • crates/ripr/src/domain/diagnostic_witness.rs, domain/mod.rs, lsp/diagnostics.rs, changelog fragment.

Scope Classification

  • One public contract

Production delta: shared rounding helper; LSP data uses it.
Evidence/support delta: lsp_diagnostic_data_confidence_uses_contract_precision (0.4, 0.92, 0.6, 0.75 on both fields).
Single acceptance criterion: see acceptance delta.
Non-goals: SARIF properties.confidence has the same f32 widening (output/sarif.rs) and is a check-output surface, left for its own claim; MCP carries no finding-level confidence.

Support-tier Impact

  • none

Policy Impact

  • none

Proof

cargo xtask precommit                                 # exit 0 (on final head)
cargo test -p ripr --lib -- lsp::diagnostics domain::  # 363 passed (also under --no-default-features --features lang-rust: 363 passed); lsp:: domain:: 1397 passed

Not established: cross-language (Rust/Python/TypeScript) fixture comparison against check JSON beyond the unit test; hosted CI; cargo xtask goldens check not run (fixture prep needs network here).

Claim Boundary

May claim: LSP confidence precision matches check. Must not claim: SARIF is fixed.

Rollback

Revert the commits.

Spec-Test-Code Traceability

  • Tests: lsp::diagnostics::lsp_next_step_parity_tests::lsp_diagnostic_data_confidence_uses_contract_precision
  • Code: domain::diagnostic_witness::contract_confidence

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • Public JSON/schema changes are documented (value precision only).

Generated by Claude Code

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 148 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 303681e8-25d4-461d-87a6-51eb5e7338bd
Commits

Reviewing files that changed from the base of the PR and between 2510980 and 142ac18.

Files selected for processing: 4
  • changelog.d/10717-lsp-confidence-two-decimals.md
  • crates/ripr/src/domain/diagnostic_witness.rs
  • crates/ripr/src/domain/mod.rs
  • crates/ripr/src/lsp/diagnostics.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent review (fresh-context reviewer, head 6d2c0a1): REPAIR_REQUIRED

The defect this PR targets is real and the diagnosis is correct. The repair is not complete: changing the shared DiagnosticConfidence DTO silently changes a second, public JSON surface that the PR's Scope, changelog fragment, and test suite do not cover, and the new helper's doc comment asserts a single-authority invariant that the code does not hold.

Inspected

  • Full patch (4 files) at head 6d2c0a1f901cb63187245df2e4a5dba3e31be9e5.
  • crates/ripr/src/domain/diagnostic_witness.rs (whole file at head), crates/ripr/src/domain/mod.rs, crates/ripr/src/lsp/diagnostics.rs (lines 3166–3229 and the complete_ts_finding fixture), crates/ripr/src/domain/context_packet.rs (lines 1–60), crates/ripr/src/output/json/context_packet.rs (lines 1–172), crates/ripr/src/output/json/formatter.rs (lines 1–40), crates/ripr/src/output/json/report.rs (line 881), crates/ripr/src/output/human/sections.rs (lines 127, 627), crates/ripr/src/domain/probe.rs (lines 627–634).
  • docs/OUTPUT_SCHEMA.md (lines 1426, 3696, 3710–3714).
  • serde_json 1.0.154 source from the local cargo registry cache: src/number.rs:323-328, src/value/from.rs:30-45, src/value/ser.rs:151-153, src/ser.rs:155-163.

Blocking

  1. The serialize_with on DiagnosticConfidence.value changes the public context-packet JSON, and that surface is outside the declared scope, absent from the changelog, and pinned by no test.

    DiagnosticConfidence is not LSP-only. ContextPacket carries pub witness: Option<DiagnosticWitness> (crates/ripr/src/domain/context_packet.rs:36), DiagnosticWitness carries pub confidence: DiagnosticConfidence (crates/ripr/src/domain/diagnostic_witness.rs:25), and the packet renders that witness with serde_json::to_string_pretty(witness) (crates/ripr/src/output/json/context_packet.rs:156). The new serialize_with therefore rewrites the packet's witness.confidence.value on the wire.

    The wire value really does change. Before this PR, DiagnosticConfidence.value is an f32 (diagnostic_witness.rs:55), and serde_json's Value::from(f32) widens it: src/value/from.rs:42-44 calls Number::from_f32, which stores N::Float(f as f64) (src/number.rs:323-328). So a stored 0.92f32 serialized as 0.9200000166893005. After this PR it serializes as 0.92.

    That surface is public and reachable: app::context::collect_context is a pub fn (crates/ripr/src/app/context.rs:10) that renders through output::json::render_context_packet_with_explain_command (app/context.rs:132, :215), and the CLI drill-in route calls it (crates/ripr/src/cli/commands/context.rs:268-282); the LSP backend renders it too (crates/ripr/src/lsp/backend.rs:7189). DiagnosticConfidence and DiagnosticWitness are themselves re-exported from the published library surface (crates/ripr/src/domain/mod.rs:55-58).

    Against that, the PR's Scope section lists only domain/diagnostic_witness.rs, domain/mod.rs, lsp/diagnostics.rs, and the changelog fragment, and the changelog fragment mentions only "LSP diagnostic data.confidence (and the witness confidence value)". The PR's own Engineering Check asserts "Public JSON/schema changes are documented (value precision only)" — that self-report does not hold for the packet surface. Nothing in the repo pins the new packet value either: no JSON fixture under fixtures/ contains a "witness" key at all, so no golden would have caught this.

    The change is an improvement on that surface (it makes the nested witness value agree with the packet's own top-level confidence, which float_field already renders at two decimals), but an undocumented and untested change to a public JSON contract is the thing this repository's operating law calls out: update the affected docs/specs/contracts/fixtures in the same change. Please either narrow the change to the LSP payload (e.g. apply the rounding where the LSP builds data, not on the shared DTO) or extend the Scope, the changelog fragment, docs/OUTPUT_SCHEMA.md, and a test to cover the packet surface.

  2. The helper is a second, unrouted owner of the two-decimal precision rule, and its doc comment claims an invariant the code does not have.

    crates/ripr/src/output/json/formatter.rs:27-35 already owns this rule as float_field, which renders {:.2}; it is what produces the finding confidence in ripr check --format json (crates/ripr/src/output/json/report.rs:881) and the packet's own top-level confidence (crates/ripr/src/output/json/context_packet.rs:82). The human renderer owns it separately (crates/ripr/src/output/human/sections.rs:127, :627), as does the LSP hover.

    The new doc comment on contract_confidence states: "check JSON and human output print {:.2}; ... Every producer that puts a confidence into a JSON value goes through this one rounding so all surfaces agree (#10717)." That is false as written. float_field is exactly a producer that puts a confidence into a JSON value, and it does not go through this helper. The outcome happens to agree today because both compute {:.2} on the same f32, but the mechanism claim in the code is not true, and it leaves four un-routed copies of the same rounding rule where the comment says there is one. If the contract precision ever changes, float_field, the human renderer, and the hover would silently diverge from the LSP.

    Either route the existing owners through the helper (the helper can own the rule and float_field can format the number it returns), or correct the comment to say what is actually true — that this helper reproduces float_field's {:.2} so the LSP agrees with the check surface — and record that the rounding rule now has more than one owner.

Non-blocking

  • The rounding semantics are unpinned. All four test cases (0.4, 0.92, 0.6, 0.75) are values whose {:.2} form is numerically unchanged, so no case actually exercises rounding. A mutant that truncates (0.9299 → 0.92) or that rounds half-away-from-zero instead of half-to-even would still pass lsp_diagnostic_data_confidence_uses_contract_precision. A case such as 0.926 → "0.93" would discriminate. The test does correctly discriminate "rounded" from "not rounded" — 0.92f32 as f64 is 0.9200000166893005, so the no-rounding mutant is caught — but the rounding rule is not.
  • The stated acceptance is not tested end to end. The acceptance is "LSP diagnostic data.confidence and witness confidence value equal the two-decimal value ripr check reports for the same finding", but the test compares the LSP payload against hard-coded strings and never renders the same finding through output::json::report. Rendering one finding through both paths and comparing the two numbers would make the acceptance falsifiable as written. The PR body already lists this as not established ("cross-language ... fixture comparison against check JSON beyond the unit test"), which is the right disclosure; the test could close it.
  • contract_confidence rounds by formatting to a String and parsing it back. That is deliberate and correct for bit-identical agreement with float_field (Rust's {:.2} is round-half-to-even), so please keep it — but say so in the comment, because a future reader may "optimize" it to (value * 100.0).round() / 100.0 and silently change the rounding mode relative to float_field.

Refuted / stale

  • Hypothesis: ripr check --format json emits the same widened f64 as the LSP did, so this helper would make check JSON and the LSP disagree. Refuted. crates/ripr/src/output/json/report.rs:881 renders the finding confidence through float_field, i.e. {:.2}, so check JSON reports 0.40 while the LSP reported 0.4000000059604645. The PR's premise — that the LSP was the divergent surface — is correct, and the LSP now reports 0.4, numerically equal to the check surface's 0.40.
  • Hypothesis: the new test's fixture has no witness, making the assertion on data["witness"]["confidence"]["value"] unsatisfiable. Not sustained. complete_ts_finding() is ExposureClass::WeaklyExposed (crates/ripr/src/lsp/diagnostics.rs:6557), and DiagnosticWitness::from_finding returns None only for Exposed findings with no missing discriminators (crates/ripr/src/domain/diagnostic_witness.rs:92-93). The witness is present.

Not run

  • No Rust toolchain on the review host — cargo, rustc, and rustup are all absent from PATH. The workspace build, the test suite, cargo xtask precommit, and cargo xtask goldens check could not be executed here. The PR's own report of "363 passed, 0 failed" is the author's claim; it is not independently verified by this review.
  • The PR is a Draft, so the hosted Rust lanes report skipping (merge-ready qualification not requested). There is no hosted Rust proof for head 6d2c0a1.
  • The goldens question was checked statically instead: no fixture under fixtures/ contains a "witness" object, so the packet-surface change is not caught by a golden — which is itself part of blocking finding 1.

Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head 6d2c0a1f901cb63187245df2e4a5dba3e31be9e5. Not an approval.

Drop the serde attribute so the context packet JSON is unchanged; round the
two LSP-built values explicitly and correct the helper doc.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNUoLW4Ze4ffvMT8Zb9EHN
@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 30, 2026 12:29

Copy link
Copy Markdown
Member Author

Repair pushed (abe95e5): rounding is now scoped to the LSP payload only (serde attribute removed, so the context-packet JSON is unchanged); the two LSP-built values are rounded explicitly; helper doc corrected; changelog/PR body updated. precommit exit 0; lsp:: + domain:: 1397 passed; Rust-only lane (--no-default-features --features lang-rust) 363 passed.


Generated by Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

merge-ready was requested, but this PR conflicts with main (head abe95e55), so GitHub creates no test-merge ref and no qualification run can start. Merge main into the branch and resolve the conflicts, then remove and re-apply merge-ready.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNUoLW4Ze4ffvMT8Zb9EHN
@EffortlessSteven
EffortlessSteven merged commit 4e1035a into main Oct 30, 2026
55 of 56 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/project-thread-6sl3rj-laneA2 branch October 30, 2026 13:50

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Independent review (fresh-context reviewer, head 142ac18): REVIEW_READY — both blocking findings from the earlier review on head 6d2c0a1 are repaired at this head, the LSP payload is the only surface that changed, and the exact head is green on the repository's required check and on the Rust gates and test-shard lanes.

Inspected:

  • Head established independently via gh pr view 11062 --json headRefOid -> 142ac1885422f72ebad2de73f6e5b248e928f1ad. Re-read before posting; head unchanged. This PR is already MERGED: merged at 2026-10-30T13:50:06Z by EffortlessSteven, merge commit 4e1035a8b9d4d2cf2344029c7b9646e778d79459. The disposition below therefore records the state of the reviewed head; merge convergence was already moot before this pass completed.
  • Branch history (4 commits): c8cf8521 (the original fix), 6d2c0a1 ("keep the confidence helper doc JSON-library-free"), abe95e55 ("scope confidence rounding to the LSP payload"), 142ac188 ("Merge main into 10717 confidence branch"). The reviewed head therefore contains both the repair and a merge of main.
  • Complete diff at the reviewed head (4 files, +54/-4): changelog.d/10717-lsp-confidence-two-decimals.md, crates/ripr/src/domain/diagnostic_witness.rs, crates/ripr/src/domain/mod.rs, crates/ripr/src/lsp/diagnostics.rs.
  • Source at the reviewed head, read through the API rather than the local checkout: crates/ripr/src/domain/diagnostic_witness.rs lines 35-80 (the DiagnosticConfidence struct, the helper, DiagnosticWitness), crates/ripr/src/output/json/formatter.rs (float_field), crates/ripr/src/lsp/diagnostics.rs (the confidence and witness construction in diagnostic_for_finding_with_causal, and the new test), docs/OUTPUT_SCHEMA.md lines 1242-1247 and 1455-1470, and the main branch protection required-checks list.
  • Prior findings, re-verified against this head rather than carried forward. The earlier EffortlessSteven review (submitted 2026-10-30T05:57:51Z) is bound to 6d2c0a1f901cb63187245df2e4a5dba3e31be9e5, an ancestor of this head, and recorded REPAIR_REQUIRED with two blocking findings. I checked both at this head:
    • Prior blocking 1 -- the serialize_with on the shared DiagnosticConfidence DTO silently changed the public context-packet JSON, outside the declared scope and pinned by no test -- is ALREADY_DISPOSED here. At this head DiagnosticConfidence (diagnostic_witness.rs:49-54) carries no serde attribute on value at all; the rounding is a standalone pub(crate) fn contract_confidence(value: f32) -> f64 (lines 64-68), and the LSP applies it at the two places that build the payload. The context-packet JSON is byte-identical to the base. The changelog fragment now states this explicitly ("Only the LSP diagnostic payload changes; ... other serializers (such as the context packet) are untouched"), and the PR body's Scope is correspondingly narrowed.
    • Prior blocking 2 -- the helper's doc comment claimed an invariant the code did not hold ("Every producer that puts a confidence into a JSON value goes through this one rounding so all surfaces agree", which float_field contradicts) -- is ALREADY_DISPOSED here. The current comment (lines 56-63) says "The LSP diagnostic payload applies this to the values it builds (#10717). Other serializers of DiagnosticConfidence (for example the context packet) are deliberately unchanged here." The false single-owner sentence is gone, and the second owner of the rounding rule is now named rather than denied.
  • Correctness of the repair, re-derived at this head rather than assumed: the LSP now builds data.confidence through crate::domain::contract_confidence(finding.confidence), replacing the previous (f64::from(finding.confidence) * 100.0).round() / 100.0, which rounded half-away-from-zero on a f64 and therefore could disagree with the check surface. The helper uses format!("{value:.2}") and parses it back, and crates/ripr/src/output/json/formatter.rs float_field renders the check surface's confidence as "{}\"{}\": {:.2}" -- the same format specifier, so the LSP and ripr check now agree by construction, including in rounding mode, not merely in the common cases.
  • Fail-closed reading of the witness patch: DiagnosticConfidence.value is Option<f32> with skip_serializing_if = "Option::is_none", and the patch is guarded both by if let Some(confidence) = witness.confidence.value and by value.pointer_mut("/confidence/value") returning None when the path is absent. A witness without a confidence value leaves the JSON untouched instead of writing a substituted one.
  • Public surface: contract_confidence is pub(crate) and re-exported pub(crate) from domain/mod.rs, so no new public API and no new public JSON field. The let ... && let ... let-chain in the patch is edition-2024 syntax, consistent with the repository's Rust 2024 / MSRV 1.95 baseline.
  • Hosted proof on the exact head: Ripr Rust Small on GitHub Hosted / Rust gates success (that job runs cargo fmt --check, cargo check -p ripr --all-targets --all-features, cargo clippy --workspace --all-targets -- -D warnings, cargo xtask goldens check, cargo xtask fixtures and cargo xtask verdict-corpus check-all), Rust tests shard 1..4 of 4 success, Rust test shards verify success, Rust-only feature lane success, Ripr Rust Small Result success at 13:48:43Z, Admit PR Candidate success, cargo-deny, dependency-review, windows-advisory-subset and Graphite / mergeability_check success. The only required status check on main is Ripr Rust Small Result, and it is green on this head. ub-review was cancelled at 13:30:35Z after running from 12:55:35Z; it is an external provider lane and not a required check, so I read it as missing external-review evidence for this head rather than as a defect of the diff.

Blocking:

  • None found.

Non-blocking:

  • The rounding MODE is still unpinned, and this is the earlier review's non-blocking finding, still open at this head (CORROBORATES). The four cases are 0.4, 0.92, 0.6 and 0.75; every one of them has the same value under truncation and under round-half-to-even, so a mutant that truncated instead of rounding would still pass lsp_diagnostic_data_confidence_uses_contract_precision. The test does discriminate "rounded to two decimals" from "not rounded" -- 0.92f32 widened is 0.9200000166893005, so the unrounded mutant is caught -- but it does not discriminate the rounding rule itself. A case such as 0.926 -> "0.93" would close that. The implementation is currently correct by construction (it uses the same {:.2} as float_field), so this is a mutation-resistance gap, not a live defect.
  • The stated acceptance is still not tested end to end, also still open at this head. The acceptance is that the LSP confidence "equal[s] the two-decimal value ripr check reports for the same finding", but the test compares the LSP payload against hard-coded strings and never renders the same finding through output::json::report. The PR body's own Proof section discloses this as not established, which is the correct disclosure; rendering one finding through both paths and comparing the two numbers would make the acceptance falsifiable as written.
  • The helper's comment still does not say that the format-then-parse is deliberate in order to match Rust's {:.2} rounding mode. A future reader could still "optimize" it to (value * 100.0).round() / 100.0 and silently move the LSP back to half-away-from-zero, away from the check surface. One sentence in the comment would close this.
  • docs/OUTPUT_SCHEMA.md demonstrates the two-decimal convention in the check-JSON finding example (line 1462, "confidence": 0.92) but does not state a precision rule in prose, so the helper's citation of "the two-decimal precision of the output contract (docs/OUTPUT_SCHEMA.md)" points at a convention the schema shows rather than one it declares. Very minor.
  • The PR body's "Support-tier Impact: none" sits beside a changelog.d fragment under the Fixed section. The changelog is the right artifact for an editor-visible payload change and its wording is accurate, but the checklist line reads oddly next to a shipped changelog entry; not a defect.

Not run:

  • No local Rust toolchain on this host: cargo/rustc are absent from PATH, so build and test execution could not be performed locally; all Rust proof below is hosted CI plus source reading.
  • No local execution of the LSP, of ripr check, or of the new parity test; the agreement claim above is derived from reading float_field and contract_confidence at the head, plus the hosted cargo xtask goldens check and cargo xtask fixtures runs.
  • No mutation/removal experiment was run against the rounding path (no toolchain here); the mutant analysis above is a source-level counterexample and is stated as such, not as an observed test result.
  • The ub-review external provider lane was cancelled on this head, so I have no external review evidence for it; per the repository's own rule, provider quota, unavailability, cancellation or skipped output means review is missing for that provider rather than that the review was clean.

Reviewed by an independent Mavis review agent on behalf of the maintainer; bound to head 142ac1885422f72ebad2de73f6e5b248e928f1ad.

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Review of record (exact-head sweep, head 142ac1885422f72ebad2de73f6e5b248e928f1ad)

PR state observed as MERGED at this head. This head had no prior substantive review: the earlier review of record (id 5708607736, 2026-10-30T05:57:51Z) is bound to head 6d2c0a1f901cb63187245df2e4a5dba3e31be9e5, before the repair commits (abe95e5 "scope confidence rounding to the LSP payload", c8cf852) and the main sync merge. Both blocking findings from that earlier review were re-checked against this head and are repaired (details in Verified). Findings below are follow-up-grade; none blocks.

Verified

  • Read the full 4-file patch (changelog.d/10717-lsp-confidence-two-decimals.md; domain/diagnostic_witness.rs +14/-0; domain/mod.rs; lsp/diagnostics.rs) and surrounding head source fetched via REST at 142ac188: lsp/diagnostics.rs, domain/diagnostic_witness.rs, domain/mod.rs, domain/fix_instruction.rs, output/json/formatter.rs, output/json/context_packet.rs, output/sarif.rs, output/human/sections.rs, docs/OUTPUT_SCHEMA.md.
  • Premise confirmed first-hand from the vendored serde_json 1.0.151 source: json!/to_value widen f32 to f64 (src/value/ser.rs:151-153 -> Value::from -> src/number.rs:323-328, N::Float(f as f64)). At base, the witness confidence.value really serialized 0.4f32 as 0.4000000059604645; the top-level data.confidence already had a partial (x*100).round()/100 fix, which this PR replaces with the shared helper.
  • Contract agreement verified: format!("{value:.2}") matches float_field (output/json/formatter.rs:27-29, {:.2}) that renders check-JSON confidence, and the human renderer (output/human/sections.rs:127, :627), including round-half-to-even ties - the formatter's own test pins 0.125 -> "0.12" (formatter.rs:177-181). The replaced (x*100).round()/100 rounded half-away-from-zero (0.125 -> 0.13), so the new helper is the more contract-faithful of the two; the behavior delta is toward consistency, not a regression.
  • Scope containment verified: contract_confidence is called at exactly the two claimed sites (lsp/diagnostics.rs:3312, :3367). The shared DiagnosticConfidence DTO is untouched (no serialize_with; head diagnostic_witness.rs:49-54), so the context packet is unchanged - and the packet witness never had the artifact anyway (output/json/context_packet.rs:167 serializes the struct directly: shortest-f32, no widening). The only remaining widened surface is SARIF properties.confidence (output/sarif.rs:498, json!(finding.confidence)), disclosed in the body as a non-goal (Finding 3).
  • Oracle check: the test routes through the production builder chain diagnostic_for_finding -> diagnostic_for_finding_with_config -> diagnostic_for_finding_with_causal (lsp/diagnostics.rs:3255-3273), and it discriminates the witness fix - without the patch, 0.4000000059604645/0.9200000166893005 fail the string comparison. The fix_instruction summary carries no confidence field (domain/fix_instruction.rs:45-53), so the changelog's "two values" claim is exact.
  • Panic-safety: the unwrap_or_else fallback is reachable only for non-finite input (NaN formats as NaN and fails parse); witness construction guards is_finite() (diagnostic_witness.rs:158), and top-level NaN -> Value::Null is identical to base. No new panic/unwrap-family paths in production code.
  • Body hygiene: governing issue #10717 exists (open; its title states exactly this defect), acceptance delta present, Scope section matches the actual 4-file diff.
  • Hosted CI observed on this head: Rust test shards 1-4 of 4 and "Rust gates" succeeded (25 success / 29 skipped advisory lanes / ub-review cancelled, an advisory bot lane).
  • Prior-review repair check: blocking finding 1 (shared-DTO serialize_with silently changing the public context packet) - repaired by scoping the change to the LSP payload; blocking finding 2 (doc comment claiming a single-authority rounding invariant the code did not hold) - repaired: the comment now states the LSP payload applies it and other serializers are deliberately unchanged, which matches verified reality.

Findings

[P2] 1. The parity test does not pin the rounding mode - lsp/diagnostics.rs:6871-6876

  • Failure mode: a mutant restoring (f64::from(x)*100.0).round()/100.0 (half-away-from-zero) or a truncating helper still passes all four cases - 0.4, 0.92, 0.6, 0.75 are all unchanged by any 2-decimal rounding rule - so the LSP could drift from check output on tie values without a test failure.
  • Why here: the check side pins the tie behavior (formatter.rs:177-181: 0.125 -> "0.12") but the LSP parity test does not mirror it; the helper's format+parse shape is load-bearing for tie agreement with float_field.
  • Fix direction: add a tie case to the loop, e.g. (0.125_f32, "0.12") and optionally (0.126, "0.13"); optionally one sentence on the helper doc warning against replacing format+parse with multiply-round-divide.
  • Validation: cargo test -p ripr --lib lsp::diagnostics::lsp_next_step_parity_tests::lsp_diagnostic_data_confidence_uses_contract_precision
  • Confidence: High (arithmetic verified against serde_json 1.0.151 and Rust {:.2} round-half-to-even).

[P2] 2. Acceptance parity is asserted against hard-coded strings, not a rendered check finding - lsp/diagnostics.rs:6882-6884

  • Failure mode: the acceptance ("equal the two-decimal value ripr check reports") is falsified only against literals; if check's own rendering changed precision, no test in this PR would notice.
  • Why here: the body discloses cross-surface comparison as not established; rendering one finding through the check JSON formatter and comparing the number would make the acceptance falsifiable as written.
  • Fix direction: extend the parity test (or a fixture) to render the same finding through output::json and compare data.confidence to the rendered value.
  • Validation: same test path; cargo xtask goldens check where fixtures apply.
  • Confidence: Medium (disclosed residual; suggested as follow-up hardening).

[P2] 3. SARIF properties.confidence still serializes the widened f64 - output/sarif.rs:498 (outside the diff; disclosed non-goal)

  • Failure mode: json!(finding.confidence) takes the same Value-tree widening path, so SARIF reports 0.9200000166893005 where check and now the LSP report 0.92.
  • Why here: deliberately out of scope per the body ("left for its own claim"); recorded so the follow-up claim starts at the exact repair site.
  • Fix direction: apply domain::contract_confidence (or float_field semantics) at the SARIF properties insertion; the SARIF surface is check-output, so that claim needs its own acceptance and golden coverage.
  • Validation: SARIF golden/fixture plus cargo xtask check-output-contracts.
  • Confidence: High.

Done well: the repair is minimal and correctly scoped - post-serialization patching of the LSP witness copy is the only way to emit an exact two-decimal f64 without touching the shared DTO (the prior head's serialize_with proved that surface is shared), and the parity test guards the /confidence/value pointer path against shape drift. Changelog fragment, body scope, and the helper doc comment all match verified behavior.

Validation signal

  • Observed: hosted check runs on head 142ac188 (Rust shards 1-4 of 4 + Rust gates success); head source fetched via REST; serde_json 1.0.151 registry source inspected.
  • Reported: PR body's cargo xtask precommit (exit 0) and focused-test counts (363 passed; lsp::/domain:: 1397 passed) - not independently run by this review.
  • Not verified: no Rust toolchain on the review host (cargo absent from PATH) and the checkout is not a git repository, so no test was executed here and the local tree was not used as head evidence.

Disposition: Findings above; none blocking (PR observed merged; findings are follow-up-grade hardening and a recorded repair site for the disclosed SARIF non-goal).

/// both for the finding and for its witness.
#[test]
fn lsp_diagnostic_data_confidence_uses_contract_precision() -> Result<(), String> {
for (stored, printed) in [

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[P2] The parity test does not pin the rounding mode

Failure mode: all four cases (0.4, 0.92, 0.6, 0.75) are unchanged by any 2-decimal rounding rule, so a mutant restoring (f64::from(x)*100.0).round()/100.0 (half-away-from-zero) or a truncating helper still passes; the LSP could drift from check output on tie values without a test failure.

Why here: the check side pins the tie behavior (output/json/formatter.rs:177-181: float_field(0.125) renders "0.12"), but this loop does not mirror it; contract_confidence's format+parse shape is load-bearing for tie agreement with float_field.

Fix direction: add a tie case, e.g. (0.125_f32, "0.12") and optionally (0.126, "0.13").

Validation: cargo test -p ripr --lib lsp::diagnostics::lsp_next_step_parity_tests::lsp_diagnostic_data_confidence_uses_contract_precision

Confidence: High (arithmetic verified against serde_json 1.0.151 Value::from(f32) widening and Rust {:.2} round-half-to-even).

/// diagnostic payload applies this to the values it builds (#10717). Other
/// serializers of `DiagnosticConfidence` (for example the context packet)
/// are deliberately unchanged here.
pub(crate) fn contract_confidence(value: f32) -> f64 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

[P2] Keep the format+parse shape; it is load-bearing for tie agreement

The format!("{value:.2}") + parse deliberately reproduces float_field (output/json/formatter.rs:27-29) exactly, including round-half-to-even ties - the formatter's own test pins 0.125 -> "0.12" (formatter.rs:177-181). A future simplification to (value * 100.0).round() / 100.0 would round half-away-from-zero (0.125 -> 0.13) and silently diverge from check output. Consider one sentence in this doc comment stating that, and mirror the 0.125 tie case in lsp_diagnostic_data_confidence_uses_contract_precision (lsp/diagnostics.rs:6871) so a drift mutant fails a test.

Confidence: High.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants