Skip to content

@remotion/lambda: Clean up generated site bundles - #9569

Merged
JonnyBurger merged 2 commits into
mainfrom
fix-deploysite-cleanup
Jul 24, 2026
Merged

@remotion/lambda: Clean up generated site bundles#9569
JonnyBurger merged 2 commits into
mainfrom
fix-deploysite-cleanup

Conversation

@samohovets

@samohovets samohovets commented Jul 24, 2026

Copy link
Copy Markdown
Member

Summary

  • capture internally generated deploySite() bundle directories as soon as the bundler creates them
  • wait for concurrent listing, upload, and stale-file deletion work to settle before cleanup
  • clean generated bundles on success and failure while preserving the original deployment error when cleanup also fails
  • add coverage for bundling, listing, upload, deletion, and cleanup failures

Why

deploySite() writes generated bundles to a directory under os.tmpdir(), but this only selects a conventional temporary location. Node.js does not automatically remove directories created there when an operation finishes, the process exits, or an error occurs.

Operating-system cleanup is platform-dependent and may happen only periodically, after a reboot, or not at all. Long-running deployment services, CI workers, and reused containers can therefore accumulate large Remotion bundles and eventually exhaust disk space. This change makes cleanup deterministic once all bundling and deployment work has settled, while leaving caller-owned bundle directories untouched.

Verification

  • bun run build
  • bun run stylecheck
  • bun test packages/lambda/src/test/unit
  • bun test packages/lambda/src/test/unit/wait-for-promises-to-finish.test.ts packages/lambda/src/test/integration/deploy-site.test.ts packages/lambda/src/test/integration/deploy-site-from-bundle.test.ts

Closes #9423

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
bugs Ready Ready Preview, Comment Jul 24, 2026 10:15am
remotion Ready Ready Preview, Comment Jul 24, 2026 10:15am

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.

Reviewed changes — adds lifecycle-aware cleanup of internally generated deploySite() bundle directories, ensuring bundles are removed on both success and failure while letting concurrent listing, upload, and stale-file deletion work settle before cleanup runs.

  • New waitForPromisesToFinish utility — wraps Promise.all and drains remaining promises via Promise.allSettled before rethrowing, so in-flight concurrent work (bundling, listing, uploads, deletions) always settles before the caller proceeds to cleanup.
  • Early onDirectoryCreated capture in deploy-site.ts — records the generated bundle directory via the bundler's existing onDirectoryCreated callback (fired after prepareOutDir creates the directory on disk), so the path is known even if bundling subsequently fails.
  • Discriminated-union deployment outcome in deploy-site.ts.then() maps success/failure of deploySiteWithBundle into {type, result/error} so cleanup always runs synchronously after the deployment settles; throws AggregateError when both deployment and cleanup fail, preserving the deployment error as cause.
  • waitForPromisesToFinish integration in deploy-site-with-bundle.ts — applied to the concurrent listObjects/getBundle pair and to the deleteFile promises, so stale-file deletions and bundling finish before the error (or cleanup) path is reached.
  • try/finally around uploads in upload-dir.ts — ensures clearInterval fires on the progress timer regardless of upload outcome.
  • Comprehensive test coverage — unit test for waitForPromisesToFinish; integration tests for bundling failure, listing failure with pending bundling, upload failure, stale-file deletion failure (verifying the bundle directory survives deletions), successful cleanup, cleanup failure after success, and the dual-failure AggregateError path.

✅ No new issues found.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Claude Opus not used — the program covers this model; add its provider key to run your pick) | 𝕏

@JonnyBurger
JonnyBurger merged commit e5b3bd0 into main Jul 24, 2026
18 checks passed
@JonnyBurger
JonnyBurger deleted the fix-deploysite-cleanup branch July 24, 2026 14:34
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.

@remotion/lambda: Clean generated deploySite() bundles after failures

2 participants