{"record":{"id":"2080a4ae3db24782","repo":"slopus/happy","slug":"no-machine-id-found-in-settings-2080a4","errorCode":null,"errorMessage":"No machine ID found in settings","messagePattern":"No machine ID found in settings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/happy-cli/src/openclaw/runOpenClaw.ts","lineNumber":152,"sourceCode":"export async function runOpenClaw(opts: RunOpenClawOptions): Promise<void> {\n  const verbose = opts.verbose === true;\n  const sessionTag = randomUUID();\n  connectionState.setBackend('openclaw');\n\n  const gatewayConfig = resolveGatewayConfig(opts);\n  const log = (msg: string) => {\n    logger.debug(`[openclaw] ${msg}`);\n    if (verbose) {\n      console.log(`[openclaw] ${msg}`);\n    }\n  };\n\n  log(`Gateway URL: ${gatewayConfig.url}`);\n\n  const api = await ApiClient.create(opts.credentials);\n  const settings = await readSettings();\n  if (!settings?.machineId) {\n    throw new Error('No machine ID found in settings');\n  }\n\n  await api.getOrCreateMachine({\n    machineId: settings.machineId,\n    metadata: initialMachineMetadata,\n  });\n\n  const { state, metadata } = createSessionMetadata({\n    flavor: 'openclaw',\n    machineId: settings.machineId,\n    startedBy: opts.startedBy,\n  });\n  const response = await api.getOrCreateSession({ tag: sessionTag, metadata, state });\n  if (response) {\n    log(`Happy Session ID: ${response.id}`);\n  }\n\n  let session: ApiSessionClient;","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/slopus/happy/blob/b824cd0a4681d41af631a8e422a813873e4455b0/packages/happy-cli/src/openclaw/runOpenClaw.ts#L134-L170","documentation":"runOpenClaw registers the machine with the Happy API using the machineId stored in happy's settings file. If readSettings() returns null or a settings object without machineId, there is no stable identity to register and it throws. This usually means happy's settings file is missing, corrupted, or was created before machine IDs were introduced.","triggerScenarios":"Calling runOpenClaw when `await readSettings()` returns null or settings.machineId is undefined — settings file absent, unreadable, or predating the machineId field.","commonSituations":"Fresh install where the daemon was never run to generate settings; manual deletion or corruption of ~/.happy/settings.json; upgrading from a very old happy version whose settings lacked machineId; running under a different HOME/user so the settings path differs.","solutions":["Run a normal happy command (e.g. `happy`) once so settings and machineId are generated","Check the settings file for a machineId field and inspect file permissions","If upgrading from an old version, re-authenticate (`happy auth`) to regenerate settings","Ensure you run as the same user whose HOME contains the happy settings"],"exampleFix":"// before\nawait api.getOrCreateMachine({ machineId: settings?.machineId });\n// after\nconst settings = await readSettings();\nif (!settings?.machineId) {\n  await runHappyOnceToInitializeSettings(); // regenerate ~/.happy/settings.json\n}\nawait api.getOrCreateMachine({ machineId: settings.machineId });","handlingStrategy":"validation","validationCode":"const settings = await readSettings();\nif (!settings?.machineId) {\n  // run `happy` once to regenerate ~/.happy/settings.json before runOpenClaw\n}","typeGuard":"const hasMachineId = (s: { machineId?: string } | null): s is { machineId: string } =>\n  typeof s?.machineId === 'string' && s.machineId.length > 0;","tryCatchPattern":"try {\n  await runOpenClaw(opts);\n} catch (err) {\n  if (err.message === 'No machine ID found in settings') {\n    await reinitializeSettings(); // e.g. `happy auth`\n    await runOpenClaw(opts);\n  } else throw err;\n}","preventionTips":["Run a plain `happy` command once after install to generate settings","Back up ~/.happy/settings.json and watch for version migrations that add machineId","Run under a consistent user/HOME so the settings path resolves"],"tags":["openclaw","settings","machine-id","configuration"],"backgroundTag":"missing-machine-id","analyzedSha":"b824cd0a4681d41af631a8e422a813873e4455b0","analyzedAt":"2026-08-31T23:12:36.205Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}