Skip to content

fix(extract): keep an importer's include on the salted id of an out-of-batch file - #5634

Closed
0xkaushik-ai wants to merge 1 commit into
Graphify-Labs:v8from
0xkaushik-ai:fix/incremental-import-salted-target
Closed

0xkaushik-ai wants to merge 1 commit into
Graphify-Labs:v8from
0xkaushik-ai:fix/incremental-import-salted-target

Conversation

@0xkaushik-ai

Copy link
Copy Markdown
Contributor

Fixes #5630.

When an update re-extracts only a file that imports one half of a same-stem pair (foo.c/foo.h, w.cpp/w.hpp, index.ts/index.js), neither colliding file is in the batch. _disambiguate_colliding_node_ids finds no collision, takes its early exit, drops the importer's target_file stamp and leaves the import on the bare id. The update then mints a sourceless node (foo) a full build never has and loses the edge to the real file.

Change

  • graphify/extract.py: pass resolution_context_nodes into _disambiguate_colliding_node_ids.
  • graphify/extractors/resolution.py: new _retarget_imports_to_context_file_nodes, run first. A file-level import edge (imports, imports_from, re_exports, references) whose stamped target file is not in the batch, and has exactly one persisted file node, takes that node's id. Symbol imports carry the same stamp but don't target the bare file id, so they are left alone.

Invariant: an incremental update gives the same nodes and edges as a full build of the same tree.

Tests

tests/test_incremental_import_salted_target.py runs graphify update and graphify extract on C, C++ and TS trees, touches only the importer, and compares with a full build.

  • On v8 all 6 cases fail (only in update: ['foo'], ['w'], ['src_index']).
  • With the fix all 6 pass.
  • Full suite: 12464 passed. One failure, test_hooks_rewrite.py::test_revert_range_rebuilds_once_and_removes_the_functions, under -n auto; it passes alone and on reruns, on this branch and on v8.
  • ruff check clean; pyright on resolution.py reports the same 32 errors as v8, none in the new code.

Found with a differential check that compares incremental rebuilds against full builds. The other cases it turned up are filed as #5631, #5632 and #5633, and fixes for those will follow as separate PRs.

🤖 Generated with Claude Code

…f-batch file

foo.c and foo.h both yield the file id `foo`, so a full build salts them to
foo_c_foo and foo_h_foo and points main.c's `#include "foo.h"` at foo_h_foo.
An update that re-extracted only main.c had neither colliding file in its
batch: _disambiguate_colliding_node_ids found no collision, dropped the
importer's target_file stamp and left the include on the bare `foo`. The
graph gained a sourceless `foo` node a full build never has and lost the edge
to the real header. The same happened to `import ... from './index'` next to
index.ts/index.js, and to C++ (w.cpp/w.hpp).

Hand the read-only resolution context nodes to the disambiguation. A
file-level import edge whose stamped target file is not in the batch, and
has exactly one persisted file node, takes that node's id. Symbol imports
carry the same stamp but do not target the bare file id, so they are left
alone.

The regression test runs `graphify update` and `graphify extract` on C, C++
and TS trees, touches only the importer, and compares with a full build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @0xkaushik-ai. 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.11 and 3.13, and that the change keeps extraction deterministic.

@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 review View in Graphify

Nothing blocking · 5 possible issues to check · Merge confidence 5/5

5 possible issues to check · High impact

The incremental CLI passes persisted nodes from unchanged files into extraction.

5 possible issues we couldn't confirm

They don't change the score.

Code graph · 5774 functions depend on this change
  • 1 function became more coupled. _disambiguate_colliding_node_ids() (4 callers).
  • 393 of 659 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed a1bad4d

safishamsi added a commit that referenced this pull request Nov 30, 2026
Extractor accuracy (Swift #5641, Apex #5627, Python #5647, TypeScript
#5604/#5614/#5612, Bash caller-var #5602), GitHub Actions run-step
extraction (#5603), incremental correctness (#5634/#5638/#5636), symlink
and semantic-cache fixes (#5617/#5618), export/report hardening and perf
(#5643/#5644/#5645/#5646/#5619/#5620/#5621), and CLI/docs/skill/install
work (#5629/#5628/#5626/#5624/#5623/#5625/#5642/#5583). AST cache schema
59 to 60; Swift/Apex/Python/Bash/GHA inputs re-extract on first build.

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

Copy link
Copy Markdown
Member

Landed in v0.9.124 (just released to PyPI), cherry-picked with your authorship preserved so it shows under your name in the history. Thanks @0xkaushik-ai for keeping an importer's include on the salted id of an out-of-batch file — verified green in the full suite and, where applicable, smoke-tested against the published package. 🙏

@safishamsi safishamsi closed this Nov 30, 2026
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

Development

Successfully merging this pull request may close these issues.

[Bug]: updating only an importer points its include at a phantom bare-stem node when the target has a same-stem sibling

2 participants