Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat: implement automated managed runtime provisioning to ensure consistent Node.js environments for the daemon and launcher.

0xken151a4b4d11acd1
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 35580ef40..dfa80be5b 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -115,6 +115,8 @@ import {
fetchManifest, downloadVerified, canary, stage, semverGt, shouldAutoUpdate, isLocalDevBuild,
type Poller, type UpdateEntry,
} from './lib/selfUpdate.js'
+import { managedNodePath } from './lib/nodeRuntime.js'
+import { ensureLauncher, ensureManagedRuntime } from './lib/runtimeInstall.js'
import { stat } from 'fs/promises'
import { CodexNormalizer, codexTaskError, lastCodexTurnText } from './engines/codex/normalizer.js'
import { CursorNormalizer, lastCursorTurnText } from './engines/cursor/normalizer.js'
@@ -3536,7 +3538,10 @@ async function runForeground(session: AuthSession): Promise<void> {
const spawnDaemon = (extraEnv: Record<string, string>): ReturnType<typeof spawn> => {
prepareLogFile(LOG_FILE, LEGACY_LOG_FILE) // before the fd + the sinceOffset below, so both see one size
const fd = openSync(LOG_FILE, 'a')
- const c = spawn(process.execPath, [SCRIPT_PATH, '__run'], {
+ // Serves the update restart AND the rollback respawn. managedNodePath() is re-read here rather
+ // than captured at boot, so a runtime provisioned during this process's lifetime is the one the
+ // next daemon runs on.
+ const c = spawn(managedNodePath(), [SCRIPT_PATH, '__run'], {
detached: true, env: { ...process.env, ...extraEnv }, stdio: ['ignore', fd, fd],
})
// A spawn failure (e.g. EMFILE) emits 'error' on the child; with no listener that is an
@@ -3929,6 +3934,12 @@ async function waitForReady(sinceOffset: number, timeoutMs = 8000): Promise<Read
async function launch(foreground: boolean): Promise<void> {
const session = readAuthSession()
if (!session) throw new Error('Not signed in. Run `harness login`.')
+ // Provision the Node we run on, and repoint the launcher at it, BEFORE anything is spawned. Before
+ // matters twice over: the parent tails the daemon log and gives up after CONNECT_WAIT_MS, so a
+ // first-run ~50MB download inside the child would surface as a bogus start-up timeout; and in the
+ // foreground this is where the user can actually see it happen.
+ const runtimeNode = await ensureManagedRuntime((m) => console.log(m))
+ if (runtimeNode) ensureLauncher(runtimeNode, (m) => console.log(m))
// Foreground mode (supervisor) OR dev/tsx (can't cleanly spawn a .ts detached) → run inline.
if (foreground || SCRIPT_PATH.endsWith('.ts')) {
if (!foreground) console.log('[cli] dev mode — running in the foreground (Ctrl-C to stop)')
@@ -3947,7 +3958,9 @@ async function launch(foreground: boolean): Promise<void> {
prepareLogFile(LOG_FILE, LEGACY_LOG_FILE) // adopt an older name + enforce the cap before we tail from here
const logOffset = existsSync(LOG_FILE) ? readFileSync(LOG_FILE).length : 0
const logFd = openSync(LOG_FILE, 'a')
- const child = spawn(process.execPath, [SCRIPT_PATH, '__run'], {
+ // The daemon starts on the managed runtime straight away rather than inheriting this process's
+ // interpreter and waiting for some later restart to adopt it.
+ const child = spawn(runtimeNode ?? process.execPath, [SCRIPT_PATH, '__run'], {
detached: true,
env: { ...process.env },
stdio: ['ignore', logFd, logFd],
diff --git a/cli/src/config/env.ts b/cli/src/config/env.ts
index c79d626fa..4bf04c908 100644
--- a/cli/src/config/env.ts
+++ b/cli/src/config/env.ts
@@ -14,6 +14,8 @@ const adapterDataDir = join(adapterCliDir, 'data')
// The private, checksum-verified Node the installers and Desktop Harness provision. `current-node`
// inside it names the binary in use; both writers rewrite that file whenever they lay down a runtime.
const adapterRuntimeDir = join(adapterRootDir, 'runtime')
+// The `harness` launcher the installers write. Not under ~/.harness: it has to sit on PATH.
+const adapterBinDir = join(homedir(), '.local', 'bin')
// The computer id lives at the PRODUCT root, one level ABOVE `cli/`, and deliberately not in the data
// dir: `harness reset` wipes that dir, the ~/.machine adoption below force-replaces entries in it, and
// a custom ADAPTER_DATA_DIR moves it. A computer's identity must outlive all three — the backend binds
@@ -372,6 +374,15 @@ const envSchema = z.object({
// lines have to name an interpreter by absolute path, because a hook fires in a shell whose PATH
// we do not control — see managedNodePath() in lib/nodeRuntime.ts.
ADAPTER_RUNTIME_DIR: z.string().default(adapterRuntimeDir),
+ // The runtime manifest — a DIFFERENT document from ADAPTER_UPDATE_URL's: keyed by platform
+ // (`darwin-arm64`, `linux-x64`, …) with url/sha256/size/archiveRoot per entry. Deliberately the
+ // same URL `install.sh` and Desktop Harness read, so all three land on identical bytes.
+ ADAPTER_RUNTIME_METADATA_URL: z
+ .string()
+ .default('https://storage.googleapis.com/s3-autonomous-upgrade-3/harness/runtime/metadata.json'),
+ // Where the `harness` launcher lives. Same name (and default) `scripts/install-cli.sh` uses, so a
+ // sandboxed install and this process agree on which launcher they are talking about.
+ HARNESS_BIN_DIR: z.string().default(adapterBinDir),
// ── the dial on the USB cable ──────────────────────────────────────────────────────────────────
// Set 'true' to leave the serial port alone entirely. The port is exclusive, so this is what a
diff --git a/cli/src/lib/runtimeInstall.spec.ts b/cli/src/lib/runtimeInstall.spec.ts
new file mode 100644
index 000000000..486e8fe85
--- /dev/null
+++ b/cli/src/lib/runtimeInstall.spec.ts
@@ -0,0 +1,255 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { execFileSync } from 'node:child_process'
+import { createHash } from 'node:crypto'
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { tmpdir } from 'node:os'
+
+let root = ''
+let runtimeDir = ''
+let binDir = ''
+let cliDir = ''
+
+async function load() {
+ vi.resetModules()
+ process.env.ADAPTER_RUNTIME_DIR = runtimeDir
+ process.env.HARNESS_BIN_DIR = binDir
+ process.env.ADAPTER_CLI_DIR = cliDir
+ process.env.ADAPTER_RUNTIME_METADATA_URL = 'https://example.test/runtime/metadata.json'
+ return import('./runtimeInstall.js')
+}
+
+/** A real gzipped tarball laid out the way nodejs.org ships one, with a runnable `bin/node`. */
+function buildArchive(version: string, key: string): { bytes: Buffer; root: string } {
+ const archiveRoot = `node-${version}-${key}`
+ const source = join(root, 'src')
+ mkdirSync(join(source, archiveRoot, 'bin'), { recursive: true })
+ writeFileSync(join(source, archiveRoot, 'bin', 'node'), '#!/bin/sh\nexit 0\n', { mode: 0o755 })
+ const archive = join(root, `${archiveRoot}.tar.gz`)
+ execFileSync('/usr/bin/tar', ['-czf', archive, '-C', source, archiveRoot])
+ return { bytes: readFileSync(archive), root: archiveRoot }
+}
+
+function currentPlatformKey(): string {
+ const os = process.platform === 'darwin' ? 'darwin' : 'linux'
+ return `${os}-${process.arch === 'arm64' ? 'arm64' : 'x64'}`
+}
+
+/** Serves the manifest and the archive; any other URL is a test bug. */
+function stubFetch(manifest: unknown, archive?: Buffer): void {
+ vi.stubGlobal('fetch', async (input: string | URL) => {
+ const url = String(input)
+ if (url.endsWith('metadata.json')) {
+ return { ok: true, json: async () => manifest } as unknown as Response
+ }
+ if (archive && url.endsWith('.tar.gz')) {
+ return { ok: true, arrayBuffer: async () => archive.buffer.slice(archive.byteOffset, archive.byteOffset + archive.byteLength) } as unknown as Response
+ }
+ return { ok: false, status: 404 } as unknown as Response
+ })
+}
+
+describe('ensureManagedRuntime', () => {
+ beforeEach(() => {
+ root = mkdtempSync(join(tmpdir(), 'harness-runtime-install-'))
+ runtimeDir = join(root, '.harness', 'runtime')
+ binDir = join(root, '.local', 'bin')
+ cliDir = join(root, '.harness', 'cli')
+ mkdirSync(runtimeDir, { recursive: true })
+ mkdirSync(binDir, { recursive: true })
+ mkdirSync(cliDir, { recursive: true })
+ })
+
+ afterEach(() => {
+ vi.unstubAllGlobals()
+ rmSync(root, { recursive: true, force: true })
+ for (const key of ['ADAPTER_RUNTIME_DIR', 'HARNESS_BIN_DIR', 'ADAPTER_CLI_DIR', 'ADAPTER_RUNTIME_METADATA_URL']) {
+ delete process.env[key]
+ }
+ })
+
+ it('does nothing, and fetches nothing, when a runtime is already installed', async () => {
+ const node = join(runtimeDir, 'node-v22', 'bin', 'node')
+ mkdirSync(join(runtimeDir, 'node-v22', 'bin'), { recursive: true })
+ writeFileSync(node, '#!/bin/sh\nexit 0\n', { mode: 0o755 })
+ writeFileSync(join(runtimeDir, 'current-node'), `${node}\n`)
+ const fetchSpy = vi.fn()
+ vi.stubGlobal('fetch', fetchSpy)
+
+ const { ensureManagedRuntime } = await load()
+
+ expect(await ensureManagedRuntime()).toBe(node)
+ expect(fetchSpy).not.toHaveBeenCalled()
+ })
+
+ it('downloads, verifies and unpacks a runtime, then records it', async () => {
+ const key = currentPlatformKey()
+ const { bytes, root: archiveRoot } = buildArchive('v22.23.2', key)
+ stubFetch({
+ node: {
+ [key]: {
+ version: 'v22.23.2',
+ url: 'https://example.test/runtime/node.tar.gz',
+ sha256: createHash('sha256').update(bytes).digest('hex'),
+ size: bytes.length,
+ archiveRoot,
+ },
+ },
+ }, bytes)
+
+ const { ensureManagedRuntime } = await load()
+ const node = await ensureManagedRuntime()
+
+ expect(node).toBe(join(runtimeDir, `node-v22.23.2-${key}`, 'bin', 'node'))
+ expect(existsSync(node!)).toBe(true)
+ expect(readFileSync(join(runtimeDir, 'current-node'), 'utf8').trim()).toBe(node)
+ // Staging never survives, whatever happened.
+ expect(readdirSync(runtimeDir).filter((n) => n.startsWith('.node-staging-'))).toEqual([])
+ })
+
+ it('refuses an archive whose bytes do not match the manifest', async () => {
+ const key = currentPlatformKey()
+ const { bytes, root: archiveRoot } = buildArchive('v22.23.2', key)
+ stubFetch({
+ node: {
+ [key]: {
+ version: 'v22.23.2',
+ url: 'https://example.test/runtime/node.tar.gz',
+ sha256: 'a'.repeat(64),
+ size: bytes.length,
+ archiveRoot,
+ },
+ },
+ }, bytes)
+
+ const { ensureManagedRuntime } = await load()
+
+ expect(await ensureManagedRuntime()).toBeNull()
+ expect(existsSync(join(runtimeDir, 'current-node'))).toBe(false)
+ })
+
+ // Served as a fully valid, correctly-hashed archive — so the ONLY thing that can reject it is the
+ // scheme check. Anything less and this passes for the wrong reason.
+ it('refuses a plaintext archive URL even when the bytes are otherwise valid', async () => {
+ const key = currentPlatformKey()
+ const { bytes, root: archiveRoot } = buildArchive('v22.23.2', key)
+ stubFetch({
+ node: {
+ [key]: {
+ version: 'v22.23.2',
+ url: 'http://example.test/runtime/node.tar.gz',
+ sha256: createHash('sha256').update(bytes).digest('hex'),
+ size: bytes.length,
+ archiveRoot,
+ },
+ },
+ }, bytes)
+
+ const { ensureManagedRuntime } = await load()
+
+ expect(await ensureManagedRuntime()).toBeNull()
+ expect(existsSync(join(runtimeDir, 'current-node'))).toBe(false)
+ })
+
+ // A daemon must not fail to start because a download failed; it keeps the interpreter it has.
+ it('returns null instead of throwing when the manifest is unreachable', async () => {
+ vi.stubGlobal('fetch', async () => { throw new Error('ENOTFOUND') })
+
+ const { ensureManagedRuntime } = await load()
+
+ await expect(ensureManagedRuntime()).resolves.toBeNull()
+ })
+})
+
+describe('ensureLauncher', () => {
+ const NODE = '/opt/harness/runtime/node-v22/bin/node'
+
+ beforeEach(() => {
+ root = mkdtempSync(join(tmpdir(), 'harness-launcher-'))
+ runtimeDir = join(root, '.harness', 'runtime')
+ binDir = join(root, '.local', 'bin')
+ cliDir = join(root, '.harness', 'cli')
+ for (const dir of [runtimeDir, binDir, cliDir]) mkdirSync(dir, { recursive: true })
+ })
+
+ afterEach(() => {
+ rmSync(root, { recursive: true, force: true })
+ for (const key of ['ADAPTER_RUNTIME_DIR', 'HARNESS_BIN_DIR', 'ADAPTER_CLI_DIR', 'ADAPTER_RUNTIME_METADATA_URL']) {
+ delete process.env[key]
+ }
+ })
+
+ const launcherPath = () => join(binDir, 'harness')
+ const cliPath = () => join(cliDir, 'cli.js')
+
+ it('repairs the bare-node launcher install-cli.sh used to write', async () => {
+ writeFileSync(launcherPath(), `#!/bin/sh\nexec node "${cliPath()}" "$@"\n`, { mode: 0o755 })
+
+ const { ensureLauncher } = await load()
+ ensureLauncher(NODE)
+
+ expect(readFileSync(launcherPath(), 'utf8')).toBe(`#!/bin/sh\nexec '${NODE}' '${cliPath()}' "$@"\n`)
+ })
+
+ it('repairs an absolute system-Node launcher from the public installer', async () => {
+ writeFileSync(launcherPath(), `#!/bin/sh\nexec '/opt/homebrew/bin/node' '${cliPath()}' "$@"\n`, { mode: 0o755 })
+
+ const { ensureLauncher } = await load()
+ ensureLauncher(NODE)
+
+ expect(readFileSync(launcherPath(), 'utf8')).toContain(`exec '${NODE}'`)
+ expect(readFileSync(launcherPath(), 'utf8')).not.toContain('homebrew')
+ })
+
+ // The pin is the promise that no release reaches this computer on its own. Repairing the
+ // interpreter must not quietly revoke it.
+ it('fixes a dev-pinned launcher without disarming the pin', async () => {
+ const pinned = [
+ '#!/bin/sh',
+ '# Local dev install, PINNED with --no-updates (see scripts/install-cli.sh).',
+ '# Self-update is off: no release will ever reach this computer on its own, not even a newer one.',
+ 'ADAPTER_UPDATE_DISABLE=true',
+ 'export ADAPTER_UPDATE_DISABLE',
+ `exec node "${cliPath()}" "$@"`,
+ '',
+ ].join('\n')
+ writeFileSync(launcherPath(), pinned, { mode: 0o755 })
+
+ const { ensureLauncher } = await load()
+ ensureLauncher(NODE)
+
+ const out = readFileSync(launcherPath(), 'utf8')
+ expect(out).toContain('ADAPTER_UPDATE_DISABLE=true')
+ expect(out).toContain('export ADAPTER_UPDATE_DISABLE')
+ expect(out).toContain('# Local dev install, PINNED with --no-updates (see scripts/install-cli.sh).')
+ expect(out).toContain(`exec '${NODE}' '${cliPath()}' "$@"`)
+ expect(out).not.toContain('exec node')
+ })
+
+ it('leaves a launcher that already points at the right Node untouched', async () => {
+ const correct = `#!/bin/sh\nexec '${NODE}' '${cliPath()}' "$@"\n`
+ writeFileSync(launcherPath(), correct, { mode: 0o755 })
+
+ const { ensureLauncher } = await load()
+ ensureLauncher(NODE)
+
+ expect(readFileSync(launcherPath(), 'utf8')).toBe(correct)
+ })
+
+ it('never touches a script it did not write', async () => {
+ const foreign = '#!/bin/sh\nexec /usr/local/bin/somebody-elses-tool "$@"\n'
+ writeFileSync(launcherPath(), foreign, { mode: 0o755 })
+
+ const { ensureLauncher } = await load()
+ ensureLauncher(NODE)
+
+ expect(readFileSync(launcherPath(), 'utf8')).toBe(foreign)
+ })
+
+ it('does not create a launcher where none exists', async () => {
+ const { ensureLauncher } = await load()
+ ensureLauncher(NODE)
+
+ expect(existsSync(launcherPath())).toBe(false)
+ })
+})
diff --git a/cli/src/lib/runtimeInstall.ts b/cli/src/lib/runtimeInstall.ts
new file mode 100644
index 000000000..27d2a8d1e
--- /dev/null
+++ b/cli/src/lib/runtimeInstall.ts
@@ -0,0 +1,151 @@
+import { execFileSync } from 'node:child_process'
+import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
+import { join, sep } from 'node:path'
+
+import { env } from '../config/env.js'
+import { managedNodePath } from './nodeRuntime.js'
+import { downloadVerified } from './selfUpdate.js'
+
+/**
+ * Provisioning the Node the CLI runs on, from inside the CLI.
+ *
+ * Until now only the shell installers ever wrote a runtime or a launcher, and nothing re-ran them —
+ * so a computer installed before the product owned its Node keeps a launcher that execs a bare `node`
+ * (or an absolute path to a system Node that may since have been removed), and stays broken until
+ * somebody re-runs an installer by hand. Doing it here means `harness start` and the post-update
+ * restart repair the machine themselves.
+ *
+ * Everything in this file is best-effort and returns rather than throws: a daemon must not fail to
+ * start because a download failed. It keeps running on the interpreter it already has, and tries
+ * again next start.
+ */
+
+/** `darwin-arm64` | `darwin-x64` | `linux-arm64` | `linux-x64`, or null off those platforms. */
+function platformKey(): string | null {
+ const os = process.platform === 'darwin' ? 'darwin' : process.platform === 'linux' ? 'linux' : null
+ const arch = process.arch === 'arm64' ? 'arm64' : process.arch === 'x64' ? 'x64' : null
+ return os && arch ? `${os}-${arch}` : null
+}
+
+interface RuntimeArtifact {
+ version: string
+ url: string
+ sha256: string
+ size?: number
+ archiveRoot: string
+}
+
+function artifactFor(document: unknown, key: string): RuntimeArtifact | null {
+ const node = (document as { node?: Record<string, unknown> } | null)?.node
+ const raw = node?.[key] as Partial<RuntimeArtifact> | undefined
+ if (!raw || typeof raw.version !== 'string' || typeof raw.url !== 'string') return null
+ if (typeof raw.sha256 !== 'string' || typeof raw.archiveRoot !== 'string') return null
+ // Refuse a plaintext URL: this archive becomes the interpreter for everything the CLI runs.
+ if (!raw.url.startsWith('https://')) return null
+ return { version: raw.version, url: raw.url, sha256: raw.sha256, size: raw.size, archiveRoot: raw.archiveRoot }
+}
+
+function runs(node: string): boolean {
+ try {
+ execFileSync(node, ['--version'], { timeout: 15_000, stdio: 'ignore' })
+ return true
+ } catch {
+ return false
+ }
+}
+
+/**
+ * The managed Node, installing it when this computer has not got one. Returns its path, or null when
+ * no runtime could be provisioned — callers keep whatever interpreter they already have.
+ *
+ * Idempotent and cheap once installed: [managedNodePath] returning a path under the runtime directory
+ * means the work is already done, and nothing is fetched.
+ */
+export async function ensureManagedRuntime(log: (message: string) => void = () => {}): Promise<string | null> {
+ const existing = managedNodePath()
+ if (existing.startsWith(env.ADAPTER_RUNTIME_DIR + sep)) return existing
+
+ const key = platformKey()
+ if (!key) return null
+
+ try {
+ const response = await fetch(env.ADAPTER_RUNTIME_METADATA_URL)
+ if (!response.ok) return null
+ const artifact = artifactFor(await response.json(), key)
+ if (!artifact) return null
+
+ const target = join(env.ADAPTER_RUNTIME_DIR, `node-${artifact.version}-${key}`)
+ const node = join(target, 'bin', 'node')
+ if (!existsSync(node)) {
+ log(`▸ installing the Harness Node runtime (${artifact.version}, ${key})…`)
+ // downloadVerified checks the sha256 but not the length, so check it here: a truncated body
+ // that somehow collided would be caught by the hash anyway, but a mismatch here is the cheaper
+ // and clearer failure.
+ const bytes = await downloadVerified(artifact)
+ if (artifact.size !== undefined && bytes.length !== artifact.size) return null
+
+ mkdirSync(env.ADAPTER_RUNTIME_DIR, { recursive: true, mode: 0o700 })
+ const staging = join(env.ADAPTER_RUNTIME_DIR, `.node-staging-${process.pid}-${Date.now()}`)
+ try {
+ mkdirSync(staging, { recursive: true, mode: 0o700 })
+ const archive = join(staging, 'node.tar.gz')
+ writeFileSync(archive, bytes)
+ execFileSync('/usr/bin/tar', ['-xzf', archive, '-C', staging], { timeout: 120_000, stdio: 'ignore' })
+ const unpacked = join(staging, artifact.archiveRoot)
+ if (!existsSync(join(unpacked, 'bin', 'node'))) return null
+ // Another start may have won the race; theirs is as good as ours.
+ if (!existsSync(target)) renameSync(unpacked, target)
+ } finally {
+ rmSync(staging, { recursive: true, force: true })
+ }
+ }
+
+ if (!runs(node)) return null
+ // Written last, and only once the binary has answered: Desktop Harness and the hook installer
+ // both read this file to decide what to execute, so it must never name something that cannot run.
+ writeFileSync(join(env.ADAPTER_RUNTIME_DIR, 'current-node'), `${node}\n`, { mode: 0o600 })
+ log(` ✓ Node runtime ready → ${target}`)
+ return node
+ } catch {
+ return null
+ }
+}
+
+/** The trailing `exec …` line, which is the only line any launcher we ship varies. */
+const EXEC_LINE = /^exec .*$/m
+
+/**
+ * Repoints the `harness` launcher at [node].
+ *
+ * Three launcher shapes have shipped — the public installer's two-liner, `install-cli.sh`'s, and its
+ * `--no-updates` variant carrying a comment block and `ADAPTER_UPDATE_DISABLE=true`. All three end in
+ * a single `exec … cli.js "$@"` line with everything else preamble, so replacing ONLY that line
+ * handles all three and preserves a developer's pin for free: the interpreter is repaired, and the
+ * promise that no release reaches that computer on its own is untouched.
+ */
+export function ensureLauncher(node: string, log: (message: string) => void = () => {}): void {
+ try {
+ const launcher = join(env.HARNESS_BIN_DIR, 'harness')
+ const current = readFileSync(launcher, 'utf-8')
+ const cli = join(env.ADAPTER_CLI_DIR, 'cli.js')
+ const exec = EXEC_LINE.exec(current)
+ // Only ever rewrite a launcher that runs OUR bundle. Anything else at this path belongs to
+ // somebody else, and a missing launcher means the CLI is being run some other way — writing one
+ // nobody asked for is a different feature.
+ if (!exec || !exec[0].includes(cli)) return
+
+ const next = current.replace(EXEC_LINE, `exec ${shellQuote(node)} ${shellQuote(cli)} "$@"`)
+ if (next === current) return
+
+ const temporary = `${launcher}.tmp-${process.pid}`
+ writeFileSync(temporary, next, { mode: 0o755 })
+ renameSync(temporary, launcher)
+ log(` ✓ repointed ${launcher} at ${node}`)
+ } catch {
+ // A read-only bin dir, a launcher owned by another user — none of it is worth failing a start.
+ }
+}
+
+function shellQuote(value: string): string {
+ return `'${value.replace(/'/g, `'\\''`)}'`
+}
diff --git a/cli/src/lib/selfUpdate.ts b/cli/src/lib/selfUpdate.ts
index e875ce52d..956c78ca3 100644
--- a/cli/src/lib/selfUpdate.ts
+++ b/cli/src/lib/selfUpdate.ts
@@ -17,6 +17,7 @@ import { createHash } from 'crypto'
import { copyFileSync, existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'fs'
import { spawnSync } from 'child_process'
import { join } from 'path'
+import { managedNodePath } from './nodeRuntime.js'
export interface FileRef {
url: string
@@ -108,7 +109,9 @@ export function canary(cliBuf: Buffer, dir: string): boolean {
mkdirSync(tmpDir, { recursive: true })
writeFileSync(join(tmpDir, PACKAGE), RUNTIME_PACKAGE)
writeFileSync(tmpCli, cliBuf)
- const r = spawnSync(process.execPath, [tmpCli, 'version'], { timeout: 15_000, stdio: 'ignore' })
+ // The interpreter the NEXT daemon will run on — see managedNodePath(). Canarying on this
+ // process's interpreter would assert about a Node the new build may never be started with.
+ const r = spawnSync(managedNodePath(), [tmpCli, 'version'], { timeout: 15_000, stdio: 'ignore' })
return r.status === 0
} catch {
return false