Repository navigation
fix(extract): keep unresolved import() targets out of the incremental prune (#4161 for extract) - #5545
Closed
poberherr wants to merge 2 commits into
Closed
fix(extract): keep unresolved import() targets out of the incremental prune (#4161 for extract)#5545poberherr wants to merge 2 commits into
import() targets out of the incremental prune (#4161 for extract)#5545poberherr wants to merge 2 commits into
Conversation
… 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]>
|
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. |
There was a problem hiding this comment.
Graphify review 
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
- A non-list nodes value in graph.json crashes the prune step instead of being skipped ·
graphify/cli.py:656 - Placeholders referenced from a re-extracted document can survive after that document drops the link ·
graphify/cli.py:668 - The corrupt-graph test assumes graph.json has a
linkskey, so it raises KeyError when the graph usesedgesinstead ·tests/test_extract_incremental_dynamic_import_stubs.py:151 - +4 more in Graphify
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
Member
|
Shipped in v0.9.123, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @poberherr! |
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #5544. Refs #4160, #4161.
_stale_graph_sourcesreads an unresolvedimport()specifier as a deletedfile, so an incremental
extractpruned the placeholder node and thereferrer's
dynamic_importedge. A new helper,_placeholder_stale_sources,removes such paths from
graph_stale_sourcesafter the AST pass, before bothprune sites (
build_merge,--no-cluster). It applies the #4161 rules: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_filevalues are skipped, as in_stale_graph_sources.It shares no code with
watch._referenced_unscanned_identities, which works on_StoredSourcePathsidentities inside watch's eviction loop; sharing onepredicate would need a separate refactor of that loop.
Type of change
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
extractwith 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):
still imports it (e.g.
dyn.tskeepsimport('./queue.js'),queue.jsisdeleted and
dyn.tsedited);.csprojthat a.slnstill references (thecontainsedge and theproject placeholder go).
The helper treats both as really deleted files; this PR does not change that.
Tests,
tests/test_extract_incremental_dynamic_import_stubs.py: carried andre-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-referrertests pass there and guard the other direction).
Limitations: not run on Windows. On v8 a non-string
source_fileingraph.json already makes incremental
extractraise inbuild_merge; notchanged here.
How was this tested?
On the branch merged into
v8at 0f22ae7, macOS, Python 3.11:The same 33 tests fail here with
cli.pyfrom v8 (11655 passed without the new test file), so none comes from thischange. I did not look into why they fail on this machine;
tests/test_serve_reload_off_loop.pyis ignored becauseit needs
anyio, which is not installed here.Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (No fragment touched.)🤖 Generated with Claude Code