{"record":{"id":"827e9927b43709da","repo":"mastra-ai/mastra","slug":"next-object-must-be-a-single-relatednodeinfo-objec","errorCode":null,"errorMessage":"Next object must be a single RelatedNodeInfo object","messagePattern":"Next object must be a single RelatedNodeInfo object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/rag/src/document/schema/node.ts","lineNumber":53,"sourceCode":"\n    return relationship;\n  }\n\n  get prevNode(): RelatedNodeInfo<T> | undefined {\n    const relationship = this.relationships[NodeRelationship.PREVIOUS];\n\n    if (Array.isArray(relationship)) {\n      throw new Error('Previous object must be a single RelatedNodeInfo object');\n    }\n\n    return relationship;\n  }\n\n  get nextNode(): RelatedNodeInfo<T> | undefined {\n    const relationship = this.relationships[NodeRelationship.NEXT];\n\n    if (Array.isArray(relationship)) {\n      throw new Error('Next object must be a single RelatedNodeInfo object');\n    }\n\n    return relationship;\n  }\n\n  get parentNode(): RelatedNodeInfo<T> | undefined {\n    const relationship = this.relationships[NodeRelationship.PARENT];\n\n    if (Array.isArray(relationship)) {\n      throw new Error('Parent object must be a single RelatedNodeInfo object');\n    }\n\n    return relationship;\n  }\n\n  get childNodes(): RelatedNodeInfo<T>[] | undefined {\n    const relationship = this.relationships[NodeRelationship.CHILD];\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/rag/src/document/schema/node.ts#L35-L71","documentation":"The BaseNode.nextNode getter reads the NEXT relationship and expects a single RelatedNodeInfo object. A node can have only one next neighbor, so an array in that slot throws.","triggerScenarios":"Accessing node.nextNode (e.g. during highlight updates / traversal) when relationships[NodeRelationship.NEXT] holds an array.","commonSituations":"Manually relinking chunks after edits, or deserialization code that array-wraps all relationship values uniformly.","solutions":["Set relationships[NodeRelationship.NEXT] to one RelatedNodeInfo object.","Fix deserialization/normalization so scalar relationships are not wrapped in arrays.","Re-run the splitter's linking logic rather than hand-editing NEXT pointers."],"exampleFix":"// before\nnode.relationships[NodeRelationship.NEXT] = [nextInfo, otherInfo];\n// after\nnode.relationships[NodeRelationship.NEXT] = nextInfo;","handlingStrategy":"type-guard","validationCode":"const rel = node.relationships[NodeRelationship.NEXT];\nconst next = rel !== undefined && !Array.isArray(rel) ? rel : undefined;","typeGuard":"const isSingleRelatedNodeInfo = (v: unknown): v is RelatedNodeInfo =>\n  v !== null && typeof v === 'object' && !Array.isArray(v) && 'nodeId' in v;","tryCatchPattern":"let next;\ntry {\n  next = node.nextNode;\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Next object must be')) {\n    const rel = node.relationships[NodeRelationship.NEXT];\n    next = Array.isArray(rel) ? rel[0] : undefined;\n  } else throw e;\n}","preventionTips":["Never reuse the CHILD array shape for NEXT pointers during relinking.","Normalize all relationship maps at deserialization boundaries.","Prefer splitter utilities for maintaining next links."],"tags":["data-structure","rag","relationships"],"backgroundTag":"invalid-relationship-shape","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}