Repository navigation
fix(media-use): remove only the temp folders media-use made, and never fail on cleanup - #8267
Conversation
…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
left a comment
There was a problem hiding this comment.
Requesting changes; details sent to you directly.
eddy-heygen
left a comment
There was a problem hiding this comment.
(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
privateOutputPathstill creates the folder withmkdtemp(unguessable name, owner-only) and records it;discardPrivateOutputacts 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.icoinside 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
left a comment
There was a problem hiding this comment.
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.
discardPrivateOutputacts only on a folder thatprivateOutputPathput inmadeduring this run (private-output.mjs:20). It also removes the entry beforermSync, so a second call is a no-op. This is stricter than the old name match in every case, including aTMPDIRthat ends in slashes. - Cleanup can no longer fail the work. The
rmSyncsits in its owntry, and resolve'sfinally(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-videoandlogoall get their path fromprivateOutputPath. The providers discard on their own failure paths, and resolve discards afterfreezeLocalFile. Before this change, theheygen-videofolder (whose name failed the old[a-z]+pattern) and the logo folder (whose<domain>.iconame failed theoutput.*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
.icorename.extfor the logo comes from the provider result, and the project file is named from the reservation, not the temp file name, sooutput.icochanges 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
0o500wouldn't block removal.
Nit (non-blocking)
- In
faviconSearch, ifwriteFileSyncthrows afterprivateOutputPath(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
left a comment
There was a problem hiding this comment.
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.
What
Follow-up to #8030 (the private output folders for media-use's local generators), covering two non-blocking points from its review.
discardPrivateOutputremoves a folder only whenprivateOutputPathmade 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.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 tooutput.mp4/output.ico; nothing reads those names.TEMPandTMP, which is what the temp folder follows on Windows.Why
From the #8030 review: the cleanup ran in a
finallyafter 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
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'sprivate-output.mjs;heygen-video-provider.test.mjs"downloads a generated avatar video and returns the generated MP4 result" andlogo-provider.test.mjs"faviconSearch hands verified bytes over as a local file" fail against main's providers.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-citationsandcheck-test-reachabilitypass.