graphify icon indicating copy to clipboard operation
graphify copied to clipboard

v0.8.43 regression: FileSlice crashes semantic extraction for oversized Markdown

Open fibo-blip opened this issue 5 months ago • 3 comments

Summary

graphify 0.8.43 regresses semantic extraction for oversized Markdown/text files that are expanded into FileSlice units. The string-path coercion added for #1386 now runs inside extract_files_direct() and attempts Path(FileSlice(...)), which crashes before any backend call is made.

This breaks normal graphify extract . --backend <backend> --out . when the changed semantic/doc corpus includes large Markdown files.

This looks related to the interaction between:

  • #1369 / v0.8.42: oversized Markdown/text slicing via FileSlice
  • #1386 / v0.8.43: str path coercion in semantic extract entry points
  • #1389: appears to move coercion to extract_corpus_parallel() and allow extract_files_direct() to receive Path | FileSlice, but it is currently open/conflicting while v0.8.43 is released with the regression.

Environment

  • graphify: 0.8.43
  • install: uv tool upgrade graphifyy
  • OS: WSL2 Ubuntu
  • backend: observed with --backend deepseek; the minimal repro also shows the failure happens before any backend request, so this is not DeepSeek-specific

Minimal reproduction without making an API call

from pathlib import Path
from tempfile import TemporaryDirectory

from graphify.file_slice import expand_oversized_files
from graphify.llm import extract_files_direct

with TemporaryDirectory() as d:
    root = Path(d)
    doc = root / "large.md"
    doc.write_text("# Large doc\n\n" + ("body text\n" * 5000), encoding="utf-8")

    units = expand_oversized_files([doc], 20_000)
    print([type(u).__name__ for u in units])  # includes FileSlice

    # api_key is dummy; the failure happens before any backend request.
    extract_files_direct(units, backend="deepseek", api_key="dummy", root=root)

Actual behavior

TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'FileSlice'

In the CLI path this is surfaced as:

[graphify extract] semantic extraction on 2 files via <backend>...
[graphify] chunk 1/1 failed: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'FileSlice'
[graphify] WARNING: 1/1 semantic chunk(s) failed — see errors above. Partial results returned.
[graphify extract] error: all semantic chunks failed for backend '<backend>' (2 uncached files)

Expected behavior

extract_corpus_parallel() may coerce user-supplied str | Path inputs before slicing, but after expand_oversized_files() the internal units are Path | FileSlice. extract_files_direct() should preserve FileSlice units and use existing helpers such as unit_path() / _partition_semantic_files() / _read_files() instead of coercing every unit through Path(...).

Suspected root cause

In the v0.8.43 installed package, graphify/llm.py contains:

def extract_files_direct(...):
    ...
    files = [Path(f) for f in files]

That line is safe for str/Path inputs, but unsafe for FileSlice units produced by the slicer. The PR #1389 head appears to remove this coercion from extract_files_direct() and type it as Sequence[Path | FileSlice], which matches the needed behavior. A patch release with that fix would unblock large-doc semantic extraction.

fibo-blip avatar Jun 19 '26 12:06 fibo-blip

Confirming on a second backend + OS — hit this independently on --backend ollama (macOS, graphify 0.8.43 via uv tool install). Same TypeError: ... not 'FileSlice' on [graphify] chunk 1/1 failed, triggered by a docs/ corpus containing Markdown over the 20,000-char _FILE_CHAR_CAP (so it's not DeepSeek-specific — it's any backend, before the request).

Verified the one-line fix resolves it (extract_semantic/extract_files_direct, llm.py:1311):

files = [f if isinstance(f, FileSlice) else Path(f) for f in files]

All downstream helpers (unit_path(), _partition_semantic_files(), _read_files(), _estimate_file_tokens()) already handle FileSlice, so just sparing it from the blanket Path(f) coercion is sufficient. Matches the approach in #1389.

shopEngineering avatar Jun 19 '26 13:06 shopEngineering

Fixed on v8 in 7d07a24. Root cause confirmed: the 0.8.43 str-path coercion (#1386) ran Path(f) over every item in extract_files_direct, but extract_corpus_parallel feeds it FileSlice units from the oversized-document slicing (#1369), and Path(FileSlice) raises TypeError before any backend call. Now only non-Path/non-FileSlice entries are coerced (str→Path); FileSlice and Path pass through untouched. The #1386 regression tests used tiny files so slicing never triggered — added a regression test with a file larger than _FILE_CHAR_CAP that actually slices. Will ship in 0.8.44.

safishamsi avatar Jun 19 '26 14:06 safishamsi

Released in 0.8.44 (now on PyPI). Upgrade with uv tool install --upgrade graphifyy (or pip install -U graphifyy). Fix commit: 7d07a24.

safishamsi avatar Jun 19 '26 14:06 safishamsi