-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
When external paper search is enabled, each under-matched edge triggers 1 LLM call (Gemini 2.5 Flash for query extraction) + 2 Semantic Scholar API requests in parallel. With Promise.allSettled in the workflow step, all edges are searched concurrently.
For a logic model with 15 under-matched edges, this fires 15 LLM calls + 30 Semantic Scholar API requests simultaneously. Semantic Scholar's free tier allows ~100 requests per 5 minutes, so larger logic models can easily hit 429 rate limit errors.
Because Promise.allSettled swallows these errors gracefully, the user experience degrades silently — the toggle is enabled but most edges return 0 external papers.
Proposed Solution
Add a concurrency limiter to searchExternalPapersStep in mastra/workflows/logic-model-with-evidence.ts or within lib/external-paper-search.ts.
Options:
- Batch processing: Process N edges at a time (e.g., 3 concurrent edge searches)
- Library-based: Use
p-limitor similar to cap concurrent requests - Built-in backoff: Add retry with exponential backoff on 429 responses in
lib/academic-apis/semantic-scholar.ts
Relevant Files
mastra/workflows/logic-model-with-evidence.ts— Step 2.5 (searchExternalPapersStep)lib/external-paper-search.ts—searchExternalPapersForEdge()lib/academic-apis/semantic-scholar.ts—executeSearch()
Context
Identified during review of PR #194. Not blocking for merge since the feature is opt-in (requires both NEXT_PUBLIC_EXTERNAL_SEARCH_ENABLED=true and user toggle), but should be addressed before wider adoption.