{"record":{"id":"991132bccb84a9e7","repo":"lobehub/lobehub","slug":"invalid-reasoninggraph-path-issue-message","errorCode":null,"errorMessage":"Invalid ReasoningGraph: ${path}${issue?.message ?? 'unknown error'}","messagePattern":"Invalid ReasoningGraph: (.+?)(.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/commands/agent.ts","lineNumber":29,"sourceCode":"  replayAgentEvents,\n  streamAgentEvents,\n  streamAgentEventsViaWebSocket,\n} from '../utils/agentStream';\nimport { resolveLocalDeviceId } from '../utils/device';\nimport { confirm, outputJson, printTable, truncate } from '../utils/format';\nimport { log, setVerbose } from '../utils/logger';\nimport { resolveAgentId } from './agent/resolveAgentId';\nimport { registerAgentSpaceFsCommand } from './agent/spaceFs';\n\nconst readGraphConfig = async (graphFile: string): Promise<unknown> => {\n  const content = await readFile(graphFile, 'utf8');\n  const graph = JSON.parse(content);\n  const result = ReasoningGraphSchema.safeParse(graph);\n\n  if (!result.success) {\n    const issue = result.error.issues[0];\n    const path = issue?.path.length ? `${issue.path.join('.')}: ` : '';\n    throw new Error(`Invalid ReasoningGraph: ${path}${issue?.message ?? 'unknown error'}`);\n  }\n\n  return result.data;\n};\n\nconst readJsonObjectFile = async (\n  filePath: string,\n  label: string,\n): Promise<Record<string, unknown>> => {\n  const content = await readFile(filePath, 'utf8');\n  const parsed = JSON.parse(content);\n\n  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n    throw new Error(`${label} JSON must be a plain object`);\n  }\n\n  return parsed as Record<string, unknown>;\n};","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/lobehub/lobehub/blob/10f24d7ade75139093a9373b364f6bc91f3cd7db/apps/cli/src/commands/agent.ts#L11-L47","documentation":"Thrown by readGraphConfig when the provided graph config file fails Zod validation against ReasoningGraphSchema. The message includes the first Zod issue's path (dot-joined field path) and its message, pinpointing which part of the graph structure is invalid. This is a schema-conformance check on the agent's reasoning graph definition.","triggerScenarios":"Running lh agent with --graph <file> where the file is valid JSON but doesn't conform to ReasoningGraphSchema — e.g. missing required nodes, invalid edge definitions, wrong node types, or unknown top-level keys.","commonSituations":"1) Graph file was authored against an older schema version that has since changed. 2) Typo in a node type or edge kind field. 3) Missing required fields like 'nodes' or 'edges'. 4) Circular or malformed edge references.","solutions":["Read the path in the error message: it tells you exactly which field failed (e.g. 'nodes.0.type' or 'edges').","Check the ReasoningGraphSchema definition in @lobechat/types to see the required shape for the failing field.","Validate the file against the schema programmatically: import { ReasoningGraphSchema } from '@lobechat/types' and run safeParse to see all issues.","Compare against a known-good graph file example from the docs or tests."],"exampleFix":"// Error: 'Invalid ReasoningGraph: nodes.0.type: invalid enum value'\n// Before:\n{ \"nodes\": [{ \"id\": \"n1\", \"type\": \"startpoint\" }], \"edges\": [] }\n// After (correct enum value per schema):\n{ \"nodes\": [{ \"id\": \"n1\", \"type\": \"start\" }], \"edges\": [] }","handlingStrategy":"validation","validationCode":"// Validate the graph file against the schema before running the CLI\nimport { readFile } from 'node:fs/promises';\nimport { ReasoningGraphSchema } from '@lobechat/types';\n\nasync function validateGraphFile(path: string): Promise<void> {\n  const content = JSON.parse(await readFile(path, 'utf8'));\n  const result = ReasoningGraphSchema.safeParse(content);\n  if (!result.success) {\n    for (const issue of result.error.issues) {\n      console.error(`${issue.path.join('.')}: ${issue.message}`);\n    }\n    process.exit(1);\n  }\n}","typeGuard":"import { ReasoningGraphSchema } from '@lobechat/types';\n\nfunction isReasoningGraph(value: unknown): boolean {\n  return ReasoningGraphSchema.safeParse(value).success;\n}","tryCatchPattern":"try {\n  await runAgentCommand({ graph: graphFile });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Invalid ReasoningGraph:')) {\n    // The error message includes the zod path and issue\n    console.error('Graph validation failed:', e.message);\n    console.error('Check the field path in the message and fix the graph file.');\n  }\n  throw e;\n}","preventionTips":["Validate graph files with ReasoningGraphSchema.safeParse before running the CLI.","Keep a known-good example graph file as a template.","Check all enum values (node types, edge kinds) against the schema.","Ensure required fields like 'nodes' and 'edges' are present."],"tags":["cli","validation","zod","schema","agent"],"backgroundTag":null,"analyzedSha":"10f24d7ade75139093a9373b364f6bc91f3cd7db","analyzedAt":"2026-08-12T11:43:19.543Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}