fix(llm): don't report a failed chunk's files as model omissions (#3616)
The #1890 dispatch/return reconciliation diffed every dispatched file
against the returned source_files and explained the whole gap with one
sentence: "The model returned a response but omitted them". For files
whose chunk raised (a provider error, a missing optional SDK), no
response ever existed, so the final warning contradicted the chunk
failure printed above it and pointed the operator at model output
instead of the real error.
Record the files of every chunk that raises, in the serial and pooled
paths, and split the uncovered set: files from failed chunks get
"Their chunk failed before returning a response (see errors above)",
the rest keep the existing omission wording. uncovered_files is
unchanged, so both still re-dispatch on the next run.
(cherry picked from commit deb42aa5e6)
This commit is contained in:
1 parent
34b96bcb31
commit
245c952f1a
2 files changed
+68
-4
No files matched your search
+23
-4
@@ -2772,6 +2772,9 @@ def extract_corpus_parallel(
|
||||
"failed_chunks": 0, # count of chunks that raised — loud failure on chunk errors
|
||||
}
|
||||
total = len(chunks)
|
||||
# Files whose chunk raised before returning a response. The #1890
|
||||
# reconciliation below must not describe them as omitted by the model (#3616).
|
||||
failed_files: set[Path] = set()
|
||||
|
||||
def _run_one(idx: int, chunk: list[Path]) -> tuple[int, dict | None, Exception | None]:
|
||||
t0 = time.time()
|
||||
@@ -2853,6 +2856,7 @@ def extract_corpus_parallel(
|
||||
if exc is not None:
|
||||
print(f"[graphify] chunk {idx + 1}/{total} failed: {exc}", file=sys.stderr)
|
||||
merged["failed_chunks"] += 1
|
||||
failed_files.update(unit_path(f) for f in chunk)
|
||||
continue
|
||||
assert result is not None
|
||||
_merge_into(merged, result)
|
||||
@@ -2878,6 +2882,7 @@ def extract_corpus_parallel(
|
||||
file=sys.stderr,
|
||||
)
|
||||
merged["failed_chunks"] += 1
|
||||
failed_files.update(unit_path(f) for f in chunks[idx])
|
||||
continue
|
||||
assert result is not None
|
||||
results_by_idx[idx] = result
|
||||
@@ -2991,11 +2996,25 @@ def extract_corpus_parallel(
|
||||
)
|
||||
merged["uncovered_files"] = [str(p) for p in uncovered]
|
||||
_stamp_semantic_origin(merged)
|
||||
if uncovered:
|
||||
shown = ", ".join(p.name for p in uncovered[:5])
|
||||
more = f" (+{len(uncovered) - 5} more)" if len(uncovered) > 5 else ""
|
||||
# Split the gap by cause (#3616): a file whose chunk raised never got a
|
||||
# response, so only the rest were actually omitted by the model.
|
||||
unanswered = [p for p in uncovered if p in failed_files]
|
||||
omitted = [p for p in uncovered if p not in failed_files]
|
||||
if unanswered:
|
||||
shown = ", ".join(p.name for p in unanswered[:5])
|
||||
more = f" (+{len(unanswered) - 5} more)" if len(unanswered) > 5 else ""
|
||||
print(
|
||||
f"[graphify] WARNING: {len(uncovered)}/{len(dispatched)} dispatched file(s) "
|
||||
f"[graphify] WARNING: {len(unanswered)}/{len(dispatched)} dispatched file(s) "
|
||||
f"produced no nodes and are absent from the graph: {shown}{more}. Their "
|
||||
"chunk failed before returning a response (see errors above); a re-run "
|
||||
"will retry them.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
if omitted:
|
||||
shown = ", ".join(p.name for p in omitted[:5])
|
||||
more = f" (+{len(omitted) - 5} more)" if len(omitted) > 5 else ""
|
||||
print(
|
||||
f"[graphify] WARNING: {len(omitted)}/{len(dispatched)} dispatched file(s) "
|
||||
f"produced no nodes and are absent from the graph: {shown}{more}. The model "
|
||||
"returned a response but omitted them; a re-run will retry them.",
|
||||
file=sys.stderr,
|
||||
|
||||
@@ -426,6 +426,51 @@ def test_omitted_documents_are_reconciled_and_warned(tmp_path, capsys):
|
||||
assert "produced no nodes" in err and "doc1.md" in err
|
||||
|
||||
|
||||
@pytest.mark.parametrize("max_concurrency", [1, 2])
|
||||
def test_files_of_a_failed_chunk_are_not_reported_as_model_omissions(
|
||||
tmp_path, capsys, max_concurrency,
|
||||
):
|
||||
"""#3616: a chunk that raises never got a model response, so its files must
|
||||
not be described as "the model returned a response but omitted them". Only
|
||||
files absent from a successful chunk keep that wording; both still land in
|
||||
`uncovered_files` so a re-run retries them. Serial and pooled paths alike."""
|
||||
from graphify.llm import extract_corpus_parallel
|
||||
|
||||
failed = tmp_path / "failed.md"
|
||||
failed.write_text("# Failed\n", encoding="utf-8")
|
||||
omitted = tmp_path / "omitted.md"
|
||||
omitted.write_text("# Omitted\n", encoding="utf-8")
|
||||
kept = tmp_path / "kept.md"
|
||||
kept.write_text("# Kept\n", encoding="utf-8")
|
||||
|
||||
def fake(chunk, **kwargs):
|
||||
name = getattr(chunk[0], "path", chunk[0]).name
|
||||
if name == "failed.md":
|
||||
raise ImportError("OpenAI package not installed.")
|
||||
nodes = [] if name == "omitted.md" else [
|
||||
{"id": "k", "source_file": name, "file_type": "document"}
|
||||
]
|
||||
return {"nodes": nodes, "edges": [], "hyperedges": [], "input_tokens": 1, "output_tokens": 1}
|
||||
|
||||
with patch("graphify.llm.extract_files_direct", side_effect=fake):
|
||||
result = extract_corpus_parallel(
|
||||
[failed, omitted, kept], backend="kimi", root=tmp_path,
|
||||
token_budget=None, chunk_size=1, max_concurrency=max_concurrency,
|
||||
)
|
||||
|
||||
assert result["failed_chunks"] == 1
|
||||
assert {Path(p).name for p in result["uncovered_files"]} == {"failed.md", "omitted.md"}
|
||||
lines = [line for line in capsys.readouterr().err.splitlines() if "produced no nodes" in line]
|
||||
failed_lines = [line for line in lines if "failed.md" in line]
|
||||
omitted_lines = [line for line in lines if "omitted.md" in line]
|
||||
assert failed_lines and omitted_lines
|
||||
assert all("failed before returning a response" in line for line in failed_lines)
|
||||
assert not any("returned a response but omitted" in line for line in failed_lines), (
|
||||
"a failed chunk's file was described as a model omission (#3616)"
|
||||
)
|
||||
assert all("returned a response but omitted" in line for line in omitted_lines)
|
||||
|
||||
|
||||
def test_out_of_scope_nodes_are_dropped_from_merged_result(tmp_path, capsys):
|
||||
"""#1895: the #1757 cache guard skips the CACHE write for a node attributed
|
||||
to a real corpus file that was not dispatched, but the node itself still
|
||||
|
||||
Reference in new issue
Block a user