Skip to content

fix(server): suggestion research survives provider search quota walls - #1862

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
imharshkumargupta:fix/web-research-quota-fallback
Oct 31, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
imharshkumargupta:fix/web-research-quota-fallback

Conversation

@imharshkumargupta

Copy link
Copy Markdown
Contributor

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, withRetry burns its 3 attempts on the same quota wall, and the whole POST /api/topics/suggest request dies. The model itself is fine — only its search tool is quota-gated.

webResearch now degrades in steps instead of failing the request:

  • With TAVILY_API_KEY set, 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.
  • Without a Tavily key, the provider's own search tool is used, unchanged.
  • When the grounded call still fails (quota, rate limit), the research retries without search so suggestions still return. searched: false and sources: 0 keep 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 — new src/lib/web-research.test.js covers the Tavily path, the Tavily-failure fallback, the quota-wall fallback, and the nothing-offers-search path.
  • With TAVILY_API_KEY unset, behavior is unchanged: provider tools, then model knowledge.
  • With a Tavily key set, the research phase calls api.tavily.com/search and the log shows sources: N from Tavily's results.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RetryError whose 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 fetch in a beforeEach, so none of them reaches the real API.
  • TAVILY_API_KEY is documented in the self-host env variables page and in server/.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.

@mintlify

mintlify Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 96d723b.

Approve preview

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gkhngyk
gkhngyk merged commit de9f34d into ansvisor:main Oct 31, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants