mirror of
https://github.com/colbymchenry/codegraph.git
synced 2026-11-09 09:33:37 +08:00
fix(sync): resolve cross-file refs when an edit adds or removes the satisfying symbol (#1240) (#1249)
* chore: ignore .kommandr/ directory * fix(sync): resolve cross-file refs when an edit adds or removes the satisfying symbol (#1240) Incremental sync scoped reference resolution to the changed files' own refs, and a completed pass deleted every ref it failed to resolve — so a symbol change in one file could never repair references in UNCHANGED files, in either direction, until a full re-index: - New-export case: a.ts imports/calls `greet` before b.ts defines it. The failed refs were deleted at index time; when b.ts later gained `greet`, nothing revisited a.ts — the calls/imports edges stayed missing while status reported a clean index. - Removal case: when a re-index (or file deletion) dropped a symbol, the incoming edges cascade-deleted and the callers — whose resolved refs had been consumed — never got a chance to rebind to an alternative definition or reconnect when the symbol returned. Fix, sharing one lifecycle: - Schema v8: unresolved_refs gains status ('pending'/'failed') and name_tail (last dotted segment, so `h.greet` is findable by `greet`). Both resolver persist paths now park unresolvable refs as failed instead of deleting them. All pending-work readers (batched drain, non-progress guard, #1187 orphan sweep, status pendingRefs) filter to pending, preserving their invariants and keeping status honest. - Sync retry: after scoped resolution, failed refs whose name tail matches a symbol name now present in the changed files are re-resolved through a per-ref-yielding path (watchdog-safe, #1091 class). Names matching >500 failed refs are skipped as external/builtin noise (#999 rationale). - Removal side: createEdges stamps each resolution edge with its originating reference (metadata.refName, + refKind when kind promotion rewrote it). When the #899 restore misses a target or sync deletes a file, the dropped edge is resurrected as exactly that ref — re-resolved in the same sync (rebinding to an alternative definition) or parked failed until the symbol reappears. Edges without the stamp (pre-upgrade, synthesized) still drop silently: reconstructing from the target's plain name would strip receiver context and risk a rebind a full re-index would never make. - Pure-removal syncs clear resolver caches so a long-lived daemon can't resolve resurrected refs against the pre-removal graph. Validated: issue repro now yields a graph byte-identical to a full re-index; move/remove-readd/file-deletion scenarios all rebind or heal; baseline-vs-new A/B on express and gin shows identical node/edge counts and no timing regression (DB grows ~25% from the parked ref rows — pure cache, reset by any full re-index). 8 regression tests added. Fixes #1240 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
386bff0f84
commit
9d0cd3a7d1
+13
-1
@@ -67,7 +67,15 @@ CREATE TABLE IF NOT EXISTS files (
|
||||
errors TEXT -- JSON array
|
||||
);
|
||||
|
||||
-- Unresolved References: References that need resolution after full indexing
|
||||
-- Unresolved References: References that need resolution after full indexing.
|
||||
-- status lifecycle: rows are inserted 'pending' by extraction; a completed
|
||||
-- resolution pass either deletes a row (resolved) or marks it 'failed'
|
||||
-- (attempted, no match — kept so a later sync can retry it when a changed
|
||||
-- file introduces a symbol that could satisfy it, #1240). name_tail is the
|
||||
-- last segment of reference_name ('util.greet' → 'greet'), written when a
|
||||
-- row is marked failed, so the retry lookup matches new node names against
|
||||
-- dotted refs too. Rows follow their from_node via ON DELETE CASCADE, so
|
||||
-- re-extracting or deleting a file clears its stale rows in any status.
|
||||
CREATE TABLE IF NOT EXISTS unresolved_refs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
from_node_id TEXT NOT NULL,
|
||||
@@ -78,6 +86,8 @@ CREATE TABLE IF NOT EXISTS unresolved_refs (
|
||||
candidates TEXT, -- JSON array
|
||||
file_path TEXT NOT NULL DEFAULT '',
|
||||
language TEXT NOT NULL DEFAULT 'unknown',
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
name_tail TEXT NOT NULL DEFAULT '',
|
||||
FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
@@ -172,6 +182,8 @@ CREATE INDEX IF NOT EXISTS idx_unresolved_from_node ON unresolved_refs(from_node
|
||||
CREATE INDEX IF NOT EXISTS idx_unresolved_name ON unresolved_refs(reference_name);
|
||||
CREATE INDEX IF NOT EXISTS idx_unresolved_file_path ON unresolved_refs(file_path);
|
||||
CREATE INDEX IF NOT EXISTS idx_unresolved_from_name ON unresolved_refs(from_node_id, reference_name);
|
||||
CREATE INDEX IF NOT EXISTS idx_unresolved_status ON unresolved_refs(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_unresolved_failed_tail ON unresolved_refs(name_tail) WHERE status = 'failed';
|
||||
CREATE INDEX IF NOT EXISTS idx_edges_provenance ON edges(provenance);
|
||||
|
||||
-- Project metadata for version/provenance tracking
|
||||
|
||||
Reference in New Issue
Block a user