Skip to content

fix(memory): SQLiteBackend schema migration + memory_store metadata support#1426

Open
dskarasev wants to merge 1 commit intoruvnet:mainfrom
dskarasev:fix/sqlite-backend-schema-migration
Open

fix(memory): SQLiteBackend schema migration + memory_store metadata support#1426
dskarasev wants to merge 1 commit intoruvnet:mainfrom
dskarasev:fix/sqlite-backend-schema-migration

Conversation

@dskarasev
Copy link
Copy Markdown

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() uses CREATE TABLE IF NOT EXISTS but never migrates existing tables. When .swarm/memory.db is first created by MCP tools (sql.js backend — memory-initializer.ts), the table is created with a different DDL that lacks columns access_level, version, and "references". Subsequent calls to rowToEntry() crash with:

SyntaxError: "undefined" is not valid JSON
  at SQLiteBackend.rowToEntry (sqlite-backend.js:537)

Fix: after CREATE TABLE IF NOT EXISTS, run PRAGMA table_info and ALTER TABLE ADD COLUMN for each missing column (safe no-op if column already exists).

Bug 2 — memory_store MCP tool discards metadata, breaking AutoMemoryBridge sync

storeEntry() hardcodes '{}' as metadata regardless of caller input. The memory_store MCP tool has no metadata parameter in its input schema. Because AutoMemoryBridge.queryRecentInsights() filters on metadata.confidence >= 0.7 (default minConfidence), every entry stored via MCP is permanently excluded from syncsyncToAutoMemory returns 0 even when the DB contains many entries.

Fix:

  • Add optional metadata parameter to memory_store input schema (documented as needed for AutoMemoryBridge)
  • Add metadata to storeEntry() options interface
  • Pass metadata through to the INSERT instead of hardcoded '{}'

Reproducer

# Store something via MCP
mcp__claude-flow__memory_store key="test" namespace="learnings" tags=["insight"] value="..."

# Run sync — observe "Synced 0 entries" despite DB having entries
node .claude/helpers/auto-memory-hook.mjs sync

Files changed

  • v3/@claude-flow/memory/src/sqlite-backend.ts — schema migration in createSchema()
  • v3/@claude-flow/cli/src/memory/memory-initializer.tsmetadata option in storeEntry()
  • v3/@claude-flow/cli/src/mcp-tools/memory-tools.tsmetadata param in memory_store schema

Test plan

  • Create a fresh DB via MCP memory_store → verify SQLiteBackend.initialize() no longer throws
  • Store entry with metadata: { confidence: 0.9 } via MCP → verify syncToAutoMemory() returns it
  • Store entry without metadata via MCP → verify existing behaviour unchanged (empty metadata {})
  • Run on existing DB with all columns present → verify ALTER TABLE no-ops silently

🤖 Generated with claude-flow

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant