Skip to content

file_hash crashes with IsADirectoryError when source_file points to a directory (cache.py:27) #455

Closed

Description

@vadafino1

Summary

graphify/cache.py:27 inside file_hash() calls p.read_bytes(), which raises IsADirectoryError if p is a directory. This triggers during save_semantic_cache when a node's source_file attribute accidentally holds a directory path (e.g. module-level nodes in Python packages where the "source" is the package dir, not a specific .py).

Repro

graphify <python-package-with-__init__.py> --directed

Cache save step crashes:

IsADirectoryError: [Errno 21] Is a directory: '/some/package/dir'

Current code

def file_hash(path: Path) -> str:
    p = Path(path)
    raw = p.read_bytes()    # line 27 — blows up on directories
    content = _body_content(raw) if p.suffix.lower() == ".md" else raw
    ...

One-line fix

Guard with is_file() before reading:

def file_hash(path: Path) -> str:
    p = Path(path)
    if not p.is_file():
        return ""   # skip sentinel; save_semantic_cache can filter out empty hashes
    raw = p.read_bytes()
    ...

Callers (e.g. save_semantic_cache) should treat the empty string as "skip, don't cache this entry" rather than hashing a non-file.

Local workaround

Client-side filter in the SKILL.md dispatch that drops nodes/edges/hyperedges where source_file isn't a regular file before calling save_semantic_cache — verified on a recent .claude/skills/ run (169 files cached with 0 drops when all source_files resolved to real files).

Companion issue: #454 (sanitize_label None crash in export.py) — same pattern of None/non-file source_file tripping downstream code.

Activity

  1. added a commit that references this issue on Apr 21, 2026
    bba301b
  2. added a commit that references this issue on Apr 23, 2026
    81b6e7d
  3. added a commit that references this issue on Sep 10, 2026
    1f1e8f9
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