Merge branch 'main' into storage-terminal-ui-dev
This commit is contained in:
@@ -7,7 +7,7 @@ dotenv.config({
|
||||
quiet: true,
|
||||
});
|
||||
|
||||
const daemonRunnerEntry = fileURLToPath(new URL("./daemon-runner.ts", import.meta.url));
|
||||
const daemonRunnerEntry = fileURLToPath(new URL("./supervisor-entrypoint.ts", import.meta.url));
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
["--inspect", "--heapsnapshot-near-heap-limit=3", "--max-old-space-size=3072", "--report-on-fatalerror", "--report-directory=/tmp/paseo-reports", ...process.execArgv, daemonRunnerEntry, "--dev", ...process.argv.slice(2)],
|
||||
|
||||
@@ -3,7 +3,10 @@ import { describe, expect, test } from "vitest";
|
||||
|
||||
describe("supervision parity", () => {
|
||||
test("has exactly one runtime callsite for runSupervisor", () => {
|
||||
const daemonRunner = readFileSync(new URL("./daemon-runner.ts", import.meta.url), "utf8");
|
||||
const daemonRunner = readFileSync(
|
||||
new URL("./supervisor-entrypoint.ts", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
const devRunner = readFileSync(new URL("./dev-runner.ts", import.meta.url), "utf8");
|
||||
|
||||
const daemonRunnerCalls = (daemonRunner.match(/\brunSupervisor\s*\(/g) ?? []).length;
|
||||
|
||||
+11
-8
@@ -1,8 +1,12 @@
|
||||
import { fileURLToPath } from "url";
|
||||
import { existsSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { loadConfig } from "../src/server/config.js";
|
||||
import { acquirePidLock, PidLockError, releasePidLock } from "../src/server/pid-lock.js";
|
||||
import {
|
||||
acquirePidLock,
|
||||
PidLockError,
|
||||
releasePidLock,
|
||||
updatePidLock,
|
||||
} from "../src/server/pid-lock.js";
|
||||
import { resolvePaseoHome } from "../src/server/paseo-home.js";
|
||||
import { runSupervisor } from "./supervisor.js";
|
||||
import { applySherpaLoaderEnv } from "../src/server/speech/providers/local/sherpa/sherpa-runtime-env.js";
|
||||
@@ -72,10 +76,7 @@ async function main(): Promise<void> {
|
||||
const config = parseConfig(process.argv.slice(2));
|
||||
const workerEntry = config.devMode ? resolveDevWorkerEntry() : resolveWorkerEntry();
|
||||
const workerExecArgv = resolveWorkerExecArgv(workerEntry);
|
||||
const workerEnv: NodeJS.ProcessEnv = {
|
||||
...process.env,
|
||||
PASEO_PID_LOCK_MODE: "external",
|
||||
};
|
||||
const workerEnv: NodeJS.ProcessEnv = { ...process.env, PASEO_SUPERVISED: "1" };
|
||||
const packagedNodeEntrypointRunner =
|
||||
process.env.ELECTRON_RUN_AS_NODE === "1"
|
||||
? resolvePackagedNodeEntrypointRunnerPath(fileURLToPath(import.meta.url))
|
||||
@@ -84,10 +85,9 @@ async function main(): Promise<void> {
|
||||
applySherpaLoaderEnv(workerEnv);
|
||||
|
||||
const paseoHome = resolvePaseoHome(workerEnv);
|
||||
const daemonConfig = loadConfig(paseoHome, { env: workerEnv });
|
||||
|
||||
try {
|
||||
await acquirePidLock(paseoHome, daemonConfig.listen, {
|
||||
await acquirePidLock(paseoHome, null, {
|
||||
ownerPid: process.pid,
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -135,6 +135,9 @@ async function main(): Promise<void> {
|
||||
})
|
||||
: undefined,
|
||||
restartOnCrash: config.devMode,
|
||||
onWorkerReady: async ({ listen }) => {
|
||||
await updatePidLock(paseoHome, { listen }, { ownerPid: process.pid });
|
||||
},
|
||||
onSupervisorExit: releaseLock,
|
||||
});
|
||||
}
|
||||
@@ -4,6 +4,10 @@ type WorkerLifecycleMessage =
|
||||
| {
|
||||
type: "paseo:shutdown";
|
||||
}
|
||||
| {
|
||||
type: "paseo:ready";
|
||||
listen: string;
|
||||
}
|
||||
| {
|
||||
type: "paseo:restart";
|
||||
reason?: string;
|
||||
@@ -21,6 +25,7 @@ type SupervisorOptions = {
|
||||
args: string[];
|
||||
env?: NodeJS.ProcessEnv;
|
||||
} | null;
|
||||
onWorkerReady?: (message: { listen: string }) => Promise<void> | void;
|
||||
restartOnCrash?: boolean;
|
||||
onSupervisorExit?: () => Promise<void> | void;
|
||||
};
|
||||
@@ -37,6 +42,13 @@ function parseLifecycleMessage(msg: unknown): WorkerLifecycleMessage | null {
|
||||
if (type === "paseo:shutdown") {
|
||||
return { type: "paseo:shutdown" };
|
||||
}
|
||||
if (type === "paseo:ready") {
|
||||
const listen = (msg as { listen?: unknown }).listen;
|
||||
if (typeof listen !== "string" || listen.trim().length === 0) {
|
||||
return null;
|
||||
}
|
||||
return { type: "paseo:ready", listen };
|
||||
}
|
||||
if (type === "paseo:restart") {
|
||||
const reason = (msg as { reason?: unknown }).reason;
|
||||
return {
|
||||
@@ -110,6 +122,16 @@ export function runSupervisor(options: SupervisorOptions): void {
|
||||
return;
|
||||
}
|
||||
|
||||
if (lifecycleMessage.type === "paseo:ready") {
|
||||
Promise.resolve(options.onWorkerReady?.({ listen: lifecycleMessage.listen })).catch(
|
||||
(error) => {
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
log(`Worker ready callback failed: ${message}`);
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lifecycleMessage.type === "paseo:shutdown") {
|
||||
requestShutdown("Shutdown requested by worker");
|
||||
return;
|
||||
@@ -127,7 +149,11 @@ export function runSupervisor(options: SupervisorOptions): void {
|
||||
return;
|
||||
}
|
||||
|
||||
if (restarting || (restartOnCrash && code !== 0 && code !== null)) {
|
||||
const crashed =
|
||||
restartOnCrash &&
|
||||
((code !== 0 && code !== null) || (signal !== null && signal === "SIGKILL"));
|
||||
|
||||
if (restarting || crashed) {
|
||||
restarting = false;
|
||||
log(`Worker exited (${exitDescriptor}). Restarting worker...`);
|
||||
spawnWorker();
|
||||
|
||||
Reference in New Issue
Block a user