Skip to content

fix(extract): keep unresolved import() targets out of the incremental prune (#4161 for extract) - #5545

Closed
poberherr wants to merge 2 commits into
Graphify-Labs:v8from
poberherr:fix/extract-keeps-dynamic-import-stubs
Closed

poberherr wants to merge 2 commits into
Graphify-Labs:v8from
poberherr:fix/extract-keeps-dynamic-import-stubs

Conversation

@poberherr

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5544. Refs #4160, #4161.

_stale_graph_sources reads an unresolved import() specifier as a deleted
file, so an incremental extract pruned the placeholder node and the
referrer's dynamic_import edge. A new helper, _placeholder_stale_sources,
removes such paths from graph_stale_sources after the AST pass, before both
prune sites (build_merge, --no-cluster). It applies the #4161 rules:

  • a stale path that produced located nodes or any edge was a real file: pruned;
  • otherwise it stays when this run emitted it again;
  • or when manifest.json never listed it and an edge from a file that is neither
    stale nor re-extracted points at it (only with a manifest that lists a
    current source).

Paths compare root-relative and NFC-normalized (graphify.paths.nfc);
non-string source_file values are skipped, as in _stale_graph_sources.

It shares no code with watch._referenced_unscanned_identities, which works on
_StoredSourcePaths identities inside watch's eviction loop; sharing one
predicate would need a separate refactor of that loop.

Type of change

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

Verification & Invariants

Invariant: a placeholder for a target that was never scanned (manifest.json
never listed it), minted by a live referrer, survives an incremental extract
with its edge; a placeholder whose referrer is gone, and a really deleted file,
are pruned. Nothing more is claimed. A cold extract does not reach the helper.

Not covered, and also wrong on v8 (cold keeps a placeholder that the incremental
run prunes):

  • a target that was a real scanned file and is deleted while a live referrer
    still imports it (e.g. dyn.ts keeps import('./queue.js'), queue.js is
    deleted and dyn.ts edited);
  • a deleted .csproj that a .sln still references (the contains edge and the
    project placeholder go).

The helper treats both as really deleted files; this PR does not change that.

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

Tests, tests/test_extract_incremental_dynamic_import_stubs.py: carried and
re-extracted referrer; deleted scanned file; deleted referrer and dropped
import (placeholder goes); missing manifest; --no-cluster; NFD file names;
corrupt source_file. 7 of 9 fail on v8 (the two removed-referrer
tests pass there and guard the other direction).

Limitations: not run on Windows. On v8 a non-string source_file in
graph.json already makes incremental extract raise in build_merge; not
changed here.

How was this tested?

On the branch merged into v8 at 0f22ae7, macOS, Python 3.11:

uv run --frozen pytest tests/test_extract_incremental_dynamic_import_stubs.py tests/test_incremental_unscanned_placeholders.py -q    # 14 passed (7 fail with cli.py from v8)
uv run --frozen pytest tests/ -q --tb=line --ignore=tests/test_serve_reload_off_loop.py    # 33 failed, 11664 passed, 391 skipped, 1 xfailed
uv run --frozen ruff check .    # All checks passed!
uv run --frozen pyright graphify/cli.py    # 1 error, the same one as on v8
uv run --frozen python -m tools.skillgen --check    # OK

The same 33 tests fail here with cli.py from v8 (11655 passed without the new test file), so none comes from this
change. I did not look into why they fail on this machine; tests/test_serve_reload_off_loop.py is ignored because
it needs anyio, which is not installed here.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No fragment touched.)
  • 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.

🤖 Generated with Claude Code

poberherr and others added 2 commits November 22, 2026 10:52
… prune

An unresolved dynamic import (`import('left-pad')`) gives a node whose
source_file is the specifier. Graphify-Labs#4161 stopped `graphify update` from evicting
such nodes; the incremental `graphify extract` path has its own sweep,
_stale_graph_sources, which read the specifier as a deleted file, and the
prune removed the node and the referrer's dynamic_import edge that a full
extract keeps. It did so whether the referrer was carried or re-extracted.

Filter those placeholders out of the stale sources with the Graphify-Labs#4161 evidence
rules: a path that produced located nodes or edges is a real file and is
pruned; otherwise it stays when this run emitted it again, or when the
manifest never listed it and an unchanged, live file still points at it.

Refs Graphify-Labs#4160, Graphify-Labs#4161.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tring sources

Review of the previous commit. On macOS the scan reports NFD names while
manifest.json keys are NFC, so the "manifest lists a current source" check
failed for an accented tree and a carried referrer's import() placeholder was
pruned again. Normalize every compared path with graphify.paths.nfc, as
_stale_graph_sources does (Graphify-Labs#2210).

A node or edge in graph.json with a non-string source_file raised TypeError in
the helper; skip it as _stale_graph_sources does. The helper also gets shorter.

Tests: NFD file names, a corrupt source_file, a deleted referrer and a referrer
that drops the import (the placeholder goes), a missing manifest, --no-cluster.

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 27, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @poberherr. 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 · 7 possible issues to check · Merge confidence 5/5

7 possible issues to check · High impact

graphify extract now filters unresolved-import placeholders out of its stale-source prune list.

7 possible issues we couldn't confirm

They don't change the score.

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

Reviewed dec10fd

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.123, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @poberherr!

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 graphify extract prunes the node of an unresolved import() target and its dynamic_import edge (#4160 on the extract path)

2 participants