Context
During PR #10084 implementation, the first test run failed with SqliteError: FOREIGN KEY constraint failed when ConceptIngestor tried to insert edges whose target strings had no matching graph node. The FK constraint is enforced in ai/graph/storage/SQLite.mjs but not surfaced in the public Database.mjs#addEdge API docs. Future implementers will hit the same error unless they proactively read the storage layer's schema.
This is a small but real discoverability gap. The fix is minutes of work; the benefit is durable across every future agent or human who touches graph ingestion.
The Fix
Add to ai/graph/Database.mjs:
addEdge(edge) — JSDoc @throws {SqliteError} tag with explicit note: "if edge.target is not already present as a node ID. The underlying SQLite schema enforces FOREIGN KEY(target) REFERENCES nodes(id). Caller is responsible for ensuring target nodes exist before edge insertion."
- (Optional) same note on the class-level JSDoc
@summary so it's visible at a glance
Mirror pattern for addNode if similar constraints exist (likely no — nodes are the parent table).
Acceptance Criteria
Origin Session ID
62d6f155-e57f-4279-9b59-36c9e4ecbc5e — surfaced in PR #10084 self-review [TOOLING_GAP] tag
Related
- Evidence of the friction: PR #10084 — the FK miss cost ~10 min of iteration + one test failure before the schema reality was surfaced
ConceptIngestor.ensureEdgeTargetsExist — the workaround pattern that emerged, now documented inline there
Context
During PR #10084 implementation, the first test run failed with
SqliteError: FOREIGN KEY constraint failedwhenConceptIngestortried to insert edges whosetargetstrings had no matching graph node. The FK constraint is enforced inai/graph/storage/SQLite.mjsbut not surfaced in the publicDatabase.mjs#addEdgeAPI docs. Future implementers will hit the same error unless they proactively read the storage layer's schema.This is a small but real discoverability gap. The fix is minutes of work; the benefit is durable across every future agent or human who touches graph ingestion.
The Fix
Add to
ai/graph/Database.mjs:addEdge(edge)— JSDoc@throws {SqliteError}tag with explicit note: "ifedge.targetis not already present as a node ID. The underlying SQLite schema enforcesFOREIGN KEY(target) REFERENCES nodes(id). Caller is responsible for ensuring target nodes exist before edge insertion."@summaryso it's visible at a glanceMirror pattern for
addNodeif similar constraints exist (likely no — nodes are the parent table).Acceptance Criteria
Database.mjs#addEdgeJSDoc includes@throws {SqliteError}with FK constraint explanationask_knowledge_base("can I add an edge to a non-existent node?")query returns the correct guidance after syncOrigin Session ID
62d6f155-e57f-4279-9b59-36c9e4ecbc5e— surfaced in PR #10084 self-review[TOOLING_GAP]tagRelated
ConceptIngestor.ensureEdgeTargetsExist— the workaround pattern that emerged, now documented inline there