Repository navigation
fix(proxy): mirror chunks as base64, as documented (agent-code#372) - #53
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JSON.stringify calls Buffer#toJSON before the replacer, so the mirror's Buffer check never matched and every chunk was written as a decimal byte array, 3.65x its payload. The replacer now reads the holder's raw value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Juliusolsson05
added a commit
that referenced
this pull request
Sep 25, 2026
…e, nested Buffers Review B: a size bound on a 24-byte chunk let a length-limited encoder pass; the recorded 2,865-byte chunk (a 10,692-byte line before) now pins byte exactness and the base64 bound on the raw mirrored line. Review A: a Buffer nested anywhere in an event is inlined too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e, nested Buffers Review B: a size bound on a 24-byte chunk let a length-limited encoder pass; the recorded 2,865-byte chunk (a 10,692-byte line before) now pins byte exactness and the base64 bound on the raw mirrored line. Review A: a Buffer nested anywhere in an event is inlined too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Juliusolsson05
force-pushed
the
fix/mirror-buffer-base64
branch
from
September 25, 2026 16:04
b7885f5 to
0800cba
Compare
…, UTF-8 and toJSON siblings pinned Every earlier test wrote one event into a fresh file, so an overwrite, a missing newline, mirroring other emits, a latin1 write or returning the raw value for toJSON-bearing siblings all passed. API.md now says older dumps hold byte arrays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Final disposition (pre-merge), head e31c670. Three reviewers: A (correctness, Codex), B (tests, Codex), C (forensic value, Pi).
Findings and dispositions:
Residual (agent-code#372): per-file byte caps, dropped counters, request-body mirroring (775 MiB in the recorded file) and the synchronous write. This PR removes only the 3.65× chunk blow-up; the recorded file's chunk lines drop from 2,266 MiB to about 830 MiB. Merges on green package CI; then the agent-code bump. 🤖 Generated with Claude Code |
This was referenced Sep 25, 2026
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.
Refs Juliusolsson05/agent-code#372 (one part of it; caps and request bodies stay there).
Plan:
docs/plans/2026-09-25-mirror-buffer-base64.md(first commit).Why
ResponsesProxy.emitmeant to mirror chunk bytes as{ _buffer_b64 }, andAPI.mddocuments that. ButJSON.stringifycallsBuffer#toJSONbefore the replacer runs, so the replacer never saw a Buffer. Every chunk has been written as{"type":"Buffer","data":[123,34,…]}.In a recorded 3.19 GB session file (2026-09-25), chunk lines are 2,266 MiB for 621 MiB of payload, a 3.65× blow-up. None of the 34 local dumps contains
_buffer_b64.Change
The replacer reads the holder's raw value (
this[key]), so a Buffer becomes base64. base64 rather than text, because a chunk can split a UTF-8 character. The expected size of that file's chunk lines drops to about 830 MiB, with nothing lost. No reader depends on the old array form (checked this repo and agent-code).Fixture redaction (steering q36)
testing/fixtures/proxy-mirror/models-chunk-2865.jsonis one recorded/v1/modelschunk (2,865 bytes). The raw chunk carried provider instruction text (model_messages.instructions_template, "You are Codex…") and model descriptions. That text is not known to be public, so every JSON string literal longer than 24 bytes is replaced byte-for-byte withx. The event shape, byte length and JSON structure are real.oldMirroredLineBytes(11,148) is recomputed from the sanitized bytes with Node's own serializer.The raw fixture was pushed briefly in
b7885f5. That commit was amended out of the branch (head0800cba), but GitHub may still serve it by SHA until garbage collection.Tests
Four tests: a 24-byte recorded chunk, a split UTF-8 character, the sanitized 2,865-byte chunk (byte-exact, base64 size bound measured on the raw line, less than half the old line), and a nested Buffer.
responsesProxy.mirror.test.tsuses a recorded chunk event and a chunk that splits a UTF-8 character. It checks the exact byte round-trip and the base64 size bound. The first two tests were red on main (_buffer_b64undefined) and are green here. The full suite passes (223 tests), andtsc --noEmitis clean.🤖 Generated with Claude Code