Repository navigation
fix(media-use): dither stages its output in a fresh folder beside the output - #8599
Merged
Merged
Conversation
… output The encode used to go to a name built from the output name and the process id, which a folder could already hold. It now goes into a newly made private folder beside the output, the way transcript-cut does, and only the finished file is moved onto the output path.
…s no folder behind A video encode whose ffmpeg can't start now fails through the normal error path, so the staging folder is removed. Removal retries briefly while ffmpeg still holds the file on Windows. The test also keeps a link at the output path and shows the script's own error when it fails.
eddy-heygen
approved these changes
Nov 23, 2026
eddy-heygen
left a comment
There was a problem hiding this comment.
(Eddy's agent) Reviewed by Eddy's Claude agent at commit 3ae96d6 (full diff read: 3 files, +68/-16)
Verdict: approve
Summary: dither.mjs no longer encodes to a sibling file named after the process id. Both the image and the video path now create a fresh folder beside the output with mkdtempSync, encode to out<ext> inside it, rename that file onto the output, and remove the folder. A name that project content could have placed in advance is no longer written to.
What I checked
privateStagingOutput: the folder name ends in a random suffix chosen at creation, and creation fails if the name exists, so nothing can sit at the staging path before the encoder opens it. The folder is in the output's own directory, so the final rename stays on one filesystem.processImageandprocessVideoboth passstaging.fileto the encoder and rename only that file. The oldtemporaryOutputhelper has no caller left and is removed.- The rename replaces whatever is at the output path itself rather than writing through it; the new tests place a link there too and check its target is not created.
- Cleanup: both paths remove the staging folder in
finally, on success and on failure. - Missing encoder binary in the video path: the two
once(..., "close")promises reject on the child'serrorevent; the added no-opcatchhandlers keep that from surfacing as an unhandled rejection before thetryblock awaits them, so the run ends through the normal error path and the folder is removed. I read this; no test covers it. skills-manifest.json: only themedia-usehash changes, andSkills: manifest in syncpasses.
Non-blockers
- A run that is killed (not failed) leaves a
.media-use-dither-*folder beside the output. Harmless, but it is a hidden folder in the user's project; a note in the skill's docs or a sweep of old ones at start would cover it. - In
processVideothe folder is created a few statements before thetry. A synchronous throw fromspawnin between would skip the cleanup. Moving thetryup, or creating the folder as its first statement, closes that. - The two new tests are skipped on Windows, so the Windows path is covered by reading only.
CI: 28 passing, 34 skipped, none failing or pending when I looked. I read the Test: skills log: it installs the encoder, and both new tests ran and passed there (image and video), 878 of 879 passing with 1 unrelated skip.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
dither.mjs(media-use) now writes its encode into a fresh private folder beside the output, then moves the finished file onto the output path. Before, it wrote to<output name>.part-<process id><ext>next to the output.Why
That old name could already exist in a project folder someone else made, for example as a link to a file elsewhere on the machine.
ffmpeg -yfollows a link at its output path, so dithering that project's media would overwrite the file the link points at, and the run would still report success. A folder made fresh for each run can't hold anything beforehand.Related work
Same approach as
transcript-cut.mjs, which already stages its encode in a fresh folder beside the output.How
privateStagingOutput(outPath)makes the folder withmkdtempSync(join(dirname(outPath), ".media-use-dither-"))and returns it with the file path inside it.renameSyncthe result onto the output, and remove the folder infinally. The folder sits beside the output, so the rename stays on one drive.{"ok":false,"error":"spawn ffmpeg ENOENT"}) instead of crashing, and the folder is removed. The removal retries briefly, since on Windows ffmpeg may still hold the file for a moment.Test plan
Unit tests added/updated
Manual testing performed
Documentation updated (if applicable)
Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug
Fails without the fix: two new tests in
skills/media-use/scripts/dither.test.mjs(image and video). Each starts the script, puts a link at the old<output name>.part-<pid><ext>name for that run, and checks that the link's target is never created, the output is a regular file, and no staging folder is left. The tests also keep a link at the output path itself, which is replaced by the finished file, and its target is never created. Both fail on main and pass here.All media-use tests, run the CI way: 323 pass, 0 fail, 1 skipped.
By hand: with
ffprobeon the PATH but noffmpeg, a video run prints the error above and leaves only the input in the folder. Main crashes there.oxlint, oxfmt, lint-skills and the comment ratchet pass.
No visible change
The output file and the script's messages are the same.