Repository navigation
fix(watch): re-extract unchanged importers of an added or deleted file - #5635
0xkaushik-ai wants to merge 1 commit into
Conversation
An incremental rebuild re-resolves only the files it re-extracts, and an unchanged importer keeps the edges it was given when it was last extracted. Two shapes left the graph different from a full build of the same tree: * Deleting a file an unchanged file imports: the importer's edges into the deleted file's nodes dangled and were dropped. A full build gives it an unresolved-import placeholder (`a`, `ref_m`, `go_pkg_ex_p`) and the edge to it. * Adding a file an unchanged file already imports: the importer stayed on the placeholder a full build no longer mints, and never gained the imports and calls edges into the new file. Seen for Python, TypeScript and Go. Re-extract such importers together with the change, next to the existing id-collision partners. For a deletion they are the files with an AST edge into a node of the deleted file. For an addition they are the files with an AST edge into a sourceless placeholder whose id carries the new file's stem or a parent directory name as whole tokens. Placeholders do not record whether they stand for an external package or a missing project file, so the name match over-approximates: it can re-extract a few extra files, never draw a wrong edge. The two partner passes move into one helper so _rebuild_code stays within pyright's analysis limit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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. |
There was a problem hiding this comment.
Graphify review 
3 possible issues to check · High impact
The update path now widens incremental extraction to include unchanged importers that point to deleted-file nodes or matching unresolved-import placeholders.
3 possible issues we couldn't confirm
- Stored nodes with a source file outside the project are treated as sourceless placeholders when pulling in importers of an added file ·
graphify/watch.py:394 - Parent directory names of an added file match very generic placeholder ids, pulling many unchanged importers into each incremental run ·
graphify/watch.py:402 - Bounded-widening test checks a private helper's return value, not that the unrelated importer was left alone ·
tests/test_incremental_import_referrers.py:152
They don't change the score.
What this review covered
- Some lookups asked for files or lines that do not exist; the review was told and carried on.
- 2 of 2 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 849 functions depend on this change
- 55 of 659 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 5dd7117
|
Thanks for this. The deleted-file-importer half here overlaps #5638, which we landed in 0.9.124 — that one covers the same cases plus transitive barrel/template re-extraction and fixes both the |
Fixes #5631. Fixes #5633.
An incremental rebuild re-resolves only the files it re-extracts, and an unchanged importer keeps the edges it got last time. So:
a,ref_m,go_pkg_ex_p), with noimports/callsedges to the new file ([Bug]: incremental update leaves an unchanged importer on the unresolved-import placeholder after the imported file is added #5631);Change (
graphify/watch.py)Such importers are now re-extracted with the change, next to the existing id-collision partners:
_import_referrer_partners:_tokens._with_incremental_partnersruns_id_collision_partnersand then this pass._rebuild_codecalls the helper, which keeps it within pyright's analysis limit (pyright output onwatch.pyis unchanged vs v8).Placeholders don't say whether they stand for an external package or a missing project file, so the name match over-approximates: at worst a few extra files are re-extracted (mostly from the AST cache), never a wrong edge. Deleting a widely imported file re-extracts all its importers, which a full-build-equivalent result needs.
Invariant: an incremental update gives the same nodes and edges as a full build of the same tree.
Tests
tests/test_incremental_import_referrers.pycompares an update with a full build for add and delete in Python, TypeScript and Go, plus a TS re-export delete, and checks that an unrelated added file re-extracts nothing extra.-n auto(test_css_extractor::test_megabyte_of_css_is_fast,test_graph_context_cache_reload::test_concurrent_first_load_of_new_path_builds_once,test_watch::test_watch_handler_honors_graphifyignore) and pass when run alone.ruff checkclean.Not covered: an existing file gaining a symbol an unchanged importer already asks for by name (
from a import fwhilea.pyhas nof, thenfis added). That needs the importers of every edited file re-resolved, which is the expensive path, so it is left for a separate change.Overlap: #5634 (fixes #5630) touches different files. #5636 (fixes #5632) also wraps the
_id_collision_partnerscall in_rebuild_code, so whichever lands second needs a small rebase: one wrapper calling both passes. I've checked that combination locally: all three branches merged give 12477 passed, 0 failed.🤖 Generated with Claude Code