Repository navigation
Description
Cache uses absolute paths in hash, making it non-portable across machines
Problem
graphify.cache.file_hash() includes str(p.resolve()) (the absolute path) in the SHA256 hash that becomes the cache filename:
# graphify/cache.py, line 20-33
def file_hash(path: Path) -> str:
p = Path(path)
raw = p.read_bytes()
content = _body_content(raw) if p.suffix.lower() == ".md" else raw
h = hashlib.sha256()
h.update(content)
h.update(b"\x00")
h.update(str(p.resolve()).encode()) # <-- absolute path
return h.hexdigest()This means the same file with identical content produces different cache keys on different machines (or even different checkout paths on the same machine):
- Machine A:
SHA256(content + /Users/alice/projects/myapp/src/foo.py)→a1b2c3...json - Machine B:
SHA256(content + /home/bob/myapp/src/foo.py)→d4e5f6...json
Impact
- Team workflows are broken — committing
graphify-out/cache/to share incremental extraction state across a team is useless because every teammate gets cache misses and does a full re-extraction anyway. - CI/CD can't benefit — a CI job that caches
graphify-out/cache/between runs will miss if the checkout path changes (common with ephemeral runners). - Same machine, different clones — even cloning the same repo to a different directory invalidates the entire cache.
The cache content (nodes, edges) correctly uses relative paths in source_file, so the extracted data is portable. Only the lookup key is not.
Suggested fix
Use the path relative to the project root instead of the resolved absolute path:
def file_hash(path: Path, root: Path = Path(".")) -> str:
p = Path(path)
raw = p.read_bytes()
content = _body_content(raw) if p.suffix.lower() == ".md" else raw
h = hashlib.sha256()
h.update(content)
h.update(b"\x00")
try:
rel = p.resolve().relative_to(root.resolve())
except ValueError:
rel = p.resolve()
h.update(str(rel).encode())
return h.hexdigest()This would make cache entries portable across machines while still preventing collisions between files with identical content at different relative paths.
Note: this is a cache-breaking change — existing caches would need to be rebuilt once. A migration path could rehash existing entries, or just document that users should rm -rf graphify-out/cache/ after upgrading.
Related
- .graphifyignore always assumes that graphify is run in that folder #303 — similar issue with
.graphifyignoreassuming paths relative to a subfolder instead of the project root
Environment
- graphifyy 0.4.10
- Python 3.14
- macOS
Activity
safishamsi commentedon Apr 13, 2026
Fixed in v0.4.12.
file_hash()now uses the path relative to the project root instead of the resolved absolute path — cache entries are portable across machines, CI runners, and different checkout directories.Note: this is a cache-breaking change. Existing cache entries will produce misses on first run after upgrading (they used absolute paths). Just delete
graphify-out/cache/once and re-run:After that one re-extraction, all subsequent runs will hit the shared cache correctly across machines.