{"record":{"id":"8e78177bee485ebc","repo":"tinyhumansai/openhuman","slug":"memory-file-not-found-path","errorCode":null,"errorMessage":"memory file not found: ${path}","messagePattern":"memory file not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/src/lib/ai/localCoreAiMemory.ts","lineNumber":96,"sourceCode":"  params: Record<string, unknown>\n): Promise<unknown> {\n  switch (method) {\n    case 'ai.list_memory_files': {\n      const dir = (params.relative_dir as string | undefined) ?? 'memory';\n      const prefix = dir.endsWith('/') ? dir : `${dir}/`;\n      const names: string[] = [];\n      for (const k of memoryFiles.keys()) {\n        if (k === dir || k.startsWith(prefix)) {\n          const rest = k.startsWith(prefix) ? k.slice(prefix.length) : k;\n          if (rest && !rest.includes('/')) names.push(rest);\n        }\n      }\n      return names;\n    }\n    case 'ai.read_memory_file': {\n      const path = params.relative_path as string;\n      const v = memoryFiles.get(path);\n      if (v === undefined) throw new Error(`memory file not found: ${path}`);\n      return v;\n    }\n    case 'ai.write_memory_file': {\n      const path = params.relative_path as string;\n      const content = params.content as string;\n      memoryFiles.set(path, content);\n      return true;\n    }\n    case 'ai.memory_init':\n      return true;\n    case 'ai.memory_get_file': {\n      const path = params.path as string;\n      return fileRecords.get(path) ?? null;\n    }\n    case 'ai.memory_delete_chunks_by_path': {\n      const path = params.path as string;\n      const ids = chunksByPath.get(path);\n      if (!ids) return 0;","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/app/src/lib/ai/localCoreAiMemory.ts#L78-L114","documentation":"localCoreAiMemory.ts implements an in-memory mock/local implementation of the ai.* memory-file API (list/read/write) used when the local core AI harness runs without the full memory store. The 'ai.read_memory_file' handler looks up params.relative_path in a Map; a miss throws 'memory file not found: <path>'. This is a key-error on the virtual memory filesystem.","triggerScenarios":"Calling the ai.read_memory_file method with a relative_path that was never written via ai.write_memory_file, or that was listed from a different directory prefix (path mismatch, leading './', case difference). Also after the in-memory map is reset (page reload / new session) while a caller retries an old path.","commonSituations":"Agent harness resuming a session whose memory files were only in the previous page lifetime; path normalization mismatch between list (keys) and read (lookup); tests exercising read before write.","solutions":["Call ai.list_memory_files for the enclosing directory first and use the exact returned names.","Normalize paths (strip leading './', lowercase consistently if the impl is case-sensitive) before read/write.","Treat read as best-effort: catch 'memory file not found' and fall back to empty/default content rather than failing the turn.","For persistence across sessions, ensure files are written through the durable memory store, not only the in-memory map."],"exampleFix":"// before\nconst content = await callAi('ai.read_memory_file', { relative_path: path });\n\n// after\nconst names = await callAi('ai.list_memory_files', { directory: dirname(path) });\nif (!names.includes(basename(path))) return defaultContent;\nconst content = await callAi('ai.read_memory_file', { relative_path: path });","handlingStrategy":"type-guard","validationCode":"const names = await callAi('ai.list_memory_files', { directory: dir });\nif (!names.includes(name)) return defaultContent;\nconst content = await callAi('ai.read_memory_file', { relative_path: `${dir}/${name}` });","typeGuard":"function hasMemoryFile(map: Map<string, string>, path: string): boolean {\n  return map.has(path.replace(/^\\.\\//, ''));\n}","tryCatchPattern":"try {\n  return await callAi('ai.read_memory_file', { relative_path: path });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('memory file not found')) {\n    return ''; // treat as empty memory, not a failure\n  }\n  throw err;\n}","preventionTips":["Normalize paths identically on write and read (strip './', fixed separators).","List-then-read instead of blind reads for optional memory files.","Remember the store is in-memory: do not assume files persist across page reloads."],"tags":["memory","virtual-filesystem","path","not-found","agent-harness"],"backgroundTag":"file-not-found","analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}