Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(journal-quality): pass consume_body=True from iter_partitions (#3652)

LearningCircuitb2b375f2c3df
diff --git a/src/local_deep_research/journal_quality/data_sources/_openalex_common.py b/src/local_deep_research/journal_quality/data_sources/_openalex_common.py
index 6fb58cb345..61fdb3cd46 100644
--- a/src/local_deep_research/journal_quality/data_sources/_openalex_common.py
+++ b/src/local_deep_research/journal_quality/data_sources/_openalex_common.py
@@ -89,7 +89,11 @@ def iter_partitions(
(e.g. ``"OpenAlex sources"`` / ``"Institutions"``).
safe_get: Dependency-injected HTTP getter (lets the caller
pick ``safe_get_with_retries`` without forcing a global
- import at module load).
+ import at module load). Must accept ``consume_body=True``
+ so body-stream transients (``ChunkedEncodingError``,
+ ``ReadTimeout``) raised during ``resp.content`` are
+ retried inside the wrapper, not propagated to abort the
+ whole multi-partition pull.
timeout: Per-partition HTTP timeout (seconds).
"""
malformed_total = 0
@@ -101,7 +105,14 @@ def iter_partitions(
records: list[dict] = []
try:
- resp = safe_get(part_url, timeout=timeout)
+ # consume_body=True: an OpenAlex S3 partition is ~10 MB
+ # gzipped. A mid-stream ChunkedEncodingError /
+ # IncompleteRead would otherwise abort the whole 30+
+ # partition pull. With consume_body, safe_get_with_retries
+ # reads resp.content inside its retry loop and retries
+ # body-stream transients the same way it retries
+ # header-stage failures.
+ resp = safe_get(part_url, timeout=timeout, consume_body=True)
resp.raise_for_status()
tmp_part.write_bytes(resp.content)
diff --git a/tests/journal_quality/test_openalex_common.py b/tests/journal_quality/test_openalex_common.py
index 692a395f48..262a74792c 100644
--- a/tests/journal_quality/test_openalex_common.py
+++ b/tests/journal_quality/test_openalex_common.py
@@ -129,6 +129,39 @@ class TestIterPartitions:
leftover = list(tmp_path.glob(".err_test_part_*.gz"))
assert leftover == []
+ def test_passes_consume_body_to_safe_get(self, tmp_path):
+ """``iter_partitions`` must pass ``consume_body=True`` to safe_get.
+
+ Body-stream transients (``ChunkedEncodingError`` / ``ReadTimeout``
+ raised during ``resp.content``) are retried by
+ ``safe_get_with_retries`` only when ``consume_body=True``. Without
+ this flag the wrapper returns headers-only and a mid-stream
+ IncompleteRead aborts the whole multi-partition download — the
+ exact failure shape that hit CI on the journal-data-integration
+ workflow.
+ """
+ entries = [{"url": "s3://openalex/data/sources/part_0.gz"}]
+ safe_get = MagicMock(
+ return_value=_response(_gz_lines([b'{"id": "S1"}']))
+ )
+
+ list(
+ iter_partitions(
+ entries,
+ tmp_path,
+ file_prefix="consume_body_test",
+ label="test",
+ safe_get=safe_get,
+ )
+ )
+
+ assert safe_get.call_count == 1
+ _, kwargs = safe_get.call_args
+ assert kwargs.get("consume_body") is True, (
+ f"iter_partitions must call safe_get with consume_body=True; "
+ f"got kwargs={kwargs!r}"
+ )
+
def test_suppresses_malformed_lines(self, tmp_path, caplog):
"""Bad JSON lines are skipped, not fatal; first-10 warnings logged."""
entries = [{"url": "s3://openalex/data/sources/part_0.gz"}]