Repository navigation
Fix: prevent cross-file member-call name collisions in extract resolver - #599
Merged
safishamsi merged 1 commit intoMay 2, 2026
Conversation
graphify per-language AST extractors strip member-expression callees
(`x.foo()`, `obj.bar()`, `Pkg::baz()`) down to the trailing identifier,
queue them in `raw_calls`, and the cross-file resolver matches by bare
lowercase name against a global symbol table. When any file in the
corpus exposes a top-level helper with a common method name (e.g. a
`function log(...)` in a one-off smoke-test script), every unrelated
`Logger.log(...)` / `this.x.find(...)` / `Pkg::baz(...)` call across the
codebase resolves to that single helper, producing phantom god nodes
with hundreds of bogus INFERRED edges.
This patch:
* Adds `_MEMBER_CALL_NODE_TYPES` enumerating member-expression AST
node types across all supported languages.
* Tags every `raw_calls.append(...)` site with `callee_node_type`.
* Skips entries whose `callee_node_type` is in
`_MEMBER_CALL_NODE_TYPES` from the cross-file resolver in
`extract()`. In-file resolution behaviour is intentionally
preserved.
On a real production codebase (~1,668 TS/JS files, NestJS + Nuxt) this
eliminates 1,262 phantom edges and removes a phantom `log()` god node
that previously sat at Graphify-Labs#2 with 265 inbound edges (255 of them bogus).
Includes 3 regression tests that fail on the original code and pass with
this patch.
phreakocious
added a commit
to phreakocious/graphify
that referenced
this pull request
May 6, 2026
PR Graphify-Labs#599 (cherry-picked as 58199eb) added `callee_node_type: func_node.type` to the unresolved-call payload, but only the C++ and generic branches of walk_calls ever assign `func_node`. Swift / Kotlin / Scala / C# / PHP extract callee_name directly without going through that variable, so the new line raised UnboundLocalError on every call site in those languages. Init `func_node = None` once at the top of the call-handling block so the existing `if func_node is not None` guard at the append site works. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: prevent cross-file member-call name collisions in extract resolver
What
The cross-file call resolver in
graphify/extract.pymatched calleesagainst a global lowercase-name → id map. Because every per-language
extractor strips member-expression callees (
x.foo(),obj.bar(),Pkg::baz()) down to the trailing identifier before queuing them, theresolver would routinely link a
this.logger.log(...)call to acompletely unrelated
function log(...)defined in some other file inthe corpus, producing phantom god nodes with hundreds of bogus INFERRED
edges.
This PR closes the cross-file leg of the bug:
_MEMBER_CALL_NODE_TYPESenumerates thetree-sitter node types that represent member-expression callees across
all supported languages (JS/TS, Go, Rust, Swift, Kotlin, Scala, C++,
PHP, Java, Elixir, Zig).
raw_calls.append(...)site in every per-language extractor nowrecords
callee_node_type(the AST node type of the callee).extract()skips entries whosecallee_node_typeis in_MEMBER_CALL_NODE_TYPES, since name-onlyresolution of member calls is fundamentally unsafe without
receiver-type information.
In-file resolution behavior is intentionally unchanged. In-file matches
require the callee to actually exist as a top-level symbol in the SAME
file, which is rarely a phantom in practice.
Why
See linked issue. On a real production codebase (~1,668 TS/JS files,
NestJS + Nuxt) this bug pulled 255 phantom INFERRED edges onto a single
1-line helper in a smoke-test script, making it the #2 god node and
distorting cohesion + suggested-questions output. After the fix:
log()god-node rankuseApi()(561)useApi()(561)The ~1,260 dropped edges are predominantly cross-file member-call
phantoms. Real edges (intra-file calls, bare-identifier cross-file
calls, imports) are unaffected.
How
_MEMBER_CALL_NODE_TYPESTag at every
raw_calls.appendSix call sites get one new field each:
(For the Zig branch, the original callee name is already pre-split by
.,so the patch synthesises a
_zig_dotted_calleemarker when the sourcetext contained a
.. For the PowerShell branch, all calls are barecommand names and get the literal
"command_name". For the Elixirbranch, the surrounding loop already inspects the callee
childnode, sochild.typeis used directly.)Resolver guard
Tests
tests/test_member_call_resolution.pyadds 3 regression tests:test_member_call_node_types_constant_present— sanity check that theconstant exists and covers every per-language extractor.
test_smoke_test_log_does_not_steal_nestjs_logger_calls— fullend-to-end: writes a 3-file corpus that triggers the bug, calls
extract(), asserts that NO cross-file edges land on the smoke-testlog()node, and asserts that legitimate intra-file calls arepreserved.
test_raw_calls_emit_callee_node_type_for_member_expressions—sanity check that the corpus exercises the relevant code paths.
Verified that all 3 tests fail on
main(4 phantom cross-file edgesdetected in the test corpus) and pass with this patch.
Trade-off (acknowledged)
This is a deliberately conservative fix. Legitimate cross-file member
calls (e.g.
import { service } from './x'; service.method()wheremethodhappens to be a top-level identifier in some unrelated file)will no longer produce edges. In practice:
be wrong without anyone knowing.
_load_tsconfig_aliasesetc.) could re-introduce these as high-confidence EXTRACTED edges with
receiver-type tracking. That's a larger change and out of scope here.
outweighs the loss.
Files changed
graphify/extract.py— add_MEMBER_CALL_NODE_TYPES, tag 6raw_calls.append(...)sites, guard the cross-file resolver.Net: +25 lines.
tests/test_member_call_resolution.py— new file, 3 regression tests.Backward compatibility
raw_callsis an internal data structure not exposed to users.LanguageConfigflag — but I'd argue the legacy behavior was always abug.
Closes #598