Skip to content

fix(studio-server): a sealed preview's wait for a video's proxy copy passes its preflight - #7856

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/studio-server-sealed-proxy-preflight
Nov 15, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/studio-server-sealed-proxy-preflight

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

A sealed preview (opaque origin, under its frame-token path) can now ask for a video's proxy copy. The runtime's wait (core/runtime/proxyWait.ts) sends Range and X-HF-Proxy-Priority, so Chrome preflights it. The token route now answers that preflight, and lets the frame read the wait's own headers.

  • On preview/~<token>/, after the token check: an OPTIONS from Origin: null, asking for GET, on a video path with ?hf-proxy= gets 204 with Access-Control-Allow-Origin: null, Access-Control-Allow-Methods: GET and Access-Control-Allow-Headers: Range, X-HF-Proxy-Priority. Any other OPTIONS goes on to the server as before.
  • Every load the token route already grants also gets Access-Control-Expose-Headers: Retry-After, X-HF-Proxy-Progress, Content-Range.

Why

Without this, a sealed preview cannot install a video's playable copy: the wait's preflight is refused, so the runtime reports the proxy as failed. Studio's preview is about to run sealed by default (#7846), so this lands first.

How

The header lists and the proxy-wait test already existed for sealed thumbnail captures in captureLoads.ts. They are now exported from there (isProxyWait, PROXY_WAIT_ALLOWED_HEADERS, PREVIEW_EXPOSED_HEADERS) and the token route uses the same ones, so both answer an opaque frame alike. The token and the private-file checks are unchanged: the preflight is answered only after the token matches, and the GET still goes through the preview route.

No visible change

Reachable only from a sealed preview, which Studio does not use by default yet.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments"

fails without the fix: cd packages/studio-server && vitest run src/routes/preview.opaqueFrameLoads.test.ts -t "proxy copy" (2 of its 7 tests fail on main), and the new browser check node packages/studio/tests/e2e/sealed-preview-proxy.mjs (on main: TypeError: Failed to fetch, the preflight refused).

On Linux, Node 24:

  • Unit: the preflight answer, five cases left unanswered (a non-video file, no proxy query, a caller that is not opaque, a method other than GET, a wrong token), and the exposed headers. packages/studio-server vitest run: 110 files, 1989 tests, 3 runs in a row.
  • Browser: Studio's dev server with VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1, Chrome 155, a project holding clip.mov. From inside the sealed preview (origin null) the runtime's request shape (Range: bytes=0-0, X-HF-Proxy-Priority: 1) fails to fetch on main and gets its answer with this change. It runs in CI next to the preview-video checks, on that job's Chrome.
  • tsc --noEmit, oxfmt --check, oxlint, the comment ratchet and fallow audit are clean.

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

Verdict: approve. Reviewed at 03032f60.

The token route answers the proxy wait's CORS preflight and exposes the wait's response headers on the loads it grants. That lets a sealed preview fetch a video's proxy copy with Range and X-HF-Proxy-Priority.

What I checked

  • Order of checks. The preflight is answered only after tokens.matches(projectId, token) and the token segment is stripped. It also has to be an OPTIONS from Origin: null, ask for GET, and name a video path carrying hf-proxy. Anything else falls through to the server as before. The 204 carries no body and touches no file, so it reveals nothing beyond what the matched token already grants. The GET still goes through the preview route and its private-file checks.
  • Reuse. isProxyWait and the two header lists come out of captureLoads.ts and are shared, so the capture page and the token route answer an opaque frame identically. That avoids a second copy.
  • Your "fails without the fix" claim:
    • With captureLoads.ts and opaqueFrameLoads.ts from main, preview.opaqueFrameLoads.test.ts fails 2 of 61: "answers its preflight with the proxy GET's method and headers" and "lets the frame read the proxy wait's headers on a granted load".
    • At head, that file plus captureLoads.test.ts pass 105/105 (core, parsers and lint built first, as CI does).
    • The five "left unanswered" cases cover the negative side: wrong file type, no proxy query, a non-opaque caller, a non-GET method, a wrong token.
  • The CI step runs the browser check inside the existing preview-video job with if: success() || failure(). No permissions change.
  • No other reviews. CI is still running at this head (41 pass, 30 pending, 0 failed when I posted).

Nit (not blocking). Access-Control-Allow-Headers is a fixed list, not an echo of the request's, which is the safer shape. A runtime that later adds a header to the wait would fail its preflight, though, so a comment in proxyWait.ts pointing at PROXY_WAIT_ALLOWED_HEADERS would keep the two in step.

Need: yes · Size: ok · Reuse: isProxyWait and the header lists shared from captureLoads.ts · Simpler: already minimal · Structure: fine (checked captureLoadGrant's existing preflight; one shared owner, no split)
Risk: low — the extra preflight answer is reachable only after the token matches.

— Rames

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 100 of those

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

Quarantined, measured but not gated (8)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit ae5829d Nov 15, 2026
138 of 139 checks passed
@miguel-heygen
miguel-heygen deleted the fix/studio-server-sealed-proxy-preflight branch November 15, 2026 20:16
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