Skip to content

fix(studio-server): a same-size clip copied over with its time kept gets its own media copy - #9098

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/proxy-cache-key-file-identity
Nov 29, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/proxy-cache-key-file-identity

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A video replaced by another of exactly the same size, copied over with its modified time kept, now gets a media copy of its own. Before, previews and the project server served the copy made from the file it replaced.

Why

The fast cache lookup names a copy by the source's path, modified time and size. cp -p, rsync with times kept, or an unzip can keep all three and still change the picture. With real ffmpeg on main: a red clip is copied (red), a blue clip of the same size is copied over it with cp -p, and asking again returns the same red copy. Found in review of #9086.

Related work

Refs #9086, which binds a copy to the file state it was made from. That check runs when a copy is made or reused by content, not when the fast lookup finds an old copy.

How

  • fastCopyKey (proxyCacheKey.ts) also takes the source's change time. No copy tool sets it, and every write or rename of the file moves it.
  • The first lookup after this lands misses once for every source, then finds its copy again by content (the .content- index), as a touched file already does. Stills have no content index, so each is cut again once.
  • A file only touched or re-saved with the same bytes still gets its old copy ("reuses the copy of a file that was only touched or re-saved with the same bytes").

Test plan

fails without the fix: packages/studio-server/src/helpers/proxyTranscoder.test.ts ("makes a new copy for a file of the same size copied over with its modified time kept").

  • Unit tests added/updated. The new row fails on main and passes here; the whole studio-server suite passes (2781 tests).
  • Manual testing performed. The real resolveProxy and ffmpeg 6.1, built from this branch and from main, on the red/blue cp -p case above, read back as colours: main returns the red copy again; this branch makes a new blue copy.
  • Documentation updated: none needed.
  • Comments follow CONTRIBUTING.md "Comments".

Package size: studio-server unpacked is 26 bytes larger, within its budget, also with #9086 counted. Not run: Windows outside CI, and a FAT or exFAT drive, where the change time may not be kept, so a hit there works as before.

@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 3cd58c8. Approve.

Read whole: proxyCacheKey.ts. Read as hunks plus the surrounding flow: proxyTranscoder.ts (getCanonicalProxyCachePath, transcodeToCache, the still path) and the "finding the copy of a source" tests. Nothing run locally (no install on this box); checks were still pending when I read.

What I checked:

  • The fast key now takes the change time, so a same-size file copied over with its modified time kept gets a new fast name. The lookup then misses and transcodeToCache reads the bytes, so a different file gets its own copy.
  • A file whose bytes did not change (touch, re-save, chmod, rename) misses the fast name once, finds its copy through the content index and writes a new fast index. The existing "only touched or re-saved" row still covers that path.
  • The body's fails without the fix: line names a real row. Both writes are 10 bytes with the same pinned modified time, so on main the second lookup returns the first copy with one ffmpeg call; the 80 ms flush inside made keeps the two change times apart.
  • Both callers of fastCopyKey (copies and stills) take the change with no other edit needed; the stills test that builds a key by hand goes through the same function.

Notes, not blockers:

  • After this lands every source misses once and is read whole to find its copy by content; for a project of large clips the first open costs one full read per clip. The body says so.
  • Stills are cut again after any change-time move (rename, permission change), since they have no content index. Cheap, and correct.

Need: yes, a replaced clip could show the old picture · Size: 2 lines + 1 test · Reuse: existing content index does the recovery · Simpler: no · Structure: fine
Risk: low; worst case is an extra read or re-cut, never a wrong copy.

— Rames

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 56 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)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit c679dff Nov 29, 2026
88 checks passed
@miguel-heygen
miguel-heygen deleted the fix/proxy-cache-key-file-identity branch November 29, 2026 14:12
@miguel-heygen miguel-heygen mentioned this pull request Nov 29, 2026
5 of 6 tasks
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