ruvnet / ruvnet/agentdb

agentdb_pattern_store_batch fails: BatchOperations.insertPatterns writes context/outcome columns the schema never creates

Open
#16 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
89
Forks
15
PR merge metrics
No merged PRs in 30d

Description

Summary

On agentdb@3.0.0-alpha.18, the agentdb_pattern_store_batch MCP tool always fails with the generic error:

❌ Batch pattern storage failed: An error occurred while processing your request.

while sequential agentdb_pattern_store calls succeed against the same database.

Root cause

Schema drift between the batch writer and the canonical schema:

  • src/controllers/ReasoningBank.ts creates reasoning_patterns with columns id, ts, task_type, approach, success_rate, uses, avg_reward, tags, metadata — no context, no outcome (dist: dist/src/controllers/ReasoningBank.js lines 65–75).

  • src/optimizations/BatchOperations.ts insertPatterns() prepares:

    INSERT INTO reasoning_patterns (
      task_type, approach, context, success_rate, outcome, uses, tags, metadata
    ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
    

    (dist: dist/src/optimizations/BatchOperations.js lines 117–121).

SQLite rejects the INSERT (table reasoning_patterns has no column named context), the handler's catch swallows the specific error, and the tool reports the generic message above.

Repro

  1. npx agentdb@latest mcp with a fresh or existing DB.
  2. Call agentdb_pattern_store_batch with any single valid pattern (taskType, approach, successRate).
  3. Fails. agentdb_pattern_store with the same payload succeeds.

Workaround

ALTER TABLE reasoning_patterns ADD COLUMN context TEXT;
ALTER TABLE reasoning_patterns ADD COLUMN outcome TEXT;

After the migration, batch insert works immediately (verified: 2 patterns in 24ms).

Suggested fix

Either add context/outcome to the canonical reasoning_patterns DDL (they seem intentional — insertPatterns embeds context in the embedding text), or drop them from the batch INSERT. Also consider surfacing the underlying SqliteError message in the batch handler's error response — the generic wrapper made this much harder to diagnose than it needed to be.

Related note

agentdb_init also fails on better-sqlite3 builds compiled with SQLITE_DQS=0: dist/src/mcp/agentdb-mcp-server.js line 891 uses WHERE type=\"table\" (double-quoted string literal). Single-quoting fixes it. Happy to split this into its own issue if preferred.

Environment

  • agentdb 3.0.0-alpha.18 via npx agentdb@latest mcp
  • macOS (darwin arm64), node from npx cache, better-sqlite3 bundled build

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the canonical schema in src/controllers/ReasoningBank.ts with insertPatterns() in src/optimizations/BatchOperations.ts, then reproduce the failure with agentdb_pattern_store_batch against a fresh database. Done means valid batch patterns insert successfully without a manual ALTER TABLE, while the sequential store still works; keep the unrelated agentdb_init quoting note separate.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.