Skip to content

perf(media): avoid intermediate multipart upload copies - #135162

Merged
steipete merged 2 commits into
mainfrom
codex/perf-provider-blob-parts
Sep 1, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf-provider-blob-parts

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

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 bufferToBlobPart implementation 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-runtime SDK 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

  • Actual-source baseline/candidate probes cover nonzero-offset Buffers, sentinels outside their visible ranges, Blob/File snapshots and SharedArrayBuffer input. A normalized multipart comparison produces identical 466-byte wire payloads. The extracted OpenAI video reference owner independently drops ArrayBuffer growth from 64 MiB to 32 MiB for a 32 MiB input; both image and video metadata/validation remain identical. Source-extracted LINE, Mattermost, PixVerse and Tlon owners preserve bytes and metadata while removing each adapter allocation.
  • A real OpenAI gpt-4o-mini-transcribe request 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.
  • The initial 341 focused tests pass across audio, image providers, ClickClack, Comfy, DeepInfra, Feishu and SDK package contracts. All 164 follow-up tests pass across OpenAI video, ClickClack, LINE, Mattermost (including actual HTTP multipart), PixVerse and Tlon. The full build, SDK surface check and complete changed-check plan pass.
  • An isolated built-package fixture resolves the exact generated export from a plugin-local peer link with no checkout dependency. Five cold imports have a 1.358 ms median and preserve byte-view/snapshot contracts. This is a built-package fixture, not an npm tarball or complete installer run. A built Feishu import profile remains approximately 129.7 MiB maximum RSS, within the baseline's 129.5 MiB process variation.
  • The existing official-plugin version sync was exercised against isolated copies of all eight separately published affected plugin manifests. It raises their plugin API floor to the target host release; the actual installer compatibility check rejects the older host and accepts that target. Publishing these plugins must retain the normal release version-sync flow so older hosts cannot receive an artifact importing the new private subpath.
  • Direct Node Blob implementation/documentation inspection confirms synchronous copying of an exact typed-array range. Independent source, package-resolution and compatibility review plus fresh Codex autoreview found no accepted findings within the selected scope and priority.

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.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 8:17 AM ET / 12:17 UTC.

ClawSweeper review

What this changes

The PR centralizes exact Buffer-range conversion for synchronous multipart Blob/File construction and adopts it across core media plus official plugin upload paths.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep 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
Reviewed head: 0c9afcb9cea298082459ce75579940914bae3dde

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused helper, resolved prior finding, real provider trace, and boundary tests support a normal good-quality review outcome.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed production owner is the core multipart audio builder and matching plugin upload owners; the PR supplies an after-fix real OpenAI transcription from an offset WAV buffer plus source-visible File/HTTP multipart tests showing retained snapshot bytes and metadata.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the core multipart audio builder and matching plugin upload owners; the PR supplies an after-fix real OpenAI transcription from an offset WAV buffer plus source-visible File/HTTP multipart tests showing retained snapshot bytes and metadata.
Evidence reviewed 8 items Range-preserving helper: The helper creates a view using the Buffer offset and byte length for ArrayBuffer-backed buffers, and makes a bounded copy only for other backing stores.
Core entry point: The shared audio multipart builder passes the helper result directly to Blob before form construction continues, preserving its existing field ordering and filename flow.
Prior finding resolved: The OpenAI reference-image/video File owner now uses the shared helper, and the updated tests use offset buffers, mutate them after construction, and assert snapshotted bytes.
Findings None None.
Security None None.

How this fits together

Core 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]
Loading

Before merge

  • Resolve merge risk (P1) - Separately published official plugins that import this private runtime must be released with a plugin API floor at or above the first host release containing it; otherwise an older host would fail module resolution.
  • Resolve merge risk (P1) - Independent retrieval of Node’s upstream Blob documentation/source was unavailable because DNS could not resolve nodejs.org, so this review could not independently recheck that runtime contract beyond the PR’s supplied real request evidence and source-level checks.
  • Complete next step (P2) - No discrete automated repair remains; this active maintainer-labeled PR needs normal exact-head CI and release-process handling.
Agent review details

Security

None.

PR surface

Source -5, Tests +8, Docs +7, Config +7, Other +2. Total +19 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 15 36 41 -5
Tests 2 11 3 +8
Docs 2 7 0 +7
Config 2 8 1 +7
Generated 0 0 0 0
Other 2 2 0 +2
Total 23 64 45 +19

Review metrics

Metric Value Why it matters
Production versus test delta production -10, tests +10, docs +7, package/boundary metadata +12 The allocation cleanup is net-negative in production code after adding the shared helper; the remaining growth registers its private runtime export and coverage.

Merge-risk options

Maintainer options:

  1. Retain host-version synchronization (recommended)
    Before publishing separately distributed consumers, synchronize their plugin API floors to the first OpenClaw host release that exports blob-runtime.
  2. Accept an explicitly constrained release
    Publish only if release owners document and accept responsibility for preventing installation on older hosts.

Technical review

Best 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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the core multipart audio builder and matching plugin upload owners; the PR supplies an after-fix real OpenAI transcription from an offset WAV buffer plus source-visible File/HTTP multipart tests showing retained snapshot bytes and metadata.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the core multipart audio builder and matching plugin upload owners; the PR supplies an after-fix real OpenAI transcription from an offset WAV buffer plus source-visible File/HTTP multipart tests showing retained snapshot bytes and metadata.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is a bounded memory-allocation improvement without evidence of a user-facing outage.
  • merge-risk: 🚨 compatibility: Future separately published official-plugin builds can import the new host-private subpath and must not target hosts released before it exists.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the core multipart audio builder and matching plugin upload owners; the PR supplies an after-fix real OpenAI transcription from an offset WAV buffer plus source-visible File/HTTP multipart tests showing retained snapshot bytes and metadata.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the core multipart audio builder and matching plugin upload owners; the PR supplies an after-fix real OpenAI transcription from an offset WAV buffer plus source-visible File/HTTP multipart tests showing retained snapshot bytes and metadata.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Retain official-plugin API-floor synchronization when releasing separately published consumers.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-01T11:45:04.264Z sha 93e628f :: needs changes before merge. :: [P1] Migrate OpenAI video-reference uploads to the shared Blob helper
  • reviewed 2026-09-01T11:53:23.346Z sha 93e628f :: found issues before merge. :: [P1] Migrate OpenAI video-reference uploads to the shared Blob helper

@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added channel: line Channel integration: line channel: mattermost Channel integration: mattermost channel: tlon Channel integration: tlon plugin: pixverse labels Sep 1, 2026
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review's OpenAI video finding in 0c9afcb9cea298082459ce75579940914bae3dde: both image-reference and video-edit uploads now use the shared Blob part owner. The existing tests use nonzero-offset Buffers, mutate them after File construction, and verify the snapshotted bytes. The actual video reference owner removes exactly one 32 MiB allocation for a 32 MiB input.

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.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 1, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 1, 2026
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Read the latest completed ClawSweeper review for 0c9afcb9cea298082459ce75579940914bae3dde; its prior OpenAI-video finding is resolved and it reports no remaining code finding.

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.

@steipete
steipete merged commit 5708157 into main Sep 1, 2026
301 checks passed
@steipete
steipete deleted the codex/perf-provider-blob-parts branch September 1, 2026 12:24
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
)

* perf(media): avoid intermediate multipart upload copies

* perf(media): remove remaining upload adapter copies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu channel: line Channel integration: line channel: mattermost Channel integration: mattermost channel: tlon Channel integration: tlon docs Improvements or additions to documentation extensions: clickclack extensions: comfy extensions: deepinfra extensions: litellm extensions: microsoft-foundry extensions: openai extensions: xai maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. plugin: pixverse proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant