fix(capability-src): correct float-to-string truncation in shared JSON writer - #272
Merged
enricopiovesan merged 1 commit intoAug 18, 2026
Merged
Conversation
…N writer wasi-capability-runtime's write_number scaled a fraction by 1_000_000.0 and truncated via `as i64`. Because that scaled value is often not exactly representable in f64 (e.g. 65.6 * 1_000_000.0 == 65599999.99999999), truncating silently produced "65.599999" instead of "65.600000" -- visible live as "65.599999% covered" / "66.099999% covered" badges on the catalog for capabilities whose real cargo llvm-cov coverage was a clean 65.6% / 66.1%. Adds a round-half-up epsilon before the truncating cast (still no f64::round/libm, per this function's existing no_std constraint). Verified end-to-end against the real deployed artifact: ran gather_catalog_data.py for real and piped it through the actual wasm32-unknown-unknown release build of catalog-builder.wasm via wasmtime; diffing against the currently-live catalog.json shows only the two known- corrupted fields corrected, nothing else changed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
enricopiovesan
enabled auto-merge (squash)
August 18, 2026 05:15
enricopiovesan
deleted the
claude/fix-json-float-truncation-catalog-coverage
branch
August 18, 2026 05:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wasi-capability-runtime's hand-rolledJSON writer (
json.rs, shared no_std code used by everycapability-srcWASM binary, including
catalog-builder).write_numberscaled afraction by
1_000_000.0and truncated viaas i64to extract sixdecimal digits.
65.6 * 1_000_000.0is65599999.99999999inf64(notexactly representable), so truncating silently produced
"65.599999"instead of
"65.600000"for any value whose scaled representation felljust under an integer boundary.
registry.traverse-framework.comshowed"65.599999% covered"and"66.099999% covered"on two capabilitycards, even though the actual measured
cargo llvm-covcoverage wascleanly 65.6% / 66.1%. Every other coverage badge on the site happened
to scale to an exact or above-boundary value and so rendered fine —
this was a latent bug for years, only visible for specific unlucky
decimals.
+ 0.5) before the truncating cast —the standard technique for correct rounding without
f64::round(thisfunction deliberately avoids
f64::round/abs/fractsince those pullin
libmsymbols not linked into thisno_stdwasm32-unknown-unknownbinary; the fix keeps that constraint, casts and integer arithmetic
only).
scripts/ci/gather_catalog_data.pyfor real (98 capabilities, livecargo llvm-covmeasurements) and fed the output through the actualwasm32-unknown-unknownrelease build ofcatalog-builder.wasmviawasmtime. Diffing the regeneratedcatalog.jsonagainst the currentlylive one shows exactly the two corrupted fields fixed
(
65.599999→65.600000,66.099999→66.100000) and nothing elsechanged.
No open issue tracks this — found via direct inspection of the live
catalog.
capability-src/is not currently covered by any approvedspec's
governslist (this crate isn't a published registry capability,per its own doc comment — it's shared build tooling), so
001-registry- foundationis cited as the closest applicable spec, matching this repo'sexisting precedent for
capability-src-only changes (e.g. #264).Governing Spec
001-registry-foundationDefinition of Done
write_numberproduces correct digits for values whose* 1_000_000.0scaling isn't exactly representable inf64.Validation
cargo test --manifest-path capability-src/wasi-capability-runtime/Cargo.toml(7 tests, including 2 new regression tests: exact reproduction of the 65.6/66.1 bug, and a 0.0–99.9-by-0.1 round-trip sweep)cargo build --release --target wasm32-unknown-unknown --manifest-path capability-src/catalog-builder/Cargo.tomlgather_catalog_data.pyoutput piped through the realcatalog-builder.wasmviawasmtime, diffed against the currently-livecatalog.json— only the two known-corrupted fields changed, to the correct valuesTest plan
build-catalogregeneratescatalog.jsonon merge; live badges should show65.6%/66.1%after the next deploy)