Skip to content

feat(core): measure preview stage layout and styles over the editing port - #8937

Merged
miguel-heygen merged 2 commits into
mainfrom
feat/stage-measure-port
Nov 26, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
feat/stage-measure-port

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What changed

  • Added a read-only stage-measure request to the runtime editing port (packages/core/src/runtime/editing/stageMeasure.ts, wired into packages/core/src/runtime/editingPort.ts and packages/core/src/runtime/editingAgent.ts).
    • Walks document.body in document order up to maxItems (hard-capped at MAX_STAGE_ITEMS = 2_000), skipping non-visual tags (SCRIPT, STYLE, TEMPLATE, NOSCRIPT, LINK, META).
    • Returns layout box, structural key, data-hf-id, id, tag, parent key, direct-child own text, fontSize, color, background, placed, visible, composition-scoped .clip keys (clipKeys), hasElementChildren, direct-text range start (textStart), hasBackgroundImage, and truncated.
    • Runs only on the editing port, which is gated on the Studio preview mark (STUDIO_PREVIEW_MARK_META) and never connects on render pages.
  • Added measurePreviewStage and readStageMeasuredItem in packages/studio/src/player/lib/previewStageMeasure.ts and exported measurePreviewStage, limits, and result types from packages/studio/src/index.ts.
    • Validates request maxItems before sending and validates and bounds every field of the frame reply (item count, finite box and text-start numbers, bounded strings, booleans, bounded clipKeys), returning null if the frame is unavailable or any field is malformed.

No visible change

This PR adds a read-only editing-port request and a library wrapper in @hyperframes/studio (.ts files only; no .tsx, .css, .html, or binary files changed) with no visible UI change yet.

What I measured

  • oxfmt --write + oxlint on all 9 added/modified files: 0 warnings, 0 errors.
  • @hyperframes/core build and @hyperframes/studio build: passed.
  • fallow audit --base origin/main --fail-on-issues: 0 dead code, 0 complexity, 0 duplication issues.
  • node scripts/verify-packed-manifests.mjs: all 15 packages verified publish-safe and within scripts/package-size-budgets.json (252 packed exports resolved, 234 Node exports executed).
  • packages/core: lint:runtime-preview-guards passed, typecheck (including tsconfig.runtime.json) passed, runtime contract and runtime fixture boundary checks passed; editing tests (stageMeasure.test.ts, editingPort.test.ts, editingAgent.test.ts) passed 3x with --sequence.shuffle (208/208 x3). Full packages/core test suite: 354/355 files passed (7424/7425 tests; 1 unrelated host-umask failure in src/cacheDir.test.ts).
  • packages/studio: typecheck passed; preview channel/element/stage-measure tests (previewStageMeasure.test.ts, previewElements.test.ts, previewChannel.test.ts) passed 3x with --sequence.shuffle (83/83 x3).
  • packages/producer: 123/124 unit test files passed (1632/1633 tests; 1 unrelated MPEG-TS ffprobe crash on this host in captureHdrResources.test.ts).
  • packages/engine: urlDownloader.runtimes.test.ts passed (2/2); full packages/engine suite had 4 unrelated host MPEG-TS ffprobe/ffmpeg failures and timed out at 300s under local cap before finishing all 223 files (CI runs the full matrix).
  • fails without the fix: disabling the maxItems cap in stageMeasure.ts fails src/runtime/editing/stageMeasure.test.ts; disabling per-item validation in previewStageMeasure.ts fails src/player/lib/previewStageMeasure.test.ts.

What I did NOT exercise

  • Full packages/engine 223-file suite completion locally (left to CI due to host MPEG-TS ffprobe failures and local runtime budget).
  • Live end-to-end host consumer wiring (lands in a follow-up consumer PR once this API is published).

@github-actions

Copy link
Copy Markdown
Contributor

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

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

No blocker at 0fef52b. Approving.

Checked what the brief asked about:

  • Request is bounded on both sides. parseStageMeasureParams (stageMeasure.ts:44-54) only takes empty params or maxItems as a safe integer in 1..2000. measurePreviewStage refuses bad maxItems before sending (previewStageMeasure.ts:112-117). The frame-side walk stops at the limit (stageMeasure.ts:53-56).
  • No hang. previewRequest goes through client.request, which defaults to EDITING_REQUEST_TIMEOUT_MS (5s, editingPort.ts:263). A timeout becomes null.
  • Frame-supplied lists are bounded before iteration with isMessageList: reply.items against limit (previewStageMeasure.ts:121-125) and clipKeys against MAX_STAGE_CLIP_KEYS (line 52). Every string is length-bounded, numbers must be finite, extra fields are dropped. One reply per request, so no message flooding.
  • Read-only, and only on the editing port that is gated on the Studio preview mark. A test covers render pages.
  • "fails without the fix:" line is in the body and names real tests at this head (stageMeasure.test.ts, previewStageMeasure.test.ts).
  • All CI checks at this head finished with no failures.

Small nit, not blocking: the body names the test files, not the test titles.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit f00e934 Nov 26, 2026
104 checks passed
@miguel-heygen
miguel-heygen deleted the feat/stage-measure-port branch November 26, 2026 21:48
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