JuliusBrussee/caveman · error

caveman agent: Cave Runtime failed to start

Error message

caveman agent: Cave Runtime failed to start (${error instanceof Error ? error.message : String(error)})

What it means

When the agent runtime spawns the Cave Runtime daemon ('caveman start'), failures to even construct the portable invocation (e.g. the CLI binary cannot be resolved for the platform) are wrapped into this error. It reports the underlying message so the caller knows the runtime process never launched.

Solutions

  1. Install the Caveman CLI so 'caveman' resolves on PATH (caveman setup --install)
  2. Check/fix the CAVEMAN_CLI_BIN env var to point at the real CLI binary
  3. Run 'caveman start' manually to see the underlying launch failure directly

Example fix

// before: stale binary path
export CAVEMAN_CLI_BIN=/usr/local/bin/caveman-old
// after
unset CAVEMAN_CLI_BIN   # or point at the installed binary
export CAVEMAN_CLI_BIN=/usr/local/bin/caveman
Defensive patterns

Strategy: try-catch

Validate before calling

const bin = process.env.CAVEMAN_CLI_BIN ?? 'caveman';
await fs.promises.access(bin, fs.constants.X_OK).catch(() => { throw new Error(`CLI not executable: ${bin}`); });

Try / catch

try {
  await startCaveRuntime();
} catch (e) {
  if (String(e.message).includes('Cave Runtime failed to start')) {
    console.error('Check CAVEMAN_CLI_BIN / PATH:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: portableInvocation(command, ['start'], ...) throws while building the spawn invocation — typically because the resolved 'caveman' binary is missing or CAVEMAN_CLI_BIN points to a nonexistent/unusable path.

Common situations: Caveman CLI not installed or not on PATH; CAVEMAN_CLI_BIN set to a stale path after a reinstall; cross-platform launch (Windows vs POSIX) where the binary name is wrong.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/e0ebfcdb4c23c42c. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/runtime.ts:5240

        `cave_gateway_identity_unverified: non-loopback gateway ${gatewayURL} requires https`,
      );
    }
    const identity = await gatewayIdentity(gatewayURL, fetchImpl);
    if (identity !== undefined) return identity.providerBilling;
    throw new Error(
      `cave_gateway_identity_unverified: ${gatewayURL}/health/ready did not identify as caveman-proxy`,
    );
  }
  const readyBilling = await runtimeReady(gatewayURL, fetchImpl);
  if (readyBilling !== undefined) return readyBilling;

  const command = process.env.CAVEMAN_CLI_BIN ?? "caveman";
  let startupFailure: Error | undefined;
  let invocation;
  try {
    invocation = portableInvocation(command, ["start"], { env: buildRuntimeControlEnv() });
  } catch (error) {
    throw new Error(`caveman agent: Cave Runtime failed to start (${error instanceof Error ? error.message : String(error)})`);
  }
  const child = spawn(invocation.command, [...invocation.args], {
    detached: true,
    windowsHide: true,
    stdio: "ignore",
    env: buildRuntimeControlEnv(),
  });
  child.once("error", (error) => {
    startupFailure = (error as NodeJS.ErrnoException).code === "ENOENT"
      ? new Error(
        "caveman agent: Caveman CLI not found; run npm install, then caveman setup --install",
      )
      : new Error(`caveman agent: Cave Runtime failed to start (${error.message})`);
  });
  child.once("exit", (code, signal) => {
    if (startupFailure !== undefined || code === 0) return;
    startupFailure = new Error(
      `caveman agent: Cave Runtime failed to start (caveman start exited ${signal ?? code}); run caveman setup --install`,

View on GitHub (pinned to 3ee70a1026)