Skip to content

extract --out <dir>: semantic cache never saved, docs missing from manifest (relative source_file resolved against --out) #4831

Open

Description

@R-u-d

Version: graphify 0.9.7 (uv tool install graphifyy), macOS, --backend claude-cli

Problem
graphify extract <dir> --out <other> never reuses the semantic cache. Every run re-extracts every doc and reports 0 files cached/unchanged. <other>/graphify-out/cache/semantic/ stays empty.

Cause
The LLM returns source_file relative to the scanned dir (e.g. n1.md). In __main__.py (extract), two places treat it as a path under the output root (out_root) instead:

  1. cache.save_semantic_cache(..., root=out_root) builds Path(root) / "n1.md", is_file() is false, so the entry is skipped. Nothing is saved.
  2. _sem_extracted (used to build _manifest_files) is compared against the absolute paths in files_by_type. A relative source_file never matches, so no doc gets a semantic_hash in manifest.json and detect_incremental re-queues all of them.

When --out is omitted (out_root == target), (1) resolves correctly.

Repro

mkdir vault out cwd
for i in 1 2 3; do echo "# Note $i. Alice uses Redis." > vault/n$i.md; done
cd cwd
graphify extract ../vault --out ../out --backend claude-cli --max-concurrency 1   # run twice

Run 2: incremental summary: 0 files cached/unchanged, 3 re-extracted, tokens spent again, out/graphify-out/cache/semantic/ empty, manifest.json is {}.

Workaround
Omit --out and set GRAPHIFY_OUT=/abs/path/graphify-out. Run 2 then reports 3 files cached/unchanged, 0 re-extracted and spends no tokens. On a ~106-doc vault this took a nightly run from ~340k in / ~66k out tokens to ~17k / ~7k.

Suggested fix
Resolve relative source_file against target (the scanned dir) in save_semantic_cache and when building _sem_extracted, while keeping the cache key relative to out_root as check_semantic_cache already does.

Activity

  1. github-actions commented on Oct 27, 2026

    @github-actions

    Thanks for opening this issue, @R-u-d. 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. nothariharan commented on Oct 28, 2026

    @nothariharan
    Contributor

    Thanks for the detailed report. Your diagnosis is correct for 0.9.7: there, extract saved the semantic cache with root=out_root, so with --out the relative source_file paths resolved against the output dir, is_file() failed, and every entry was skipped. Separately, the manifest never stamped those docs.

    Both halves have been fixed since then:

    The regression tests for this (tests/test_semantic_cache_out_root.py plus the manifest-stamping tests) pass on current v8 (0.9.97).

    Please upgrade with uv tool upgrade graphifyy and drop the GRAPHIFY_OUT workaround. Run 2 of your repro should then report 3 files cached/unchanged, 0 re-extracted. If it still re-extracts on 0.9.20 or later, please reopen with the output and we'll dig in.

  3. Deepjyoti-Sarmah commented on Oct 28, 2026

    @Deepjyoti-Sarmah
    Contributor

    Reproduced this without a backend, against the v0.9.7 tag and current v8 (0.9.97). Both halves of the report check out.

    At v0.9.7, __main__.py passed root=out_root to both _check_semantic_cache and _save_semantic_cache:

    • save_semantic_cache resolved the model's corpus-relative source_file against out_root, so is_file() was false for every group and no entry was written.
    • The manifest filter compared those same relative strings against detect()'s absolute paths, so no doc got a semantic_hash.

    Measured on a 3-doc vault with --out (no LLM; same functions the CLI calls):

    v0.9.7 v8 (0.9.97)
    save_semantic_cache 0 saved, no cache dir 3 saved under --out
    check_semantic_cache 3 uncached 0 uncached
    docs stamped in manifest 0 3
    corpus tree after run clean clean

    The fixes from 0.9.17 (manifest stamping) and 0.9.20 (root=target, cache_root=out_root) are both present on v8.

    One gap the reproduction exposed: mutating only the check call back to root=out_root leaves the current suite green, because no test consumes a cache entry that the manifest has not already stamped. I have two regression tests for that on a branch (two runs with --out and zero backend calls; an AST guard that pins both roots at every call site) and can open a PR if useful.

    For the reporter: after uv tool upgrade graphifyy, run 2 of the repro should report 3 files cached/unchanged, 0 re-extracted, and the GRAPHIFY_OUT workaround can go. The cache now lands under <out>/graphify-out/cache/semantic and is content-keyed, so it stays portable if the corpus moves.

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