Skip to content

fix: preserve UTF-8 in logged ReadableStream byte chunks - #2701

Merged
Luca Forstner (lforst) merged 2 commits into
braintrustdata:mainfrom
DiadkoShmek:fix/logged-byte-stream-utf8
Nov 2, 2026
Merged

Luca Forstner (lforst) merged 2 commits into
braintrustdata:mainfrom
DiadkoShmek:fix/logged-byte-stream-utf8

Conversation

@DiadkoShmek

Copy link
Copy Markdown
Contributor

Logging a raw ReadableStream<Uint8Array> can corrupt ordinary Unicode output when a multibyte UTF-8 character crosses chunk boundaries. The public initLogger / span log / flush path currently decodes each byte chunk independently in createFinalValuePassThroughStream; split bytes become replacement characters in the serialized /logs3 row. ASCII and the same Unicode text in one chunk are passing controls.

Decode byte chunks once with streaming decoder state, use that same text for forwarding and accumulation, and flush the decoder at EOF or before a non-byte chunk. Preserve the existing structured/string chunk order, JSON/reasoning precedence, errors and the application-facing stream branch. This is separate from the existing SSE parser repair in #2091.

Added public logger regressions with a fake Braintrust HTTP boundary, plus every split of two-, three- and four-byte characters, mixed strings/structured chunks, empty inputs, incomplete EOF and error controls. No fabricated provider response or provider e2e coverage is involved. A patch changeset is included and matches this PR title.

Validation:

  • Original source with the final focused tests: 6 failed, 13 passed.
  • Fixed related logger/stream suites: 178 passed on Node 24.14 and configured Node 26.8.2; source and test TypeScript checks pass on both.
  • Independent AI review reran the 19 focused tests on both Node versions and passed 1,051 additional byte-boundary/error/cancellation/isolation checks on Node 24, including actual public /logs3 output and preservation of the original application consumer.
  • Changeset validation and repository formatting pass on Node 26. ESLint exits 0 with 1,109 warnings; this is not a warning-free whole-tree claim.

The full monorepo, published-package build, browser runtime and real-provider/e2e matrix were not run.

AI assistance: OpenAI Codex performed source inspection, implementation, local execution and independent AI review. No human code review or upstream approval is claimed.

@lforst

Copy link
Copy Markdown
Member

Thanks!

@lforst
Luca Forstner (lforst) merged commit 2718187 into braintrustdata:main Nov 2, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants