/** * Graph Edge Writer — ADR-130 Phase 1 * * Provides a minimal interface for inserting rows into the graph_edges * SQLite table defined by MEMORY_SCHEMA_V3. * * #2431 fix (2026-06-22) — replaces the prior sql.js implementation. The * prior version opened sql.js, performed in-memory updates, then called * `fs.writeFileSync(dbPath, db.export())` after every edge insert. This * whole-file flush overwrote the main `memory.db` while the better-sqlite3 * bridge was actively writing through its WAL — exactly the dual-write * race that ADR-068 (#1257) removed. Symptom: PRAGMA integrity_check * reports `database disk image is malformed (11)` after a single * memory_store + causal-edge sequence. * * Fix posture: use better-sqlite3 directly (the same native engine the * memory bridge uses). WAL-native, no whole-file fsync, no race. Keeps * the public API surface identical so callers don't have to change. * * Note: this is the minimum-safe fix. The architecturally cleaner fix * (route writes through the bridge's controller layer) is scoped to a * future ADR — see #2431 for the discussion. Until that ADR lands, this * module owns its own better-sqlite3 handle but on the same file, with * WAL mode enabled (which makes concurrent writers safe by SQLite's own * design — no overlapping fsync). * * The module is designed for fire-and-forget callers — every public * function suppresses errors internally so callers never need try/catch. * * @module v3/cli/memory/graph-edge-writer */ /** * Return the better-sqlite3 Database instance for graph_edges writes. * Creates the graph_edges table if it is absent (idempotent). * Returns null if better-sqlite3 is not available or db cannot be opened. * * #2246 fix: `createIfMissing` (default false for back-compat) — when true, * lazily creates an empty memory.db with the graph_edges schema so * graph-pathfinder works on fresh environments before any memory writes. * * #2431 fix: better-sqlite3 + WAL mode replaces sql.js + whole-file * writeFileSync. Eliminates the dual-write race that corrupted memory.db * when called alongside the memory bridge's better-sqlite3 writer. */ export declare function getBridgeDb(customDbPath?: string, opts?: { createIfMissing?: boolean; }): Promise; export interface GraphEdgeInput { sourceId: string; targetId: string; relation: string; weight?: number; confidence?: number; decayRate?: number; lastReinforced?: string; witnessId?: string; embedding?: number[]; metadata?: Record; dbPath?: string; } /** * Insert a single edge into graph_edges. * Fire-and-forget — errors are suppressed. * Returns true if the write succeeded, false otherwise. * * #2431 fix: uses better-sqlite3 prepared statements + implicit WAL * journal. No `fs.writeFileSync` whole-file flush — the WAL handles * durability without overwriting the main file out from under other * writers. */ export declare function insertGraphEdge(input: GraphEdgeInput): Promise; /** * Query graph_edges by source_id. * Returns rows or empty array on error. */ export declare function queryEdgesBySource(sourceId: string, relation?: string, dbPath?: string): Promise>; /** * Count rows in graph_edges (for test assertions). */ export declare function countGraphEdges(dbPath?: string): Promise; /** * Reset the cached db handle (for tests that need a fresh DB). * * #2431 fix: also explicitly closes the prior handle so file locks * release immediately — better-sqlite3 holds an OS-level file handle * which the prior sql.js implementation did not. * * #2736-followup fix: `close()` alone only checkpoints the WAL back into * the main file as a best-effort PASSIVE checkpoint when SQLite considers * this the last connection — which is not guaranteed to fully flush under * contention, and was observed leaving writes invisible to a same-process * sql.js reader that re-reads the raw file immediately after close() on * Linux CI runners (not reproduced on Windows). Force a blocking TRUNCATE * checkpoint before close so cross-engine readers always see committed * writes deterministically, regardless of platform/timing. */ export declare function _resetBridgeDb(): void; //# sourceMappingURL=graph-edge-writer.d.ts.map