Skip to content

fix: preserve cross-file edges during incremental updates - #3812

Closed
hopstreax wants to merge 2 commits into
Graphify-Labs:v8from
hopstreax:fix/3776-incremental-cross-file-edges
Closed

hopstreax wants to merge 2 commits into
Graphify-Labs:v8from
hopstreax:fix/3776-incremental-cross-file-edges

Conversation

@hopstreax

Copy link
Copy Markdown
Contributor

Summary

Fixes #3776

Fixes the loss of cross-file imports and calls edges when re-extracting files during incremental updates.

Previously, symbol resolution only indexed freshly extracted nodes. When a changed file imported or called a symbol defined in an unchanged file, the target symbol was unavailable during resolution and the edge was silently skipped.

Changes

  • Pass resolution_context_nodes into the symbol-resolution pipeline.
  • Include unchanged-file symbols when building the resolution index.
  • Ensure freshly extracted nodes take precedence over resolution-context nodes.
  • Preserve existing incremental edge reconciliation and removed-import pruning behavior.
  • Add a regression test covering cross-file imports and calls to an unchanged file.

Validation

  • pytest tests/test_incremental.py — 11 passed
  • pytest tests/test_symbol_resolution.py tests/test_python_import_resolution.py tests/test_forwarding_review_findings.py tests/test_imported_export_forwarding.py — 66 passed
  • pytest tests/test_js_import_resolution.py — 71 passed
  • pytest -k "incremental or resolution" tests/test_watch.py — 36 passed, 1 skipped
  • git diff --check — clean

Scope

This PR addresses the symbol-resolution issue causing imports and calls to disappear during incremental updates.

The separate non-relative imports_from target-canonicalization issue is not included in this change.

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

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.


Graphify review — findings

Fixes cross-file import and call resolution during incremental updates (#3776): _apply_symbol_resolution_facts and _augment_symbol_resolution_edges now accept resolution_context_nodes and seed the symbol table with definitions from unchanged files, so a symbol defined in a file that wasn't re-extracted still resolves rather than being dropped. Context-node labels beginning with . are treated as members and won't shadow same-named top-level symbols, and nodes whose id or source path is already present in the fresh set are skipped. Adds an incremental test asserting the imports and calls edges from a.py to an untouched b.py survive a --code-only rebuild.

Worth a look

  • extract() call to _augment_symbol_resolution_edges has malformed/broken syntax — graphify/extract.py:7485 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Malformed _augment_symbol_resolution_edges definition makes resolution.py uncompilable — graphify/extractors/resolution.py:2520 · Escalate · high
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 2398 functions depend on the 429 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _rebuild_code() — 144 callers, 55 callees
  • new: _extract_generic() — 18 callers, 29 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: _resolve_js_module_path() — 34 callers, 9 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: extract_objc() — 27 callers, 9 callees
  • …and 49 more — each is listed as a finding

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

Test selection

Test selection

131 of 300 test file(s) selected (44%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_file_node_id_spec.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_builtin_call_targets.py — impact
  • tests/test_go_import_repoint.py — impact
  • tests/test_go_interface_methods.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_import_self_loops.py — impact
  • tests/test_imported_export_forwarding.py — impact
  • tests/test_incremental.py — impact, changed-test
  • tests/test_indirect_call_arrow_single_param_shadow.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_call_catch_binding_shadow.py — impact
  • tests/test_indirect_call_external_import_shadow.py — impact
  • tests/test_indirect_call_for_of_binding_shadow.py — impact
  • tests/test_indirect_call_function_expression_shadow.py — impact
  • tests/test_indirect_call_nested_closure_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • … and 81 more

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.

· 57 more finding(s) on lines outside this diff (see the check run).

@Abhirup0 Abhirup0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the merge from v8 (8b4f059) had some conflict resolution slip-ups that are breaking test collection in CI:

  1. In graphify/extractors/resolution.py:2515, there's a leftover signature chunk inside _augment_symbol_resolution_edges:
    else:
        _apply_symbol_resolution_facts(paths, nodes, edges, root, facts)
    ambiguous_python_modules: set[str] | None = None,
) -> None:
    facts = _SymbolResolutionFacts()

Also make sure ambiguous_python_modules stays in the parameters and gets forwarded to _collect_python_symbol_resolution_facts so the recent v8 import fix doesn't regress.

  1. In graphify/extract.py:7482, _augment_symbol_resolution_edges is missing a closing paren and got duplicated before _suppress_ambiguous_python_imports. We should keep just the one call after suppression:
_augment_symbol_resolution_edges(
    paths, all_nodes, all_edges, root,
    ambiguous_python_modules=ambiguous_python_modules,
    resolution_context_nodes=resolution_context_nodes,
)
  1. In tests/test_incremental.py, should step 2 use update directly (_run(["update", str(proj)], tmp_path)) rather than extract? That would match the exact reproduction path from #3776.

safishamsi added a commit that referenced this pull request Sep 25, 2026
Complete the skillgen --watch INPUT_PATH injection fix in the add-watch
reference (#3742), preserve cross-file edges on incremental update
(#3812), stop C# type references resolving to same-named non-type nodes
(#3815), prefer a real source location over richness in dedup (#3786),
and resolve Maven inherited groupId + ${...} properties in pom.xml
(#3823).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.68 (now on PyPI). Thanks @hopstreax (and @himanshupatro-334, preserved as commit author)!

The design was right; the pushed diff had drifted against v8 (the _augment_symbol_resolution_edges signature and the extract.py call site). I re-based it so resolution_context_nodes is threaded alongside ambiguous_python_modules (keeping _suppress_ambiguous_python_imports), and added a negative regression test (edit a file to drop its import while the target file is unchanged → the edge must not be resurrected via the context index). Full incremental + resolution suites green on 3.10 and 3.13.

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.68

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.

Incremental --update silently loses cross-file edges; --force does not repair it, only deleting graphify-out does

3 participants