Repository navigation
fix(tts): reject non-audio speech synthesis responses - #117345
Conversation
A successful HTTP 200 carrying a JSON error, an HTML sign-in page, or a zero-byte body was returned as an audio buffer and written out as a playable attachment. Route the xAI, Gradium, and Azure Speech synthesizers through the shared binary-response contract that the OpenAI-compatible speech provider already uses, so the media kind is validated before the body is read and the unread body is canceled when it is rejected. Each provider keeps its own overflow wording, so operator-facing messages are unchanged apart from the new malformed-response rejection.
|
The single red here is No rule is reported and no file is named; exit 143 is SIGTERM. The same job failed identically on #117345's sibling PR (#117339) in a separate workflow run at roughly the same time, so it looks like runner capacity rather than either branch. Everything else on this head is green (44 success / 0 genuine failures), and I re-checked the two lanes that could plausibly be mine, locally: A rerun should clear it; let me know if you'd rather I push to trigger one. |
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 7:03 PM ET / 23:03 UTC. ClawSweeper reviewWhat this changesThe PR makes Azure Speech, Gradium, OpenAI, and xAI TTS reject successful non-audio or empty HTTP responses instead of returning corrupt audio buffers. Merge readinessKeep this PR open for normal maintainer landing: current main still accepts successful JSON, HTML, and empty bodies as TTS audio in all four affected raw-binary providers, while the branch applies the existing shared response contract at each provider-owned boundary with focused coverage and real-socket proof. Priority: P2 Review scores
Verification
How this fits togetherBundled TTS plugins make authenticated speech requests, validate and consume their provider HTTP responses, then return audio to the agent or channel workflow. This patch acts at the provider response boundary before malformed bytes can be delivered as an audio attachment. flowchart LR
A[Speech request] --> B[Bundled TTS provider]
B --> C[Provider HTTP response]
C --> D[Status and binary validation]
D -->|valid nonempty audio| E[Bounded body read]
D -->|non-audio response| F[Cancel unread body]
E --> G[Audio returned to caller]
F --> H[Actionable provider error]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +54, Tests +174. Total +228 across 8 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Merge the consistent provider-owned binary-response validation after the exact-head build and lint checks complete; keep the current shared helper contract and each plugin’s existing overflow wording. Do we have a high-confidence way to reproduce the issue? Yes: current main visibly reads successful response bytes after only an HTTP-status check, and the shared binary-response contract establishes the missing rejection behavior. The PR additionally supplies a real localhost socket test for the Azure owner boundary. Is this the best way to solve the issue? Yes: applying the existing shared contract at each raw-binary provider owner is the narrowest maintainable repair, retains provider-specific overflow messages, and avoids inventing a parallel abstraction or new configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against eb8c22ed13f9. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
On the real-behavior gate: I tried to build the same loopback proof I added to the sibling PR (#117339), and I could not get one that is honest for these three owners. Rather than ship a weaker harness and call it real, here is exactly what blocks it and what I think stands in its place. What worked on the sibling PR. #117339 now carries a real-socket run: a Why the same harness cannot reach these three. Each owner blocks the loopback for a different reason, measured rather than assumed:
Unlike What I can offer instead. The tests here do drive the real owner functions end to end and assert on real If a live-provider capture is required regardless, that needs xAI, Gradium and Azure Speech credentials plus a way to make each return a successful non-audio body, which I cannot produce from outside. I am happy to add anything reachable that would close this — including a real-TLS loopback if you would accept a self-signed certificate in the test, or a seam if you would rather have one. |
Adds a loopback node:http server that answers 200 with a JSON content type and then never ends the body, driven through the real azureSpeechTTS path with the real global fetch and no stubbed transport. Without the guard the synthesis hangs to its timeout with the socket still open; with it the response is rejected immediately and the server observes the close.
|
Real behavior proof added in
The close is asserted server-side ( The same control run exposes the other half of the defect. With the guard removed the three mocked malformed cases stop throwing and resolve instead:
Command: On the second listed merge risk: the loopback run covers one changed owner end to end with a genuine stream, which is what the cancellation and release path needed. xAI and Gradium keep mocked-fetch coverage and share the identical boundary shape; if you would rather have the same loopback case duplicated for those two, say so and I will add it. Suites on this head: azure-speech |
|
Maintainer exact-head verification:
Detailed before/after matrix and provider-proof boundaries are recorded in the updated PR body. |
|
Merged via squash.
|
* fix(tts): reject non-audio speech synthesis responses A successful HTTP 200 carrying a JSON error, an HTML sign-in page, or a zero-byte body was returned as an audio buffer and written out as a playable attachment. Route the xAI, Gradium, and Azure Speech synthesizers through the shared binary-response contract that the OpenAI-compatible speech provider already uses, so the media kind is validated before the body is read and the unread body is canceled when it is rejected. Each provider keeps its own overflow wording, so operator-facing messages are unchanged apart from the new malformed-response rejection. * test(azure-speech): prove the audio guard closes a real upstream socket Adds a loopback node:http server that answers 200 with a JSON content type and then never ends the body, driven through the real azureSpeechTTS path with the real global fetch and no stubbed transport. Without the guard the synthesis hangs to its timeout with the socket still open; with it the response is rejected immediately and the server observes the close. * fix(openai): reject malformed binary speech responses --------- Co-authored-by: Peter Steinberger <[email protected]>
Related: #117339
Related: #117227
AI-assisted (Claude Code). I ran every measurement below myself; the mutation runs are reproducible with the commands shown.
What Problem This Solves
Fixes an issue where users generating speech through xAI, Gradium, Azure Speech, or OpenAI would receive a corrupt audio attachment instead of an error when the provider answered with HTTP 200 but a non-audio body.
A successful-status JSON error, an HTML sign-in or captcha page, or a zero-byte response was read straight into the buffer and delivered as playable audio. The user gets a file that will not play, and the provider's actual error message is discarded.
Why This Change Was Made
The repository already owns this contract, and one speech path already uses it:
src/tts/openai-compatible-speech-provider.ts:399reads its audio throughreadProviderBinaryResponse(..., "audio"). The four affected bundled raw-binary synthesizers were never migrated, so whether a malformed 200 was caught depended on which provider a user routed through — OpenAI-compatible speech was guarded, while native xAI, Gradium, Azure Speech, and OpenAI were not.This applies the split form (
assertProviderBinaryResponseContent+readResponseWithLimit) rather thanreadProviderBinaryResponse, because the combined helper hardcodes its ownonOverflowafter spreading caller options and would therefore change each provider's existing byte-cap message. Keeping the split form preserves<Provider> TTS audio response exceeds N bytesexactly as it is today. The same reasoning is whyextensions/byteplusandextensions/runwayuse the split form on the video side.Cancellation uses
void ... .catch(() => undefined)rather thanawait, matchingextensions/google/video-generation-provider.ts:241-243andsrc/infra/net/fetch-guard.ts: under debug-proxy capture the body is one branch of aResponse.clone()tee, and persrc/proxy-capture/runtime.ts:41-46cancelling such a branch never settles while its sibling is live.extensions/openai/tts.tscarried the same defect and is now included in a separately attributed maintainer follow-up commit. #117227 changes only the OpenAI video-generation provider and its test, so its file ownership does not overlap the OpenAI TTS owner or test here.User Impact
A malformed synthesis response now fails with
<Provider> TTS API error: malformed audio responseinstead of producing an unplayable file, and the upstream socket is closed rather than left open until GC.Evidence
Original contributor validation at historical head
1450696a8f1:The added tests are load-bearing, verified by mutation. Reverting only the production files to
mainturns exactly the new cases red, in two runs (vitest splits these across projects, so they are measured separately):npx oxlintis clean on all six changed files.Real behavior proof: a real socket, a real never-ending response, no mocks
Added in
91b601ff667after the review asked for evidence beyond mocked transports.extensions/azure-speech/tts.test.tsstarts a realnode:httpserver on127.0.0.1that answers200withcontent-type: application/jsonand then never ends the body, then calls the realazureSpeechTTSagainst it throughendpoint— real globalfetch, real SSRF guard, real socket,no
vi.stubGlobal, no provider account. Only the guard differs between the two runs:mainbehaviour)request timed out— synthesis hangs to its deadline with the socket still openAzure Speech TTS API error: malformed audio response, and the server observes its socket closeThe close is asserted on the server side (
request.socket.once("close", ...)raced against a 250 msdeadline), so the pass is the operating system reporting the connection gone, not the client claiming
it cancelled.
The same control run also shows the defect's other half in its rawest form. With the guard removed,
the three mocked malformed cases stop throwing and instead resolve:
123, 34, 101, 114, 114is{"errand60, 104, 116, 109, 108is<html— the provider's JSON errorand its HTML sign-in page, handed back as the audio buffer that a channel then delivers as a voice
message.
Command:
node scripts/run-vitest.mjs run extensions/azure-speech/tts.test.ts --reporter=verboseProof boundary: xAI and Gradium remain covered through their focused provider-owner tests because their provider network/hostname policies intentionally reject loopback. Azure Speech and OpenAI are each covered end to end with real localhost HTTP, real global
fetch, their real SSRF guards, and synthetic credentials as detailed below. No hosted provider account was used.Maintainer complete-owner verification (exact head
97b84c2c8e95b4be937274631708f5d095219c07)Preserved both original @Yigtwxx commits
1450696a8f1bcc94289c72fea351bf308e4bbca6and91b601ff667a6e6beaa8f476451ca09edc34c297with their exact original author/date; one separately Peter-authored commit adds onlyextensions/openai/tts.tsand its existing focused test.Audited all eight bundled TTS owners: ElevenLabs and Fish Audio already use the canonical binary-response contract; Inworld and Volcengine intentionally consume JSON/base64-framed audio rather than raw audio; Azure Speech, Gradium, xAI, and OpenAI are the complete four-owner raw-binary gap fixed here.
Drove actual Azure Speech and OpenAI production owner functions separately against a real
node:httplocalhost server using real globalfetch, their actual SSRF guards, actual synthetic credential transmission, and real TCP connections—14 real authenticated HTTP requests per run, no mocked fetch/time/transport. Untouched currentmainaccepted all eight malformed successful responses as supposed audio: JSON,application/problem+json, HTML, and zero-byte audio for each owner. Exact PR head rejects all eight with the owner-specific visiblemalformed audio responseerror. Both owners preserve a genuine 204-byte RIFF/WAVE response withaudio/wav, the OpenAI SDK's explicitly supportedapplication/octet-stream, and an absentContent-Type; all real sockets are released.Focused exact-owner test command:
The existing Azure never-ending-body test also proves operating-system-observed real upstream socket closure. Existing focused cases preserve provider-specific exact overflow messages, non-2xx HTTP diagnostics, OpenAI debug capture, bounded body reads, and dispatcher release. Cancellation remains fire-and-forget because awaiting one branch of a debug-capture
Response.clone()tee can deadlock.Direct installed official OpenAI SDK
openai/src/resources/audio/speech.tssendsAccept: application/octet-stream, marks__binaryResponse: true, and documents MP3/Opus/AAC/FLAC/WAV/PCM; official API contract: https://platform.openai.com/docs/api-reference/audio/createSpeech . Fresh full four-provider Codex Sol xhigh structured review: clean (0.99). Exact-head Workflow Sanity 30722198801: success; full CI attachment tracked separately.