singularity-forge/web/app/api/boot/route.ts
Tom Boucher 2e04253c0b fix: resolve Node v24 web boot failure — ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING (#1864)
Node v24 forbids --experimental-strip-types for files under node_modules/.
When GSD is globally installed, all src/ files live under node_modules/gsd-pi/,
causing every subprocess worker to crash with ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING.

Bug 1: Extract resolveTypeStrippingFlag() into src/web/ts-subprocess-flags.ts.
When the package root is under node_modules/ and Node >= 22.7, the function
returns --experimental-transform-types (which handles node_modules paths).
All 15 service files and cli-entry.ts now call this function instead of
hardcoding --experimental-strip-types.

Bug 2: waitForBootReady() now tracks consecutive 5xx responses and aborts
after 3 in a row, including the response body in the error message.
Connection-level errors (transient during cold start) reset the counter.

Bug 3: The /api/boot route handler now wraps collectBootPayload() in
try/catch and returns { error: message } with status 500, matching the
error response pattern used by other API routes.

Fixes #1849

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 15:24:07 -06:00

46 lines
1.4 KiB
TypeScript

import { collectBootPayload, resolveProjectCwd } from "../../../../src/web/bridge-service.ts";
import { cancelShutdown } from "../../../lib/shutdown-gate";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(request: Request): Promise<Response> {
// A boot request proves the client is alive — cancel any pending shutdown
// that was scheduled by pagehide during a page refresh.
cancelShutdown();
const projectCwd = resolveProjectCwd(request);
// When no project is configured (no GSD_WEB_PROJECT_CWD env and no ?project param),
// return a minimal "no project" payload so the frontend can show the project picker.
if (!projectCwd) {
return Response.json({
project: null,
workspace: null,
auto: null,
onboarding: { locked: false },
onboardingNeeded: false,
resumableSessions: [],
bridge: null,
projectDetection: null,
}, {
headers: { "Cache-Control": "no-store" },
});
}
try {
const bootPayload = await collectBootPayload(projectCwd);
return Response.json(bootPayload, {
headers: {
"Cache-Control": "no-store",
},
});
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
return Response.json(
{ error: message },
{ status: 500, headers: { "Cache-Control": "no-store" } },
);
}
}