Skip to content

fix(engine,cli,producer): ffmpeg reading project media runs from an empty folder - #8832

Merged
vanceingalls merged 3 commits into
mainfrom
11-24-ffmpeg_neutral_working_dir
Nov 25, 2026
Merged

vanceingalls merged 3 commits into
mainfrom
11-24-ffmpeg_neutral_working_dir

Conversation

@vanceingalls

@vanceingalls vanceingalls commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What

ffmpeg and ffprobe that read project media now run from an empty temporary folder, not the caller's working directory.

Why

ffmpeg opens some names as written, rather than joined to the folder of the file that names them. It resolves those names against its own working directory. That directory was inherited from the caller, which is often the project folder. Running from an empty folder means such a name finds nothing there.

Related work

This follows #8827, which made the playlist walk treat these names as leaving their folder. That PR makes the walk refuse them; this one makes sure the working directory they resolve against holds nothing.

How

  • @hyperframes/parsers/ff-binaries adds fromEmptyFolder(work), an AsyncLocalStorage scope, and ffmpegCwd().
    • ffmpegCwd() returns one empty mkdtemp folder per process inside the scope, and undefined outside it.
    • The folder is re-created if a tmp cleaner removes it, and removed on exit.
  • These spawners pass cwd: ffmpegCwd():
    • engine runFfmpeg
    • engine ffprobe
    • the streaming encoder
    • the audio pad/trim probe
    • CLI runFfmpegOnce
    • the snapshot and held-video probes
    • the audio decode
  • Outside a scope nothing changes, so library callers that pass relative paths keep working.
  • These entries opt in. Each one resolves its own path arguments first.
    • Producer executeRenderJob. Every local render goes through it: CLI render (received projects included), the studio server, and the producer server. Desktop runs the CLI.
    • CLI --start/--end renders through renderSpan.
    • The compile worker thread. The scope's store does not cross threads, so the parent passes emptyFolder in workerData and the worker re-enters the scope.
    • CLI captureSnapshots. It also resolves against.
    • CLI describeProject and heardClips.
    • The check command's project-media inspection. This covers both HDR and audio.
  • Measure's guarded reads, of a file a composition names, always run from the empty folder, with the file resolved first.
  • The video frame extractor and the animated-GIF/HEIF prep resolve the configured cache folder, so a relative HYPERFRAMES_EXTRACT_CACHE_DIR still works inside a render.

Size budget

@hyperframes/producer's unpacked budget goes up from 3702639 to 3740484 bytes. main packs to 3738858 bytes, 807 under the 1% ceiling, and the scope's wrappers add 1626 bytes across the producer's bundles. Its dependencies stay external, so nothing new is bundled.

Not covered (these keep the inherited working directory)

  • Distributed and cloud entries: renderChunk, assemble, plan, buildAudioSidecar. They run on Lambda or GCP from absolute /tmp paths, and their working directory is the task root, which holds no project content.
  • CLI commands that read files the user names, not composition media: measure on unguarded input, background removal, and grade-compare.

Test plan

  • Unit tests added/updated
    • runFfmpeg.windowsHide.test.ts: runFfmpeg and runFfprobe spawn with no cwd outside the scope, and inside fromEmptyFolder with an existing empty folder that is not process.cwd().
      • Fails without the fix: cwd is undefined inside the scope.
    • renderOrchestrator.emptyFolder.test.ts: inside executeRenderJob, the compile stage sees ffmpegCwd() as an empty folder, and it is undefined again afterwards.
      • Fails without the opt-in: expected undefined to be defined. I checked this by removing the wrapper.
  • Locally, with 2 workers:
    • engine runFfmpeg, ffprobe, config and videoFrameExtractor
    • CLI measure, snapshot, check, audio, timeline and capture (1508 passed). The only failures are 2 Chromium WebGL tests: the local headless browser has no WebGL context, so they fail regardless of this change.
    • producer renderOrchestrator*, captureHdr* and the bun-run media prep tests
    • tsc for parsers, engine, cli and producer
    • bun run lint and the comment ratchet
  • Manual testing performed. The Linux branch, where a render's work folder sits beside the output, is first exercised by ubuntu CI.
  • Documentation updated (if applicable): no user-visible behaviour change.
  • Comments follow CONTRIBUTING.md "Comments"

🤖 Generated with Claude Code

vanceingalls and others added 3 commits November 25, 2026 00:28
…mpty folder

ffmpeg opens some names as written and resolves them against its working
directory, which was the caller's, often a project folder. Inside
`fromEmptyFolder` (@hyperframes/parsers/ff-binaries), ffmpeg and ffprobe
spawned by the engine and by the CLI's media readers run from one empty
temporary folder per process; outside it they keep the caller's folder.

Each entry that opts in resolves its own paths first:
- producer executeRenderJob (every local render: CLI render, studio
  server, producer server)
- CLI captureSnapshots, describeProject, heardClips, and the check
  command's project-media inspection

The guarded measure reads of a file a composition names also run from it,
with the file resolved first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er and span renders

The compile worker runs on its own thread, where the scope's store does
not reach, so the parent passes whether it is inside one. A `--start/--end`
render goes through renderSpan, now inside the scope with its paths
resolved. The animated-GIF/HEIF cache folder is resolved like the frame
cache, and the streaming encoder and audio pad/trim probe spawn from the
scope's folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cope's wrappers

main packs to 3738858 bytes, 807 under the 1% ceiling; the scope's
wrappers add 1626 bytes across the producer's bundles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 58 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

Unstable (1)

  • seqab-none-center-r0-root-z100: tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.03, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

@jrusso1020 jrusso1020 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 3ccef59b: APPROVE.

  • Delta since 1b1f16ba: one commit that only touches scripts/package-size-budgets.json. It raises the producer's unpacked budget from 3702639 to 3740484 bytes; its packed budget stays 1065767. That is about 1.6 KB for the new wrappers over main's 3738858 bytes. No code changes.

What I checked:

  • Scope wiring. fromEmptyFolder is an AsyncLocalStorage scope, so concurrent renders in one server process each keep their own scope. Code outside the scope still gets cwd: undefined, so library callers are unchanged. The compile worker gets the flag through workerData and re-enters the scope, which is needed because the store doesn't cross threads. I checked the other workers: the shader-transition pool, lint, health and drawElement workers don't spawn ffmpeg on project media.
  • Paths inside the scope are absolute. executeRenderJob and renderSpan resolve projectDir and outputPath. The work folder is built from the resolved output path, or from resolveRenderDebugDir(), which is absolute. The extract cache and the animated-GIF cache now resolve a relative HYPERFRAMES_EXTRACT_CACHE_DIR. HLS -hls_segment_filename is join(outputDir, …) off that resolved path. RenderConfig has no other path field that reaches ffmpeg (entryFile resolves against the project). No ffmpeg call in these paths writes into its working folder: I found no -pass, passlogfile or -report. That means the shared per-process folder stays empty.
  • CLI entries. captureSnapshots resolves against. describeProject and heardClips resolve their roots. The measure guarded paths resolve before probing.
  • Tests, fails without the fix.
    • runFfmpeg.windowsHide.test.ts passes 2/2 at head. Removing cwd: ffmpegCwd() from runFfmpeg.ts and ffprobe.ts makes the new case fail.
    • renderOrchestrator.emptyFolder.test.ts passes at head. Replacing the fromEmptyFolder wrapper with a plain call fails it: expected undefined to be defined.

Nits, not blocking:

  • absoluteLocal in audio/analysis/decode.ts resolves outside the scope too. That is harmless, because it resolves against the same folder ffmpeg would have inherited.
  • If a tmp cleaner removes the folder, ffmpegWorkingDir() makes a new one, and the exit hook only removes the latest. Only an empty folder is left behind, so this is fine.

Need · Size · Reuse · Simpler · Structure: completes the playlist-walk follow-up at the process level · +284/−70 · one helper in ff-binaries used by every spawner · a global process.chdir would hit every caller, so the scope is the right size · fine.
Risk: low to medium. A missed relative path inside a scoped entry would fail loudly as file-not-found, not silently. The Windows render job in CI covers the platform I didn't run.

— Rames

@vanceingalls
vanceingalls merged commit e1e9bb8 into main Nov 25, 2026
99 of 100 checks passed
@vanceingalls
vanceingalls deleted the 11-24-ffmpeg_neutral_working_dir branch November 25, 2026 09:06
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