Found during dogfooding v3.10.1-dev.80
Severity: Medium (crashes the watch process; not consistently reproducible)
Command: codegraph watch <dir>
Reproduction
Not 100% reproducible, but the crash was observed after this sequence:
codegraph build . --no-incremental --engine native
codegraph embed -m minilm # 7969 embeddings
echo "// emb-test" >> src/cli.ts
codegraph build . # incremental → 19139/40857
git checkout src/cli.ts # restore
# Note: a separate incremental rebuild after restore was NOT done; watch starts on possibly-stale state
codegraph watch .
# In another terminal:
echo "// w-test" >> src/cli.ts
On the very first watcher tick after the edit:
SqliteError: FOREIGN KEY constraint failed
at rebuildFile (.../dist/domain/graph/builder/incremental.js:354:23)
at processPendingFiles (.../dist/domain/graph/watcher.js:46:31)
at Timeout._onTimeout (.../dist/domain/graph/watcher.js:154:15)
at listOnTimeout (node:internal/timers:608:17)
at process.processTimers (node:internal/timers:543:7) {
code: 'SQLITE_CONSTRAINT_FOREIGNKEY'
}
Node.js v24.10.0
The watcher process then exits (does not recover).
Expected behavior
A FK constraint failure on a single file rebuild should be caught, logged, and the watcher should continue processing other changes. It should never bring down the watcher.
Root cause (hypothesis)
Likely related to #1174 (incremental rebuild drops imports edges). When the DB state is internally inconsistent (e.g., a node referenced by an edge in another table has been deleted but the referencing rows weren't), watch's rebuildFile triggers an FK violation on the next insert that touches the dangling reference.
The native engine likely has PRAGMA foreign_keys = ON and either:
- The Stage 6b purge order is wrong (deleting a parent before its dependent rows), or
- An edge is being inserted with a
from_id/to_id pointing at a node that no longer exists.
Suggested fix
- Wrap
rebuildFile's DB writes in a try/catch that logs and skips the file rather than crashing.
- Investigate the FK constraint at
incremental.js:354 (transpiled from src/domain/graph/builder/incremental.ts) — what specific FK is being violated?
- Likely fixed by addressing #1174.
Found during dogfooding v3.10.1-dev.80
Severity: Medium (crashes the watch process; not consistently reproducible)
Command:
codegraph watch <dir>Reproduction
Not 100% reproducible, but the crash was observed after this sequence:
On the very first watcher tick after the edit:
The watcher process then exits (does not recover).
Expected behavior
A FK constraint failure on a single file rebuild should be caught, logged, and the watcher should continue processing other changes. It should never bring down the watcher.
Root cause (hypothesis)
Likely related to #1174 (incremental rebuild drops
importsedges). When the DB state is internally inconsistent (e.g., a node referenced by an edge in another table has been deleted but the referencing rows weren't), watch'srebuildFiletriggers an FK violation on the next insert that touches the dangling reference.The native engine likely has
PRAGMA foreign_keys = ONand either:from_id/to_idpointing at a node that no longer exists.Suggested fix
rebuildFile's DB writes in a try/catch that logs and skips the file rather than crashing.incremental.js:354(transpiled fromsrc/domain/graph/builder/incremental.ts) — what specific FK is being violated?