Skip to content

FOREIGN KEY constraint failed during watch sync (v0.9.5 — regression from #28/#42/#53) #455

@jaepo01

Description

@jaepo01

Summary

FOREIGN KEY constraint failed errors during watch sync, identical to previously fixed #28/#42/#53. However, this occurs on v0.9.5 (latest), where the fix from PR #62 should already be included.

Environment

  • CodeGraph version: 0.9.5 (latest via npm)
  • OS: Ubuntu 24.04, Linux x64
  • Project: Python monorepo, 397 files, 7710 nodes, 7325 edges
  • Languages: Python (384), YAML (12), JavaScript (1)
  • Storage: External USB drive (ext4)
  • Runtime: Node.js v22.22.2

Reproduction

  1. codegraph init + codegraph index — succeeds cleanly
  2. Start daemon via codegraph serve --mcp
  3. Watch sync triggers on file changes → FK errors appear intermittently
  4. Some syncs succeed, some fail — inconsistent

daemon.log (after fresh reinit)

[CodeGraph daemon] Listening on ... (pid 593640, v0.9.5). Idle timeout 300000ms.
[CodeGraph MCP] File watcher active — graph will auto-sync on changes
[CodeGraph MCP] Auto-synced 1 file(s) in 1025ms
[CodeGraph MCP] Auto-synced 1 file(s) in 307ms
[CodeGraph MCP] Auto-synced 2 file(s) in 324ms
[CodeGraph MCP] Auto-synced 1 file(s) in 285ms
[CodeGraph] Watch sync failed { error: 'FOREIGN KEY constraint failed' }
[CodeGraph MCP] Auto-sync error: FOREIGN KEY constraint failed
[CodeGraph] Watch sync failed { error: 'FOREIGN KEY constraint failed' }
[CodeGraph MCP] Auto-sync error: FOREIGN KEY constraint failed
... (76 occurrences total in ~2 days of uptime)

Key observations

  1. Not limited to C/C++ headers: Previous issues (Failed to index: FOREIGN KEY constraint failed (tensorflow) #28/CodeGraph v0.6.2: FOREIGN KEY constraint failed #42/Failed to index: FOREIGN KEY constraint failed #53) were triggered by tree-sitter producing empty-named nodes in C header files. This project is Python-only (384 files) — the trigger is different.
  2. Intermittent: Some watch syncs succeed, others fail. Not deterministic.
  3. Compounding: Once FK integrity is broken, subsequent syncs continue to fail.
  4. Survives reindex: After fresh codegraph init + codegraph index, the daemon produces FK errors again on its first watch sync cycle (2 errors observed immediately).

Workaround

Delete .codegraph/ entirely and reinitialize:

rm -rf .codegraph/
codegraph init .
codegraph index .

This resolves it temporarily, but FK errors reappear over time.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions