Files
ruflo/scripts
ruv c73c8d96e7 fix(graph): migrate agentdb-tools.ts db.exec(sql, params) to better-sqlite3 API; checkpoint trajectory WAL
Two distinct issues, both downstream of graph-schema-smoke being unblocked.

1. **agentdb_graph-query (4 call sites) — SQLITE_MISMATCH "datatype mismatch"**
   After #2431 migrated the graph writer from sql.js to better-sqlite3,
   the corresponding *query* paths in agentdb-tools.ts still called
   \`db.exec(sql, params)\` (sql.js semantic). better-sqlite3's exec is
   a parameterless runner — the second arg is silently ignored, the
   \`?\` placeholder in \`LIMIT ?\` binds to nothing, SQLite rejects with
   "datatype mismatch" (SQLITE_MISMATCH).

   Migrated all 4 sites — k-hop CTE, semantic mode, pagerank mode,
   pathfinder — to \`db.prepare(sql).raw().all(params)\`, which gives
   the same array-of-arrays shape the downstream code expects.

   Reproduced bare-metal:
     \`db.exec("SELECT * FROM foo LIMIT ?", [5])\` →
       SqliteError: datatype mismatch (SQLITE_MISMATCH)
     \`db.prepare("SELECT * FROM foo LIMIT ?").raw().all(5)\` → OK.

2. **trajectory smoke — WAL not checkpointed before sql.js readback**
   Same fix pattern as smoke-graph-schema-migration.mjs in this PR.
   The trajectory hooks fire-and-forget insertGraphEdge through the
   better-sqlite3 writer; without closing the writer connection the
   data sits in .db-wal and sql.js (which reads only the main file)
   reports count=0. Call _resetBridgeDb() before sql.js readback.

Local results after fixes:
  smoke-graph-query-dispatch.mjs   → 21/21
  smoke-graph-pathfinder.mjs       → 20/20
  smoke-trajectory-graph-edges.mjs → 10/10

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-06-25 19:22:58 -04:00
..
2026-01-04 19:30:59 +00:00