fix: move PID lock to bootstrap.ts for all entrypoints

This commit is contained in:
Mohamed Boudra
2026-01-30 12:09:56 +07:00
parent f689cb1385
commit f8da5ada71
2 changed files with 16 additions and 1 deletions

View File

@@ -59,6 +59,7 @@ import type {
AgentClient,
AgentProvider,
} from "./agent/agent-sdk-types.js";
import { acquirePidLock, releasePidLock } from "./pid-lock.js";
type AgentMcpTransportMap = Map<string, StreamableHTTPServerTransport>;
@@ -498,6 +499,9 @@ export async function createPaseoDaemon(
);
const start = async () => {
// Acquire PID lock
await acquirePidLock(config.paseoHome, selfIdMcpSocketPath);
// Start Self-ID MCP socket server first
await new Promise<void>((resolve, reject) => {
const onError = (err: Error) => {
@@ -604,6 +608,8 @@ export async function createPaseoDaemon(
if (existsSync(selfIdMcpSocketPath)) {
unlinkSync(selfIdMcpSocketPath);
}
// Release PID lock
await releasePidLock(config.paseoHome);
};
return {

View File

@@ -9,6 +9,7 @@ import { loadConfig } from "./config.js";
import { resolvePaseoHome } from "./paseo-home.js";
import { createRootLogger } from "./logger.js";
import { loadPersistedConfig } from "./persisted-config.js";
import { PidLockError } from "./pid-lock.js";
async function main() {
const paseoHome = resolvePaseoHome();
@@ -21,7 +22,15 @@ async function main() {
}
const daemon = await createPaseoDaemon(config, logger);
await daemon.start();
try {
await daemon.start();
} catch (err) {
if (err instanceof PidLockError) {
logger.error({ pid: err.existingLock?.pid }, err.message);
process.exit(1);
}
throw err;
}
let shuttingDown = false;
const handleShutdown = async (signal: string) => {