Skip to content

Upgrade leaves stale state: save_manifest and --force both merge instead of replacing #3581

Open

Description

@jax-at-videolink

Summary

Upgrading in place from 0.5.4 → 0.9.62 leaves stale state behind in two separate places,
because both manifest.json and graph.json are merged into rather than replaced. The result
is a graph that keeps entries pointing at files that no longer exist at those paths, indefinitely,
with no warning.

The graph.json half is the more damaging of the two, and it survives --force.

1. save_manifest merges, so stale keys are never dropped

Before the upgrade, manifest.json held 38 keys, all absolute paths. After the upgrade wrote
new repo-relative keys, the file held 301 — the 263 new relative keys plus all 38 stale
absolute ones
. Nothing was removed.

So one file ends up describing the same tree twice, under two different key conventions, and the
stale half never expires.

Workaround: delete manifest.json before the first update. Doing so produced a clean
263 keys, 0 absolute, confirming the new code path is correct and only the merge is at fault.

2. graphify update --force merges graph.json too — this is the bigger one

--force reads as "discard and rebuild", and the guard message reinforces that reading:

WARNING: new graph has 4809 nodes but existing graph.json has 8473.
Refusing to overwrite — you may be missing chunk files from a previous session.
Pass --force to override.

It does not discard. Measured against a byte-identical backup of the pre-force graph.json:

count
nodes after --force 4809
of those, already present before 3708
newly created this run 1101
dropped 4765

Among the survivors, 219 nodes carry an absolute source_file under a directory the project was
checked out at previously and no longer is
. Zero of those 219 were newly created — every one
is a carry-over. They cannot be regenerated, because nothing exists at those paths now; they can
only persist.

Deleting manifest.json does not help here, because these live in graph.json.

Why this is worth fixing rather than documenting

  • The guard counts nodes only. On another repo in the same rollout the node count rose 61%
    while hyperedges fell 81% — the headline number hid the loss entirely. A merge that silently
    preserves unreachable nodes makes that harder to notice, not easier.
  • A tool that reports a knowledge graph of a codebase is expected to describe the current
    codebase. Nodes keyed to a path the code has not lived at for months are indistinguishable, to a
    consumer of graph.json, from live ones.
  • The only reliable remedy found was rm -rf of the whole output directory and a full rebuild,
    which also discards every LLM-derived rationale node — an expensive price for what reads like
    a cache-invalidation bug.

Reproduction

  1. On 0.5.4, build a graph for a project at path A.
  2. Move or re-clone the project to path B.
  3. Upgrade to 0.9.62.
  4. graphify update <B> → the guard refuses (fewer nodes without an LLM run, since rationale
    nodes cannot be reproduced).
  5. graphify update <B> --force.
  6. Inspect graph.json: nodes whose source_file still begins with path A are present, and
    none of them are new.

Expected

  • save_manifest replaces the manifest for the paths it rewrites, rather than unioning old and
    new key conventions.
  • --force replaces the graph, or the flag/message says plainly that it merges and that stale
    nodes are retained.
  • Ideally, nodes whose source_file no longer resolves are pruned on rebuild regardless of flag.

Environment

  • graphify 0.9.62 (upgraded in place from 0.5.4), installed as a uv tool
  • macOS, Python 3.14
  • Python project, ~160 source files, AST-only extraction (no LLM key configured at update time)

Activity

  1. L4XB commented on Sep 15, 2026

    @L4XB
    Contributor

    I reproduced part 1 on v8 (c7ec108, 0.9.62) and it splits into two cases that behave differently, which I think narrows the fix quite a bit.

    Harness: write a 0.5.4-shaped manifest at A (absolute keys, no root), copy the tree with graphify-out/ to B, then save from B the way cli.py does (kind="both", root=B, scan_corpus=<full detect corpus>).

    [reclone  scan_corpus=True ]  after=6  absolute=3    <- your 301 = 263 + 38
    [reclone  scan_corpus=False]  after=6  absolute=3
    [move     scan_corpus=True ]  after=3  absolute=0
    [move     scan_corpus=False]  after=3  absolute=0
    

    So move is already clean today and only re-clone reproduces. The difference is that after a re-clone the old checkout still exists, so the stale rows survive the Path(f).exists() prune in the seed loop. Might be worth confirming whether A was still on disk in your run, since that decides whether this is the same bug you hit or a third one.

    Once the row is past the exists() prune, two things keep it alive for ever:

    1. save_manifest's seed loop prunes a row that the full scan no longer covers only when it is in root:

      if scan_set is not None and not _in_scan(f) and _in_root(f):
          continue  # excluded-but-alive: drop the stale row (#1908)
    2. _to_relative_for_storage keeps out-of-root keys absolute, so the row is rewritten in the old convention on every save and never collides with the new relative key.

    The _in_root guard looks deliberate rather than accidental: test_save_manifest_full_scan_keeps_out_of_root_rows pins it, with the rationale that out-of-root entries (--include sources, symlinked corpora) are never walked by detect, so their absence from the corpus is not exclusion evidence. A stale key from a previous checkout is indistinguishable from a legitimate --include source by that test alone, which is why I have not sent a patch for this half: whichever way it goes is a call about what an out-of-root row means, not a bug fix.

    The options I can see, in case it is useful:

    • prune out-of-root rows that are in neither scan_corpus nor the stamped files of a full-scan save. Smallest change, but it inverts test_save_manifest_full_scan_keeps_out_of_root_rows, so --include sources would have to be re-stamped on every run to survive.
    • keep them, but warn once per save naming the count and the common prefix, so the "no warning" half of the report goes away without changing what is retained.
    • keep them and gate the prune behind an explicit flag.

    Happy to implement whichever you prefer.

    One adjacent case did turn out to have no trade-off, so I sent it separately as #3583: a key that names a file which really is under root but spells it differently (symlinked checkout path, or a case variant on APFS/NTFS) also relativizes to ../…, stays absolute, and ends up duplicated beside the fresh relative key. That one is unambiguous, and it is a second way to arrive at the "one file describing the same tree twice" shape you saw. It does not touch the re-clone case, and does not close this issue.

    I have not looked into part 2 (--force on graph.json) yet.

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