Repository navigation
perf(media): avoid intermediate multipart upload copies - #135162
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please review the synchronous Buffer-to-Blob ownership boundary and private SDK export/package compatibility. The PR includes controlled before/after allocation proof, real OpenAI transcription, 341 focused tests, complete build/changed gates, a dependency-free built-package resolution fixture and official-plugin release-sync compatibility evidence. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 8:17 AM ET / 12:17 UTC. ClawSweeper reviewWhat this changesThe PR centralizes exact Buffer-range conversion for synchronous multipart Blob/File construction and adopts it across core media plus official plugin upload paths. Merge readinessKeep this current maintainer-owned PR open. The prior OpenAI video finding is fixed on the current head, and no introduced correctness or security defect was found; separately published official plugins must retain their normal host-version floor synchronization before release. Priority: P3 Review scores
Verification
How this fits togetherCore media and plugins turn input buffers into Blob/File parts, then send multipart forms to provider and channel APIs. The new private runtime helper gives those constructors the exact Buffer range so they can snapshot it without an intermediate typed-array copy. flowchart LR
A[Media buffer] --> B[Core or plugin upload owner]
B --> C[Exact Buffer range helper]
C --> D[Blob or File snapshot]
D --> E[Multipart form]
E --> F[Provider or channel API]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -5, Tests +8, Docs +7, Config +7, Other +2. Total +19 across 23 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one dependency-free private helper for all affected multipart owners, and release external official-plugin consumers only through the existing host-version synchronization flow. Do we have a high-confidence way to reproduce the issue? Not applicable: this is an allocation optimization, not a report of broken user-visible behavior. The supplied PR evidence does include a concrete real OpenAI transcription through the changed multipart path. Is this the best way to solve the issue? Yes. A narrow shared private runtime helper replaces repeated conversion code while keeping each owner’s Blob/File creation and multipart protocol behavior in place; raw non-multipart byte-body uploads are a different contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against cfefc2614eeb. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles) |
|
Addressed the review's OpenAI video finding in An independent exhaustive Blob/File-constructor audit also found and removed the same adapters in LINE rich-menu uploads, Mattermost files, PixVerse image inputs and Tlon uploads. Source-extracted before/after probes preserve exact bytes, metadata, field order and SharedArrayBuffer behavior for all four. The existing Mattermost loopback test now checks exact multipart file bytes received over HTTP. All 164 follow-up tests, the complete changed-check plan, full build and fresh Codex autoreview pass. The original 341 focused tests and real OpenAI transcription proof remain applicable; the helper and original callers are unchanged. Production source is -8 LOC overall (-6 including maintained SDK classification metadata); tests +8. The version-floor Rank-up move remains satisfied by the normal official-plugin release sync. Its isolated proof now covers all eight separately published consumers: the actual sync updates plugin API/build versions to the target release, and the actual installer rejects the older host and accepts that target. No version publication or release-floor bypass is part of this PR. The private export remains dependency-free with unchanged typed public SDK budgets. |
|
Read the latest completed ClawSweeper review for The release-floor move is covered by the existing release owner: before separately publishing any consumer, the normal version synchronization must raise its plugin API floor to the first host version containing this export. The isolated synchronizer/installer proof covers all eight separately published consumers and verifies rejection on the older host. This PR does not publish a plugin or change versions. I also independently retrieved the current Node Blob constructor documentation, which specifies that typed-array input is copied into the Blob, and the File contract, which extends Blob. That closes the review worker's DNS-related evidence gap and agrees with the inspected Node implementation, offset/mutation tests, real HTTP upload, and authenticated OpenAI transcription. The exact-head CI run, native preparation, complete local changed checks/build, 341 original plus 164 follow-up focused tests, and fresh Codex autoreview all passed. Proceeding through the native merge checks with the normal release-floor requirement retained. |
|
Merged via squash.
|
What Problem This Solves
Upload builders copy each Buffer into a new typed array before Blob or File immediately snapshots it again. Large audio, image, video, workflow and attachment uploads therefore hold an avoidable second full-size copy during construction.
Why This Change Was Made
Use one dependency-free
bufferToBlobPartimplementation for the core audio adapter and eleven official plugins (thirteen upload owners). Ordinary ArrayBuffer-backed Buffers become exact offset/length views; SharedArrayBuffer backing is copied into an ordinary ArrayBuffer. Every caller constructs its Blob or File synchronously, preserving the existing snapshot boundary. Delete the duplicate Comfy, Feishu and OpenAI video conversion helpers and the other intermediate copies.The implementation lives directly in the private
blob-runtimeSDK entrypoint. Importing broader provider/fetch facades added unrelated runtime dependencies in measured plugin imports, so this leaf has no imports. Its built runtime closure is two files totaling 451 bytes. Canonical SDK generation adds its JavaScript-only package export and local declaration aliases; the typed public SDK counts remain 147 entrypoints, 4,359 exports and 2,594 callables, with no budget changes.User Impact
A controlled 32 MiB upload through the actual core multipart builder reduces ArrayBuffer growth during Blob construction from 67,111,808 to 33,557,376 bytes: one 33,554,432-byte intermediate copy removed. The wire bytes, filename, MIME type, form-field order and mutation-after-construction behavior remain identical. This measures upload-construction allocation, not a whole-Gateway resident-memory reduction.
Production source is net -8 lines; the two maintained SDK classification entries bring production plus maintained metadata to net -6. Generated package/path metadata is +10, documentation +7 and tests +8. Existing OpenAI video tests now protect offset Buffers and snapshot timing; the existing Mattermost HTTP loopback test also asserts exact uploaded bytes.
Evidence
gpt-4o-mini-transcriberequest through the core audio adapter uploaded a synthetic 91,244-byte WAV from an offset Buffer and returned “Memory probe complete.” The request completed in 1,047 ms; this is functional live proof, not a latency benchmark.Other provider services were covered by their existing tests and shared multipart contract proof; no live Feishu, Comfy or non-OpenAI image-service call is claimed. Node Blob contract.