Skip to content

detect() carve-out for graphify-out/memory/ leaks: gitignore filter still applies even though the dir is walked #1047

Closed

Description

@RobRipley

detect() carve-out for graphify-out/memory/ is half-implemented — gitignore still filters memory files

Summary

detect.py L26-29 includes special-case logic to always walk graphify-out/memory/ so that save-result Q&A artifacts can be folded back into the graph on the next --update:

# Always include graphify-out/memory/ - query results filed back into the graph
memory_dir = root / "graphify-out" / "memory"
scan_paths = [root]
if memory_dir.exists():
    scan_paths.append(memory_dir)

But the downstream _is_ignored(p, root, ignore_patterns) filter on L73 still applies the normal gitignore rules to every file found. If the user's .gitignore contains graphify-out/ (a very common pattern — graphify itself suggests it in the post-commit-hook installer), all memory files get filtered out even though the scan deliberately walked the directory.

Net effect: the save-result → --update → graph loop silently breaks for any user who gitignores graphify-out/. Memory artifacts pile up on disk and never become graph nodes.

Reproducer

# In a project where graphify-out/ is gitignored (the common case):
cd /path/to/your/project
echo 'graphify-out/' >> .gitignore

# Run a query and save the result
graphify query "How does X work?"
graphify save-result --question "How does X work?" --answer "..." --type query --nodes "..."
ls graphify-out/memory/   # ← file is on disk

# Try to fold it into the graph
graphify --update         # ← memory file is silently filtered

python3 -c "
from graphify.detect import detect
from pathlib import Path
r = detect(Path('.'))
mem = [f for files in r['files'].values() for f in files if '/memory/' in f]
print(f'Memory files detected: {len(mem)}')   # 0
"

In our project (safishamsi/graphify users testing, also confirmed in a CDP protocol repo, 9 memory files):

>>> from graphify.detect import _is_ignored, _load_graphifyignore
>>> from pathlib import Path
>>> root = Path('.').resolve()
>>> test = root / 'graphify-out' / 'memory' / 'query_2026...md'
>>> _is_ignored(test, root, _load_graphifyignore(root))
True                # ← filtered, even though detect() walks the dir

Why the carve-out leaks

The L73 _is_ignored call is unconditional. It runs on every walked file, regardless of which scan_root it came from. The scan correctly includes memory_dir, but the filter doesn't know it's supposed to exempt files inside that path.

A .graphifyinclude workaround doesn't help either — _load_graphifyinclude's docstring states include patterns are for "opt[ing] hidden files/dirs into traversal", and the include_patterns variable isn't passed to _is_ignored.

Workarounds (what users have to do today)

  1. Fenced gitignore rule — replace graphify-out/ with graphify-out/*\n!graphify-out/memory/\n!graphify-out/memory/**. Works but ugly; users have to figure this out themselves and edit project-level gitignore.

  2. Don't gitignore graphify-out/ — keeps the loop alive but bloats the repo with regenerated graph.json, GRAPH_REPORT.md, and per-rebuild backup dirs (6+ MB each).

  3. Move memory dir elsewhere via symlink — mv graphify-out/memory docs/graphify-qa && ln -s ../docs/graphify-qa graphify-out/memory. Works but fragile and not discoverable.

Proposed fix

Either:

(a) Apply the carve-out in _is_ignored. Inside detect.py L73, mirror the existing in_memory short-circuit from L67-68 by skipping the gitignore check for paths inside memory_dir:

in_memory = memory_dir.exists() and str(p).startswith(str(memory_dir))
if in_memory:
    pass  # carve-out: memory files are always included
elif _is_ignored(p, root, ignore_patterns):
    continue

This matches the intent stated in the L25 comment. The user's gitignore is opt-in tracking for the rest of graphify-out/; memory files should be exempt because they're explicitly meant to round-trip.

(b) Make the memory dir configurable via env var (GRAPHIFY_MEMORY_DIR) or a .graphifyrc. Users who want memory artifacts elsewhere (e.g. under docs/graphify-qa/) can point graphify at the new path, and the same exemption applies to whatever path is configured.

(a) is the minimum fix. (b) is the larger improvement that solves "I want memory artifacts under docs/ not graphify-out/" cleanly.

Environment

  • graphify version: 0.8.17
  • Python: 3.13
  • Install: uv tool install graphifyy
  • Project gitignore: graphify-out/ (single line, common pattern)

Related

  • save-result --memory-dir flag exists for writing memory to a custom path, but the read-side (detect carve-out) is hardcoded to graphify-out/memory/. Asymmetric.

Activity

  1. safishamsi commented on May 27, 2026

    @safishamsi
    Member

    Fixed in v8 (commit 9f73400). The _is_ignored call at line 938 was unconditional — files in graphify-out/memory/ were correctly walked but then silently filtered by gitignore patterns anyway. One-line fix: if not in_memory and _is_ignored(p, root, ignore_patterns): — the memory carve-out now also exempts from gitignore filtering, so the save-result → --update round-trip works correctly even when graphify-out/ is gitignored.

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