Skip to content

extract --out leaks graphify-out/cache/stat-index.json into the scan root on an incremental run (detect_incremental has no cache_root param) #3847

Closed

Description

@jonasplima

graphifyy==0.9.68 (uv tool), Python 3.11, macOS.

Summary

#1747 and #1774 fixed the fresh-run case: extract . --out <dir> no longer creates a stray graphify-out/ in the corpus root. That fix is real and I confirmed it holds on a cold run. It does not hold on the second, incremental run against a destination that already has a manifest, where a stray graphify-out/cache/stat-index.json still lands at the scan root.

Root cause

cli.py's extract command branches on whether a manifest already exists at the destination (cli.py:~3505 and ~3576):

if <manifest exists>:
    detection = _detect_incremental(
        target,
        manifest_path=str(manifest_path),
        google_workspace=google_workspace or None,
        extra_excludes=_effective_excludes or None,
        gitignore=_effective_gitignore,
    )
else:
    detection = _detect(
        target,
        google_workspace=google_workspace or None,
        extra_excludes=_effective_excludes or None,
        cache_root=out_root,
        gitignore=_effective_gitignore,
    )

Only the else (fresh-scan) branch passes cache_root=out_root. detect_incremental() (detect.py:2450) has no cache_root parameter at all, unlike detect(), which does and forwards it into cached_word_count(..., cache_root=cache_root) (detect.py:1778). On the incremental branch there is no parameter to receive out_root even if the caller wanted to pass it, so the word-count cache falls back to anchoring on root (the scan root), and _ensure_stat_index (cache.py:329) writes graphify-out/cache/stat-index.json there. The comment on the file_hash/cached_word_count call sites (cache.py:450-454) documents exactly this failure mode as the thing #1774 closed, it just does not hold for this call path.

Reproduction

Company/__init__.py, Company/Apps/__init__.py, Company/Apps/Jobs/__init__.py   (empty)
Company/Apps/Jobs/Team/__init__.py, Company/Apps/Jobs/Team/lib/__init__.py,
Company/Apps/Jobs/Team/app/__init__.py                                          (empty)
Company/Apps/Jobs/Team/lib/delivery.py    def deliver(files): return len(files)
Company/Apps/Jobs/Team/app/main.py        from Company.Apps.Jobs.Team.lib import delivery
                                           def run(): return delivery.deliver(["a"])
Company/Apps/Jobs/Team/README.md          one line of prose
cd <root>
graphify extract . --code-only --out Company/Apps/Jobs/Team/graphify-root
# clean: no stray dir at <root>

graphify extract . --backend claude-cli --out Company/Apps/Jobs/Team/graphify-root
# leaks <root>/graphify-out/cache/stat-index.json

The first call is a fresh scan against that destination and stays clean, confirming #1747/#1774 still work there. The second call finds the manifest the first call wrote, takes the incremental branch, and leaks.

Impact

On a private monorepo, running this sequence at the repo root polluted the repo root itself with an untracked graphify-out/ (caught by git status before commit, not shipped). The workaround from #1747, gitignoring graphify-out/ in the corpus, does not help when the corpus is a big shared repo and the leak lands above the intended --out subdirectory, in a directory nobody expects graphify to touch at all.

Suggestion

Add cache_root: Path | None = None to detect_incremental(), forward it to cached_word_count, and pass cache_root=out_root from the incremental branch in cli.py, matching what the fresh-scan branch already does two lines below it.

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