{"record":{"id":"396c216698cabc23","repo":"mastra-ai/mastra","slug":"mastra-opencode-failed-to-initialize-memory-stor","errorCode":null,"errorMessage":"@mastra/opencode: failed to initialize memory storage from ${storagePath}","messagePattern":"@mastra/opencode: failed to initialize memory storage from (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/opencode/src/index.ts","lineNumber":199,"sourceCode":"          }\n        }\n      }\n    } catch {\n      // Credentials not available from opencode — rely on .env\n    }\n    credentialsReady = true;\n  };\n\n  // Storage: SQLite via Mastra's LibSQLStore\n  const dbRelativePath = config.storagePath ?? DEFAULT_STORAGE_PATH;\n  const dbAbsolutePath = join(ctx.directory, dbRelativePath);\n  await mkdir(dirname(dbAbsolutePath), { recursive: true });\n  const storagePath = `file:${dbAbsolutePath}`;\n  const store = new LibSQLStore({ id: 'mastra-om', url: storagePath });\n  await store.init();\n  const storage = await store.getStore('memory');\n  if (!storage) {\n    throw new Error(`@mastra/opencode: failed to initialize memory storage from ${storagePath}`);\n  }\n\n  // Observational Memory: uses Mastra's full OM class\n  // Model string IDs (e.g., 'google/gemini-2.5-flash') are resolved by Mastra's provider registry.\n  const om = new ObservationalMemory({\n    storage,\n    model: config.model,\n    observation: config.observation,\n    reflection: config.reflection,\n    scope: config.scope,\n    shareTokenBudget: config.shareTokenBudget,\n  });\n\n  // Notify user that OM is active (delayed to let TUI initialize)\n  setTimeout(() => {\n    void ctx.client.tui.showToast({\n      body: {\n        title: 'Mastra',","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/integrations/opencode/src/index.ts#L181-L217","documentation":"The @mastra/opencode plugin creates a LibSQL store at a local file path to back Observational Memory. After initializing the store it calls store.getStore('memory'); if that returns null, the underlying memory storage could not be created, so the plugin aborts with this error including the storage URL.","triggerScenarios":"Calling the MastraPlugin (or loading the @mastra/opencode plugin) where `new LibSQLStore({ url: 'file:...' }).init()` succeeds but getStore('memory') returns null — e.g. corrupted or unreadable DB file, incompatible store version, or init not persisting the memory domain.","commonSituations":"A stale/corrupt SQLite file left over from a previous version of the plugin; the DB path being created in a directory with odd permissions; running with an older @mastra/core whose LibSQLStore doesn't expose the memory domain.","solutions":["Delete the existing DB file at the storagePath reported in the message (or its directory) and let the plugin recreate it, then retry.","Update @mastra/core (LibSQLStore) and @mastra/opencode to matching versions so getStore('memory') is supported.","Verify the dbAbsolutePath directory is writable and `await store.init()` completed without warnings before getStore."],"exampleFix":"// before (corrupt db file from old version)\nrm ~/.opencode/mastra-om.db\n// after — restart the opencode session; plugin re-initializes storage cleanly","handlingStrategy":"try-catch","validationCode":"const storage = await store.getStore('memory');\nif (!storage) throw new Error(`memory storage unavailable at ${storagePath}; recreate the DB file`);","typeGuard":"function isMemoryStorage(s: unknown): boolean {\n  return s != null && typeof (s as { getMessages?: unknown }).getMessages === 'function';\n}","tryCatchPattern":"try {\n  const plugin = await MastraPlugin(/* ... */);\n} catch (e) {\n  if ((e as Error).message.includes('failed to initialize memory storage')) {\n    fs.rmSync(dbAbsolutePath, { force: true });\n    // retry plugin init once\n  } else throw e;\n}","preventionTips":["Keep @mastra/core and @mastra/opencode versions aligned","Monitor for corrupt/oversized DB files in the plugin storage directory","Recreate the DB when upgrading the plugin to avoid stale schema states"],"tags":["storage","libsql","memory","opencode"],"backgroundTag":"storage-init-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}