Repository navigation
Conversation
…abs#2779) Node ids are casefolded (ids.py), so a Go file declaring both `Run` and `run` produced one id and add_node silently dropped the second declaration: the unexported half vanished from the graph and its call sites bound by bare name to a same-named function in another package — an edge Go's visibility rules forbid. Detect case-only collisions in a pre-pass over the file's declarations. The exported member keeps the plain id (cross-package edges and semantic nodes reference it, so it must stay stable across incremental rebuilds); the unexported sibling gets a sha1(name) salt; when no unique exported member exists, every member is salted so the outcome never depends on declaration order.
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
This pull request modifies the Go extractor (graphify/extractors/go.py) to handle case-only naming collisions between symbols in the same file — for example, an exported Run and an unexported run — which previously produced identical casefolded node IDs. It adds a pre-scan pass (_scan_declarations, _plain_symbol_nid, _receiver_type_of) to detect such collisions and a symbol_nid helper that salts the ID of non-exported members while keeping the exported member's ID stable, applying this to both function and method declarations. The PR also adds a suite of tests in tests/test_go_qualified_resolution.py covering that both case-only siblings are extracted as distinct nodes, that they don't bind to same-named symbols in other packages, that the exported symbol's ID stays stable when a sibling is added, and that incremental/partial rebuilds preserve cross-package edges.
No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 54 functions depend on the 40 functions this change touches.
Health — this change adds coupling hotspots:
- new:
extract_go()— 16 callers, 7 callees - new:
walk()— 1 callers, 8 callees
Verification — 54 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 54 function(s) in the blast radius were not formally verified this run
Formal verification
Could not verify: Could not verify extract\_go.
The verifier did not have enough to check extract\_go, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set
· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).
| salt = hashlib.sha1(name.encode("utf-8"), usedforsecurity=False).hexdigest()[:6] | ||
| return _make_id(plain_nid, salt) | ||
|
|
||
| def walk(node) -> None: |
There was a problem hiding this comment.
walk()
fans out to 8 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
|
Landed in v0.9.45, just published to PyPI. Cherry-picked onto |
ids.py:make_id strips leading/trailing underscores from every name part before normalizing, so _get_connection/get_connection (and more broadly any name pair differing only by underscore wrapping -- x/_x/__x/__x__ dunder variants all collapse the same way) mint the SAME node id. add_node's first-wins dedup then silently drops whichever declaration is walked second: a public method could be entirely absent from the graph while its private-by-convention sibling occupied the public name, with no warning and exit 0. Adds a Python-scoped pre-scan (_python_pre_scan_underscore_collisions) that groups module-level functions and direct class methods by their would-be node id, plus a resolver (_python_underscore_salted_nid) that salts every group member except a unique public (no leading underscore) one -- mirroring the established convention the Go extractor already uses for its own case-only collision (#2779/#2780): when no unique public member exists, every member is salted, so the outcome never depends on declaration order. The public member's id stays exactly what it would be with no colliding sibling at all, so adding/removing a private-by-convention sibling in an incremental rebuild re-points nothing. Both hooks are gated on config.ts_module == "tree_sitter_python" and live inside the shared _extract_generic engine (Python has no dedicated extractor file, unlike Go/Rust/SQL), following the existing precedent for per-language pre-scans already there (csharp_interface_names, swift_protocol_names). Call-site resolution needed no changes: label_to_nid is rebuilt from the final nodes list after the walk completes, so it naturally picks up whichever id (salted or not) a method actually got. 9 new tests in tests/test_python_underscore_resolution.py: the exact repro, id stability across incremental add/remove of a private sibling, the call edge correctly binding to the salted target, the module-level (non-method) case, the no-unique-public-member case (both members salted), a dunder+plain collision, an unaffected no-collision file, and scope isolation (a collision in one class must not touch an unrelated same-named-but-non-colliding member in another class). Note: tests/ on the current v8 HEAD has 7 pre-existing failures unrelated to this change (test_cli_export.py, test_cross_repo_shared_types.py, test_extract_code_only_cli.py, test_merge_graphs_cli.py) -- confirmed via `git stash` that they fail identically on pristine v8 without this diff. Full suite otherwise: 5116 passed. ruff and skillgen --check clean. Fixes #3302. (cherry picked from commit cb8cceb)
Summary
Fixes #2779 — a Go file declaring both
Runandrunproduced one casefoldednode id,
add_nodesilently dropped the second declaration, and the survivingcall sites bound by bare name to a same-named unexported function in another
package (an edge Go's visibility rules make impossible).
Scope: Go extractor only. The same first-wins
add_nodepattern exists in theother extractors; #2774 reports the Rust flavor of the symptom (different
trigger — bare-name collision, not case-only), so I kept this PR to the language
I can verify end-to-end rather than patching 17 extractors blind.
Root cause
ids.py:normalize_idcasefolds by design (AST / LLM / builder parity — #811,#550, #1033, #1104), so the fix cannot be "stop lowercasing".
_disambiguate_colliding_node_idscannot help either: it skips same-filegroups (
len(source_keys) < 2) and its(old_id, source_key)remap key cannottell two symbols in the same file apart. So the collision has to be resolved
where both declarations are still visible: inside the extractor, before ids
leave the file.
Approach
A pre-pass over the file's declarations groups function/method names by their
would-be node id. When a group holds two case-variants:
reachable across packages, so cross-package edges (and edges already stored in
graph.json from files an incremental rebuild does not touch) all target the
exported one; keeping its id stable means adding/removing an unexported
sibling in an
updatere-points nothing. Docs likewise reference the exportedAPI, so the casefolded id a semantic node produces lands on the symbol it
describes.
sha1(name)[:6],usedforsecurity=Falseper the existing convention). Calls to it can onlycome from the same package and only resolve once it exists, so salting it
re-points nothing.
Run/RUN), every member is salted— the outcome never depends on declaration order.
With distinct ids, the existing resolver already does the rest:
Run -> runbinds within the file as EXTRACTED, and the cross-package phantom disappears.
An earlier draft kept the plain id on the lowercase member instead; it
verified worse — a partial (hook /
update) rebuild of just the declaring filere-pointed stored cross-package edges from
Runtorun. The exported-memberrule survives that scenario (pinned by the two incremental tests).
Known limit
The reverse refactor — a file that only had unexported
run(plain id) gainsRun, then a partial rebuild of only that file — re-points same-packagecross-file edges at the plain id to
Run. Stock v8 mis-points the same edge inthat scenario and loses the
runnode entirely (first-wins isdeclaration-order dependent), so this is no worse on any observable, but it is
not fixed either; a full rebuild reconciles it.
Verification
tests/test_go_qualified_resolution.py:incremental behavior that ruled out the earlier draft
uv run --frozen pytest tests/ -q— 4520 passed / 7 skipped /0 failed (Python 3.12)
-llboth clean on the touched filesreappear, the phantom cross-package edge disappears, 5 body edges reattach to
their real owner, zero changes outside the declaring file, and every
pre-existing node id keeps its label — the "impossible edge" audit from Go: case-only sibling symbols (
Run/run) collapse to one node id — the unexported half vanishes and its call sites bind to a same-named function in another package #2779goes 1 -> 0.