can1357/oh-my-pi · error

Timed out initializing daemon broker token in ${runtimeDir}

Error message

Timed out initializing daemon broker token in ${runtimeDir}

What it means

readOrCreateToken polls for the token file to appear in the runtime dir (handling EEXIST from concurrent creation), sleeping 10ms between attempts. If the token file never becomes readable before the loop budget is exhausted, it gives up with this timeout error.

Source

Thrown at packages/coding-agent/src/launch/client.ts:93

		} catch (error) {
			if (!isEnoent(error)) throw error;
		}

		try {
			const handle = await fs.open(tokenPath, "wx", 0o600);
			try {
				const token = crypto.randomUUID().replaceAll("-", "") + crypto.randomUUID().replaceAll("-", "");
				await handle.writeFile(token, "utf8");
				return token;
			} finally {
				await handle.close();
			}
		} catch (error) {
			if (!isEexist(error)) throw error;
		}
		await Bun.sleep(10);
	}
	throw new Error(`Timed out initializing daemon broker token in ${runtimeDir}`);
}

function requestTimeoutMs(operation: DaemonOperation): number {
	switch (operation.op) {
		case "start":
			return (operation.spec.ready?.timeoutMs ?? CONNECT_TIMEOUT_MS) + 5_000;
		case "wait":
		case "logs":
		case "stop":
			return operation.timeoutMs + 5_000;
		default:
			return 30_000;
	}
}

function openSocket(endpoint: string, timeoutMs: number): Promise<net.Socket> {
	const { promise, resolve, reject } = Promise.withResolvers<net.Socket>();
	const socket = net.createConnection({ path: endpoint });

View on GitHub (pinned to 9690622007)

Solutions

  1. Confirm the broker process is alive and was started with correct DAEMON_RUNTIME_DIR_ENV
  2. Check the runtime dir path is correct and writable; remove stale dirs so a fresh broker initializes
  3. Investigate the broker's own startup error — this timeout is usually downstream of the broker crashing

Example fix

// before
const token = await client.token(); // throws on timeout
// after
let token: string;
try { token = await client.token(); }
catch (err) { await startBroker(runtimeDir); token = await client.token(); }
Defensive patterns

Strategy: retry

Validate before calling

if (!runtimeDir || !(await fs.stat(runtimeDir).catch(() => null))) throw new Error('runtimeDir does not exist: ' + runtimeDir);

Try / catch

try {
  const token = await client.token();
} catch (err) {
  if (err.message.startsWith('Timed out initializing daemon broker token')) {
    await startBroker(runtimeDir); // broker likely never started
    const token = await client.token();
  } else throw err;
}

Prevention

When it happens

Trigger: Calling DaemonBrokerClient.token()/readOrCreateToken while the broker process never creates the token file (broker failed to start, wrong runtimeDir, broker crashed before writing the token).

Common situations: Broker died at startup (e.g. missing env vars — see 'Daemon broker environment is incomplete'); pointing at a runtime dir owned by a dead broker; extremely slow filesystem; permissions preventing token creation.

Understand the failure class

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/44708bd7acb4a4cf. Report an issue: GitHub.