Repository navigation
Description
Semantic nodes are silently evicted when a commit touches a non-extractable file, with the shrink guard disabled
Version: graphifyy 0.9.20 · Python 3.10.12 · Linux (Ubuntu 22.04) · uv tool install
Summary
When an incremental rebuild's change set contains a file that detect() filters out
(no AST extractor — e.g. .yml, .json, .txt), _rebuild_code() classifies that
file as deleted and evicts every node claiming it as source_file — including
LLM-extracted concept/rationale/document nodes from a prior semantic pass.
The same condition sets had_explicit_deletions=True, which makes _check_shrink()
return early and skip the shrink guard entirely. So the node loss is both caused
and un-caught by the same flag, and nothing is printed to warn the user.
This is a data-loss bug specifically for the expensive half of the graph: AST nodes
are free to regenerate, semantic nodes cost real LLM tokens (~600k input for our
~90-file corpus).
Root cause
graphify/watch.py:724 — first line of _check_shrink():
if force or not existing_data or had_explicit_deletions:
return TrueThe caller at watch.py:1232 passes had_explicit_deletions=bool(deleted_paths).
deleted_paths is populated at watch.py:1017 for files that still exist on disk:
existing_in_root = next(
(cand for cand in candidates if cand.exists() and _is_relative_to(cand, watch_root)),
None,
)
if existing_in_root is not None:
# The path exists under the watched root but detect filtered it out.
# Evict any stale nodes that still claim it.
_add_deleted_source(existing_in_root)
continueThe comment says "evict any stale nodes", but the eviction is unconditional: it
also removes current, valid semantic nodes whose only fault is that their source file
has no AST extractor. Docstring intent ("the caller has declared which files were
removed … a smaller graph is the expected outcome") does not hold here — nothing was
removed.
Reproduction
Corpus: a repo with a semantic pass over docker-compose.yml (5 nodes: 3 code,
2 rationale), plus normal TS sources. Existing graph: 3,811 nodes / 536 semantic.
Instrument _check_shrink to report its inputs and abort the write:
from pathlib import Path
import graphify.watch as w
def spy(force, existing, new, tmp=None, *, had_explicit_deletions=False, rebuilt_sources=None):
new_ids = {n.get('id') for n in new.get('nodes', [])}
lost = [n for n in existing.get('nodes', []) if n.get('id') not in new_ids]
print('had_explicit_deletions:', had_explicit_deletions)
for n in lost:
print(f" LOST {n.get('file_type'):10s} {n.get('source_file')} :: {n.get('label')}")
return False # abort write
w._check_shrink = spy
w._rebuild_code(
Path('/path/to/repo'),
changed_paths=[Path('src/auth/guard.ts'), Path('docker-compose.yml')],
force=False,
)Actual output:
had_explicit_deletions: True
LOST code docker-compose.yml :: <service node A>
LOST code docker-compose.yml :: <service node B>
LOST code docker-compose.yml :: <service node C>
LOST rationale docker-compose.yml :: <rationale node A>
LOST rationale docker-compose.yml :: <rationale node B>
Graph goes 3,811 → 3,806 nodes. With the real _check_shrink, this write is
permitted (guard skipped) and nothing is logged.
docker-compose.yml was neither deleted nor renamed — it is present and unmodified.
Comparison across change-set shapes (same instrumentation):
| change set | had_explicit_deletions |
guard skipped | nodes |
|---|---|---|---|
| code file only | — | — | no topology change |
| code + real deletion | — | — | no topology change |
| code + existing non-code file | True | True | 3811 → 3806 |
| code + gitignored file | — | — | no topology change |
Impact
The loss is cumulative and silent. Each commit touching a different non-extractable
file evicts that file's semantic nodes, unguarded. Over ~30 commits our graph
degraded from ~4,000 nodes to a 50-node stub containing only doc-derived nodes:
$ grep -E "Rebuilt:" ~/.cache/graphify-rebuild.log
[graphify watch] Rebuilt: 4072 nodes, 8891 edges, 320 communities
[graphify watch] Rebuilt: 29 nodes, 27 edges, 6 communities
[graphify watch] Rebuilt: 50 nodes, 45 edges, 8 communities
Zero WARNING/Refusing lines across the whole log — the guard was never consulted.
Compounding it, the collapse ratchets: incremental rebuilds preserve unchanged
nodes from the existing graph.json, so once small it stays small until a
post-checkout full rebuild. Verified: rebuilding from a sabotaged 42-node graph
produced 63 nodes, not ~3,800.
Because post-commit fires on every commit, projects whose convention is to touch a
config/doc file alongside code hit this constantly.
Suggested fix
Two independent issues; either fix alone reduces the severity.
-
Don't classify a present file as deleted (
watch.py:1017). A file that exists
but was filtered bydetectis not a deletion. If the intent is to drop stale AST
nodes, scope the eviction to_origin == "ast"nodes and leave semantic nodes
alone — they were produced by a pass thatdetect's AST filter has no authority
over. -
Narrow the
had_explicit_deletionsbypass (watch.py:724). Rather than
skipping the guard wholesale, reuse the existingrebuilt_sourcesaccounting
already implemented a few lines below — a shrink is legitimate when every lost node
belongs to a genuinely deleted file, and suspicious otherwise. The bypass makes the
rebuilt_sourceslogic unreachable in exactly the case it was written for.
A cheap third mitigation: log at INFO when the guard is skipped, so the loss is at
least visible in ~/.cache/graphify-rebuild.log.
Workaround
We wrapped both hooks with an external guard that snapshots a known-good graph and
restores it when node count drops below max(1000, 50% of known-good) or the
semantic layer goes to zero. Effective, but it repairs after the bad write rather
than preventing it, since the write happens via atomic replace inside the package.
Related issues
graphify update .replaces a merged doc+code graph with a code-only rebuild (-37% nodes, -74% edges, labels lost) - no shrink guard on the watch path, and its backup step overwrites a same-day snapshot #2053 (closed) reports that the shrink guard does not engage on the
watch._rebuild_codewrite path at whole-graph scale via the CLI. This issue gives
the precise reason it does not engage on the incremental path:
had_explicit_deletionsshort-circuits_check_shrink()before any comparison.- Possible silent downgrade of semantic Markdown nodes during AST-only rebuild #2014 reports semantic Markdown nodes being downgraded to AST heading nodes.
Same class of loss (semantic layer degraded by an AST-only rebuild), different
route: here the nodes are evicted outright rather than replaced, and the file
need not have an AST extractor at all. - Stale semantic nodes for deleted files are preserved indefinitely and returned as authoritative #2051 reports the inverse for genuinely deleted files (stale semantic nodes
preserved indefinitely). Worth checking that a fix there does not widen the
eviction path described here.
Activity
fix(watch): correct semantic-node eviction/preservation on update
chore: changelog for 0.9.21 data-integrity fixes (#2051/#2056/#2014/#…
safishamsi commentedon Jul 20, 2026
Fixed in v0.9.21: a present-but-unextractable file in an incremental change set is preserved rather than treated as a deletion, and the shrink guard no longer waves the loss through on the mere presence of a deletion. https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.21
fix(watch): correct semantic-node eviction/preservation on update
chore: changelog for 0.9.21 data-integrity fixes (Graphify-Labs#2051/G…