diff --git a/config/build-plugins/cli-main-entry-names.ts b/config/build-plugins/cli-main-entry-names.ts index 2668645fa61..92a872d7a51 100644 --- a/config/build-plugins/cli-main-entry-names.ts +++ b/config/build-plugins/cli-main-entry-names.ts @@ -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', diff --git a/config/electron-builder.config.cjs b/config/electron-builder.config.cjs index 800c2d36089..45e04fdcd0a 100644 --- a/config/electron-builder.config.cjs +++ b/config/electron-builder.config.cjs @@ -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/**', diff --git a/src/main/orcad/orcad-stale-lock-reclaim.ts b/src/main/orcad/orcad-stale-lock-reclaim.ts index 40f1d277f38..7baf1ce9fd8 100644 --- a/src/main/orcad/orcad-stale-lock-reclaim.ts +++ b/src/main/orcad/orcad-stale-lock-reclaim.ts @@ -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 { const endpoints = new Set() 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 diff --git a/src/main/runtime/rpc/server/runtime-rpc-lifecycle.ts b/src/main/runtime/rpc/server/runtime-rpc-lifecycle.ts index 8da07756c51..9a6c89046ab 100644 --- a/src/main/runtime/rpc/server/runtime-rpc-lifecycle.ts +++ b/src/main/runtime/rpc/server/runtime-rpc-lifecycle.ts @@ -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) }