tinyhumansai/openhuman · error · Error

RPC token not provided and ${tokenPath} could not be read. P

Error message

RPC token not provided and ${tokenPath} could not be read. Pass --token or set OPENHUMAN_CORE_TOKEN.

What it means

readToken() in scripts/debug/agent-prepare-context-audit.mjs resolves the RPC bearer in order: --token flag, then <workspace>/core.token where workspace is --workspace / OPENHUMAN_WORKSPACE / the auto-resolved default. If no flag/env token exists and the core.token file cannot be read, it throws this error naming the exact path it tried. The core writes core.token at the workspace root when it starts, so an unreadable file usually means no core ever ran under that workspace.

Source

Thrown at scripts/debug/agent-prepare-context-audit.mjs:240

    const match = active.match(/^\s*user_id\s*=\s*"([^"]+)"\s*$/m);
    if (match?.[1])
      return path.join(openhumanDir, "users", match[1], "workspace");
  } catch {
    // fall through to legacy root
  }
  return openhumanDir;
}

async function readToken(opts) {
  if (opts.token.trim()) return opts.token.trim();
  const tokenPath = path.join(
    opts.workspace || (await defaultWorkspace()),
    "core.token",
  );
  try {
    return (await readFile(tokenPath, "utf8")).trim();
  } catch {
    throw new Error(
      `RPC token not provided and ${tokenPath} could not be read. Pass --token or set OPENHUMAN_CORE_TOKEN.`,
    );
  }
}

async function rpc(coreUrl, token, method, params, timeoutMs = 600_000) {
  const controller = new AbortController();
  const timeout = setTimeout(() => controller.abort(), timeoutMs);
  let res;
  try {
    res = await fetch(coreUrl, {
      method: "POST",
      signal: controller.signal,
      headers: {
        "content-type": "application/json",
        authorization: `Bearer ${token}`,
      },
      body: JSON.stringify({

View on GitHub (pinned to a221052e0d)

Solutions

  1. Pass the token explicitly: --token <value> (or export OPENHUMAN_CORE_TOKEN)
  2. Point --workspace at the exact workspace the core is serving — its core.token sits at that root; check the error message for the path actually tried
  3. If the core hasn't run yet, start it once (or use --spawn-core, which generates and injects its own token) so core.token exists
  4. Align OPENHUMAN_APP_ENV between the shell that ran the core and the shell running the audit

Example fix

# before
$ node scripts/debug/agent-prepare-context-audit.mjs --workspace /tmp/wrong-dir
Error: RPC token not provided and /tmp/wrong-dir/core.token could not be read. ...

# after
$ node scripts/debug/agent-prepare-context-audit.mjs --workspace ~/.openhuman/users/<id>/workspace
# or
$ node scripts/debug/agent-prepare-context-audit.mjs --token "$(cat ~/path/core.token)"
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync, existsSync } from "node:fs";
import path from "node:path";
const ws = process.env.OPENHUMAN_WORKSPACE || defaultWorkspace;
const token = process.env.OPENHUMAN_CORE_TOKEN || (existsSync(path.join(ws, "core.token")) ? readFileSync(path.join(ws, "core.token"), "utf8").trim() : "");
if (!token) throw new Error(`no bearer: pass --token or ensure ${path.join(ws, "core.token")} exists (start the core once)`);

Prevention

When it happens

Trigger: Attaching to a running core (no --spawn-core) while: never passing --token, having no OPENHUMAN_CORE_TOKEN in env, and pointing --workspace (or OPENHUMAN_WORKSPACE) at a directory where the core never wrote core.token. Also when the default workspace resolution (OPENHUMAN_APP_ENV staging vs prod ~/.openhuman dirs) picks a different directory than the one the core actually uses.

Common situations: Fresh machines or CI where the audit script runs before any core has started; OPENHUMAN_APP_ENV=staging set in one shell (core writes ~/.openhuman-staging/.../core.token) but not in the shell running the script, so the auto-picked dir mismatches; typos in the --workspace path.

Related errors


AI-assisted analysis of tinyhumansai/openhuman@a221052e0d (2026-08-16). Data as JSON: /api/errors/8e2b5a429874ed7e. Report an issue: GitHub.