Skip to content

fix(engine): a running render keeps its cached video frames through other renders' cleanup - #9080

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/render-cache-lease
Nov 29, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/render-cache-lease

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What changes for people

A long render can no longer lose its video frames when another render, or hyperframes clean, sweeps the shared frame cache. Until now, the only thing keeping a running render's cache entries safe was their age: an entry untouched for an hour could be removed while that render still needed it. The render re-touched its entries only while capturing, so any longer pause left them exposed, for example between extraction and capture.

How

  • A render takes a lease on the cache entries it reads. For each entry the extractor finds or writes, the lease puts a hold file next to it, named <entry>.hold-<pid>, holding the process's owner record. Several renders in one process share the file, and it goes away when the last of them releases.
  • The cache sweep skips an entry while its hold names a process that is still running. It removes holds left by processes that have exited. A hold it cannot read, or one from another machine or container, leaves the entry to the age guard, as before.
  • The render creates its lease before extraction and releases it in its normal end-of-render cleanup, so failed and cancelled renders release too. A released lease takes no new holds, so an aborted extraction that finishes late cannot leave one behind.
  • The check for whether a process is still running already existed for render work folders. It moves from producer into engine so the cache and the work folders use the same one. Producer now imports it, and its behaviour is unchanged.

Tests

  • New engine cache tests: a held entry survives a sweep however old it is, a held partial folder survives the stale-partial sweep, one process's second render keeps the hold after the first releases, a released lease takes no new hold, an exited process's hold is dropped along with the entry, and an unreadable hold falls back to the age guard.
  • New extractor test: one render misses and another hits the same entry. With the entry aged two hours, a sweep keeps its frames until both renders release, then removes them.
  • fails without the fix: videoFrameExtractor.vfr.test.ts "another render's sweep leaves the frames a running render found, on a miss and on a hit" (on main the aged entry is swept while both renders still read it).
  • Each new test fails when the code it covers is broken: the sweep ignoring holds, the sweep keeping exited holds, the in-process count dropped, a released lease still taking holds, and the extractor not taking a hold.
  • A real render from source: during the render, the cache held one hold file stamped with the render's own process id. After the render finished, the hold was gone and the entry was still there for the next render.

…ther renders' cleanup

A render now holds each extraction cache entry it reads with a per-process hold file beside the entry. The cache sweep skips an entry while its holder is still running and drops holds left by processes that exited. The render releases its holds when it ends.
The hold scan moves into its own function. The engine size budget rises by the process-liveness check that moved here from producer.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Size budget: @hyperframes/engine rises to its measured size (packed 527892, unpacked 1767535). The process-liveness check that render work folders already used moved from producer into engine, so the extraction cache can use the same one. Producer loses the same code.

@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.

Reviewed at 61c442a. Approving.

Read whole at 9546ed8: extractionCache.ts, processOwner.ts, the changed parts of videoFrameExtractor.ts and renderOrchestrator.ts, and the tests. Since then I read the full diff to this head: only the hold scan moved into liveHolds and the engine size budget rose. Nothing was run.

What I checked:

  • A render holds what it reads. The lease is made before extraction and released in the deferred cleanup, and both a cache hit and a miss take the hold in rehydratePublishedCache, including the two paths where publishing fails.
  • The sweep skips held entries. It reads each hold file's owner and keeps the entry while that owner is alive; a hold whose owner is gone is removed, so a crashed render does not pin an entry for good.
  • The moved liveness check is the same code. processOwner.ts is byte-equivalent to the file it came from, with the old path re-exporting it.
  • This head. liveHolds(rootDir, children, remove) does what the inline loop did, in the same order. The budget rise (packed 522000 to 527892, unpacked 1742862 to 1767535) matches the reason posted on the PR. Fallow audit is green at this head; Build was still running when I posted.
  • Body has the fails without the fix: line naming a test.

Non-blocking: a hold file that cannot be read, or that some other tool wrote, is never removed, even after its entry is evicted. They are tiny, but they accumulate.

Need: yes, a sweep could remove frames a running render was reading · Size: moderate, most of it the moved file and tests · Reuse: reuses the existing owner-record check instead of a second one · Simpler: no · Structure: fine after the liveHolds split
Risk: medium-low. Worst case of a wrong hold is an entry kept longer than needed, not one removed early.

— Rames

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 61 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-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

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

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

Quarantined, measured but not gated (0)

Unstable (1)

  • seqnudge-none-px-r0-nested-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo false, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit b5fec73 Nov 29, 2026
100 checks passed
@miguel-heygen
miguel-heygen deleted the fix/render-cache-lease branch November 29, 2026 10:55
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