fix(lint): run Studio and producer lint off the host's own thread (#7974)

* fix(lint): run Studio and producer lint off the host's own thread

A composition that sends the linter's parser into a runaway froze or
crashed the long-lived hosts that lint it in their own process.

CLI Studio's single-page lint now runs in a child process with a heap
cap and a 15 s limit. Producer /lint (runHyperframeLint) runs on a
worker thread with the same limits. A page that times out, runs out of
memory, or whose child or thread ends without an answer gets one
lint_aborted error finding and is never linted in the host process.
Studio's project lint keeps its timeout and gains a heap cap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* fix(producer): cap concurrent /lint workers at two

Each lint worker can hold up to 512 MB, so parallel /lint requests
multiplied that without bound. At most two run at once; the rest wait
in order, and a request still waiting when its own 15 s runs out gets
the lint_aborted result.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-11-16 12:10:39 -08:00
committed by GitHub
co-authored by Claude Sonnet 5.5
parent 95e4e7f880
commit 778a005641
15 changed files with 439 additions and 18 deletions
@@ -3,12 +3,15 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { tmpdir } from "node:os";
// Studio must lint outside its own process; any in-process project lint fails the request.
// Studio must lint outside its own process; any in-process project or page lint fails the request.
vi.mock("@hyperframes/lint", async (importOriginal) => ({
...(await importOriginal<typeof import("@hyperframes/lint")>()),
lintProject: () => {
throw new Error("project lint ran on the Studio server's event loop");
},
lintHyperframeHtml: () => {
throw new Error("page lint ran on the Studio server's event loop");
},
}));
const { createStudioServer } = await import("./studioServer.js");
@@ -24,6 +27,9 @@ beforeEach(() => {
<div id="root" data-composition-id="main" data-width="320" data-height="180"></div>
</body></html>`,
);
// Not linked from the entry, so the project lint skips it and the route lints it as a page.
fs.mkdirSync(path.join(root, "loose"));
fs.writeFileSync(path.join(root, "loose", "page.html"), `<div>no composition</div>`);
server = createStudioServer({ projectDir: root, projectName: "film" });
});
@@ -40,4 +46,12 @@ describe("studio lint", () => {
expect(response.status).toBe(200);
expect(body.findings?.some((f) => f.message.includes("window.__timelines"))).toBe(true);
}, 60_000);
it("lints a page the project lint skips in a separate process too", async () => {
const response = await server.app.request("/api/projects/film/lint");
const body = (await response.json()) as { findings?: Array<{ file?: string }> };
expect(response.status).toBe(200);
expect(body.findings?.some((f) => f.file === "loose/page.html")).toBe(true);
}, 60_000);
});
+9 -5
View File
@@ -49,6 +49,7 @@ import { recordFolder } from "../utils/projectRecords.js";
import { outsideAssetsAllowed } from "../utils/receivedRender.js";
import { insideHostApp } from "../utils/desktopApp.js";
import { runRenderSetupWorker } from "../utils/cancellableProcess.js";
import { lintHtmlOutOfProcess } from "../utils/lintHtmlWorker.js";
import { acquireRenderLock, describeRenderLockHolder } from "../utils/renderLock.js";
import type { ProjectLintResult } from "@hyperframes/lint";
import { resolveRenderBrowser } from "../browser/preflight.js";
@@ -110,6 +111,7 @@ const STUDIO_MANUAL_EDITS_PATH = ".hyperframes/studio-manual-edits.json";
const RENDER_SHUTDOWN_WAIT_MS = 2_000;
const LINT_WORKER_TIMEOUT_MS = 120_000;
const LINT_WORKER_HEAP_MB = 1024;
// Vite emits only content-hashed files under dist/assets; hand-authored
// public/ files land at the dist root. The route is the signal because the
@@ -618,10 +620,7 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
if (resolve(dir) === resolve(projectDir)) cachedProjectSignature = null;
},
async lint(html, opts) {
const { lintHyperframeHtml } = await import("@hyperframes/lint");
return await lintHyperframeHtml(html, { ...opts, host: "studio" });
},
lint: (html, opts) => lintHtmlOutOfProcess(html, { ...opts, host: "studio" }),
// Out of process: linting a large composition is seconds of synchronous parsing, and on
// this event loop it stalls every other Studio request, the preview included.
@@ -629,7 +628,12 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
runRenderSetupWorker<ProjectLintResult>(
"lint",
{ projectDir: dir, host: "studio", background: true },
{ maxBufferBytes: 8 * 1024 * 1024, signal, timeoutMs: LINT_WORKER_TIMEOUT_MS },
{
execArgv: [`--max-old-space-size=${LINT_WORKER_HEAP_MB}`],
maxBufferBytes: 8 * 1024 * 1024,
signal,
timeoutMs: LINT_WORKER_TIMEOUT_MS,
},
),
runtimeUrl: "/api/runtime.js",