Dashboardopencode-loreResponses streaming JSON.parse parity

Responses streaming JSON.parse parity

Category: gotcha
Confidence: 1.00
ID: 01a09671-47ef-76cf-bb60-39e3967b8798
Project ID: 6f4be9ff-ed84-4cca-a9e7-732a0b0b8677
Cross-project: No
Recalled in other projects: 0
Source session: 0DW6lYKmUybOcEf1K
Created: 2026-09-08 11:15:00
Updated: 2026-09-12 16:26:41

Content

Responses streaming and native parsing must have identical public behavior across STREAMING_PARSE_SPOOL_BYTES. Trap: rejecting only a raw BOM at byte zero looks sufficient because a BOM normally starts a document, but @streamparser/json accepts a BOM after leading JSON whitespace while JSON.parse rejects it. Fix: use non-fatal UTF-8 decoding with ignoreBOM:true, reject U+FEFF outside JSON strings, then tokenize re-encoded text; retain native parsing below 256 KiB. Test threshold crossings, leading-whitespace BOM, malformed UTF-8, roots, duplicate keys, trailing data, split escapes, and split multibyte characters.

Move to: