Skip to content

fix(engine): a page can no longer grow the served-script record or the server log - #8854

Queued
miguel-heygen wants to merge 1 commit into
mainfrom
fix/served-scripts-cap-name-too-long
Queued

miguel-heygen wants to merge 1 commit into
mainfrom
fix/served-scripts-cap-name-too-long

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

Two places a rendered page could still grow what the render server keeps or logs:

  • A render stops with a plain error once the page loads more than 10,000 different scripts from the composition server: "The composition loaded more than 10,000 different scripts, more than a render can track. Load fewer scripts."
  • A request for a file whose name is too long for the file system is answered 404, like any missing file, and the 404 log line cuts the path to 2,000 characters.

Why

The render keeps a digest of every script URL the composition server answered, to tell a project script's throw from the document's. Each entry is a fixed 28 characters, but nothing capped how many there were: a page that fetches scripts under ever-new URLs grew the set for as long as the render ran. A count cap that simply stopped adding would let a throw from a later project script go unattributed, so the render stops instead. Under the cap every served script is still remembered, so attribution is unchanged.

A page can also ask the file server for a name longer than the file system allows. openSync throws ENAMETOOLONG, which openRegularFile did not treat as "no such file". Its fallback statSync throws the same error, so the request ended in a 500, and the server logged the page's whole path (10,000+ characters) with a stack trace on every such request.

Related work

None open on these paths.

How

  • engine/pageTextBounds.ts: SERVED_SCRIPTS_MAX = 10_000, beside the other page bounds.
  • engine/frameCapture.ts: the response listener adds a new script's digest only below the cap; a new script past it sets tooManyServedScripts on the session. assertVfxIntact becomes assertCaptureIntact, the one check that stops a session, and it now throws TooManyServedScriptsError too, at the same four points (after the page is ready and before each frame or batch).
  • producer/fileServer.ts: openRegularFile returns null for ENOENT, ENOTDIR and ENAMETOOLONG, so the server answers 404. The 404 warning cuts the request path with boundedPageText, now exported from the engine.

Test plan

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

  • frameCapture.test.ts, "stops the render once the page loads more different scripts than a render tracks": through the real listeners, 10,000 distinct served scripts plus one repeat do not stop capture; the 10,001st does, for both single-frame and batch capture.

  • fileServer.test.ts, "answers a name too long for the file system with 404 and logs it cut short": a request for a 10,000-character .png name gets 404, and no log line is over 2,100 characters.

fails without the fix: on main 4c0d614, the first test fails because capture carries on past the 10,001st script (it reaches the stand-in page instead of stopping), and the second fails with 500 instead of 404. With the change, each passes 3 runs in a row.

  • engine: frameCapture.test.ts and frameCapture-subTimelineMemo.test.ts, 84 passed, 3 runs in a row, including "records every served script's throw, however many and long". The whole engine suite: 3,763 passed; the 4 failures are in ffprobe.test.ts, whose HDR PNG fixture was not fetched from LFS in that checkout.
  • producer: every fileServer*.test.ts file under its own runner (bun or vitest), 139 passed.
  • tsc --noEmit clean for engine and producer; oxlint, oxfmt, the comment ratchet and the commit hooks are green.

@github-actions

Copy link
Copy Markdown
Contributor

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

Unstable (1)

  • seqrepeat-none-center-r0-root-z100: tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true / tracking 0.05, pressJump 0, drop 0, reload 0, render 0.02, renderKey -, undo true, teleport true

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

Reviewed at f967657. No blocker in the code; approval follows green on one required check.

Checked:

  • Cap count: the 10,000 distinct digests are kept, a repeat of a kept one is a no-op, and the 10,001st new one sets tooManyServedScripts. No off-by-one. The set can never exceed 10,000 entries (28 chars each), so growth is bounded before the cap trips.
  • Failure is loud: assertCaptureIntact throws TooManyServedScriptsError with a message that names the limit, at all four points where assertVfxIntact ran (after page ready, before each frame, before each batch). It is not a silent truncation or a hang.
  • File server: ENAMETOOLONG now returns null from openRegularFile, so the request is a 404. The other path checks before it (isPathInside via existsSync, realFilePath with its catch-all) do not throw on a long name, so the outside-files mode is covered too. The 404 log cuts the URL path with boundedPageText before terminalText escapes it, so it stays near 2,000 chars. The line logs only the request path, not an absolute path.
  • Tests: both are red on main and green here. The frameCapture test goes through the real response listeners and covers the 10,000/repeat/10,001st boundary for single-frame and batch capture. The fileServer test asserts 404 and the log line length. The PR body has the fails without the fix: line naming both tests.

Required check Tests on windows-latest is red at this head, from two timeouts in files this PR does not touch: videoFrameExtractor.supersetIsolation.test.ts ("Hook timed out in 10000ms", engine-cli-3) and cli/src/ui/renderDiagnostic.test.ts ("Test timed out in 20000ms", engine-cli-2). That looks like Windows runner slowness, not this change. Every other check finished green. I will approve once the Windows lanes are green on a rerun.

For the owners, not a blocker: 10,000 is far above a normal composition, but the count is by full URL including the query string. A composition that re-injects a script with a changing query (a cache-buster per frame) would now fail a long render instead of just growing memory. The limit value is the owners' call.

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

On the query string: yes, the cap counts each distinct full URL, query included, because that is the key the record already used. A throw's stack names the URL with its query, and the digest is looked up by that exact URL.

So a composition that loads one script under a new query each time (a cache-buster per frame) adds one entry per load. Before this change that grew the record without end. Now a render stops at the 10,001st, which at 30 fps is about 5.5 minutes of one load per frame. A composition that loads each script once, or reloads the same URL, never comes near it.

If that pattern should keep rendering, the record could key on the URL without its query. The server serves the same file for any query, so attribution would not change, and the count would then be bounded by the scripts the project actually has. That is a change to what the limit counts, so I am leaving it to the owners rather than folding it into this PR.

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

Approved at f967657. The two Windows timeouts (engine-cli-2/3, files this PR does not touch) passed on rerun; all checks are green. Earlier read stands: the cap counts correctly with no off-by-one, TooManyServedScriptsError names the limit, ENAMETOOLONG answers 404 with the path cut before logging, both tests are red on main. Open question for Vance (non-blocking): the cap counts full URLs including the query string.

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 25, 2026
Any commits made after this event will not be merged.

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