Back off on Semantic Scholar rate limits and cache aggressively

#2
by davanstrien HF Staff - opened

The Space was stuck in RUNTIME_ERROR: example caching at startup hit unauthenticated Semantic Scholar 429s, which surfaced as KeyError 'recommendedPapers' and killed launch.

  • Retry S2 calls with exponential backoff + jitter via stamina (429, 5xx, network errors; 6 attempts, 120 s budget)
  • raise_for_status + 30 s request timeout; distinct user-facing message for rate limiting vs not-indexed
  • Cache recommendations for 7 days (maxsize 10k) instead of 6 h / 500
  • cache_examples='lazy' so an S2 outage can't stop startup
  • Optional S2_API_KEY secret sent as x-api-key

๐Ÿค– Generated with Claude Code

https://claude.ai/code/session_01CVY2JFkXfL8hsUc8x7FUPr

Update: bumped all deps (gradio 6.1โ†’6.30, huggingface-hub 1.2โ†’2.3, cachetools 6โ†’7, starlette 0.50โ†’1.9, requests 2.32โ†’2.34 โ€ฆ) and dropped unused datasets, beautifulsoup4, lxml (removes pandas/pyarrow from the image). Also fixed lazy caching: gradio 6 wants cache_examples=True, cache_mode="lazy", not cache_examples="lazy".

Smoke-tested locally on both the old and new pins (CommitScheduler stubbed): app launches, /return_recommendations endpoint name unchanged, returns recommendations for 2309.12307.

Ready for merge

davanstrien changed pull request status to open

Merging: S2 backoff + caching + dep bump

davanstrien changed pull request status to merged

Sign up or log in to comment