fix(memory): SQLiteBackend schema migration + memory_store metadata support#1426
Open
dskarasev wants to merge 1 commit intoruvnet:mainfrom
Open
fix(memory): SQLiteBackend schema migration + memory_store metadata support#1426dskarasev wants to merge 1 commit intoruvnet:mainfrom
dskarasev wants to merge 1 commit intoruvnet:mainfrom
Conversation
…upport
**Bug 1 — SQLiteBackend crashes on DB created by MCP sql.js backend**
`createSchema()` uses `CREATE TABLE IF NOT EXISTS` but never migrates
existing tables. When `.swarm/memory.db` is first created by MCP tools
(sql.js backend), the table lacks columns `access_level`, `version`, and
`"references"`. Subsequent calls to `rowToEntry()` crash with:
SyntaxError: "undefined" is not valid JSON
Fix: after `CREATE TABLE IF NOT EXISTS`, run `PRAGMA table_info` and
`ALTER TABLE ADD COLUMN` for each missing column (no-op if present).
**Bug 2 — memory_store MCP tool discards metadata, breaking AutoMemoryBridge sync**
`storeEntry()` hardcodes `'{}'` as metadata regardless of input.
`memory_store` MCP tool has no `metadata` parameter in its input schema.
As a result, `AutoMemoryBridge.queryRecentInsights()` (which filters on
`metadata.confidence >= 0.7`) always returns 0 entries — `syncToAutoMemory`
never writes anything even when the DB is full of entries.
Fix:
- Add optional `metadata` parameter to `memory_store` input schema
- Add `metadata` to `storeEntry()` options interface
- Pass `metadata` through to the INSERT instead of hardcoded `'{}'`
Reproducer: store any entry via `mcp__claude-flow__memory_store`, then
run `auto-memory-hook.mjs sync` — observe "Synced 0 entries".
Co-Authored-By: claude-flow <ruv@ruv.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related bugs that together make
AutoMemoryBridge.syncToAutoMemory()always return 0 entries when the database was created by MCP tools.Bug 1 — SQLiteBackend crashes on DB created by the MCP sql.js backend
createSchema()usesCREATE TABLE IF NOT EXISTSbut never migrates existing tables. When.swarm/memory.dbis first created by MCP tools (sql.js backend —memory-initializer.ts), the table is created with a different DDL that lacks columnsaccess_level,version, and"references". Subsequent calls torowToEntry()crash with:Fix: after
CREATE TABLE IF NOT EXISTS, runPRAGMA table_infoandALTER TABLE ADD COLUMNfor each missing column (safe no-op if column already exists).Bug 2 —
memory_storeMCP tool discards metadata, breaking AutoMemoryBridge syncstoreEntry()hardcodes'{}'asmetadataregardless of caller input. Thememory_storeMCP tool has nometadataparameter in its input schema. BecauseAutoMemoryBridge.queryRecentInsights()filters onmetadata.confidence >= 0.7(defaultminConfidence), every entry stored via MCP is permanently excluded from sync —syncToAutoMemoryreturns 0 even when the DB contains many entries.Fix:
metadataparameter tomemory_storeinput schema (documented as needed for AutoMemoryBridge)metadatatostoreEntry()options interfacemetadatathrough to the INSERT instead of hardcoded'{}'Reproducer
Files changed
v3/@claude-flow/memory/src/sqlite-backend.ts— schema migration increateSchema()v3/@claude-flow/cli/src/memory/memory-initializer.ts—metadataoption instoreEntry()v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts—metadataparam inmemory_storeschemaTest plan
memory_store→ verifySQLiteBackend.initialize()no longer throwsmetadata: { confidence: 0.9 }via MCP → verifysyncToAutoMemory()returns itmetadatavia MCP → verify existing behaviour unchanged (empty metadata{})ALTER TABLEno-ops silently🤖 Generated with claude-flow