Skip to content

fix(media-server): preserve audio output and report stream failures - #2882

Open
yashranaway wants to merge 2 commits into
CapSoftware:mainfrom
yashranaway:fix/media-server-process-failure
Open

yashranaway wants to merge 2 commits into
CapSoftware:mainfrom
yashranaway:fix/media-server-process-failure

Conversation

@yashranaway

@yashranaway yashranaway commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

the media server's streaming audio extract cleaned up as soon as ffmpeg exited, which cancelled stdout even if the client hadn't read the last chunks yet. a slow consumer could get truncated or empty audio, and because the exit code was ignored, an ffmpeg failure or a timeout just looked like a short successful stream.

now a clean exit leaves stdout to drain fully before closing, and a non zero exit or a timeout errors the stream instead. the integration tests run real ffmpeg with a slow reader and a failing input.

RetriggerView in GreptileConfidence Score: 4/5

Fix successful cleanup before merging; slow readers can still lose audio and receive a cancellation error.

Findings

  1. P1 Successful audio streams fail ▶
Fix with agent prompt
### Issue 1
apps/media-server/src/lib/media-audio.ts:407
`cleanup()` now errors the stream even after a successful extraction. With `highWaterMark: 4`, `pull()` can reach stdout EOF while chunks remain queued for a slow reader. `controller.close()` waits for those chunks to drain, but the following `cleanup()` calls `error()`, discarding them and rejecting the reader with `Audio extraction cancelled`.

Separate successful cleanup from cancellation, and add a test that pauses between reads through EOF.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR keeps stdout available after FFmpeg exits successfully and reports nonzero exits and timeouts as stream errors.

  • Streamed audio responses keep their output and report FFmpeg failures.

Reviews (1) · Last reviewed commit: "fix(media-server): preserve audio output..." · Reviewed by Greptile

@yashranaway

Copy link
Copy Markdown
Contributor Author

@greptileai review

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Oct 22, 2026 8:37am UTC

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 22, 2026 07:18 Inactive
const cleanup = (error = new Error("Audio extraction cancelled")) => {
if (cleaned) return;
cleaned = true;
streamController?.error(error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Successful audio streams fail

cleanup() now errors the stream even after a successful extraction. With highWaterMark: 4, pull() can reach stdout EOF while chunks remain queued for a slow reader. controller.close() waits for those chunks to drain, but the following cleanup() calls error(), discarding them and rejecting the reader with Audio extraction cancelled.

Separate successful cleanup from cancellation, and add a test that pauses between reads through EOF.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/media-server/src/lib/media-audio.ts
Line: 407

Comment:
**Successful audio streams fail**

`cleanup()` now errors the stream even after a successful extraction. With `highWaterMark: 4`, `pull()` can reach stdout EOF while chunks remain queued for a slow reader. `controller.close()` waits for those chunks to drain, but the following `cleanup()` calls `error()`, discarding them and rejecting the reader with `Audio extraction cancelled`.

Separate successful cleanup from cancellation, and add a test that pauses between reads through EOF.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, that was a real regression. A clean EOF now just closes the stream so the queued audio still reaches the reader, and only cancel, timeout or an ffmpeg failure errors it. Added a test that reads slowly through EOF and checks the full output, it failed before the fix (024bb01).

@vercel
vercel Bot temporarily deployed to Preview – cap-status October 22, 2026 08:37 Inactive

This branch was previously deployed

1 inactive deployment
Preview – cap-status — 024bb01a Deployed Oct 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant