Skip to content

[Bug]: incremental graphify extract prunes the node of an unresolved import() target and its dynamic_import edge (#4160 on the extract path) #5544

Done

Description

@poberherr

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

An unresolved dynamic import (import('left-pad')) gives a node whose
source_file is the specifier. #4161 stopped graphify update from evicting
such nodes. The incremental graphify extract path has its own sweep,
_stale_graph_sources, which reads the specifier as a deleted file, and the
prune removes the node and the referrer's dynamic_import edge. A full extract
of the same tree keeps both. It happens whether the referrer is carried over or
re-extracted, because the prune runs on the merged graph.

Expected: the placeholder and its edge survive while a live referrer still
imports it, as in a full extract and in update.

Steps to reproduce

V=$(mktemp -d) && uv venv -q -p 3.11 "$V" && uv pip install -q -p "$V" graphifyy==0.9.121
G="$V/bin/graphify"
W=$(mktemp -d) && cd "$W"
printf 'export function foo() { return 1 }\n' > a.ts
printf "export async function load() { return await import('left-pad'); }\n" > dyn.ts
$G extract . --code-only > /dev/null

# change a.ts only; dyn.ts is carried over
sed -i.bak 's/return 1/return 2/' a.ts && rm a.ts.bak
$G extract . --code-only | grep -E 'Pruned|incremental summary'

C=$(mktemp -d) && cp a.ts dyn.ts "$C" && (cd "$C" && $G extract . --code-only > /dev/null)

"$V/bin/python" - "$C/graphify-out/graph.json" "$W/graphify-out/graph.json" <<'EOF'
import json, sys
for label, path in zip(("cold", "warm"), sys.argv[1:]):
    g = json.load(open(path))
    print(label, "left_pad node:", any(n["id"] == "left_pad" for n in g["nodes"]),
          "| dynamic_import edges:", [(l["source"], l["target"]) for l in g["links"]
                                      if l["relation"] == "dynamic_import"])
EOF

Error output or graph output

[graphify] Replaced 2 node(s) from re-extracted source file(s).
[graphify] Pruned 1 node(s) from 1 deleted or excluded source file(s).
[graphify extract] incremental summary: 1 files cached/unchanged, 1 re-extracted, 0 deleted
cold left_pad node: True | dynamic_import edges: [('dyn', 'left_pad')]
warm left_pad node: False | dynamic_import edges: []

Editing dyn.ts instead of a.ts gives the same result. graphify update . in
place of the second extract keeps the node.

Root cause (at 0f22ae7)

_stale_graph_sources
(cli.py#L604-L788)
lists every in-root source_file that is neither scanned nor on disk;
left-pad is both. The list reaches build_merge as prune_sources. The #4161
guard (watch._referenced_unscanned_identities,
watch.py#L1132-L1204)
exists only on the watch path.

Graphify version

0.9.121 (v8 at 0f22ae7)

Operating System

macOS 26

Python Version

3.11.18

Installation Method

pip (uv pip, fresh venv)

Additional Environment Details

No provider environment variables (--code-only). Also reproduced in a clean v8
checkout.

Additional context

I have a fix with regression tests (the #4161 evidence rules on the extract
path) and can open a PR.

Activity

  1. github-actions commented on Nov 27, 2026

    @github-actions

    Thanks for opening this issue, @poberherr. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. poberherr commented on Dec 1, 2026

    @poberherr
    ContributorAuthor

    Fixed by #5545, shipped in v0.9.123. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions