Skip to content

fix(core): a held stage act still hears frame keys while sealed canvas keys are armed - #8959

Merged
miguel-heygen merged 17 commits into
mainfrom
fix/stage-input-through-shield
Nov 27, 2026
Merged

miguel-heygen merged 17 commits into
mainfrom
fix/stage-input-through-shield

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

While a stage act is held in a sealed preview, the frame keeps reporting the person's keys to Studio as stage-input, even when canvas keys are armed.

Why

#8935 installs a key shield at load in sealed previews. Once Studio arms canvas keys, the shield stops each trusted key before any later window listener runs. stageAct listened for keydown with its own window capture listener, which was added after the shield, so an armed shield swallowed the keys a held stage act reports. A run that should end on a key kept going.

Related work

Stacked on #8935, which is stacked on #8946.

How

  • canvasKeys.ts owns frame keydown. listenFrameKeydown(view, listener) adds the listener to the shield when the shield is installed on that window. The shield then calls every such listener first for each keydown, trusted or not, before it prevents or stops anything. With no shield, as in a same-origin preview, it is a plain capture listener, as before.
  • stageAct.ts listens for keydown through it. pointerdown and drop keep their window listeners, because the shield never stops pointer or drop events. The stage-input message is unchanged.

No visible change

Core only: the frame now reports key input it previously dropped. Nothing changes on screen until a stage-act consumer acts on that input.

Test plan

  • Unit test added: canvasKeys.test.ts > "still reports keys to a live stage-act hold while canvas keys are armed". With Delete armed and a live hold, a trusted Delete posts stage-input and then the canvas Delete, and a synthetic keydown still posts stage-input.
  • fails without the fix: the same test fails when stageAct adds its own keydown window listener again; the trusted Delete never reaches the stage act.
  • Core editing, port and agent suites: 599 tests, 3 runs in a row. test:hyperframe-runtime-ci exits 0. tsc --noEmit is clean. The Studio sealed-keys, stage-act and preview-channel suites pass (87 tests).
  • Comments follow CONTRIBUTING.md "Comments".

# Conflicts:
#	packages/core/src/runtime/editingAgent.test.ts
#	packages/core/src/runtime/editingAgent.ts
#	packages/core/src/runtime/editingPort.test.ts
#	packages/core/src/runtime/editingPort.ts
#	packages/studio/src/components/editor/useDomEditNudge.ts
…s first draw

Studio's first nudge on a cold read now uses this start, so a GSAP clip is not moved twice.
…d settle every delete

Backspace stays with Studio while Reset Keyframes may claim it.
A Delete no canvas session takes is rolled back.
A cold first nudge on a GSAP clip starts from the frame's pre-draw position.
…he load-time shield arms

A Delete pressed while armed saves even when it lands after the canvas session ends.
Arming no longer installs the key shield, so same-origin frames are never shielded.
The shield stays the first key listener. Unarmed, it lets keys through as main does.
Keeps both the canvas-key and stage-act request kinds and push listeners.
The editing port's push handling becomes a table so both fit under the complexity gate.
…d, not the group selected since

The canvas Delete passes the arm's members for the handles the frame removed.
It rolls back when any removed handle has no member. Also cuts two comments the ratchet flagged.
…s keys are armed

canvasKeys owns frame keydown. stageAct listens through it and hears every keydown first.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 · Keep key suppression independent of reporting. In packages/core/src/runtime/editing/canvasKeys.ts:461–468, observers now execute in the shield's own event listener, before it suppresses the key. If a reporting callback throws, the shield exits before its stop/prevent logic. Separate DOM listeners isolated that failure before. Isolate each callback's errors using the existing diagnostics path, so key suppression and forwarding still run even if stage-input reporting fails.

Source review at the pinned head. The base PR is still open.

— tai (automated review)

…hield

Each listener's error is swallowed, so the shield still prevents, stops and forwards the key.
@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at 6914b76b. The shield now calls each frame keydown listener inside its own try. An error goes to the runtime's swallow diagnostics under canvasKeys.frameKeydown. The shield then still prevents, stops and handles the key, and the other listeners still run.

Test: canvasKeys.test.ts > "still stops and handles an armed key when a frame keydown listener throws". With Delete armed and a listener that throws, a trusted Delete still removes the target in-frame, and the page's own listener never sees the key. Without the try it fails.

Checked: the core editing, port and agent suites (600 tests), 3 runs in a row; tsc --noEmit; the comment ratchet.

Base automatically changed from feat/sealed-runtime-keys to main November 27, 2026 03:47
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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

…gh-shield

# Conflicts:
#	packages/core/src/runtime/editing/canvasKeys.test.ts
#	packages/core/src/runtime/editing/canvasKeys.ts
#	packages/core/src/runtime/editingPort.ts

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The patch ID matches the pre-retarget change. Reporting errors are handled per observer, so a failed observer leaves key suppression and forwarding intact. All 231 targeted tests and all applicable required checks passed on this head.

— tai (automated review)

…gh-shield

# Conflicts:
#	packages/core/src/runtime/editing/stageAct.ts

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The merge keeps both imports in stageAct.ts. The added and removed lines against main match the previously reviewed patch. All applicable required checks passed on this head, including Windows tests.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 27, 2026
@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 8fe81cb Nov 27, 2026
104 checks passed
@miguel-heygen
miguel-heygen deleted the fix/stage-input-through-shield branch November 27, 2026 05:54
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