Skip to content

With --out, the final semantic-cache save resolves relative source_file paths against out_root and silently writes 0 entries #1991

Closed

Description

@tomipetteri-ops

Summary

At the end of a successful extraction, cli.py persists the fresh semantic
results with _save_semantic_cache(..., root=out_root, ...). Inside
save_semantic_cache, each result group's source_file (commonly a
corpus-relative path such as report.md) is resolved against that same root
— i.e. against the --out directory:

def resolved_source_path(value):
    path = Path(value)
    if not path.is_absolute():
        path = root_path / path        # root_path = out_root here
    ...
# write loop:
p = resolved_source_path(fpath)
if p.is_file():                        # <out>/report.md does not exist -> False
    ...                                # group silently skipped, no warning

<out>/report.md does not exist, p.is_file() is False, and the group is
skipped without any warning (the out-of-scope warning only covers the
allowed_source_files branch, not the not-a-file branch). Net effect with
--out pointing outside the corpus: the semantic cache the reader would
consult is never populated at all
. The loss becomes visible whenever semantic
files must be reconstructed or redispatched, such as recovery from an
interrupted first build or rebuilding without the prior graph/manifest. An
ordinary unchanged incremental run may instead preserve the existing graph
without consulting the cache, so it does not necessarily re-bill. Combined with
#1990 (checkpoints written to the corpus root), the semantic cache round-trip
needed for reconstruction and recovery is fully broken in the --out
configuration, invisibly: the successful run itself builds the graph from the
in-memory merge.

This is a write-side sibling of #826 (0.7.13: absolute-vs-relative
source_file mismatch broke cache lookup); here the wrong anchor root
breaks the cache write.

Environment

  • graphifyy 0.9.18 (PyPI, uv tool install), Python 3.14 (uv-managed), Windows 11
  • backend: claude-cli (Sonnet); mechanism is backend-independent

Reproduction

graphify extract <corpus> --backend claude-cli --token-budget 15000 --out <scratch>
# run succeeds, graph.json written, log shows NO cache warnings, then:
find <scratch>/graphify-out/cache/semantic -name '*.json'   # -> nothing

Observed identically on two corpora (8 markdown files; 1 sliced 54k-char file).
The per-file stat-index.json under <scratch> does get 1 entry per doc,
which makes the empty semantic cache easy to miss.

Expected

Either the fresh entries are written under out_root keyed/anchored correctly
(resolve source_file against the corpus target, write under cache_root=out_root
— the split the AST path already uses), or at minimum a loud warning when every
group is skipped ("0 of N semantic result groups written — source_file paths do
not resolve under root").

Suggested fix

Same plumbing as #1990: give save_semantic_cache separate root
(source-key/source_file anchor = corpus target) and cache_root
(cache location = out_root) parameters; cli.py's final save passes both.
Add a warning when a group is dropped because resolved_source_path(...) is
not a file. Add a separate regression test for the final-save call site: after
a successful extraction with external --out, assert that the out-root semantic
cache contains every dispatched document and that a fresh cache-only replay
returns hits without an LLM call. This is distinct from the interrupted-
checkpoint recovery test in #1990 even though both use the same
root/cache_root split.

Related

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