Skip to content

Fix numeric precision in schema JSON documents - #742

Closed
maharshi-coding wants to merge 1 commit into
aws:mainfrom
maharshi-coding:fix/3614-lossless-document-numbers
Closed

maharshi-coding wants to merge 1 commit into
aws:mainfrom
maharshi-coding:fix/3614-lossless-document-numbers

Conversation

@maharshi-coding

Copy link
Copy Markdown

Issue #, if available:

Fixes aws/aws-sdk-go-v2#3614.

Description of changes:

Schema JSON ReadDocument builds an opaque document through parser.value(), which converted every numeric token with strconv.ParseFloat(..., 64). This silently rounds integers above 2^53 and can make a subsequent typed int64 document decode fail near MaxInt64.

Keep validated numeric tokens as encoding/json.Number. The existing document decoder then exposes document.Number or parses the requested concrete numeric type without an intermediate float. The numeric text is copied because documents can outlive the pooled deserializer and its input buffer.

Also recognize json.Number in the reflection-based document encoder. This keeps numbers numeric when forwarding an opaque document through WriteDocument, rather than quoting them as strings. It uses the existing JSON number grammar validation; ordinary strings, existing document.Number values, and the existing empty-number zero-value behavior are preserved. Typed schema numeric readers and public interfaces are unchanged. No generated SDK files are modified.

Validation:

  • Reproduced the exact issue program using a mocked Neptune HTTP response, the latest SDK checkout (407b01fa), and a local Smithy replacement. No Neptune cluster or AWS credentials were used.
  • Before: 9007199254740993 re-marshaled as 9007199254740992; MaxInt64 re-marshaled as 9223372036854776000 and failed typed decoding. After: both retain every digit, dynamic values are document.Number, and typed int64 decoding succeeds with no error. All three external HTTP regression tests fail against original Smithy and pass with the fix, including with -race.
  • make unit-race passes, including go vet --all and race tests across the root and four nested runtime modules. The complete root suite passes on the minimum supported Go 1.24.0; the final encoder suite also passes on that toolchain.
  • Neptune's existing package tests pass with -race against the local runtime replacement. The affected JSON parser package passes a fresh race run. Changed Go files are formatted.
  • Added cases cover signed/unsigned integer limits, negatives, decimals, exponents, numbers beyond float64 range, nested maps/lists/nulls, numeric strings, negative zero, typed conversions/errors, document forwarding, invalid literals, and numeric text ownership. Existing parser/fuzz comparisons now use the standard decoder's UseNumber; five valid-number JSONTestSuite cases no longer need overflow skips.
  • Differential parser fuzzing passes a 30-second run (6,681 executions). Live OSS-Agent code, security, and maintainer reviews were run through its documented interfaces.

Performance:

Eight 200ms benchmark samples per case on Go 1.27.3, Darwin/arm64: the six-number document fixture's median changes from 728.4 to 526.1 ns/op, with 680 to 800 B/op and 17 to 22 allocations/op. Keeping owned numeric text costs storage but avoids float parsing. The typed-deserialization benchmark retains 3,824 B/op and 104 allocations/op; its timing variation is not treated as a significant speedup. These are local microbenchmarks, not a general workload guarantee.

This contribution was prepared with AI assistance and independently reviewed through OSS-Agent.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@maharshi-coding
maharshi-coding requested review from a team as code owners November 1, 2026 09:21
@lucix-aws

Copy link
Copy Markdown
Collaborator

closing in favor of #745

@lucix-aws lucix-aws closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants