Skip to content

Fix UNIQUE constraint crash on large C/C++ projects#21

Merged
colbymchenry merged 1 commit into
mainfrom
fix/unique-constraint-collision
Feb 10, 2026
Merged

Fix UNIQUE constraint crash on large C/C++ projects#21
colbymchenry merged 1 commit into
mainfrom
fix/unique-constraint-collision

Conversation

@colbymchenry

@colbymchenry colbymchenry commented Feb 10, 2026

Copy link
Copy Markdown
Owner

Closes #11

Summary

  • Fixes UNIQUE constraint failed: nodes.id crash reported on large C/C++ and React/JSX projects
  • Node insertion used plain INSERT which crashes on duplicate IDs
  • In large projects, tree-sitter can produce duplicate nodes for the same symbol — e.g. typedef struct in C/C++ where both struct_specifier and type_definition resolve to the same name/kind/line, or in React projects with many barrel index.js files and similarly-named components/hooks across directories

Changes

  • INSERT OR REPLACE INTO nodes — if the same symbol ID appears twice, the second write wins (idempotent, same data anyway)
  • INSERT OR IGNORE INTO edges — silently skip duplicate edges

Why this is safe

The node ID is sha256(filePath:kind:name:line) which already uses full relative paths (not just filenames), so cross-directory collisions were never the issue. A hash collision means it's genuinely the same symbol extracted twice from the same location — replacing is correct.

Test plan

  • Build passes
  • No regressions in existing test suite
  • Verify on a large C/C++ project with duplicate filenames across directories
  • Verify on a large React/JSX project with barrel index.js files

🤖 Generated with Claude Code

Node insertion used plain INSERT which crashes on duplicate IDs.
In large C/C++ projects, tree-sitter can produce duplicate nodes for
the same symbol (e.g. typedef struct where both struct_specifier and
type_definition resolve to the same name/kind/line, or multiple
anonymous constructs on the same line).

- Change nodes INSERT to INSERT OR REPLACE (idempotent, same data)
- Change edges INSERT to INSERT OR IGNORE (skip duplicate edges)

The node ID is sha256(filePath:kind:name:line) which already uses full
relative paths, so cross-directory collisions are not the issue.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@colbymchenry colbymchenry merged commit 48cc3a8 into main Feb 10, 2026
@colbymchenry colbymchenry deleted the fix/unique-constraint-collision branch February 10, 2026 22:47
jorgerobles pushed a commit to jorgerobles/codegraph that referenced this pull request Jun 1, 2026
…raint-collision

Fix UNIQUE constraint crash on large C/C++ projects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UNIQUE constraint failed: nodes.id during indexing on React/JSX codebase

1 participant