openclaw/scripts/lib/runtime-process-core-build-entries.mts
Vincent Koc b9cd492ac6
fix(tooling): enforce Linux process-tree memory limits (#160024)
Add opt-in aggregate Linux process-tree memory containment to the managed tooling runner. Own the invocation-specific scope through verified cleanup before releasing its resource claim; preserve uncapped caller behavior.

Validated real-kernel OOM, descendant cleanup, signals, cancellation and packaged launcher behavior; focused lifecycle/preload tests and exact-head CI/security gates passed. Related: #160010.
2026-09-28 11:58:07 +08:00

57 lines
1.9 KiB
TypeScript

import { fileURLToPath } from "node:url";
import { runtimeProcessEntrypoints } from "../../src/infra/runtime-process-entrypoints.ts";
import { managedMemoryEntrypoint } from "./managed-memory-entrypoint.mts";
import { managedWindowsJobEntrypoint } from "./managed-windows-job-entrypoint.mts";
export function createRuntimeProcessBuildEntries(
entries: readonly {
currentModuleUrl: string;
sourceWorkerName: string;
distWorkerPath: string;
sourceExtension?: ".ts" | ".mts";
}[],
) {
return Object.fromEntries(
entries.map((entry) => [
entry.distWorkerPath.replace(/\.js$/u, ""),
fileURLToPath(
new URL(
`./${entry.sourceWorkerName}${entry.sourceExtension ?? ".ts"}`,
entry.currentModuleUrl,
),
),
]),
);
}
export const runtimeProcessCoreEntrypoints = [
...Object.values(runtimeProcessEntrypoints),
managedWindowsJobEntrypoint,
managedMemoryEntrypoint,
];
export const runtimeProcessCoreBuildEntries = createRuntimeProcessBuildEntries(
runtimeProcessCoreEntrypoints,
);
// Keep small helper processes out of the shared runtime bundle.
export const standaloneRuntimeProcessBuildEntries = createRuntimeProcessBuildEntries([
managedMemoryEntrypoint,
runtimeProcessEntrypoints.sqliteReadOnly,
runtimeProcessEntrypoints.sqliteSourceRevision,
runtimeProcessEntrypoints.stateRead,
runtimeProcessEntrypoints.nativeHookRelayClient,
runtimeProcessEntrypoints.spawnBroker,
runtimeProcessEntrypoints.stateLeaseHeartbeat,
]);
export function shouldBundleRuntimeSqliteDependency(id: string): boolean {
return id === "kysely" || id.startsWith("kysely/");
}
export function sharedRuntimeProcessBuildEntries(entries: Record<string, string>) {
return Object.fromEntries(
Object.entries(entries).filter(
([name]) => !Object.hasOwn(standaloneRuntimeProcessBuildEntries, name),
),
);
}