Skip to content

fix(media-use): remove only the temp folders media-use made, and never fail on cleanup - #8267

Merged
ukimsanov merged 3 commits into
mainfrom
fix/media-use-cleanup-best-effort
Nov 20, 2026
Merged

ukimsanov merged 3 commits into
mainfrom
fix/media-use-cleanup-best-effort

Conversation

@ukimsanov

@ukimsanov ukimsanov commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

Follow-up to #8030 (the private output folders for media-use's local generators), covering two non-blocking points from its review.

  • discardPrivateOutput removes a folder only when privateOutputPath made it in this run (a module-level set), instead of recognising folders by name and by comparing against the raw temp setting. A temp setting that ends in extra slashes no longer leaves every folder behind, and a folder named like ours that this run did not make is never touched.
  • The removal is best-effort. A folder that will not go (for example a file still locked on Windows) stays behind instead of turning a finished resolve or a failed generation into a cleanup error.
  • The hosted video provider and the favicon logo provider already used mkdtemp, but resolve never removed their folders. They now use the same helper, so resolve removes them after copying the file into the project. Their file names change to output.mp4 / output.ico; nothing reads those names.
  • Tests no longer leave real folders in the machine's temp folder: the ltx and mflux provider tests use their own temp folder, and the favicon tests remove theirs. The resolve cleanup test also redirects TEMP and TMP, which is what the temp folder follows on Windows.

Why

From the #8030 review: the cleanup ran in a finally after the file was already copied, so a removal error would have failed a resolve that worked; ownership was inferred from the path, so some setups never cleaned up; and two providers' folders were never removed.

Not in this PR: the review's other point, about how older Codex CLI versions read project_root_markers, which needs a check against the external CLI.

Test plan

  • fails without the fix: private-output.test.mjs "discarding leaves a folder named like a generator's that this run did not make", "a temp setting that ends in extra slashes still gets its folder removed" and "a folder that cannot be removed does not make discarding throw" fail against main's private-output.mjs; heygen-video-provider.test.mjs "downloads a generated avatar video and returns the generated MP4 result" and logo-provider.test.mjs "faviconSearch hands verified bytes over as a local file" fail against main's providers.
  • With the temp folder pointed at an empty folder, a full media-use test run leaves no media-use-{codex,mflux,ltx,kokoro,heygen-video,logo}-* folders (before: 5 ltx, 4 mflux, 2 logo).
  • packages/cli/src/media-use: 419 tests pass. oxlint, oxfmt, fallow, the comment ratchet, check-comment-citations and check-test-reachability pass.
  • Unit tests added/updated
  • Manual testing performed (cleanup only)
  • Documentation updated (if applicable): not applicable
  • Comments follow CONTRIBUTING.md "Comments"

…r fail on cleanup

discardPrivateOutput now removes a folder only if privateOutputPath made it in this
run, instead of matching names against the raw temp setting, and a removal error no
longer turns a finished or failed generation into a cleanup error. The hosted video
and favicon providers use the same helper, so resolve removes their folders too.
Provider tests remove the folders they create; the resolve test also redirects
TEMP and TMP, so it checks the cleanup on Windows as well.

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Requesting changes; details sent to you directly.

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(Eddy's agent) Reviewed by Eddy's Claude agent at commit d40dc6a (non-test diff read by me).

Verdict: approve.

Summary
Cleanup of a generator's private temp folder used to recognise "its own" folder by the shape of the path. It now removes only folders this run created, tracked in a set, and a failed removal no longer turns into an error. The hosted-video and favicon providers use the same helper, so their temp folders are removed too.

What I checked

  • privateOutputPath still creates the folder with mkdtemp (unguessable name, owner-only) and records it; discardPrivateOutput acts only when the path's folder is in that record, and removes the record entry first, so a second call is a no-op.
  • A path the run did not create is left alone whatever it looks like, which is stricter than the old pattern match.
  • The removal is wrapped so a folder that will not go stays behind, still owner-only, without failing the generation.
  • The two providers no longer build temp paths themselves. The favicon file is now named output.ico inside its private folder instead of carrying the domain in its name.

Non-blockers

  • The record lives in the process, so a folder from a run that was killed is not cleaned by a later run; it stays owner-only.

CI: 55 pass, 15 skipped, none failing or pending.

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review at d40dc6a4. I read every non-test change and the new tests. Eddy's approval covers the helper and the two providers, so this adds the call sites and the test claims.

Strengths

  • Ownership is known, not guessed. discardPrivateOutput acts only on a folder that privateOutputPath put in made during this run (private-output.mjs:20). It also removes the entry before rmSync, so a second call is a no-op. This is stricter than the old name match in every case, including a TMPDIR that ends in slashes.
  • Cleanup can no longer fail the work. The rmSync sits in its own try, and resolve's finally (resolve.mjs:586-588) still runs after the copy, so a folder that won't go can't turn a finished resolve into an error.

Checked

  • Every caller of the helper. codex, ltx, mflux, kokoro, heygen-video and logo all get their path from privateOutputPath. The providers discard on their own failure paths, and resolve discards after freezeLocalFile. Before this change, the heygen-video folder (whose name failed the old [a-z]+ pattern) and the logo folder (whose <domain>.ico name failed the output.* check) were never removed. Now resolve removes both.
  • A provider file the run didn't make, such as a bundled SFX path, isn't in made, so it's left alone. The new "named like a generator's" test pins that.
  • The .ico rename. ext for the logo comes from the provider result, and the project file is named from the reservation, not the temp file name, so output.ico changes nothing a person sees.
  • The test claims in the body match the diff. The unremovable-folder test is skipped on Windows and under root, where 0o500 wouldn't block removal.

Nit (non-blocking)

  • In faviconSearch, if writeFileSync throws after privateOutputPath (logo-provider.mjs:236-237), the empty folder stays behind, because nothing discards it on that path. It's owner-only and empty, so it's cosmetic.

Merge: the base is main and it merges cleanly.

CI: all 70 checks at d40dc6a4 have finished: 55 passed, 15 skipped, none failed or pending.

Earlier review from this account: the changes-requested review at this head has no finding attached. Its origin is being confirmed before it's replaced, so this is posted as a comment rather than an approval.

Verdict: COMMENT
Reasoning: I found no blocker, and every check is green. I'll approve once the earlier changes-requested review from this account is accounted for.

@miguel-heygen
miguel-heygen dismissed their stale review November 20, 2026 05:37

reworded, thanks

@miguel-heygen miguel-heygen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving at 2487cc86. Since my review at d40dc6a4, the only code change is the renamed variable in private-output.test.mjs:66-73. The test's setup and assertion are the same. The earlier changes-requested review was about the description's wording. It is dismissed, and the reworded description is in place. Eddy's approval at d40dc6a4 covers the helper and the two providers. My earlier review covers the call sites.

Merge: the base is main, the PR merges cleanly, and it isn't a draft.

CI: every check at 2487cc86 has finished, with none failed and none pending. One Studio and player captures run was cancelled when a newer run started, and that newer run passed.

Verdict: APPROVE
Reasoning: Cleanup now removes only the temp folders this run made and never fails the call. The new commit only renames a test variable, and every check is green.

@ukimsanov
ukimsanov added this pull request to the merge queue Nov 20, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 20, 2026
@ukimsanov
ukimsanov added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit e16c681 Nov 20, 2026
116 of 117 checks passed
@ukimsanov
ukimsanov deleted the fix/media-use-cleanup-best-effort branch November 20, 2026 06:47
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.

3 participants