fix(runtime): ship the socket-dir check with the packaged CLI; keep main sync fs flat

The CLI imports daemon-socket-endpoint-path, but electron-vite replaces
out/main, so packaging lost the module and the installed CLI crashed.
Add it to the CLI main entries and unpack it with its mode constants.
The lifecycle sweep and the stale-lock reclaim now use async fs for the
relocated dir, so the main sync-fs count stays at its baseline.
This commit is contained in:
m4air
2026-11-08 14:02:32 -08:00
parent c93287ad8d
commit 66dfd0cd53
4 changed files with 19 additions and 11 deletions
@@ -4,6 +4,8 @@ export const CLI_MAIN_ENTRY_NAMES = [
'gitlab/project-ref-parser',
'orca-profiles/profile-index-store',
'claude-accounts/keychain',
// The CLI checks a relocated runtime socket dir before it sends the auth token.
'daemon/endpoint/publication/daemon-socket-endpoint-path',
'skills/bundled-skill-install/bundled-skill-local-host',
'skills/bundled-skill-install/bundled-skill-installation',
'filesystem/macos-tree-clone',
+2
View File
@@ -345,6 +345,8 @@ module.exports = {
'out/main/antigravity/**',
'out/main/claude/**',
'out/main/codex/**',
// The CLI loads the socket-dir check; tsc-emitted output also needs its mode constants beside it.
'out/main/daemon/endpoint/publication/daemon-{socket-endpoint-path,private-file-modes}.js',
'out/main/copilot/**',
'out/main/cursor/**',
'out/main/droid/**',
+9 -9
View File
@@ -1,5 +1,6 @@
// Shared-home locks need explicit operator confirmation: local silence cannot prove a remote holder exited.
import { existsSync, readdirSync, statSync } from 'node:fs'
import { readdirSync, statSync } from 'node:fs'
import { readdir } from 'node:fs/promises'
import { createConnection } from 'node:net'
import { hostname } from 'node:os'
import { join } from 'node:path'
@@ -179,7 +180,7 @@ async function checkStaleLock(
if (!(now - writtenMs >= ORCAD_STALE_LOCK_MIN_AGE_MS)) {
return { refusal: `The lock is less than ${ORCAD_STALE_LOCK_MIN_AGE_MS / 60_000} minutes old.` }
}
const endpoints = holderEndpoints(dataRoot, holder.pid)
const endpoints = await holderEndpoints(dataRoot, holder.pid)
if (!endpoints) {
return { refusal: 'The runtime record in the data root cannot be read.' }
}
@@ -208,7 +209,7 @@ async function checkStaleLock(
}
/** Null leaves endpoints unverifiable when runtime metadata is unreadable. */
function holderEndpoints(dataRoot: string, pid: number): string[] | null {
async function holderEndpoints(dataRoot: string, pid: number): Promise<string[] | null> {
const endpoints = new Set<string>()
try {
const metadata = readRuntimeMetadata(dataRoot)
@@ -218,12 +219,11 @@ function holderEndpoints(dataRoot: string, pid: number): string[] | null {
}
}
for (const dir of runtimeSocketDirs(dataRoot)) {
// A long data root relocates the holder's socket; a missing relocated dir holds nothing.
for (const entry of dir === dataRoot || existsSync(dir) ? readdirSync(dir) : []) {
if (RUNTIME_SOCKET_NAME_REGEX.exec(entry)?.[1] === String(pid)) {
endpoints.add(join(dir, entry))
}
}
// A long data root relocates the holder's socket; it only listens in a dir this user can read.
const entries = dir === dataRoot ? readdirSync(dir) : await readdir(dir).catch(() => [])
entries
.filter((entry) => RUNTIME_SOCKET_NAME_REGEX.exec(entry)?.[1] === String(pid))
.forEach((entry) => endpoints.add(join(dir, entry)))
}
} catch {
return null
@@ -1,4 +1,4 @@
import { existsSync } from 'node:fs'
import { stat } from 'node:fs/promises'
import { basename, join } from 'node:path'
import { AGENT_LAUNCH_RUNTIME_CAPABILITY } from '../../../../shared/agent-launch/contracts/agent-launch-runtime-capability'
import { ORCA_LAYOUT_OWNER_IS_MAIN } from '../../../../shared/layout-owner-switch'
@@ -63,7 +63,11 @@ export class RuntimeRpcLifecycle extends RuntimeRpcWebSocketDispatch {
for (const dir of runtimeSocketDirs(this.userDataPath)) {
if (
dir === this.userDataPath ||
(existsSync(dir) && daemonSocketDirIsTrusted(join(dir, basename(transportMeta.endpoint))))
((await stat(dir).then(
() => true,
() => false
)) &&
daemonSocketDirIsTrusted(join(dir, basename(transportMeta.endpoint))))
) {
sweepOrphanedRuntimeSockets(dir, this.pid)
}