Skip to content

fix(studio-server): signing a project with a large folder keeps no record per file - #9129

Open
miguel-heygen wants to merge 2 commits into
mainfrom
fix/studio-server-signature-streaming
Open

miguel-heygen wants to merge 2 commits into
mainfrom
fix/studio-server-signature-streaming

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Signing a project no longer keeps a record per file. createProjectSignature and createProjectSignatureAsync fold each file into the signature as the walk reaches it, and the awaited walk stats at most 64 entries of a folder at a time.

Why

Both walks collected one record for every file, then sorted and hashed them all at the end. The awaited walk also started an lstat for every entry of a folder at once. A project whose frames/ folder holds tens of thousands of stills (an agent rendering a sequence does this) cost hundreds of MB to sign: heap grew by 22 MB at 10,000 files, 126 MB at 50,000 and 360 MB at 150,000 (Node 22, awaited walk). Hosts that sign on every preview or thumbnail request paid that on each one.

Related work

None.

How

  • The walk takes a callback (walkProject / walkProjectAsync). Each folder's names are sorted, the walk goes depth first, then the two Studio manifests follow. Both walks visit files in the same order, so they still return the same signature.
  • SignatureFold takes each file as it arrives. The fingerprint (path, size, mtime, ctime, text or binary) and every binary file go straight into their hashes. Only text-eligible files are kept, because their content is read after the walk, and only when the fingerprint is not cached. The settled-before-signing check keeps the newest time instead of scanning a list.
  • The awaited walk stats a folder in batches of 64 (STAT_BATCH) instead of all its entries in one Promise.all.
  • listProjectFilesAsync uses the same walk. It still returns its full list, as its callers need.
  • The signature value changes once. Order is now each folder sorted rather than one localeCompare sort of every path, and binary files are hashed before text files. A host's cache keyed on the old value rebuilds once.

Test plan

  • Unit tests added/updated: projectSignature.memory.test.ts signs a project with a 50,000-file frames/ folder served from a mocked node:fs (no disk, so it is quick on every OS). It forces GC and samples the heap during the walk. "the synchronous walk keeps no record per file" and "the awaited walk keeps no record per file and stats a bounded number of entries at once" both fail on main: 168 bytes per file retained, and 50,000 stat calls in flight. With the change they read about 10 bytes per file and 64 in flight. Two deliberate breaks each fail them: an unbounded batch, and keeping every entry in a list. The test passes 3 runs in a row.
  • The existing projectSignature.test.ts passes unchanged, including "returns the signature the synchronous walk returns". The whole studio-server suite passes: 2,785 tests, 6 skipped.
  • Manual testing performed: not against a real project of that size. The figures in Why come from a script that filled a temp folder with tiny files and timed the published package.
  • Documentation updated (if applicable): not applicable.
  • Comments follow CONTRIBUTING.md "Comments"

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

What the changed signature costs on update

  • Thumbnails: the only cache keyed on the signature that outlives a restart. Its files in each project's .thumbnails/ carry the composition's input signature in their name, so after the update each thumbnail is captured again the first time it is shown: one headless browser capture per thumbnail, as on a cache miss today. The old files are left to the existing prune (expiry and size budget). The count follows compositions and thumbnail sizes, not project files, so a project with a big frames/ folder has no more thumbnails to redo than a small one. I did not time a capture for this PR.
  • Preview builds and the signature memo: held in memory per server process, so a restart rebuilds them anyway. The update adds nothing there.
  • Nothing is lost: every cache treats an unknown signature as a miss.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

No deployments
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.

1 participant