Repository navigation
Conversation
…ments (#99163) canonicalizeBase64 in packages/media-core/src/base64.ts built its output string using character-by-character concatenation () in a loop. For large base64 payloads (~2.7M chars from a ~2MB clipboard PNG screenshot), this created a deeply nested V8 cons-string tree. When any downstream operation triggered V8 string flattening — e.g. or in sniffMimeFromBase64 — V8 recursed into the cons-string tree and overflowed the call stack, producing: RangeError: Maximum call stack size exceeded in the gateway's chat.send attachment parse/stage pipeline. Smaller images (~200KB) worked fine because their cons-string trees were shallow enough to flatten without stack overflow. Fix: accumulate characters in an array and join once at the end, producing a flat string in O(n) without deep V8 recursion. The function is called from sniffMimeFromBase64 → parseMessageWithAttachments → chat.send handler, so this fix resolves the crash for all attachment types that go through the base64 canonicalization path. Tests: - Added regression test in base64.test.ts verifying canonicalizeBase64 handles ~2MB PNG payloads without RangeError on .slice() or Buffer.from() - Added regression test in base64.test.ts for large payloads with whitespace - Added end-to-end regression test in chat-attachments.test.ts verifying parseMessageWithAttachments processes ~2MB PNG without RangeError
|
Codex review: needs real behavior proof before merge. Reviewed July 2, 2026, 1:08 PM ET / 17:08 UTC. Summary PR surface: Source +9, Tests +68. Total +77 across 3 files. Reproducibility: yes. at source/report level, but I did not run a live current-main reproduction in this read-only review. Current main builds canonical base64 with repeated concatenation and the linked issue supplies matching v2026.6.11 gateway RangeError logs. Review metrics: none identified. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Mantis proof suggestion Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Keep the media-core fix shape, correct the gateway regression test to use a payload above the offload threshold or assert inline boundary behavior, and add redacted real Control UI/Gateway proof before merge. Do we have a high-confidence way to reproduce the issue? Yes at source/report level, but I did not run a live current-main reproduction in this read-only review. Current main builds canonical base64 with repeated concatenation and the linked issue supplies matching v2026.6.11 gateway RangeError logs. Is this the best way to solve the issue? No, not merge-ready as submitted. The runtime fix is the right narrow layer, but the gateway regression test must match the strict offload threshold and the external PR still needs real behavior proof. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 3f289fdb4042. Label changesLabel justifications:
Evidence reviewedPR surface: Source +9, Tests +68. Total +77 across 3 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Thanks @jtcole. Closing this older candidate as superseded by the actively maintained canonical fix in #99213. The current branch is far behind main, and its threshold regression does not exercise the claimed offload branch: it allocates exactly 2,000,000 bytes while the production condition is strictly greater than 2,000,000. Its one-string-per-character array also amplifies the same large-payload memory pressure under investigation. #99213 owns the shared base64 canonicalizer and strict Gateway validation path, preserves malformed-tail rejection, and carries focused parser plus real Control UI browser proof. We will keep #99163 open until that canonical branch lands. Thank you for investigating the large-attachment failure. |
Summary
Pasting a ~2MB PNG screenshot into the Control UI webchat triggered
RangeError: Maximum call stack size exceededserver-side in thechat.sendattachment parse/stage pipeline. Smaller images (~200KB) worked fine.Root Cause
canonicalizeBase64inpackages/media-core/src/base64.tsbuilt its output string using character-by-character concatenation (cleaned += base64[i]) in a loop. For large base64 payloads (~2.7M chars from a ~2MB clipboard PNG), this created a deeply nested V8 cons-string tree. When any downstream operation triggered V8 string flattening — e.g..slice()orBuffer.from(..., "base64")insniffMimeFromBase64— V8 recursed into the cons-string tree and overflowed the call stack.The call chain is:
Fix
Replace character-by-character string concatenation with array accumulation + single
join("")at the end. This produces a flat string in O(n) without deep V8 recursion.Before:
After:
Tests
packages/media-core/src/base64.test.ts: Added regression test verifyingcanonicalizeBase64handles ~2MB PNG payloads (~2.7M base64 chars) withoutRangeErroron.slice()orBuffer.from(). Also tests large payloads with embedded whitespace.src/gateway/chat-attachments.test.ts: Added end-to-end regression test verifyingparseMessageWithAttachmentsprocesses a ~2MB PNG screenshot attachment withoutRangeError, confirming the full attachment pipeline (sniff → size check → offload) works.Affected Paths
canonicalizeBase64is also called from:src/media/input-files.ts— inbound file attachment handlingsrc/infra/outbound/message-action-params.ts— outbound message paramssrc/image-generation/image-assets.ts— generated image assetssrc/agents/tool-images.ts— agent tool image handlingpackages/media-core/src/inline-image-data-url.ts— inline image data URL sanitizationAll of these paths benefit from the fix.
Closes #99163