{"record":{"id":"00bc986f421b2ba8","repo":"mastra-ai/mastra","slug":"knowledge-node-not-found-id","errorCode":null,"errorMessage":"Knowledge node not found: ${id}","messagePattern":"Knowledge node not found: (.+?)","errorType":"exception","errorClass":"KnowledgeNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/knowledge/inmemory.ts","lineNumber":206,"sourceCode":"      .filter(\n        node =>\n          !cursor ||\n          node.updatedAt < cursor.updatedAt ||\n          (node.updatedAt.getTime() === cursor.updatedAt.getTime() &&\n            (node.name > cursor.name || (node.name === cursor.name && node.id > cursor.id))),\n      )\n      .slice(0, input.limit ?? 100)\n      .map(cloneNode);\n  }\n\n  async updateNode(input: UpdateKnowledgeNodeInput): Promise<KnowledgeNode> {\n    return this.#runAtomicMutation(() => this.#updateNode(input));\n  }\n\n  #updateNode(input: UpdateKnowledgeNodeInput): KnowledgeNode {\n    assertKnowledgeDescriptionWithinBound(input.description);\n    const existing = this.#db.knowledgeNodes.get(input.id);\n    if (!existing) throw new KnowledgeNotFoundError('node', input.id);\n    if (existing.version !== input.version) throw new KnowledgeConflictError(input.id);\n    if (existing.mergedInto) throw new Error(`Cannot update merged knowledge node: ${input.id}`);\n\n    const scope = canonicalizeKnowledgeScope(input.scope ?? existing.scope);\n    const name = (input.name ?? existing.name).trim();\n    const oldKey = recordKey(existing.name, existing.scope);\n    const newKey = recordKey(name, scope);\n    const collision = this.#db.knowledgeNodeKeys.get(newKey);\n    if (collision && collision !== input.id) throw new Error(`Knowledge node already exists in scope: ${name}`);\n\n    const updated: KnowledgeNode = {\n      ...existing,\n      name,\n      kind: input.kind ?? existing.kind,\n      content: input.content ?? existing.content,\n      description: input.description ?? existing.description,\n      scope,\n      version: existing.version + 1,","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/knowledge/inmemory.ts#L188-L224","documentation":"updateNode was called with an id that does not exist in the knowledgeNodes map; the store throws KnowledgeNotFoundError('node', id). The node was never created, was deleted, or the id is wrong (or belongs to a different store instance).","triggerScenarios":"Calling updateNode({ id }) where #db.knowledgeNodes.has(id) is false: typo'd id, node deleted in a prior call, or updating against a different/refreshed in-memory store instance that lost the node.","commonSituations":"Holding a node id from a previous process run while using an in-memory store (data is not persistent); deleting the node earlier in the same workflow; id copied from the wrong environment.","solutions":["Verify the id by listing/fetching nodes before updating (getNode with the same id)","Create the node if it does not exist (upsert pattern: try update, on KnowledgeNotFoundError call createNode)","Fix persistence: switch to a durable storage domain if node ids must survive process restarts"],"exampleFix":"// before\nawait store.updateNode({ id, version: 1, description: 'new' });\n// after\ntry {\n  await store.updateNode({ id, version: 1, description: 'new' });\n} catch (e) {\n  if (e instanceof KnowledgeNotFoundError) await store.createNode({ name, scope, description: 'new' });\n  else throw e;\n}","handlingStrategy":"try-catch","validationCode":"const existing = await store.getNode({ id, resolutionScope: scope }).catch(() => null);\nif (!existing) throw new Error(`cannot update: node ${id} does not exist`);","typeGuard":"function isKnowledgeNode(v: unknown): v is KnowledgeNode {\n  return !!v && typeof v === 'object' && 'id' in v && 'version' in v;\n}","tryCatchPattern":"try {\n  await store.updateNode({ id, version, ...patch });\n} catch (e) {\n  if (e instanceof KnowledgeNotFoundError) {\n    await store.createNode({ name, scope, ...patch });\n  } else throw e;\n}","preventionTips":["Treat in-memory store data as process-local; never persist node ids across restarts","Confirm ids with getNode before updating","Implement upsert (update-or-create) helpers for knowledge writes","Check earlier workflow steps for deletes that may have removed the node"],"tags":["knowledge-store","not-found","update","inmemory"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}