{"record":{"id":"4764f069d40976f5","repo":"can1357/oh-my-pi","slug":"mnemopi-backend-is-not-initialised-for-this-sessio","errorCode":null,"errorMessage":"Mnemopi backend is not initialised for this session.","messagePattern":"Mnemopi backend is not initialised for this session\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/learn.ts","lineNumber":58,"sourceCode":"\treadonly summary = \"Capture a reusable lesson to memory (and optionally a managed skill)\";\n\n\tconstructor(private readonly session: ToolSession) {}\n\n\tstatic createIf(session: ToolSession): LearnTool | null {\n\t\tif (!session.settings.get(\"autolearn.enabled\")) return null;\n\t\tconst backend = session.settings.get(\"memory.backend\");\n\t\tif (backend !== \"hindsight\" && backend !== \"mnemopi\" && backend !== \"local\") return null;\n\t\treturn new LearnTool(session);\n\t}\n\n\tasync execute(_id: string, params: LearnParams): Promise<AgentToolResult> {\n\t\t// 1) Persist or queue the lesson to long-term memory (mirrors MemoryRetainTool).\n\t\tconst backend = this.session.settings.get(\"memory.backend\");\n\t\tlet memoryMessage = \"Lesson stored\";\n\t\tif (backend === \"mnemopi\") {\n\t\t\tconst state = this.session.getMnemopiSessionState?.();\n\t\t\tif (!state) {\n\t\t\t\tthrow new Error(\"Mnemopi backend is not initialised for this session.\");\n\t\t\t}\n\t\t\tconst id = state.rememberScoped(params.memory, {\n\t\t\t\tsource: \"coding-agent-learn\",\n\t\t\t\timportance: 0.8,\n\t\t\t\tmetadata: {\n\t\t\t\t\tsession_id: state.sessionId,\n\t\t\t\t\tcwd: state.session.sessionManager.getCwd(),\n\t\t\t\t\tcontext: params.context ?? null,\n\t\t\t\t\ttool: \"learn\",\n\t\t\t\t},\n\t\t\t\tscope: \"bank\",\n\t\t\t\textract: true,\n\t\t\t\textractEntities: true,\n\t\t\t\tveracity: \"tool\",\n\t\t\t\tmemoryType: \"fact\",\n\t\t\t});\n\t\t\t// rememberScoped returns undefined when the retain failed (closed DB /\n\t\t\t// disk error); mirror mnemopiBackend.save and fail loudly rather than","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/learn.ts#L40-L76","documentation":"The learn tool persists lessons through the memory backend configured in memory.backend. When that setting is \"mnemopi\", the tool requires a live Mnemopi session state obtained from session.getMnemopiSessionState(). If the accessor is absent or returns falsy, the session's Mnemopi backend was never initialized, so the lesson cannot be stored and the tool throws this plain Error rather than silently dropping it.","triggerScenarios":"Executing the learn tool in a session where memory.backend === \"mnemopi\" but getMnemopiSessionState() returns undefined/null — e.g. the Mnemopi backend failed to start, was disabled after startup, or the tool was invoked through a session object lacking the accessor.","commonSituations":"memory.backend switched to \"mnemopi\" in settings without the Mnemopi service/database being available at session start; Mnemopi initialization failed (bad config, missing binary/DB) but the setting remained; embedding the SDK and constructing a ToolSession without wiring the Mnemopi state.","solutions":["Check session logs for Mnemopi initialization errors and fix the underlying startup failure (config, DB path, service availability).","Set memory.backend to \"local\" or \"hindsight\" if you do not actually run Mnemopi.","Restart the session so the Mnemopi backend initializes cleanly.","If embedding, ensure getMnemopiSessionState is implemented and returns initialized state before tools run."],"exampleFix":"// before: settings claim mnemopi but backend never came up\n\"memory.backend\": \"mnemopi\" // Mnemopi init failed at startup -> tool throws\n// after: align the setting with the running backend\n\"memory.backend\": \"local\" // or fix Mnemopi startup so state exists","handlingStrategy":"validation","validationCode":"if (settings.get(\"memory.backend\") === \"mnemopi\" && !session.getMnemopiSessionState?.()) {\n  throw new Error(\"Fix memory.backend or Mnemopi startup before calling learn.\");\n}","typeGuard":"function hasMnemopiState(session: ToolSession): boolean {\n  return typeof session.getMnemopiSessionState === \"function\" &&\n    Boolean(session.getMnemopiSessionState());\n}","tryCatchPattern":"try {\n  await learnTool.execute(id, params);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Mnemopi backend is not initialised\")) {\n    // fall back to local backend or re-init mnemopi\n  } else {\n    throw err;\n  }\n}","preventionTips":["Keep memory.backend aligned with a backend that actually initializes at startup.","Check session startup logs for Mnemopi errors before enabling learn.","Prefer \"local\" when Mnemopi is optional in your deployment."],"tags":["memory-backend","mnemopi","initialization","configuration"],"backgroundTag":"backend-not-initialised","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}