{"record":{"id":"503de7367ed9eb8c","repo":"tinyhumansai/openhuman","slug":"rpc-token-not-provided-and-tokenpath-could-not-503de7","errorCode":null,"errorMessage":"RPC token not provided and ${tokenPath} could not be read. Pass --token or set OPENHUMAN_CORE_TOKEN.","messagePattern":"RPC token not provided and (.+?) could not be read\\. Pass --token or set OPENHUMAN_CORE_TOKEN\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/debug/harness-cache-audit.mjs","lineNumber":189,"sourceCode":"    if (match?.[1]) {\n      return path.join(openhumanDir, \"users\", match[1], \"workspace\");\n    }\n  } catch {\n    // Fall back to the legacy root workspace below.\n  }\n  return openhumanDir;\n}\n\nasync function readToken(opts) {\n  if (opts.token.trim()) return opts.token.trim();\n  const tokenPath = path.join(\n    opts.workspace || (await defaultWorkspace()),\n    \"core.token\",\n  );\n  try {\n    return (await readFile(tokenPath, \"utf8\")).trim();\n  } catch {\n    throw new Error(\n      `RPC token not provided and ${tokenPath} could not be read. Pass --token or set OPENHUMAN_CORE_TOKEN.`,\n    );\n  }\n}\n\nasync function rpc(coreUrl, token, method, params, timeoutMs = 600_000) {\n  const controller = new AbortController();\n  const timeout = setTimeout(() => controller.abort(), timeoutMs);\n  let res;\n  try {\n    res = await fetch(coreUrl, {\n      method: \"POST\",\n      signal: controller.signal,\n      headers: {\n        \"content-type\": \"application/json\",\n        authorization: `Bearer ${token}`,\n      },\n      body: JSON.stringify({","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/a221052e0df5b1f7598fceba7329fd1af95d6699/scripts/debug/harness-cache-audit.mjs#L171-L207","documentation":"readToken() in harness-cache-audit.mjs resolves the RPC bearer as --token, then OPENHUMAN_CORE_TOKEN (seeded into opts), then <workspace>/core.token, and throws this error naming the file it could not read if all three fail. The embedded core's /rpc endpoint authenticates every call with this per-launch bearer, so the audit cannot proceed without it. Identical resolution order to goals-live.mjs's readToken, with slightly different wording.","triggerScenarios":"Auditing an external core started with a custom OPENHUMAN_CORE_TOKEN that was never written to disk; --workspace (or OPENHUMAN_WORKSPACE) pointing at a directory without core.token; OPENHUMAN_APP_ENV=staging switching the default search dir to ~/.openhuman-staging while the token lives in ~/.openhuman; the desktop app never having started the core on this machine.","commonSituations":"Running `pnpm debug harness-cache-audit` before ever booting the app; juggling multiple user profiles under ~/.openhuman/users/<id>/workspace; core restarted so the old token is stale (file exists but value rotated — that yields 401 later, not this error; a missing file yields this one).","solutions":["Pass the bearer: `--token <value>` or `OPENHUMAN_CORE_TOKEN=<value>`","Align --workspace with the core's actual OPENHUMAN_WORKSPACE so <workspace>/core.token resolves","Start the app (or `openhuman-core serve`) once so core.token is written, then rerun","Use --spawn-core so the script mints and injects its own token"],"exampleFix":"# before\nnode scripts/debug/harness-cache-audit.mjs --core-url http://127.0.0.1:7788/rpc\n# Error: RPC token not provided and .../core.token could not be read.\n\n# after\nOPENHUMAN_CORE_TOKEN=$(cat ~/.openhuman/users/<id>/workspace/core.token) \\\n  node scripts/debug/harness-cache-audit.mjs --core-url http://127.0.0.1:7788/rpc","handlingStrategy":"validation","validationCode":"import { access, readFile } from \"node:fs/promises\";\n\nasync function bearerAvailable() {\n  if ((process.env.OPENHUMAN_CORE_TOKEN || \"\").trim()) return true;\n  const ws = process.env.OPENHUMAN_WORKSPACE || `${defaultOpenhumanDir()}/users/<id>/workspace`;\n  try { await access(path.join(ws, \"core.token\")); return true; } catch { return false; }\n}\nif (!(await bearerAvailable())) {\n  console.error(\"no bearer resolvable — pass --token, export OPENHUMAN_CORE_TOKEN, or boot the core once\");\n  process.exit(2);\n}","typeGuard":null,"tryCatchPattern":"try {\n  token = await readToken(opts);\n} catch (err) {\n  if (/could not be read/.test(err.message)) {\n    opts.spawnCore = true; // fallback: audit a self-spawned core with its own token\n    ({ token } = await startCore(opts));\n  } else throw err;\n}","preventionTips":["Boot the target core once before auditing it so core.token exists on disk","Pass --workspace explicitly when multiple user workspaces exist under ~/.openhuman/users","Use --spawn-core for CI runs — it removes the token-resolution dependency entirely"],"tags":["auth","rpc","token","filesystem"],"backgroundTag":null,"analyzedSha":"a221052e0df5b1f7598fceba7329fd1af95d6699","analyzedAt":"2026-08-16T12:47:06.542Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}