Skip to content

fix(studio): a failed preview reload logs whether the project or our code threw - #8920

Open
miguel-heygen wants to merge 4 commits into
mainfrom
dpreview/reload-origin
Open

miguel-heygen wants to merge 4 commits into
mainfrom
dpreview/reload-origin

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

When a preview reload fails, Studio's console line now ends with where the page's first script error came from: Its first page error came from: project. (or runtime, studio, unknown). The message handed to onReloadFailed, which a host may show to people, is unchanged.

Why

A host that forwards console errors to its error tracker has to strip the error's own text, since it is the project's content. What is left is only the error's class, for example "the preview reload hit a TypeError". That reads the same whether the project's own script threw (often an agent halfway through an edit) or the HyperFrames runtime or Studio did, so whoever is on call cannot tell a project's broken script from a bug of ours without digging through sessions by hand.

studio-server's early-errors script already records a closed origin for every error the page raises (window.__hfPreviewErrorKinds, one { name, origin } per error, origin from the throwing script's path). Nothing read it when a reload failed.

How

failShadow already holds the failed reload's iframe when it builds the message. A new firstErrorFrom(iframe) reads the first recorded origin from that page and the console line appends it. It reads nothing from a sealed frame (the same guard got uses) or a page whose document it cannot read, and adds nothing when the page recorded no error. The value stays a closed word; the error's text is never added.

Test plan

  • Two tests in useTimelinePlayer.shadowReload.test.ts: a page that recorded a project error and then a runtime error logs came from: project at the end of the console line, and onReloadFailed gets the message without it; a page that recorded no error logs no origin.

  • fails without the fix: with ${errorFrom} removed from the console line, the first test fails and the other 65 in the file pass.

  • With the fix: the file passes 3 runs in a row (66 tests), and all 27 files under src/player/hooks pass (293 tests) on a Linux devbox.

  • tsc --noEmit for studio, oxlint, oxfmt, and the commit hook's fallow and typecheck: clean.

  • Not exercised: a real reload failing in a running Studio. Next, the host maps this word into its redacted line; that change lives in the host.

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments"

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

Reviewed at 0b9ba5b, by reading (no test run on my box). I read useShadowPreviewReload.ts around the change, the server script that records the kinds, and both new tests.

No blocker. What I checked:

  • The people-facing message. message is built as before and handed to onReloadFailed unchanged; only the console line gets the tail. The first test asserts both.
  • Reading the frame. firstErrorFrom returns nothing when contentDocument is null (another site's page, a detached frame), so the window is never touched where reading it would throw. A sealed frame is skipped by the same guard got uses. The read happens before the shadow is stopped and dropped.
  • Where the words come from. The server's early-errors script pushes one of unknown, runtime, project, studio per error, from the throwing script's path on the page's own origin. The reader takes entry 0.
  • Fix rule. The fails without the fix: line names the first new test in useTimelinePlayer.shadowReload.test.ts; it is at this head and pins the tail at the end of the line.

Notes, not blocking:

  • The array is an ordinary property of the page's window, so a project's own script can write to it. The reader accepts any string there. If the host is going to copy this word into a line it otherwise strips, either accept only the four words here (one small set check) or have the host match on them. Worth saying which in the follow-up.
  • "First" is the first error since the page loaded, not the one that broke the reload. A harmless early project error followed by a runtime failure reads as project. The line says "first page error", so it is honest, but whoever reads the tracker should know.
  • The test comment names one host and one vendor; the PR body says "a host" and "its error tracker". Matching the body would read better here.

Need: yes, failed reloads cannot be told apart by source today · Size: +59, 18 in source · Reuse: the kinds the server already records, the existing sealed guard · Simpler: no · Structure: one reader beside pageGotTo
Risk: low. Console text only, no change to reload or retry behaviour.

— Rames

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

No visible change

Nothing on screen changes: the only new output is the end of a console line when a preview reload fails. The message onReloadFailed hands a host is unchanged.

Review notes

  • Any string in the kinds array: the host's error filter is the trust boundary and keeps only the four words (project, runtime, studio, unknown), dropping anything else. The console line already carries the project's own error text in its cause, so the reader adds nothing a project could not already print there.
  • "First" error: when the reload failed on a page script's error, the cause is the first recorded message (firstAuthorError reads __hfPreviewErrors[0]), and the early-errors script pushes that message and its kind in the same handler, so the origin names the same error. When the reload failed for another reason (timeout, no timeline), the word is the first page error's origin, which is why the line says "first page error" rather than claiming it broke the reload.
  • Test comment: now says "a host's error tracker" (f45b439).

Also at 22e3ada: the reader's doc comment is gone, since the comment ratchet only lets a file's comment share go down. Its name and STUDIO_PREVIEW_ERROR_KINDS carry it.

@github-actions

Copy link
Copy Markdown
Contributor

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

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.

2 participants