Silent node loss: same-file qualified_name collisions are dropped on insert
Summary
Two same-named symbols in one file collapse into a single node on insert, so the graph silently drops the earlier definitions. A build reports more nodes than the database actually stores, and caller/callee analysis on those names resolves to a single merged node.
Root cause
qualified_name is the stable identity key, built by GraphStore._make_qualified as file::name or file::parent.name. That key is not unique per symbol: methods of different object literals, or repeated generated helpers, produce the same key. upsert_node inserts with ON CONFLICT(qualified_name) DO UPDATE, so colliding rows collapse last writer wins and earlier definitions are lost.
The discrepancy is also visible in the counts: full_build reports total_nodes summed in memory from the parsed node lists, while status reads SELECT COUNT(*). The gap is exactly the number of dropped nodes.
Reproduction
// db.ts
export const personas = { getById(id) { return id } };
export const users = { getById(id) { return id } };
export const cart = { getById(id) { return id } };
$ code-review-graph build
Full build: 1 files, 4 nodes, 3 edges (postprocess=full)
$ code-review-graph status
Nodes: 2
Build claims 4 nodes (one File plus three getById); the database holds 2 (the three getById collapse into one). The same pattern shows up in real object modules and in generated files with repeated helper names at module scope.
Proposed fix
Deduplicate per file in the batch store functions (store_file_nodes_edges, store_file_batch), which already receive the whole file's node list. Keep the first occurrence at its bare key so existing edges still resolve to it, and suffix later collisions with :L<line_start>, which is always unique because two definitions cannot share a start line. Unique nodes keep byte identical keys, so embeddings and incremental updates are unaffected.
I also propose surfacing the disambiguation so collisions stop being invisible: a find_disambiguated_nodes() helper, a disambiguated_nodes field in the build result, and a one line CLI summary.
Convention question
Does the :L<line_start> suffix work for you, or would you prefer a different marker for the second and later collisions? One honest caveat: a collided node's identity shifts if its own start line moves. That affects only ambiguous duplicates, never the unique majority.
A PR implementing this (two commits, tests, suite green) is ready to open against main.
Maintainer status: PR #586 was closed because :L<line> suffixes preserve rows but do not preserve graph meaning. Ambiguous edges still resolve to the first definition, later duplicates cannot receive callers, identities change after harmless line shifts, and direct upsert_node() behavior remains inconsistent.
This issue remains open for a parser/resolver-level design with stable receiver/scope identity, explicit ambiguity handling, correct caller resolution for every duplicate, and incremental identity-migration coverage.
I opened #715 with a fix for this.
The first definition keeps its existing qualified name, while genuine same-file collisions receive a stable :L<line_start> suffix. Re-indexing the same definition at the same location updates it in place, and evidence-backed edge endpoints are aligned with the disambiguated node so caller/callee lookups continue to resolve.
Validation: 1,964 tests passed; Ruff and mypy are clean.
@SarveshaKumarKS thanks for #715, and sorry for the silence since July.
Status. I re-ran @CodeBlackwell's original repro against staging today. It still reproduces exactly as filed:
Full build: 1 files, 4 nodes, 3 edges (postprocess=full)
Nodes: 2
Build counts in memory, the database holds two, the three getById collapse. So the defect is unfixed and this issue is correctly open.
On #715: it is open but does not merge into staging any more (CONFLICTING). It needs a rebase before I can evaluate it. If you rebase it, the thing I will be reading for is the objection I raised against #586, which #715 says it handles but which I have not verified: that a :L<line_start> suffix preserves the row without preserving the meaning unless caller resolution follows the disambiguated node. Your PR description says evidence-backed edge endpoints are realigned. That is the claim the review turns on, so please make sure the tests state it directly: a call to the second duplicate must resolve to the second node, not the first.
The second thing I want covered is identity churn. A collided node's qualified name moves when its own start line moves, which makes every incremental update after an unrelated edit above it look like a delete plus an insert. Whatever the suffix ends up being, there should be a test that edits a line above two colliding definitions and asserts the graph does not churn beyond the file.
Related, in case it changes how you scope it: #999 is the same identity problem one level up (two same-leaf classes in one file sharing one Function qualified name), and #943 is the design thread for making declaration identity carry scope properly. If a rebase of #715 turns into a rewrite, #943 is probably the better home for it.