Skip to content

detect_incremental reports live files as deleted when a file leaves the scan scope, and --update prunes them from the graph #2870

Open

Description

@AlternateLogic

Summary

detect_incremental derives its deleted set as "manifest key not in the scanned file set", while
save_manifest retains a manifest entry whenever "the file exists on disk". The two predicates
disagree. A file that leaves the scan scope — because .graphifyignore grew, for instance — but stays on
disk therefore satisfies the retain test and fails the deleted test, so it is reported deleted on every
subsequent run, permanently.

That set flows straight into build_merge(prune_sources=...), so a completed --update evicts live
sources from the graph. The failure is silent and looks like a normal incremental.

Mechanism

Two lines, in graphify/detect.py (0.8.33):

save_manifest, in the seed-from-existing block (detect.py:1190-1205) — retains on existence:

for f, entry in existing.items():
    ...
    if Path(f).exists():
        manifest[f] = normalised

detect_incremental (detect.py:1322) — deletes on scan membership:

current_files = {f for flist in full["files"].values() for f in flist}
deleted_files = [f for f in manifest if f not in current_files]

detect() honours .graphifyignore / .gitignore (detect.py:707-711), so scan membership can shrink
while the file is still on disk. Nothing ever removes the orphaned entry, because the only prune test is
existence.

The sink is graphify/__main__.py:4183:

prune_sources=deleted_files or None,

and the same call appears in the --update skill flow
(graphify/skills/*/references/update.md, the build_merge step).

Reproduction

  1. Build a graph over a repo. The manifest now holds every scanned file.
  2. Add a directory to .graphifyignore that the manifest already covers, and leave the files on disk.
  3. Run the --update detect step.

deleted_files now holds every file under that prefix. Every one exists.

Observed on a repository where .graphifyignore gained three prefixes while their files stayed on disk.
The pre-run manifest held 3,808 entries; entries under the three newly-ignored prefixes numbered
620 + 612 + 6 = 1,238, which is exactly the deleted count --update reported. After 1,220 of those
files were later deleted from disk, the count fell to 18 on its own, with no fix applied — which is
the mechanism confirming itself.

A useful diagnostic:

from pathlib import Path
from graphify.detect import detect, load_manifest, _MANIFEST_PATH
cur = {f for v in detect(Path('.'))['files'].values() for f in v}
man = load_manifest(_MANIFEST_PATH, root=Path('.'))
d = [f for f in man if f not in cur]
print('deleted:', len(d), 'of which still on disk:', sum(1 for f in d if Path(f).exists()))

Any non-zero second number is a set of phantom deletions.

Two things this is NOT

Both were proposed and both are wrong, so they may save you a wrong turn:

  1. Not a path-format mismatch between writers. Every in-product save_manifest call passes root=
    (watch.py:603/641/712, __main__.py:4152/4241), so the on-disk manifest is uniformly relative, and
    detect_incremental re-anchors it on read at detect.py:1268. The key sets are format-compatible.
    The arithmetic also rules it out: zero key overlap would make every scanned file new, whereas the
    failing run reported 766 changed against a 3,808-entry manifest — 67 percent overlap.
  2. Not a missing relativize inside detect_incremental. It already passes root to
    load_manifest.

Suggested fix

Restrict the deleted set to entries whose file is actually gone:

deleted_files = [
    f for f in manifest
    if f not in current_files and not Path(f).exists()
]

prune_sources exists to evict nodes for files that no longer exist. A file that exists but left the
scan scope has no nodes to evict, because the graph was never built from it.

Optionally, and separately: have save_manifest also drop entries outside the current scan scope, so the
manifest stops accumulating orphans. The reader change above is the safety half; that is the cleanup
half.

Two lower-severity observations from the same investigation

  1. --update's merge step calls save_manifest(incremental['files']) with no root=
    (graphify/skills/*/references/update.md), so it writes the legacy absolute-keyed manifest while
    watch.py writes the relative form. It self-heals on the next watch run and it is not the cause
    of the bug above, but the two writers disagreeing on format is confusing to anyone debugging this
    area — it sent our first two analyses down the wrong path.
  2. The to_json node-count guard and _check_shrink both fired correctly and are what prevented
    real damage here. Worth keeping. Neither sits inside --update itself, so a prune arriving through
    build_merge is not covered by them.

Environment

  • graphifyy 0.8.33, installed via uv tool install, Python 3.13.7
  • Windows 11
  • .graphifyignore present at the scan root

Activity

  1. abhay-codes07 commented on Aug 20, 2026

    @abhay-codes07
    Contributor

    This does not reproduce on current v8 (0.9.48) — the two predicates were reconciled by #1908, which split the manifest-minus-corpus set in two.

    Ran the exact scenario: build a graph, then add a directory to .graphifyignore while its files stay on disk.

    manifest seeded with 4 files
    deleted_files : []
    excluded_files: ['old0.py', 'old1.py', 'old2.py']
    

    The live-but-now-ignored files land in excluded_files, and deleted_files is empty — so nothing feeds them to prune_sources as deletions and the eviction you describe cannot happen. detect.py now reads:

    # Manifest rows that left the corpus, split by disk existence (#1908):
    # a row whose file is gone from DISK is a genuine deletion (its cached
    # nodes are ghosts); a row whose file still exists but is out of the
    # current scan was EXCLUDED (ignore rules / --exclude changed) and must
    # not be reported as deleted.
    (excluded_files if alive else deleted_files).append(f)

    Your analysis was right for 0.8.33 — the single-predicate version you quote is genuinely there in that release. It looks like this was fixed between then and now without the issue being closed.

    Worth flagging the flip side, though, because it is still live and it is the same seam: the --update runbook reads only deleted_files and never excluded_files, so where 0.8.33 pruned too much, current versions prune too little — an added .graphifyignore rule never removes what it excluded, and after one more run the manifest row is gone so nothing can prune it again. That is #2773, with a fix open at #2806.

    So the seam you found is real; the direction it fails in flipped. This one can probably be closed as fixed by #1908 — happy to be told otherwise if you can still reproduce it on 0.9.48.

  2. ayushcodes10 commented on Sep 16, 2026

    @ayushcodes10
    Contributor

    Already fixed on current v8, via #1908.

    save_manifest's scan_corpus parameter is wired through every caller that matters (cli.py and watch.py, three call sites each). Reproduced directly: seeded a manifest with scan_corpus, excluded a live file via .graphifyignore while leaving it on disk, then re-ran detect_incremental — deleted_files comes back empty, so a live-but-newly-excluded file is no longer misreported as deleted.

  3. ayushcodes10 commented on Oct 20, 2026

    @ayushcodes10
    Contributor

    Reproduced this issue's exact scenario against current upstream v8 (post 0.9.9x, well past the 0.8.33 this was filed against) and the described bug no longer occurs.

    detect_incremental in graphify/detect.py now splits the manifest rows that left the scan into two sets by disk existence, exactly as this issue's own suggested fix proposes:

    (excluded_files if alive else deleted_files).append(f)

    A direct repro confirms it: two files tracked in the manifest, then one excluded via a fresh .graphifyignore entry while staying on disk.

    deleted_files: []
    excluded_files: ['/private/tmp/2870-repro/pkg/b.py']
    b.py still on disk: True
    

    The CLI (graphify/cli.py) keeps the two sets separate end to end: they're reported separately ("N deleted, M excluded"), and while both do feed prune_sources for build_merge (an excluded file's nodes are correctly removed from the graph, since it's no longer part of the corpus), a file that merely left scope is never counted or reported as deleted, matching this issue's actual complaint about misreporting, not about whether its nodes should be pruned.

    This was fixed by #1908/#1909 (commit 75cf56bf, "excluded files are pruned from graph and manifest, not misreported as deleted"), filed and merged on 2026-07-15, about a month before this issue (#2870) was opened on 2026-08-19 — looks like a duplicate filed against an older install that predated that fix. The code comments at detect.py and two sites in cli.py cite #1908 directly.

    No code change needed; suggest closing as a duplicate of #1908.

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