Repository navigation
refactor(sse): declare the ArrayBuffer backing on media byte producers - #8665
Merged
diegosouzapw merged 1 commit intoJul 27, 2026
Conversation
backryun
force-pushed
the
chore/ts7-types-buffer-arraybuffer
branch
2 times, most recently
from
July 27, 2026 15:18
dcbc2cc to
801a02b
Compare
Six declarations spell a byte buffer as bare `Buffer` / `Uint8Array`. Without its type argument that widens to `ArrayBufferLike`, which also admits `SharedArrayBuffer` — so the value is rejected at every Web API boundary it is actually passed to: `BodyInit` for `new Response(...)` and `BlobPart` for `new Blob([...])`. Every one of them is already ArrayBuffer-backed at runtime. `hexToBytes()` allocates with `new Uint8Array(len)`; `synthesizeGtts()` and `pcmToWav()` return `Buffer.concat(...)`; `fetchRemoteImage()` returns `Buffer.from(await response.arrayBuffer())`; `readPageResponseBody()` returns `Buffer.from(body)`, which copies. The declarations were simply less specific than the values, so this states what the code already guarantees. Same fix diegosouzapw#8533 applied to the multipart and gRPC-web bodies. Fixes 5 of the 208 `tsc -p open-sse/tsconfig.json` diagnostics with no new ones: 3 in audioSpeech.ts (MiniMax hex, gTTS, Vertex Gemini TTS), 1 in imageGeneration.ts (Topaz Blob upload) and 1 in browserBackedChat.ts. Refs diegosouzapw#8484
backryun
force-pushed
the
chore/ts7-types-buffer-arraybuffer
branch
from
July 27, 2026 15:35
801a02b to
24adb2d
Compare
Merged
HouMinXi
pushed a commit
to HouMinXi/OmniRoute
that referenced
this pull request
Aug 2, 2026
diegosouzapw#8665) Six declarations spell a byte buffer as bare `Buffer` / `Uint8Array`. Without its type argument that widens to `ArrayBufferLike`, which also admits `SharedArrayBuffer` — so the value is rejected at every Web API boundary it is actually passed to: `BodyInit` for `new Response(...)` and `BlobPart` for `new Blob([...])`. Every one of them is already ArrayBuffer-backed at runtime. `hexToBytes()` allocates with `new Uint8Array(len)`; `synthesizeGtts()` and `pcmToWav()` return `Buffer.concat(...)`; `fetchRemoteImage()` returns `Buffer.from(await response.arrayBuffer())`; `readPageResponseBody()` returns `Buffer.from(body)`, which copies. The declarations were simply less specific than the values, so this states what the code already guarantees. Same fix diegosouzapw#8533 applied to the multipart and gRPC-web bodies. Fixes 5 of the 208 `tsc -p open-sse/tsconfig.json` diagnostics with no new ones: 3 in audioSpeech.ts (MiniMax hex, gTTS, Vertex Gemini TTS), 1 in imageGeneration.ts (Topaz Blob upload) and 1 in browserBackedChat.ts. Refs diegosouzapw#8484
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
diegosouzapw#8665) Six declarations spell a byte buffer as bare `Buffer` / `Uint8Array`. Without its type argument that widens to `ArrayBufferLike`, which also admits `SharedArrayBuffer` — so the value is rejected at every Web API boundary it is actually passed to: `BodyInit` for `new Response(...)` and `BlobPart` for `new Blob([...])`. Every one of them is already ArrayBuffer-backed at runtime. `hexToBytes()` allocates with `new Uint8Array(len)`; `synthesizeGtts()` and `pcmToWav()` return `Buffer.concat(...)`; `fetchRemoteImage()` returns `Buffer.from(await response.arrayBuffer())`; `readPageResponseBody()` returns `Buffer.from(body)`, which copies. The declarations were simply less specific than the values, so this states what the code already guarantees. Same fix diegosouzapw#8533 applied to the multipart and gRPC-web bodies. Fixes 5 of the 208 `tsc -p open-sse/tsconfig.json` diagnostics with no new ones: 3 in audioSpeech.ts (MiniMax hex, gTTS, Vertex Gemini TTS), 1 in imageGeneration.ts (Topaz Blob upload) and 1 in browserBackedChat.ts. Refs diegosouzapw#8484
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.
Part of the TS7 readiness campaign (#8484). One root cause, 5 diagnostics, zero new.
Root cause
Six declarations spell a byte buffer as bare
Buffer/Uint8Array. Without its type argument that widens toArrayBufferLike, which also admitsSharedArrayBuffer— so the value is rejected at every Web API boundary it is actually passed to:BodyInitfornew Response(...),BlobPartfornew Blob([...]).Every one of them is already
ArrayBuffer-backed at runtime:hexToBytes()(audioSpeech.ts)new Uint8Array(len)new Response(bytes)— MiniMax T2A v2synthesizeGtts()(gtts.ts)Buffer.concat(...)new Response(audio)— gTTSpcmToWav()→vertexGenerateSpeech()(vertexMedia.ts)Buffer.concat([header, pcm])new Response(audio)— Vertex Gemini TTSfetchRemoteImage()(remoteImageFetch.ts)Buffer.from(await response.arrayBuffer())new Blob([...])— Topaz uploadreadPageResponseBody()(browserPool.ts)Buffer.from(body)(copies)browserBackedChat.tsresponse bodyThe declarations were simply less specific than the values, so this states what the code already guarantees. It is the same fix #8533 applied to the multipart and gRPC-web bodies.
Diagnostics fixed
open-sse/handlers/audioSpeech.tsBodyInitopen-sse/handlers/imageGeneration.tsBlobPartopen-sse/services/browserBackedChat.tsBuffer<ArrayBuffer>Measured as a line-number-agnostic diff of the complete
tsc -p open-sse/tsconfig.jsonerror set against a freshly re-measured base: 208 → 203, 5 fixed, 0 new.Note that three of the five fixed diagnostics are in files this PR does not touch — the fix is at each producer, not at the call site.
Behaviour
Type annotations only; no runtime change. The narrowing is safe in both directions:
Buffer<ArrayBuffer>is assignable toBuffer, so no existing consumer is affected, and every producer's allocation is ArrayBuffer-backed (Node buffers are neverSharedArrayBuffer-backed, pooled or not).Test plan
New
tests/unit/media-body-arraybuffer-backing.test.ts— 4 tests, one per reachable producer. Each asserts both the backing and that the value really is accepted by the Web API it is passed to in production:The existing tests for these functions assert their contents — the RIFF header (
vertex-media.test.ts), the concatenated chunks (gtts-provider.test.ts), the decoded base64 (remote-image-fetch.test.ts). None asserted the backing, which is the one property the narrowed return types exist to guarantee and the one a refactor to a shared allocation would break.The sixth producer,
hexToBytes(), is module-private; itsnew Response(bytes)path is already exercised end-to-end byminimax-tts-1043.test.ts, which builds the response and reads its body.Regression run over every touched producer's existing suite —
gtts-provider,vertex-media,vertex-tts,remote-image-fetch,remote-image-fetch-dns-rebinding,remote-image-fetch-pin-dns-connection,browser-pool-optional-import,minimax-tts-1043,audio-speech-handler,audio-speech-fishaudio,image-generation-handler: 108 pass, 0 fail.Gates:
typecheck:coreclean,check:file-sizeOK, ESLint clean on all touched files.