Repository navigation
perf: reuse owned provider response buffers - #135014
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Requesting the initial pre-merge review for |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 5:00 AM ET / 09:00 UTC. ClawSweeper reviewWhat this changesThe branch changes the shared provider binary reader to declare its existing Buffer result and removes redundant full-response copies from speech, music, and video downloads. Merge readinessThis maintainer-authored PR should remain open for normal maintainer handling. The bounded reader already creates the owned Buffer and the introduced callers retain its validation and transport-release boundary; no blocking defect was found. Likely related people: steipete (recent shared-HTTP contributor, medium confidence) and Dallin Romney (bounded-response consolidation contributor, low confidence). Priority: P3 Review scores
Verification
How this fits togetherProvider and plugin HTTP responses pass through a bounded binary reader before speech, music, and video features return downloaded bytes. The reader validates the response and produces an owned buffer that downstream features consume and release their transport around. flowchart LR
A[Provider HTTP response] --> B[Bounded binary reader]
B --> C[Content and size validation]
C --> D[Owned response buffer]
D --> E[Speech synthesis]
D --> F[Music and video downloads]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -16, Tests -35. Total -51 across 13 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one canonical owned Buffer at the bounded-reader boundary and merge the direct-return callers after ordinary exact-head checks confirm the intended public SDK declaration. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a performance and type-accuracy change rather than a report of broken behavior. Source inspection establishes the redundant copy and unchanged reader boundary. Is this the best way to solve the issue? Yes: exposing the concrete Buffer produced by the canonical bounded reader removes the copies at their consumers without duplicating validation or lifecycle policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ce872444b9fe. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Completed maintainer review, including the declared SDK return type. Retaining the Buffer declaration is intentional: the bounded reader already returns an owned Buffer, and Buffer is assignable to Uint8Array, so existing consumers retain their result contract. Returning the wider annotation would hide that ownership and keep the unnecessary consumer copies. Typed mocks returning generic Uint8Array may need correction; the affected in-tree fixtures now use the real reader instead of a divergent substitute. No compatibility wrapper is needed for real consumers. The current head has green CI and completed native preparation. Owner/sibling tests, the actual 32 MiB HTTP asset probes, the real OpenAI WAV request, the full build and changed checks passed. There are no requested repair findings beyond the type decision and normal maintainer handling addressed here. |
|
Merged via squash.
|
* perf(media): return owned provider response buffers * test(tts): use real binary readers in provider fixtures
What Problem This Solves
The bounded provider response reader already returns an owned Buffer, but its Uint8Array return type hid that fact. Speech and generated-media callers consequently copied the complete response with Buffer.from before returning it.
Why This Change Was Made
Preserve Buffer in the shared reader's return type and return those already-owned bytes directly from all affected buffered speech, video and music callers. The transport is still released only after the read completes; content-type, empty-body, timeout and size-limit behavior stays at the shared reader.
The OpenAI-compatible speech tests, including the DeepInfra and OpenRouter factories, also contained handwritten binary-reader replacements that returned a different runtime type. They now use the real reader, deleting those duplicate implementations while preserving byte, request-header and transport-release assertions.
User Impact
Buffered speech and generated-media downloads avoid an additional response-sized allocation and copy. The public helper already returned Buffer at runtime, so Uint8Array consumers remain compatible. Production LOC +32/-48 (net -16).
Evidence
check-changedpassed, including core and plugin typechecks, lint and guards. Fullpnpm buildpassed, including generated SDK declarations and built plugin checks.