Skip to content

save_semantic_cache crashes with IsADirectoryError when a node's source_file points at a directory #448

Closed

Description

@harnill

Context

During Step 3 Part C merge, save_semantic_cache aborted with:

File ".../graphify/cache.py", line 31, in file_hash
    raw = p.read_bytes()
  ...
IsADirectoryError: [Errno 21] Is a directory: 'analysis-engine/data/quote_validation/sp_images'

The subagent that produced the offending chunk had written a node with source_file = 'analysis-engine/data/quote_validation/sp_images' (a directory, not a file). file_hash then tried to read_bytes() it.

Impact

Semantic cache save failed → on re-run, all 410 files would be re-extracted rather than hitting cache. For large corpora this doubles the API cost of any update.

Proposed fix (one-liner in cache.py::file_hash)

def file_hash(p: Path, root: Path) -> str:
    if not p.is_file():   # new guard
        return ''         # or raise a catchable warning
    raw = p.read_bytes()
    ...

Alternatively, have save_cached skip paths that fail is_file() with a warning.

Secondary consideration

The upstream reason is that a semantic-extraction subagent sometimes returns a directory string in source_file — prompt clarity could also be tightened. But defence-in-depth at the cache layer is the robust fix.

Repro

Any corpus where a semantic subagent labels a group of images collectively with the containing directory as source_file. Triggered reliably on a corpus with multiple directories of example images.

Activity

  1. added a commit that references this issue on Apr 21, 2026
  2. safishamsi commented on Apr 21, 2026

    @safishamsi
    Member

    Fixed in v0.4.24: save_cached now skips directory paths instead of raising IsADirectoryError.

  3. added a commit that references this issue on Apr 23, 2026
  4. added a commit that references this issue on Sep 10, 2026
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