Skip to content

fix(watch): re-extract unchanged importers waiting on an added file - #5651

Open
0xkaushik-ai wants to merge 2 commits into
Graphify-Labs:v8from
0xkaushik-ai:fix/incremental-added-import-target-v2
Open

0xkaushik-ai wants to merge 2 commits into
Graphify-Labs:v8from
0xkaushik-ai:fix/incremental-added-import-target-v2

Conversation

@0xkaushik-ai

@0xkaushik-ai 0xkaushik-ai commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5631. Resubmits the add-a-file half of #5635, tightened as asked in #5635 (comment) (the deleted-file half landed via #5638).

An importer extracted before the file it imports existed holds an unresolved-import placeholder (a, ref_m, pkg_sub_a, go_pkg_ex_p). When the file is then added, an incremental run re-extracted only the new file, so the importer kept the placeholder a full build no longer mints and never gained the imports / calls edges into the new file.

Fix: graphify/watch.py, _added_import_partners, chained into _incremental_partners, so it runs on both incremental paths: _rebuild_code (update / hook / watch) and the graphify extract incremental block in cli.py.

Matching (the tightening): a placeholder names the import, so its id ends with the module the import resolves to. A placeholder is followed only when its id equals, or ends with _ + one of:

  • the added file's stem (a.py → a, ref_m, pkg_sub_a), with the .d of a TypeScript declaration file dropped (api.d.ts → ref_api);
  • its directory, only for a directory module: an index / __init__ / mod file, or any Go file, since Go imports a package directory (p/p.go → go_pkg_ex_p).

A directory name anywhere else in an id no longer matches: adding src/zeta.py or lib/zeta.py widens nothing, where the old matcher took every parent-directory component as a key. A same-named external package can still widen the run (placeholders don't record which they are), which costs a re-extraction, never a wrong edge.

Tests: tests/test_incremental_added_import_target.py

  • End to end, update and extract × Python, TypeScript, TypeScript directory import (./lib → lib/index.ts), TypeScript declaration files (api.d.ts, types/index.d.ts) and Go: each incremental graph is compared with a full build. On v8 all 12 fail; with the fix all pass (20 tests in the file).
  • The matcher on a stored graph: an added src/zeta.py, lib/zeta.py, src/lib/zeta.py or other/lib.py widens nothing; lib/helpers.py, src/core.py, tools/util.py and src/core/__init__.py widen only the importer whose placeholder ends with that name.
  • Full suite: 12653 passed, 0 failed. ruff check clean.

Not covered: a Python package import (from pkg.mod import f → added pkg/mod/__init__.py). The importer is now picked for re-extraction, but its AST cache entry is keyed on its own unchanged content, so the cached result with the placeholder comes back. That is the extraction cache, not the widening, so I've left it out of this PR.

🤖 Generated with Claude Code

An importer extracted before the file it imports existed holds an
unresolved-import placeholder. Adding the file re-extracted only the new file,
so the importer kept the placeholder and never gained the import/call edges a
full build draws. _added_import_partners follows the importers of a
placeholder whose id ends with the added file's stem, or its directory for a
directory module (index/__init__/mod, or any Go file); a directory name
elsewhere in an id matches nothing. Chained into _incremental_partners, so both
update and the extract incremental block use it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 30, 2026
@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

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

The incremental watcher now identifies unchanged importers whose unresolved-import placeholders may match a newly added file and includes them in the re-extraction set.

Code graph · 855 functions depend on this change
  • 1 function became more coupled. _incremental_partners() (3 callers).
  • 56 of 666 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed d1afbdb · 1 of 1 earlier findings resolved

Comment thread graphify/watch.py Resolved
`./api` resolves to an added `api.d.ts`, but the matcher took its stem as
`api.d`, so the `ref_api` placeholder never matched and the importer kept it.
Drop the `.d` of a .d.ts/.d.mts/.d.cts stem (so `types/index.d.ts` is a
directory module too).

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

This branch has not been deployed

No deployments
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]: incremental update leaves an unchanged importer on the unresolved-import placeholder after the imported file is added

1 participant