{"record":{"id":"f7b4d20d0343e46d","repo":"can1357/oh-my-pi","slug":"hindsight-backend-is-not-initialised-for-this-sess","errorCode":null,"errorMessage":"Hindsight backend is not initialised for this session.","messagePattern":"Hindsight backend is not initialised for this session\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/learn.ts","lineNumber":92,"sourceCode":"\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\n\t\t\t// reporting (and minting a skill for) a lesson that was silently dropped.\n\t\t\tif (!id) {\n\t\t\t\tthrow new Error(\"Mnemopi did not store the lesson (no memory id returned).\");\n\t\t\t}\n\t\t} else if (backend === \"local\") {\n\t\t\tconst result = await localBackend.save?.(\n\t\t\t\t{ agentDir: this.session.settings.getAgentDir(), cwd: this.session.settings.getCwd() },\n\t\t\t\t{ content: params.memory, context: params.context, source: \"coding-agent-learn\", importance: 0.8 },\n\t\t\t);\n\t\t\tif (!result || result.stored === 0) {\n\t\t\t\tthrow new Error(\"Lesson was empty after sanitization; nothing stored.\");\n\t\t\t}\n\t\t} else {\n\t\t\tconst state = this.session.getHindsightSessionState?.();\n\t\t\tif (!state) {\n\t\t\t\tthrow new Error(\"Hindsight backend is not initialised for this session.\");\n\t\t\t}\n\t\t\tstate.enqueueRetain(params.memory, params.context);\n\t\t\tmemoryMessage = \"Lesson queued for retention\";\n\t\t}\n\n\t\t// 2) Optionally mint/enhance a managed skill. A failure here is surfaced\n\t\t// as a partial outcome — the lesson is already stored or queued.\n\t\tif (params.skill) {\n\t\t\t// A managed skill resolves below any authored skill of the same name, so\n\t\t\t// minting one under a claimed name writes a file that never surfaces. The\n\t\t\t// lesson is already stored/queued; refuse the skill rather than report a\n\t\t\t// false \"Created\" (mirrors ManageSkillTool).\n\t\t\tlet safeSkillName: string | undefined;\n\t\t\ttry {\n\t\t\t\tsafeSkillName = sanitizeSkillName(params.skill.name);\n\t\t\t} catch {\n\t\t\t\tsafeSkillName = undefined;\n\t\t\t}","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/learn.ts#L74-L110","documentation":"For any memory.backend other than \"mnemopi\" or \"local\" (i.e. hindsight), the learn tool requires a live Hindsight session state from session.getHindsightSessionState(). If the accessor is missing or returns falsy, the Hindsight backend was not initialized for this session, so the lesson cannot be queued and the tool throws this Error.","triggerScenarios":"Executing learn with memory.backend set to \"hindsight\" (or the tool reached via the else-branch default) while getHindsightSessionState() returns undefined — Hindsight failed/never initialized, was disabled, or the session object lacks the accessor.","commonSituations":"Hindsight service unavailable or misconfigured at session start while the setting still says hindsight; config migration left a stale backend value; SDK embedding without Hindsight wiring.","solutions":["Fix Hindsight initialization (check startup logs for connection/config errors) and restart the session.","Set memory.backend to \"local\" or \"mnemopi\" if Hindsight is not actually deployed.","If embedding, implement getHindsightSessionState and return initialized state before tools execute."],"exampleFix":"// before: hindsight configured but service down\n\"memory.backend\": \"hindsight\" // getHindsightSessionState() -> undefined\n// after: use a backend that is actually running\n\"memory.backend\": \"local\"","handlingStrategy":"validation","validationCode":"if (settings.get(\"memory.backend\") === \"hindsight\" && !session.getHindsightSessionState?.()) {\n  throw new Error(\"Hindsight is configured but not initialised; fix startup or switch backends.\");\n}","typeGuard":"function hasHindsightState(session: ToolSession): boolean {\n  return typeof session.getHindsightSessionState === \"function\" &&\n    Boolean(session.getHindsightSessionState());\n}","tryCatchPattern":"try {\n  await learnTool.execute(id, params);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Hindsight backend is not initialised\")) {\n    // re-init hindsight or fall back to local backend\n  } else {\n    throw err;\n  }\n}","preventionTips":["Verify the Hindsight service is reachable before sessions start.","Remove stale memory.backend values when decommissioning Hindsight.","Wire getHindsightSessionState when embedding the SDK."],"tags":["memory-backend","hindsight","initialization","configuration"],"backgroundTag":"backend-not-initialised","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}