Skip to content

feat(search): per-source rate limits and concurrency for UnifiedSearch, plus real-world fixes (#373) - #380

Merged
JonasHeinickeBio merged 5 commits into
mainfrom
feat/unified-search-rate-limits
Oct 26, 2026
Merged

JonasHeinickeBio merged 5 commits into
mainfrom
feat/unified-search-rate-limits

Conversation

@JonasHeinickeBio

@JonasHeinickeBio JonasHeinickeBio commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Per-source rate limiting and concurrency for UnifiedSearch (closes #373), plus three defects that real-world runs against the live services exposed along the way.

The feature (#373)

  • rate_limits={"arxiv": 5.0}: delay between requests per source; wins over rate_limit_delay. Order: rate_limits[source], an explicit rate_limit_delay, then 1.2 s but never below the provider's ask (arXiv, DBLP, Zenodo: 3 s, a default change, see "Changed" in the CHANGELOG).
  • source_concurrency (int or {source: n}, default 1): simultaneous calls per source across all threads sharing the object; max_workers stays the sources-per-search level.
  • The limits that applied are in every result (report.metadata["effective_limits"]); diagnostics rows add rate_limit_delay, max_concurrency, waited_seconds.

Found by running it for real (all fixed here)

  1. rate_limit_delay was never applied to a successful request by the HTTP source clients (arXiv, PubMed, DOAJ, CORE, HAL, Zenodo, DBLP, ClinicalTrials.gov): the sleep sat at the end of the retry loop, which a success leaves by returning. Measured on real arXiv with a 3 s delay: requests 0.3 s apart. Each client now reserves a start slot under a lock (BaseHTTPClient._wait_turn): arXiv now sees exactly 3.0 s between requests, from any number of threads. Searches over these sources are correspondingly slower, as the delays always intended.
  2. search(sources=[...]) skipped sources outside the configured set without a word: the MCP tool unified_search(sources=["openalex", ...]) returned only Europe PMC and PubMed. Any registered source can now be named; clients are created on first use; one that cannot be created is unavailable with the real reason; an unknown name raises ValueError.
  3. Swallowed failures looked like "no results": Semantic Scholar answers HTTP 403, DBLP now serves a bot-check page, and the OpenAlex and Europe PMC adapters catch every request error; all returned [], so a source was empty. They now record last_error, and UnifiedSearch raises it when the answer is empty: error / rate_limited with the real message.

Live result for ten sources in one call: 8 ok (79 merged records, 6 papers matched by more than one source), Semantic Scholar error: HTTPError 403, DBLP error: JSONDecodeError.

Test plan

  • test_unified_search_limits.py (21 + 11 new): delay order, validation, concurrency peaks, throttle (gaps, threads, first request free, zero delay), sources named in a call, creation once
  • test_unified_search_diagnostics.py (+7): swallowed failures, rate limit via Retry-After, partial results kept, no leak between calls, base client records non-JSON bodies
  • real-world tests tests/integration/test_real_world_unified_search.py (--run-integration, live): 11 sources reported honestly, matched sources, effective limits, and three overlapping searches reach arXiv >= the delay apart
  • full suite on brws039: exit 0; mypy src/: no issues in 220 files

🤖 Generated with Claude Code

…arch (#373)

rate_limits={source: seconds} sets the delay per source (wins over
rate_limit_delay); source_concurrency (int or dict, default 1) caps simultaneous
calls to one source across all threads sharing the object. The limits that
applied are in report.metadata["effective_limits"], and diagnostics rows add
rate_limit_delay, max_concurrency and waited_seconds. Without an explicit delay
arXiv, DBLP and Zenodo are now paced at 3 s (their provider limit / own default)
instead of 1.2 s.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation tests labels Oct 26, 2026
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1c92f77a-91a9-4a83-9f31-ae6abd209653
Commits

Reviewing files that changed from the base of the PR and between 53c1753 and 0a35123.

Files selected for processing: 13
  • CHANGELOG.md
  • docs/api/README.md
  • docs/features/multi-source-search.md
  • src/pyeuropepmc/features/common/base.py
  • src/pyeuropepmc/features/literature/adapters.py
  • src/pyeuropepmc/features/search/base.py
  • src/pyeuropepmc/features/search/sources/pubmed.py
  • src/pyeuropepmc/features/search/unified_search.py
  • src/pyeuropepmc/mcp/README.md
  • tests/features/search/unit/test_unified_search_diagnostics.py
  • tests/features/search/unit/test_unified_search_limits.py
  • tests/integration/test_real_world_unified_search.py
  • tests/mcp/e2e/test_mcp_real_world_unified.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #380      +/-   ##
==========================================
+ Coverage   82.47%   82.52%   +0.04%     
==========================================
  Files         216      216              
  Lines       32966    33052      +86     
  Branches     5957     5970      +13     
==========================================
+ Hits        27190    27276      +86     
  Misses       4491     4491              
  Partials     1285     1285              
Files with missing lines Coverage Δ
src/pyeuropepmc/features/common/base.py 87.03% <100.00%> (+3.31%) ⬆️
src/pyeuropepmc/features/literature/adapters.py 85.43% <100.00%> (+0.17%) ⬆️
src/pyeuropepmc/features/search/base.py 93.60% <100.00%> (+0.10%) ⬆️
src/pyeuropepmc/features/search/sources/pubmed.py 91.22% <100.00%> (+0.03%) ⬆️
src/pyeuropepmc/features/search/unified_search.py 97.56% <100.00%> (+0.64%) ⬆️

…t swallowed failures

Found by running the live services through UnifiedSearch:
- rate_limit_delay was never applied to a successful request by the HTTP
  source clients; each client now reserves a start slot under a lock
  (BaseHTTPClient._wait_turn), so requests start >= delay apart (arXiv: 3.0 s)
- search(sources=[...]) skipped sources outside the configured set; any
  registered source can be named, its client is created on first use
- clients that caught their own failure (Semantic Scholar 403, OpenAlex, DBLP
  bot check) looked like empty sources; last_error is raised by UnifiedSearch
- real-world tests against the live services

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@JonasHeinickeBio JonasHeinickeBio changed the title feat(search): add per-source rate limits and concurrency to UnifiedSearch (#373) feat(search): per-source rate limits and concurrency for UnifiedSearch, plus real-world fixes (#373) Oct 26, 2026
JonasHeinickeBio and others added 3 commits October 26, 2026 16:17
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…erging main

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@JonasHeinickeBio
JonasHeinickeBio merged commit d4a78d3 into main Oct 26, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add configurable per-source rate limiting to UnifiedSearch

1 participant