Skip to content

@remotion/serverless: Don't merge a chunk twice when a streamed chunk is retried - #12337

Merged
JonnyBurger merged 1 commit into
remotion-dev:mainfrom
parbhatkapila4:fix/streaming-retry-duplicate-chunks
Oct 16, 2026
Merged

JonnyBurger merged 1 commit into
remotion-dev:mainfrom
parbhatkapila4:fix/streaming-retry-duplicate-chunks

Conversation

@parbhatkapila4

Copy link
Copy Markdown
Contributor

When a renderer chunk is retried over response streaming, the retry sends its audio and video chunks again, and each name gets pushed into the same files list. If the first attempt got its audio chunk through before failing (say a socket hang up while the video chunk is still streaming), files ends up with that audio file twice. concatVideos() passes the list straight to the ffmpeg concat step, so the merged audio contains that chunk twice and everything after it is out of sync. Same for the video file if the stream drops after both were sent.

Both retry layers hit this: renderRendererFunctionWithRetry() reuses files, and callFunctionWithStreamingImplementation() retries with the same message handler.

Chunk file names are fixed per chunk, so the retry already overwrites the same file on disk. The fix just skips a name that's already in the list.

Added a test next to the artifact replay one: the first attempt sends the audio chunk and fails with a socket hang up, the second sends everything, and files has each chunk once.

Related but not in this PR: if the stream drops after chunk-complete, the chunk gets retried even though it finished, and its timing is counted twice in the cost estimate. Happy to send that separately.

@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
bugs Ready Ready Preview Oct 16, 2026 10:06am UTC
remotion Ready Ready Preview Oct 16, 2026 10:06am UTC

Request Review

@pullfrog pullfrog Bot left a comment

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.

✅ No new issues found.

Reviewed changes

  • Dedup files on retried streaming chunks — stream-renderer.ts:124-126 and stream-renderer.ts:147-149 now guard files.push(filename) with !files.includes(filename), so a retried chunk that re-sends its audio/video payload off the response stream is only merged once. Filenames are derived from outdir + the padded chunk index (chunkFilename), so the key is stable across attempts and unique per chunk.
  • Regression test — streaming-renderer-launcher.test.ts:147 reproduces the exact scenario (audio chunk lands on attempt 1, then socket hang up), retries, and asserts files equals ['…:audio', '…:video']. The test fails without the source change ([audio, audio, video]), so it genuinely covers the bug.

Both retry layers are covered by the single guard: the outer renderRendererFunctionWithRetry reuses files, and the inner callFunctionWithStreamingImplementation retry (lambda-client/src/call-lambda-streaming.ts:244) re-invokes through the same receivedStreamingPayload closure, which mutates the same files array. The rewrite-on-disk behavior (either writeFileSync overwrite or the getBinaryPayloadSink createWriteStream truncating) means the dropped duplicate stays correct.

The s3Renderer path is unaffected — it only pushes at status.state === 'completed' immediately before returning success, which ends the retry loop, so a chunk can never be pushed twice there.

The author's noted follow-up (a stream drop after chunk-complete retrying a finished chunk and double-counting its timing via addChunkCompleted) is pre-existing and out of scope for this change.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash | 𝕏

@JonnyBurger

Copy link
Copy Markdown
Member

Thanks!

@JonnyBurger
JonnyBurger merged commit 238facb into remotion-dev:main Oct 16, 2026
20 checks passed

This branch was successfully deployed

2 active deployments
Preview – remotion — da61ca51 Deployed Oct 16, 2026 by vercel[bot]
Preview – bugs — da61ca51 Deployed Oct 16, 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.

2 participants