Spaces:
Running
Running
siddhm11 Claude Opus 5.5 commited on
Commit ·
933bf47
1
Parent(s): f894733
fix(citations): a batch Semantic Scholar knows none of is all unknown
Browse filesS2's batch endpoint answers 400 "No valid paper ids given" when it knows
none of the ids, instead of a list of nulls. The daily run sorts ids, so
its last batch is papers announced a few hours earlier; on 2026-10-21 the
batch from 2610.28261 on was all unknown at 08:50 UTC (all 309 found by
18:00). _post retried the 400 fourteen times (~10 min) and the run failed
after a clean ingest, skipping its verify stage.
That answer now means "every paper unknown", the same as a null per id,
so stored counts are kept and the run goes on. Rate limits still retry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files changed (2)
86 unmodified lines87888990919286 unmodified linesr = Noneif r is not None and r.status_code == 200:return r.json()codes.append(r.status_code if r is not None else "net")if r is not None and r.status_code in (401, 403) and headers:print("[citations] S2_API_KEY rejected; using the public pool from now on", file=sys.stderr)86 unmodified lines878889909192939495969786 unmodified linesr = Noneif r is not None and r.status_code == 200:return r.json()# S2 answers 400 "No valid paper ids given" when it knows NONE of the# ids: the daily run's last batch is papers announced hours earlier.# That is every paper unknown (null each), and retrying can't change it.if r is not None and r.status_code == 400 and "No valid paper ids" in r.text:return [None] * len(ids)codes.append(r.status_code if r is not None else "net")if r is not None and r.status_code in (401, 403) and headers:print("[citations] S2_API_KEY rejected; using the public pool from now on", file=sys.stderr)
3 unmodified lines45678985 unmodified lines9596973 unmodified linesfrom pathlib import Pathfrom types import SimpleNamespace_spec = importlib.util.spec_from_file_location("refresh_citations", Path(__file__).resolve().parents[1] / "scripts" / "refresh_citations.py")rc = importlib.util.module_from_spec(_spec)85 unmodified linesstaged = sqlite3.connect(stage).execute("SELECT COUNT(*) FROM citations").fetchone()[0]assert staged == 200 # the two batches before the failure, in orderassert len(calls) <= 5 # nothing like the full 10 batches was queued3 unmodified lines456789101185 unmodified lines9798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271283 unmodified linesfrom pathlib import Pathfrom types import SimpleNamespaceimport httpx_spec = importlib.util.spec_from_file_location("refresh_citations", Path(__file__).resolve().parents[1] / "scripts" / "refresh_citations.py")rc = importlib.util.module_from_spec(_spec)85 unmodified linesstaged = sqlite3.connect(stage).execute("SELECT COUNT(*) FROM citations").fetchone()[0]assert staged == 200 # the two batches before the failure, in orderassert len(calls) <= 5 # nothing like the full 10 batches was queueddef _client(responses, seen):"""An httpx client that answers each batch POST with the next response."""def handler(request):seen.append(request)return responses.pop(0)return httpx.Client(transport=httpx.MockTransport(handler))def test_a_batch_s2_knows_none_of_is_all_unknown_not_a_failure(monkeypatch):# 2026-10-21: the daily run's last batch was papers announced that morning;# S2 answered 400 "No valid paper ids given" 14 times and the run failed.monkeypatch.setitem(rc._KEY, "value", None)monkeypatch.setattr(rc.time, "sleep", lambda s: None)seen = []client = _client([httpx.Response(400, json={"error": "No valid paper ids given"})], seen)assert rc._post(client, ["2610.28261", "2610.28263"]) == [None, None]assert len(seen) == 1 # not retrieddef test_rate_limits_are_still_retried(monkeypatch):monkeypatch.setitem(rc._KEY, "value", None)monkeypatch.setattr(rc.time, "sleep", lambda s: None)seen = []client = _client([httpx.Response(429, json={"message": "Too Many Requests"}),httpx.Response(200, json=[{"citationCount": 3}, None])], seen)assert rc._post(client, ["2608.11967", "2612.99991"]) == [{"citationCount": 3}, None]assert len(seen) == 2
scripts/refresh_citations.py+5
tests/test_refresh_citations.py+31