Skip to content

fix: an import from outside the corpus must shadow indirect_call reso… - #2758

Closed
phudayyy wants to merge 1 commit into
Graphify-Labs:v8from
phudayyy:fix/js-external-import-shadow
Closed

phudayyy wants to merge 1 commit into
Graphify-Labs:v8from
phudayyy:fix/js-external-import-shadow

Conversation

@phudayyy

@phudayyy phudayyy commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2757

_js_local_bound_names collects a function's locals from parameters and variable_declarator nodes, and _js_module_bound_names only the latter. A name introduced by import { X } from "pkg" is neither, so it was absent from both shadow sets: listing it in a dispatch table ({ icon: X }) or passing it on as a call argument read as an unresolved by-name reference, resolved against the corpus-wide label index, and fabricated an indirect_call edge (INFERRED, 0.8) to an unrelated same-named callable elsewhere in the corpus.

Same class as the catch-binding (#2241 family), single-parameter-arrow and untracked-closure shadows already fixed — an import is simply a module-scoped binding. A UI icon kit makes it land constantly: Palette, Search, Filter and Menu are icon exports and ordinary component names, so any repo with both grows cross-package edges between files that never referenced one another. Found on a monorepo where three unrelated components appeared to call a Palette() in a different package; all three import the lucide-react icon.

The guard asks _resolve_js_import_target rather than forming a second opinion, so a relative import — which resolves to a real file, and whose edge is the whole point of the graph — keeps resolving. node_modules is tested separately because a tsconfig paths entry pointing a package at its own installed copy ("lucide-react": ["./node_modules/lucide-react"]) does resolve, to a tree every scan prunes.

Tests: 5 of 7 red on v8 without the patch, 7 of 7 green with it. The two that pass either way are the counter-tests that bound the fix — a relative import must still resolve, and an unshadowed by-name reference in a file that also imports something external must still emit.

Full suite, same machine, with and without: 5 failed / 4386 passed and 5 failed / 4393 passed. Identical failures both ways (test_ollama_retry_cap needs openai, test_install needs the codex CLI), so they are environmental; the delta is exactly the 7 new tests.

…lution

Issue Graphify-Labs#2757

`_js_local_bound_names` collects a function's locals from parameters and
`variable_declarator` nodes, and `_js_module_bound_names` only the latter. A name
introduced by `import { X } from "pkg"` is neither, so it was absent from both
shadow sets: listing it in a dispatch table (`{ icon: X }`) or passing it on as a
call argument read as an unresolved by-name reference, resolved against the
corpus-wide label index, and fabricated an `indirect_call` edge (INFERRED, 0.8)
to an unrelated same-named callable elsewhere in the corpus.

Same class as the `catch`-binding (Graphify-Labs#2241 family), single-parameter-arrow and
untracked-closure shadows already fixed — an import is simply a module-scoped
binding. A UI icon kit makes it land constantly: `Palette`, `Search`, `Filter`
and `Menu` are icon exports *and* ordinary component names, so any repo with both
grows cross-package edges between files that never referenced one another. Found
on a monorepo where three unrelated components appeared to call a `Palette()` in
a different package; all three import the lucide-react icon.

The guard asks `_resolve_js_import_target` rather than forming a second opinion,
so a relative import — which resolves to a real file, and whose edge is the whole
point of the graph — keeps resolving. `node_modules` is tested separately because
a `tsconfig` `paths` entry pointing a package at its own installed copy
(`"lucide-react": ["./node_modules/lucide-react"]`) *does* resolve, to a tree
every scan prunes.

Tests: 5 of 7 red on v8 without the patch, 7 of 7 green with it. The two that
pass either way are the counter-tests that bound the fix — a relative import must
still resolve, and an unshadowed by-name reference in a file that also imports
something external must still emit.

Full suite, same machine, with and without: 5 failed / 4386 passed and
5 failed / 4393 passed. Identical failures both ways (`test_ollama_retry_cap`
needs `openai`, `test_install` needs the codex CLI), so they are environmental;
the delta is exactly the 7 new tests.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PR adds handling for JavaScript/TypeScript import bindings when resolving indirect_call edges in the extractor engine. It introduces two new helpers (_js_import_binds_external and _js_external_import_names) that identify names imported from modules outside the scanned corpus, computes that set once per JS/TS file, and adds a guard in _emit_indirect_by_name's caller to skip fabricating indirect-call edges for those externally-imported names. The change treats external imports as module-scoped shadows (analogous to existing catch/parameter/closure shadow handling), while intentionally leaving relative imports resolvable. A new test file exercises named, default, namespace, and aliased external imports, a tsconfig paths-into-node_modules case, and counter-cases for relative imports and unimported same-file callables. Surface area is concentrated in graphify/extractors/engine.py and one new test module; the long list of changed rationale/symbol identifiers appears to reflect renumbering/comment-block shifts around the edited region.

No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 609 functions depend on the 213 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: _extract_generic() — 18 callers, 24 callees

Verification — 609 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: 550 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, 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 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.44, just published to PyPI. I cherry-picked this onto v8 with your authorship preserved in the commit, so both the change and the credit are in the history. Thanks @phudayyy for the fix. Closing since it is now released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS/TS: an import from outside the corpus does not shadow indirect_call resolution, fabricating cross-package edges

2 participants