--update leaves stale graph nodes when files leave scan scope
Summary
The --update skill flow can leave stale graph nodes behind when a file
remains on disk but leaves the active scan scope, for example after being
added to .graphifyignore.
detect_incremental() correctly classifies the file as excluded_files,
but the skill update flow only passes deleted_files to build_merge().
At the end of the update, save_manifest(..., scan_corpus=...) removes the
excluded file from the manifest. This leaves the graph and manifest
inconsistent, and on subsequent runs the stale graph nodes are no longer
detectable through incremental manifest-based detection.
Reproduction
- Build a graph containing a file
A.py. - Confirm that
A.pyis present in both the graph and manifest. - Add
A.pyto.graphifyignorewhile leaving the file on disk. - Run the
--updateskill flow.
Observed:
deleted_files = []
excluded_files = [A.py]
The current skill flow passes only deleted_files to build_merge():
prune = list(deleted) or None
G = build_merge(
[new_extraction],
...,
prune_sources=prune,
)
As a result, A.py's existing graph nodes remain.
The subsequent manifest save uses the current scan scope and removes
A.py from the manifest.
After the first update:
graph.json:
A.py nodes still present
manifest.json:
A.py absent
Run --update again without changing anything else.
The second run reports:
deleted_files = []
excluded_files = []
because A.py is no longer present in the manifest.
The stale A.py graph nodes therefore remain indefinitely.
Expected behavior
When a previously indexed file leaves the scan scope, its graph contribution should be removed during the same incremental update that removes it from the manifest.
The expected transition is:
included file
↓
file becomes excluded
↓
excluded_files = [A.py]
↓
prune A.py from graph
↓
remove A.py from manifest
↓
clean steady state
If the file is later brought back into the scan scope, it should be treated as a new file and indexed again.
CLI comparison
The CLI incremental path already includes both deleted_files and
excluded_files when constructing prune_sources:
_prune_sources = list(deleted_files)
for _src in list(excluded_files) + graph_stale_sources:
if _src not in _prune_sources:
_prune_sources.append(_src)
Running the same scenario through the CLI correctly removes the graph
nodes for A.py while also removing its manifest entry.
The skill --update flow does not currently mirror this behavior.
Root cause
excluded_files was introduced to distinguish files that are still alive
on disk but have left the scan scope from files that have actually been
deleted.
The manifest handling was subsequently updated to remove excluded files
from the manifest, but the skill --update merge step continued to pass
only deleted_files to build_merge().
This creates an inconsistent transition:
graph:
A.py still present
manifest:
A.py removed
Once the manifest entry is removed, subsequent incremental runs have no manifest record from which to discover the stale graph contribution.
Evidence
Reproduced on current v8 with a minimal corpus containing:
def hello():
return "world"
Initial state:
A.pyexists on diskA.pyis present in the manifestA.pycontributes 2 nodes to the graph
After adding A.py to .graphifyignore and running the skill update:
deleted_files = []excluded_files = [A.py]- graph still contains 2 nodes sourced from
A.py - manifest no longer contains
A.py
After a second unchanged update:
deleted_files = []excluded_files = []- graph still contains the 2
A.pynodes - manifest remains empty
The equivalent CLI flow prunes the nodes correctly.
Related
This was discovered while investigating #2870.
The original #2870 condition — incorrectly treating live files that leave
the scan scope as deleted_files — is already handled by the current
detect_incremental() implementation.
This issue concerns the downstream handling of those correctly identified
excluded_files in the skill --update flow.
+1
Data point from graphify 0.9.69 (macOS, Claude Code skill flow).
- A full build ran, then a directory of PR screenshots was added to
.graphifyignorethe next day. - A later skill
--update(578 changed files) left 347 nodes and ~15 hyperedges whosesource_filesits under the ignored directory. The manifest had already dropped those files, so later updates could not see them — exactly the inconsistency described above. - The stale nodes were not harmless: 3 of the 7 "suggested questions" in
GRAPH_REPORT.mdcame from AMBIGUOUS edges between those ignored images. - Only a full rebuild with
--forceremoved them (the semantic cache made that cheap, but nothing in the update output hinted it was needed).
The CLI graphify update got the #2495 fix in 0.9.35, but the skill's references/update.md still passes only deleted_files to build_merge(prune_sources=...). Passing deleted_files + excluded_files there looks like it would close this.
Still reproduces on 0.9.89 (released today, v8 at e8eb76e7), Linux, Python 3.13, uv tool install, Claude Code skill flow.
graphify/skills/claude/references/update.md line 113 is still prune = list(deleted) or None, and the runbook's first block exits on new_total == 0 and not deleted, so an exclusion-only change never even reaches build_merge.
Minimal repro (code only, no LLM needed):
mkdir reproA && cd reproA && git init -q .
printf 'def alpha():\n return beta_helper()\n\ndef beta_helper():\n return 1\n' > a.py
printf 'def gamma():\n return 2\n\nclass Delta:\n def run(self):\n return gamma()\n' > b.py
# full build the way SKILL.md steps 2-4 do it
python -c "
from pathlib import Path
from graphify.detect import detect, save_manifest
from graphify.paths import out_path
from graphify.watch import _read_build_excludes, _read_build_gitignore
from graphify.extract import extract
from graphify.build import build_from_json
from graphify.cluster import cluster
from graphify.export import to_json
Path('graphify-out').mkdir(exist_ok=True)
d = detect(Path('.'), extra_excludes=_read_build_excludes(out_path()), gitignore=_read_build_gitignore(out_path()))
ast = extract([Path(f) for f in d['files']['code']], cache_root=Path('.'))
G = build_from_json({'nodes': ast['nodes'], 'edges': ast['edges'], 'hyperedges': []}, root='.', directed=False)
to_json(G, cluster(G), 'graphify-out/graph.json')
save_manifest(d['files'], root='.', scan_corpus={f for fl in d['files'].values() for f in fl})
"
echo 'b.py' > .graphifyignore
# first block of references/update.md
python -c "
from pathlib import Path
from graphify.detect import detect_incremental
from graphify.paths import out_path
from graphify.watch import _read_build_excludes, _read_build_gitignore
r = detect_incremental(Path('.'), extra_excludes=_read_build_excludes(out_path()), gitignore=_read_build_gitignore(out_path()))
print('new_total', r.get('new_total'), 'deleted', r.get('deleted_files'), 'excluded', [Path(x).name for x in r.get('excluded_files', [])])
if r.get('new_total', 0) == 0 and not r.get('deleted_files'): print('No files changed since last run. Nothing to update.')
"
python -c "import json; g = json.load(open('graphify-out/graph.json')); print(sorted({n.get('source_file') for n in g['nodes'] if n.get('source_file')}))"
# same state, CLI
graphify update .
python -c "import json; g = json.load(open('graphify-out/graph.json')); print(sorted({n.get('source_file') for n in g['nodes'] if n.get('source_file')}))"
Output:
new_total 0 deleted [] excluded ['b.py']
No files changed since last run. Nothing to update.
['a.py', 'b.py'] <- skill --update: b.py nodes stay
[graphify watch] pruned 4 node(s) from 1 newly-ignored file(s) (matched by a live ignore rule while absent from the scan corpus).
['a.py'] <- CLI update: pruned
Real-world case: a docs folder kept both an original .pdf and its verified .md conversion. Adding docs/*.pdf to .graphifyignore to drop the duplicate copy, then running the skill --update, would leave all 11 PDF-sourced nodes in graph.json while reporting "Nothing to update".
Suggested fix, matching the CLI path: in update.md, count excluded_files as a change in the early-exit check and pass deleted + excluded as prune_sources to build_merge.