Repository navigation
fix(lsp): round diagnostic confidence to the contract's two decimals (#10717) - #11062
Conversation
…10717) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNUoLW4Ze4ffvMT8Zb9EHN
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNUoLW4Ze4ffvMT8Zb9EHN
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
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. View limit details
Comment |
EffortlessSteven
left a comment
There was a problem hiding this comment.
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 thecomplete_ts_findingfixture),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_json1.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
-
The
serialize_withonDiagnosticConfidence.valuechanges the public context-packet JSON, and that surface is outside the declared scope, absent from the changelog, and pinned by no test.DiagnosticConfidenceis not LSP-only.ContextPacketcarriespub witness: Option<DiagnosticWitness>(crates/ripr/src/domain/context_packet.rs:36),DiagnosticWitnesscarriespub confidence: DiagnosticConfidence(crates/ripr/src/domain/diagnostic_witness.rs:25), and the packet renders that witness withserde_json::to_string_pretty(witness)(crates/ripr/src/output/json/context_packet.rs:156). The newserialize_withtherefore rewrites the packet'switness.confidence.valueon the wire.The wire value really does change. Before this PR,
DiagnosticConfidence.valueis anf32(diagnostic_witness.rs:55), and serde_json'sValue::from(f32)widens it:src/value/from.rs:42-44callsNumber::from_f32, which storesN::Float(f as f64)(src/number.rs:323-328). So a stored0.92f32serialized as0.9200000166893005. After this PR it serializes as0.92.That surface is public and reachable:
app::context::collect_contextis apub fn(crates/ripr/src/app/context.rs:10) that renders throughoutput::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).DiagnosticConfidenceandDiagnosticWitnessare 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 diagnosticdata.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 underfixtures/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, whichfloat_fieldalready 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 buildsdata, not on the shared DTO) or extend the Scope, the changelog fragment,docs/OUTPUT_SCHEMA.md, and a test to cover the packet surface. -
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-35already owns this rule asfloat_field, which renders{:.2}; it is what produces the findingconfidenceinripr check --format json(crates/ripr/src/output/json/report.rs:881) and the packet's own top-levelconfidence(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_confidencestates: "checkJSON 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_fieldis 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 samef32, 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_fieldcan format the number it returns), or correct the comment to say what is actually true — that this helper reproducesfloat_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 passlsp_diagnostic_data_confidence_uses_contract_precision. A case such as0.926 → "0.93"would discriminate. The test does correctly discriminate "rounded" from "not rounded" —0.92f32asf64is0.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.confidenceand witness confidence value equal the two-decimal valueripr checkreports for the same finding", but the test compares the LSP payload against hard-coded strings and never renders the same finding throughoutput::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_confidencerounds by formatting to aStringand parsing it back. That is deliberate and correct for bit-identical agreement withfloat_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.0and silently change the rounding mode relative tofloat_field.
Refuted / stale
- Hypothesis:
ripr check --format jsonemits the same widenedf64as the LSP did, so this helper would make check JSON and the LSP disagree. Refuted.crates/ripr/src/output/json/report.rs:881renders the findingconfidencethroughfloat_field, i.e.{:.2}, so check JSON reports0.40while the LSP reported0.4000000059604645. The PR's premise — that the LSP was the divergent surface — is correct, and the LSP now reports0.4, numerically equal to the check surface's0.40. - Hypothesis: the new test's fixture has no witness, making the assertion on
data["witness"]["confidence"]["value"]unsatisfiable. Not sustained.complete_ts_finding()isExposureClass::WeaklyExposed(crates/ripr/src/lsp/diagnostics.rs:6557), andDiagnosticWitness::from_findingreturnsNoneonly forExposedfindings 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, andrustupare all absent fromPATH. The workspace build, the test suite,cargo xtask precommit, andcargo xtask goldens checkcould 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 head6d2c0a1. - 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
|
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 |
|
|
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UNUoLW4Ze4ffvMT8Zb9EHN
EffortlessSteven
left a comment
There was a problem hiding this comment.
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 byEffortlessSteven, merge commit4e1035a8b9d4d2cf2344029c7b9646e778d79459. 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 ofmain. - 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.rslines 35-80 (theDiagnosticConfidencestruct, the helper,DiagnosticWitness),crates/ripr/src/output/json/formatter.rs(float_field),crates/ripr/src/lsp/diagnostics.rs(theconfidenceandwitnessconstruction indiagnostic_for_finding_with_causal, and the new test),docs/OUTPUT_SCHEMA.mdlines 1242-1247 and 1455-1470, and themainbranch protection required-checks list. - Prior findings, re-verified against this head rather than carried forward. The earlier
EffortlessStevenreview (submitted 2026-10-30T05:57:51Z) is bound to6d2c0a1f901cb63187245df2e4a5dba3e31be9e5, an ancestor of this head, and recorded REPAIR_REQUIRED with two blocking findings. I checked both at this head:- Prior blocking 1 -- the
serialize_withon the sharedDiagnosticConfidenceDTO silently changed the public context-packet JSON, outside the declared scope and pinned by no test -- is ALREADY_DISPOSED here. At this headDiagnosticConfidence(diagnostic_witness.rs:49-54) carries no serde attribute onvalueat all; the rounding is a standalonepub(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_fieldcontradicts) -- 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 ofDiagnosticConfidence(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.
- Prior blocking 1 -- the
- Correctness of the repair, re-derived at this head rather than assumed: the LSP now builds
data.confidencethroughcrate::domain::contract_confidence(finding.confidence), replacing the previous(f64::from(finding.confidence) * 100.0).round() / 100.0, which rounded half-away-from-zero on af64and therefore could disagree with the check surface. The helper usesformat!("{value:.2}")and parses it back, andcrates/ripr/src/output/json/formatter.rsfloat_fieldrenders the check surface's confidence as"{}\"{}\": {:.2}"-- the same format specifier, so the LSP andripr checknow agree by construction, including in rounding mode, not merely in the common cases. - Fail-closed reading of the witness patch:
DiagnosticConfidence.valueisOption<f32>withskip_serializing_if = "Option::is_none", and the patch is guarded both byif let Some(confidence) = witness.confidence.valueand byvalue.pointer_mut("/confidence/value")returningNonewhen the path is absent. A witness without a confidence value leaves the JSON untouched instead of writing a substituted one. - Public surface:
contract_confidenceispub(crate)and re-exportedpub(crate)fromdomain/mod.rs, so no new public API and no new public JSON field. Thelet ... && 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 gatessuccess (that job runscargo fmt --check,cargo check -p ripr --all-targets --all-features,cargo clippy --workspace --all-targets -- -D warnings,cargo xtask goldens check,cargo xtask fixturesandcargo xtask verdict-corpus check-all),Rust tests shard 1..4 of 4success,Rust test shards verifysuccess,Rust-only feature lanesuccess,Ripr Rust Small Resultsuccess at 13:48:43Z,Admit PR Candidatesuccess,cargo-deny,dependency-review,windows-advisory-subsetandGraphite / mergeability_checksuccess. The only required status check onmainisRipr Rust Small Result, and it is green on this head.ub-reviewwas 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.6and0.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 passlsp_diagnostic_data_confidence_uses_contract_precision. The test does discriminate "rounded to two decimals" from "not rounded" --0.92f32widened is0.9200000166893005, so the unrounded mutant is caught -- but it does not discriminate the rounding rule itself. A case such as0.926 -> "0.93"would close that. The implementation is currently correct by construction (it uses the same{:.2}asfloat_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 checkreports for the same finding", but the test compares the LSP payload against hard-coded strings and never renders the same finding throughoutput::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.0and 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.mddemonstrates 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.dfragment under theFixedsection. 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/rustcare 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 readingfloat_fieldandcontract_confidenceat the head, plus the hostedcargo xtask goldens checkandcargo xtask fixturesruns. - 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-reviewexternal 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
left a comment
There was a problem hiding this comment.
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 at142ac188: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_valuewidenf32tof64(src/value/ser.rs:151-153->Value::from->src/number.rs:323-328,N::Float(f as f64)). At base, the witnessconfidence.valuereally serialized0.4f32as0.4000000059604645; the top-leveldata.confidencealready had a partial(x*100).round()/100fix, which this PR replaces with the shared helper. - Contract agreement verified:
format!("{value:.2}")matchesfloat_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 pins0.125 -> "0.12"(formatter.rs:177-181). The replaced(x*100).round()/100rounded 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_confidenceis called at exactly the two claimed sites (lsp/diagnostics.rs:3312,:3367). The sharedDiagnosticConfidenceDTO is untouched (noserialize_with; headdiagnostic_witness.rs:49-54), so the context packet is unchanged - and the packet witness never had the artifact anyway (output/json/context_packet.rs:167serializes the struct directly: shortest-f32, no widening). The only remaining widened surface is SARIFproperties.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.9200000166893005fail the string comparison. Thefix_instructionsummary carries no confidence field (domain/fix_instruction.rs:45-53), so the changelog's "two values" claim is exact. - Panic-safety: the
unwrap_or_elsefallback is reachable only for non-finite input (NaN formats asNaNand fails parse); witness construction guardsis_finite()(diagnostic_witness.rs:158), and top-level NaN ->Value::Nullis 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-reviewcancelled, an advisory bot lane). - Prior-review repair check: blocking finding 1 (shared-DTO
serialize_withsilently 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.75are 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 withfloat_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 checkreports") 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::jsonand comparedata.confidenceto the rendered value. - Validation: same test path;
cargo xtask goldens checkwhere 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 reports0.9200000166893005where check and now the LSP report0.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(orfloat_fieldsemantics) 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 (
cargoabsent 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 [ |
There was a problem hiding this comment.
[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 { |
There was a problem hiding this comment.
[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.
Requested by Steven Zimmerman · project thread
Summary
data.confidencewas thef32widened tof64(0.4000000059604645). It now goes through one shared helper,domain::contract_confidence, which rounds to the two-decimal contract precision thatripr checkprints ({:.2}), so0.4reads0.4.data.confidence,data.witness.confidence.value) use the shared helper; other serializers ofDiagnosticConfidence(e.g. the context packet JSON) are unchanged.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Governing issue or accepted claim: #10717
Acceptance delta (one sentence): LSP diagnostic
data.confidenceand witness confidence value equal the two-decimal valueripr checkreports 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
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.confidencehas 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
Policy Impact
Proof
Not established: cross-language (Rust/Python/TypeScript) fixture comparison against check JSON beyond the unit test; hosted CI;
cargo xtask goldens checknot 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
lsp::diagnostics::lsp_next_step_parity_tests::lsp_diagnostic_data_confidence_uses_contract_precisiondomain::diagnostic_witness::contract_confidenceStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Generated by Claude Code