Expose fuzzer test failures by reducing Writer buffer sizes and adding comprehensive stress tests #952
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.
Problem
The fuzzer test in
automated.spec.tswas intermittently failing with floating point precision mismatches like:The agent instructions requested creating conditions to make this test fail more consistently by tweaking the Writer buffer sizes and investigating potential bugs in buffer size estimation.
Root Causes Identified
1. Floating Point Precision Loss in Random Number Generation
The
Random.num()method adds/subtracts tiny floating point values (0.000000000000001) to avoid exact boundary values when generating numbers withgte/lteconstraints:For integer types like
u16(used inConfiguration.database.port), this produces values like4.000000000000001. When JSON encodes and decodes this number, the precision is lost, resulting in4, causing test assertion failures.2. Stale Buffer References in Generated Code
The
AbstractBinaryCodegengenerates encoder code that cachesuint8andviewreferences at the start:If the buffer grows during encoding (when
encoder.writeStr()or other methods callwriter.ensureCapacity()internally), these cached references become stale and point to the old, discarded buffer. This can cause data corruption or encoding errors.3. Capacity Estimation Edge Cases
The capacity estimator may underestimate the required buffer size for:
",\, newlines, etc.)Changes Made
Reduced Writer Buffer Sizes
automated.spec.ts: Changed fromnew Writer(16)tonew Writer(1)writer.ts: Changed default fromnew Writer()(64KB) tonew Writer(1)By using extremely small initial buffer sizes (1 byte), we force the buffer to grow during encoding, which:
Added Comprehensive Test Suites
precision-edge-case.spec.ts: Demonstrates floating point precision loss through JSON round-tripbuffer-capacity.spec.ts: Stress tests with progressively larger data and 1000 iterationsstale-buffer-bug.spec.ts: Targets stale references with long strings and unicode to force buffer growthinspect-codegen.spec.ts: Debugging helper to inspect generated encoder codecomprehensive-issues.spec.ts: Combined stress test with 100 random iterations, categorizing failuresDocumentation
Created
ISSUES_FOUND.mdwith:Impact
These changes successfully create conditions that expose the underlying issues:
The failing tests provide clear diagnostics about which specific issue caused the failure, making it easier to develop targeted fixes.
Testing
Run the new test suites:
yarn test packages/json-type/src/codegen/binary/json/__tests__/The tests are designed to:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
classic.yarnpkg.com/usr/local/bin/node /home/REDACTED/.cache/node/corepack/v1/yarn/4.10.3/yarn.js set version classic --only-if-needed --yarn-path(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #951
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.