Repository navigation
fix(server): suggestion research survives provider search quota walls - #1862
Conversation
Google Search grounding 429s on free AI Studio keys, which 500s the whole topic-suggestion flow (3 attempts, then die). webResearch now: - runs Tavily research first when TAVILY_API_KEY is set (search via Tavily, query distilled and results synthesized by plain model calls), - falls back to the provider's own search tool when no Tavily key, - and when that call fails (quota, rate limit), retries the research without search so suggestions still return, logged as sources: 0.
There was a problem hiding this comment.
Welcome to Ansvisor, and thank you for your first PR! A maintainer will be by soon to review.
In the meantime, two things that make review faster:
- A short description of why the change matters, not just what it does — most of our PRs link a
Fixes #...to the issue that explains the why. - A quick local test note if there's anything worth eyeballing in the browser.
If you'd like to keep an eye on where Ansvisor goes next, a ⭐ on the repo helps others discover it (and Watch sends you a ping when related issues land). Either way — looking forward to your next one.
Other grounded-call failures reach the caller instead of quietly becoming research without search. The Tavily search gets a 15s timeout, the tests stub fetch before each test so none reaches the real API, and TAVILY_API_KEY is listed in the self-host env docs.
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks for this. Approving with one commit on top (6b9e33e), pushed to this branch:
- The grounded call now falls back to research without search only on a quota or rate-limit wall (a 429, or a
RetryErrorwhose last error is one). Other errors (a bad key, a wrong model id, a 5xx) reach the caller as before. - The Tavily request has a 15-second timeout.
- The tests stub
fetchin abeforeEach, so none of them reaches the real API. TAVILY_API_KEYis documented in the self-host env variables page and inserver/.env.example, with its cost per search.
New tests cover a non-quota failure (rethrown, no second call), the timeout signal and a 429 inside a RetryError. We'll merge after a manual check with a Tavily key.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks again. Merging now: this commit merges current main into the branch, and its tree is what main will be after this squash, checked with the full server and web suites, tsc, lint, format and next build.
What changed and why
On a self-hosted instance with a free Google AI Studio key, topic suggestions 500: the research phase's Search grounding call 429s,
withRetryburns its 3 attempts on the same quota wall, and the wholePOST /api/topics/suggestrequest dies. The model itself is fine — only its search tool is quota-gated.webResearchnow degrades in steps instead of failing the request:TAVILY_API_KEYset, research runs through Tavily: one plain-model call distills the research prompt into a short query, Tavily fetches the results, and a plain-model call synthesizes them. No new dependency, just a fetch.searched: falseandsources: 0keep the downgrade visible in the logs.Both callers benefit: topic suggestions and the competitor research route. The key is documented in
server/.env.example.How to test
npm test— newsrc/lib/web-research.test.jscovers the Tavily path, the Tavily-failure fallback, the quota-wall fallback, and the nothing-offers-search path.TAVILY_API_KEYunset, behavior is unchanged: provider tools, then model knowledge.api.tavily.com/searchand the log showssources: Nfrom Tavily's results.