Skip to content

fix(studio): agent tools see the film in a sealed preview - #8281

Merged
miguel-heygen merged 5 commits into
mainfrom
fix/sealed-agent-tools
Nov 20, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
fix/sealed-agent-tools

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What

In a sealed preview (Studio cannot script the frame), Studio's agent tools now see the film:

  • studio_look lists the scene, with the same handles a live preview gives. Before, it always said loading with no elements.
  • studio_select, studio_inspect and every targeted write (studio_set_style, studio_set_text, studio_transform, the animation tools) find the element a handle names. Before, each one answered "the preview is not mounted yet".
  • A move, resize or text write is read back off the frame's element, so its receipt says whether it changed. Before, it measured Studio's stand-in, which has no size and never changes.
  • studio_look says the scene is still loading until the player has the film's timeline. In a sealed preview the timeline lands a round trip after the first seek answers, so an agent looking right after a seek read a duration of 0 and no clips.

The sealed preview is off by default until the sealed-by-default change (#7846) lands, so nothing changes for anyone before then.

Why

The agent tools read previewIframe.contentDocument, which is always null for a sealed frame. Studio already finds elements in a sealed frame through its runtime: findSelectionElement (a handle's element, or the frame's description of it) and collectPreviewLayerItems (the layers list the Layers panel shows). The agent tools never went through them.

How

  • New webmcp/agentPreview.ts, the agent tools' one read of the preview, sealed or not:
    • load: the preview's current load (its document, or the sealed frame's per-load port client);
    • find: a handle's element, through findSelectionElement;
    • readNow: an element's box and text as the preview shows them now;
    • scene: the look scene, through collectPreviewLayerItems when sealed.
  • resolveLiveHandleSelection takes that read instead of a document getter. It still reacquires once across a reload: a reload is a new load, and a stand-in stays held while its load does.
  • buildSelection already accepted the frame's description (buildDomSelectionFromTarget), so selections are the same ones a click makes.
  • readBox becomes readNow; studio_set_text compares the text it reads back instead of the selection's old node.
  • buildStudioLook reports loading while the duration is 0. Every runtime timeline post carries at least 1 s.
  • The paused-video sockets walk waits for studio_look's ready scene instead of looking once.

No new port requests.

Test plan

  • agentPreview.sealed.test.ts, on a sealed frame served by the real runtime agent:
    • look lists the same elements, with the same handles, as on a live preview;
    • select, inspect and a style write find the element by its handle;
    • a move's receipt reads the frame's new box; a text write's receipt reads the frame's new text;
    • look before the timeline is known says loading and lists nothing.
  • Existing webmcp tests now find elements through the same read (documentPreview over a live document), and the box read's tests moved to readNow.

A sealed selection has no text fields yet, so the set_text test gives its selection one. The real one comes with #8156 (text fields over the port).

fails without the fix:

  • with the sealed scene not read through the runtime, "looks at the same scene" fails;
  • with a handle found only in a live document, or no load for a sealed frame, or a stand-in taken for a detached node, select, inspect, the style write and both read-backs fail;
  • with the read-back measuring the stand-in, the move and text read-backs fail;
  • with studio_look ready before the timeline posts, "says the scene is still loading" fails.

Run on Linux: Studio webmcp, topology lens and the public export tests (215) pass three runs in a row; Studio tsc no errors; format clean; the code audit passes.

Walk

The paused-video sockets walk (undo-socket-pool.mjs) on a dev Studio, with this change on top of the sealed-by-default change:

preview walk failures
sealed, before (sealed-by-default change alone) fails: studio_look found no #target (sceneStatus: loading, duration: 0, no elements) 1
sealed, after passes, 3 rounds, nothing stalled, every undo reverted and repainted 0
unsealed, after passes, 3 rounds, nothing stalled, every undo reverted and repainted 0

A probe of studio_look right after the walk's first seek, before this change: sealed read a duration of 0 and no clips 1 ms after the seek and 20 s with 9 clips 267 ms later, with the scene loading throughout; unsealed read 20 s, 9 clips and a ready scene at once.

Before

Sealed preview (main, sealed preview switched on), the inline-text-caret fixture, at 1 s. The agent looks, then selects #title by its handle: the look says loading with no elements and the select is refused, so nothing is selected.

before: the agent's look lists nothing and selecting #title is refused

After

The same at this head: the look lists the scene's 3 elements, with the handles an unsealed preview gives, and the select finds #title, which Studio shows selected.

after: the agent selects #title and the selection outline sits on it

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

Unstable (1)

  • seqplainkeys-none-center-r0-root-z100: tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.06, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@eddy-heygen eddy-heygen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Eddy's agent) Reviewed by Eddy's Claude agent at commit 2c1b6c9 (full diff reviewed in a worktree; the new preview module read by hand).

Verdict: approve.

Summary
With a sealed preview (off by default), Studio's agent tools saw nothing because they read the frame's document directly. They now go through one new module that asks the frame's runtime over the existing port when the frame is sealed, and reads the document as before when it is not. Look, select, inspect, targeted writes and the read-back after a move, resize or text write all use it. Look reports "loading" until the player has a timeline.

What I checked

  • Nothing new crosses the seal: the change is confined to the agent-tools folder and one end-to-end script. No runtime or port code changes and no new request kind; the tools reach the same layer, describe and query requests the editor's own selection already uses.
  • Replies from the frame pass the existing shape checks before use, and the new code has no HTML sink. Handle validation and the write path's project-scope check are untouched.
  • A read-back never measures Studio's stand-in: for a selection that names a frame element it returns the frame's answer or fails.
  • With the preview unsealed (today's default) the paths reduce to the previous document reads.

Non-blockers

  • A sealed look reads one page of layers and drops the "truncated" signal, so on a very large film elements past the first page are reported as absent. Page through, or surface truncation, before the sealed preview becomes the default.
  • Setting text on a sealed selection still stops at "no editable text field"; the sealed text read-back is covered only by a test that builds the selection by hand. The description says so and names the follow-up.
  • The "loading while duration is 0" rule also applies to unsealed previews and is computed in two places. I found no way the current runtime leaves the duration at 0 for a loaded film, so this is hardening only.
  • In a sealed frame the values the tools return (labels, text, boxes, the file a write is addressed to) come from the frame, which runs beside the film's own scripts, so a film can misreport them. This is the same trust the existing sealed selection already places in the frame, not a widening.

CI: 63 pass, 16 skipped, none failing; 2 pending (Windows engine CLI tests, which do not cover the changed code). The Studio and runtime test jobs, including Windows Studio, passed.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit c34df57 Nov 20, 2026
151 of 153 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-agent-tools branch November 20, 2026 09:51
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