Skip to content

fix(js): shadow a file-scope callback's own params (#4448) - #4457

Closed
bercedev wants to merge 1 commit into
Graphify-Labs:v8from
bercedev:fix/js-file-scope-callback-params
Closed

bercedev wants to merge 1 commit into
Graphify-Labs:v8from
bercedev:fix/js-file-scope-callback-params

Conversation

@bercedev

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4448.

A closure passed in a module-level call statement (items.forEach(function (value) { ... }), the AngularJS .controller('X', function ($scope) { ... }) shape, a test's it('...', () => { ... })) is walked under the file node since #3124. That walk never got the closure's own parameters and locals. So a parameter passed on as a call argument was looked up in the corpus-wide label index, and a.js got an indirect_call to any function with the same name, even a module-private one in another package.

Inside a named function this was already right (#2241, #2568). The fix records the closure's bindings in closure_locals_by_body at the #3124 site, the same three lines the #2568 branch uses for const-assigned closures. walk_calls then gets them as extra_locals for that body only.

// a.js
items.forEach(function (value) { s.on(value); });
// b.js
function value(x) { return x; }

Before: a.js --indirect_call [argument]--> value(). After: no edge.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: the only edges that go away are indirect_call edges whose argument is a binding of the anonymous closure it sits in.

I compared extract() output from v8 and this branch on three private JS/TS codebases I work on (563 files, React/Vite frontends and Node backends):

nodes added or removed:              0
edges removed in application code:  2
edges added in application code:    0

Both removed edges come from one test file (checked out twice in that repo):

it("...", async () => {
  interceptStats((config) => jsonResponse(config, STATS));
});

config here is the arrow's own parameter, and the old edge pointed at an unrelated config function in a vendored bundle. That inner arrow is also an expression statement, so the #3124 branch tracks it on its own and the closure-descend path in walk_calls never adds its params. This fix covers that case too.

One of the codebases has Playwright's minified bundles inside a checked-in virtualenv. There the branch removes 29 more indirect_call edges of the same kind (single-letter callback params pointing at single-letter functions in other bundles). One of those pairs now shows up once as a collection edge instead of an argument edge.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Limitations:

How was this tested?

tests/test_indirect_call_file_scope_callback_shadow.py covers the issue's table: member and bare calls, a nested file-scope callback, arrows with and without parentheses, a var local. It also covers two cases that must still resolve: an unbound name inside the callback, and a sibling closure in the same call whose own param does not shadow. One more test is the describe / it / inner-arrow shape from the codebase above.

uv run --frozen pytest tests/test_indirect_call_file_scope_callback_shadow.py -q
8 passed            (on v8: 6 failed, 2 passed)

uv run --frozen pytest -q
7778 passed, 184 skipped

I also ran the issue's AngularJS + TypeScript repro (legacy/controller.js and app/src/transport.ts): no indirect_call on this branch.

Linux, Python from the repo's uv.lock.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

Note: I used Claude Code while working on this fix. I reviewed and ran all of it myself.

A closure passed in a module-level call statement is walked under the
file node (Graphify-Labs#3124), but its params and locals were never registered for
that walk. A parameter passed on as a call argument then resolved against
the corpus-wide label index and produced an indirect_call to any function
with the same name, including module-private ones in other packages.

Record the closure's bindings in closure_locals_by_body, the same way the
Graphify-Labs#2568 branch already does for const-assigned closures.
@bercedev
bercedev requested a review from safishamsi as a code owner October 14, 2026 14:55
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @bercedev. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 14, 2026

@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.

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).

Not verified on this run: \_js\_extra\_walk (vacuous: never exercised).


Graphify review — findings

Fixes file-scope anonymous callbacks (items.forEach(function (value) { s.on(value) }), .controller(...), it(...)) leaking their own params and locals into corpus-wide call resolution. The #3124 branch of _js_extra_walk now records each closure's bound names as that body's extra locals, so a parameter like value no longer becomes an indirect_call to an unrelated same-named function. Names that the callback doesn't bind, including a sibling callback's param, still resolve as before, and a new test file covers member, bare, arrow, nested, and describe/it cases.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 921 functions depend on the 342 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • _extract_generic() — 20 callers, 41 callees (high)
  • extract_js() — 91 callers, 7 callees (high)
  • extract_objc() — 25 callers, 13 callees (high)
  • extract_xaml() — 19 callers, 17 callees (high)
  • extract_php() — 38 callers, 5 callees (high)
  • extract_cpp() — 37 callers, 5 callees (high)
  • extract_julia() — 22 callers, 8 callees (high)
  • extract_svelte() — 14 callers, 8 callees (high)
  • …and 2 more

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

Test selection

Test selection

37 of 419 test file(s) selected (9%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_call_file_scope_callback_shadow.py — impact, changed-test
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact
  • tests/test_php_unparsed_casts.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_context_bounds.py — impact
  • tests/test_scala_given_instances.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_scala_top_level_binding.py — impact
  • tests/test_scala_type_definition.py — impact
  • tests/test_svelte_extraction.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_vue_extraction.py — impact

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Formal verification

Could not verify: Could not verify \_js\_extra\_walk.

The verifier did not have enough to check \_js\_extra\_walk, 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: no capturable inputs from the test suite; property tier: not verifiable: all 264 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

safishamsi added a commit that referenced this pull request Oct 14, 2026
Eight community PRs: Windows MCP-stdio hang (#4441), Rust use->declaration
(#4443), JS/TS file-scope callback param shadowing (#4457), sibling-file-id
symbol retention (#4452), TS class-field receiver scoping (#4297), Ollama
/api/chat num_ctx (#4414), cluster label retention on majority overlap (#4451),
and an ingest symlink test fix (#4442). AST cache schema bumped to 16.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in 0.9.91 as 1af5104 (cherry-picked with your authorship preserved, so it shows on your contributions). Thanks @bercedev! Released to PyPI: https://pypi.org/project/graphifyy/0.9.91/

@safishamsi safishamsi closed this Oct 14, 2026
@bercedev
bercedev deleted the fix/js-file-scope-callback-params branch October 14, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

2 participants