fix(graph): dedupe node_rows + use INSERT OR REPLACE to avoid UNIQUE constraint failures — closes #114#127
Merged
Conversation
…constraint failures — closes #114 Bug: populate_graph_tables() in scripts/graph_model.py built node_rows from flat_nodes, which can contain duplicate node_id values (file:line:fn) when e.g. a class and its __init__ method share the same line, or when two declarations collide on the same line number. The graph_nodes.node_id column has a UNIQUE constraint, so a bare INSERT raised sqlite3.IntegrityError and rolled back the entire BEGIN EXCLUSIVE transaction — leaving graph_nodes empty. Fix applies two layers of defense: 1. Dedupe node_rows by node_id (last occurrence wins, matching the 'last match wins' semantics of the flat registry) before the batch insert. Applied to both populate_graph_tables() and incremental_graph_update(). 2. Use INSERT OR REPLACE instead of bare INSERT so even if a duplicate slips through (e.g. from a prior partial write), the batch succeeds instead of failing the whole transaction. Verified: scan on clean_app fixture now consistently populates graph_nodes (31 nodes) and graph_edges (113 edges) without IntegrityError. Test suite: 1183 passed, 1 pre-existing failure (#118, unrelated).
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What
Fixes RED TEAM issue #114:
populate_graph_tables()failed withsqlite3.IntegrityError: UNIQUE constraint failed: graph_nodes.node_id, leaving the graph empty.Root cause
populate_graph_tables()inscripts/graph_model.pybuiltnode_rowsfromflat_nodes, which can contain duplicatenode_idvalues (file:line:fn) when e.g. a class and its__init__method share the same line, or when two declarations collide on the same line number. Thegraph_nodes.node_idcolumn has a UNIQUE constraint, so a bareINSERTraisedsqlite3.IntegrityErrorand rolled back the entireBEGIN EXCLUSIVEtransaction — leavinggraph_nodesempty.Fix — two layers of defense
Dedupe
node_rowsbynode_id(last occurrence wins, matching the "last match wins" semantics of the flat registry) before the batch insert. Applied to bothpopulate_graph_tables()andincremental_graph_update().Use
INSERT OR REPLACEinstead of bareINSERTso even if a duplicate slips through (e.g. from a prior partial write), the batch succeeds instead of failing the whole transaction.Verification
Test suite: 1183 passed, 1 pre-existing failure (#118 — test expectation mismatch, unrelated).
Test plan
Risk
Low. Dedup uses last-occurrence-wins which matches flat registry semantics. INSERT OR REPLACE is idempotent and the transaction is already wrapped in BEGIN EXCLUSIVE / COMMIT.