~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.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(journal-quality): bump retry budget for OpenAlex partition fetches (#3685)
LearningCircuit6b06525b8477
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.pyindex 61fdb3cd46..eeb5ffe1da 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@@ -58,6 +58,22 @@ def validate_manifest_entries(entries: list[dict], label: str) -> None:)+# Per-partition retry budget. The default ``safe_get_with_retries``+# budget (3 retries, 1-2-4 s backoff = ~7 s total) is sized for small+# request bodies and trips on a sustained mid-stream S3 hiccup: every+# retry of a ~5–10 MB partition that lands inside the same bad window+# fails the same way, exhausts the budget in seconds, and aborts the+# whole 30-partition pull. The release-gate workflow saw this twice in+# a row on 2026-04-26.+#+# 5 retries with 2-5-10-20-40 s backoff rides out a ~75 s S3 blip+# instead, while still bounding total wall-clock per partition at+# roughly ``timeout * 6 + 77 s`` — well inside the 45 min job timeout+# even if every partition needed all retries.+_PARTITION_MAX_RETRIES = 5+_PARTITION_BACKOFF_SECONDS = (2, 5, 10, 20, 40)++def iter_partitions(entries: list[dict],data_dir: Path,@@ -66,6 +82,8 @@ def iter_partitions(label: str,safe_get: Callable,timeout: int = 120,+ max_retries: int = _PARTITION_MAX_RETRIES,+ backoff_times: tuple = _PARTITION_BACKOFF_SECONDS,) -> Iterator[Tuple[int, int, list[dict]]]:"""Download each partition, yielding ``(idx, total_parts, records)``.@@ -95,6 +113,14 @@ def iter_partitions(retried inside the wrapper, not propagated to abort thewhole multi-partition pull.timeout: Per-partition HTTP timeout (seconds).+ max_retries: Per-partition retry budget. Defaults higher than+ ``safe_get_with_retries``' generic 3 because partition+ bodies are MB-sized and a mid-stream IncompleteRead aborts+ the whole multi-partition pull on exhaustion.+ backoff_times: Per-attempt sleep schedule. Defaults to a+ longer schedule than the generic ``safe_get_with_retries``+ (1, 2, 4) so we ride out a sustained S3 blip instead of+ burning all retries inside the same bad window."""malformed_total = 0total_parts = len(entries)@@ -112,7 +138,13 @@ def iter_partitions(# 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 = safe_get(+ part_url,+ timeout=timeout,+ consume_body=True,+ max_retries=max_retries,+ backoff_times=backoff_times,+ )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.pyindex 262a74792c..c5e77a9f62 100644--- a/tests/journal_quality/test_openalex_common.py+++ b/tests/journal_quality/test_openalex_common.py@@ -162,6 +162,76 @@ class TestIterPartitions:f"got kwargs={kwargs!r}")+ def test_uses_higher_retry_budget_than_safe_get_default(self, tmp_path):+ """Partition fetches must override the generic safe_get retry budget.++ ``safe_get_with_retries`` defaults to 3 retries with (1, 2, 4) s+ backoff — ~7 s of total resilience, sized for small request+ bodies. OpenAlex partitions are MB-sized and a sustained S3+ blip (≥ ~10 s of mid-stream IncompleteReads) trips every retry+ inside the same bad window, exhausting the budget and aborting+ the whole multi-partition pull. The release-gate workflow saw+ this twice in a row on 2026-04-26.++ ``iter_partitions`` is responsible for setting a longer-lived+ retry budget. Assert that the kwargs passed to ``safe_get``+ request more than 3 retries AND a backoff schedule whose total+ sleep exceeds the generic 7 s.+ """+ 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="retry_budget_test",+ label="test",+ safe_get=safe_get,+ )+ )++ _, kwargs = safe_get.call_args+ assert kwargs.get("max_retries", 3) > 3, (+ f"partition fetch must use more than the safe_get default of "+ f"3 retries; got max_retries={kwargs.get('max_retries')!r}"+ )+ backoff = kwargs.get("backoff_times")+ assert backoff is not None and sum(backoff) > 7, (+ f"partition fetch must use a longer total backoff than the "+ f"safe_get default of 1+2+4=7s; got backoff_times={backoff!r}"+ )++ def test_forwards_overridden_retry_kwargs_to_safe_get(self, tmp_path):+ """Caller-supplied ``max_retries`` / ``backoff_times`` win.++ Default tuning lives in ``iter_partitions``, but downstream+ callers must still be able to override (e.g. tests that don't+ want to wait, or future callers with different SLAs).+ """+ 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="override_test",+ label="test",+ safe_get=safe_get,+ max_retries=1,+ backoff_times=(0,),+ )+ )++ _, kwargs = safe_get.call_args+ assert kwargs.get("max_retries") == 1+ assert kwargs.get("backoff_times") == (0,)+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"}]