GeezerVison is showing github.com — websearch: custom providers cannot signal rate limits — excluded from provider failover · Issue #58327 · anomalyco/opencode
websearch: custom providers cannot signal rate limits — excluded from provider failover #58327DescriptionSummary
Built-in websearch providers participate in the HTTP-429 → Retry-After cooldown → switch-to-another-available-provider path, but custom providers registered via ctx.websearch.transform have no way to signal a rate limit: any execute() failure surfaces as ServiceUnavailableError and hard-fails the search. A pinned plugin provider therefore loses the failover story built-ins get for free.
Environment
- opencode version: 2.1.2
- OS: Darwin 25.6.0 (darwin arm64)
- Terminal: ghostty (
TERM=xterm-ghostty)
- Shell: /bin/zsh
- Install/channel: release (Homebrew tap,
channel=latest)
- Active plugins: custom websearch provider via
ctx.websearch.transform (plus two unrelated plugins)
Reproduction
- Register a websearch provider whose
execute() throws an error carrying .status = 429:
export default {
id: "failtest",
async setup(ctx) {
await ctx.websearch.transform((editor) => {
editor.add({
id: "fail429",
name: "Fail 429",
execute: async () => {
const e = new Error("forced 429");
e.status = 429;
throw e;
},
});
});
},
};
- Pin it in config:
"websearch": { "provider": "fail429" } (with TAVILY_API_KEY present so a healthy built-in provider is available).
- Trigger a search:
opencode api post /api/websearch -d '{"query":"anything"}'.
Observed response:
{"_tag":"ServiceUnavailableError","message":"Web search request failed: fail429","service":"fail429"}
No retry occurs on the available tavily provider. A plain throw new Error(...) behaves identically.
Expected Behavior
A documented error contract that a custom provider can use to signal rate limiting — e.g. a typed WebSearch.RateLimited { retryAfter? } error (or honoring status/retryAfter on thrown errors) — which the provider selector treats with the same cooldown + switch-provider behavior it applies to built-ins.
Actual Behavior
Plugin errors are opaque: wrapped as ServiceUnavailableError, request fails. The 429 handling ("Web search rate limited (HTTP 429)" status map + Retry-After cooldown) exists only inside the built-in providers' own HTTP call path; the WebSearch.* error taxonomy exposes ProviderRequired/ProviderNotFound but no rate-limited kind.
Additional Context
"random" selection also appears to consider built-ins only: with a custom provider registered and a key present, random picked a built-in 4/4 times — custom providers currently participate only via explicit pinning.
- Current workaround we ship: the plugin itself catches Brave failures and queries the Tavily REST API as a fallback. It works, but every provider-plugin author would re-implement core failover/cooldown logic with no shared state.
- Docs nicety: state which selection/failover semantics apply to plugin-registered providers.
Activityopencode-agent commented on Oct 23, 2026 Thanks for the detailed write-up and the minimal repro plugin!
In short, you're asking for a documented way for a custom web search provider (registered via ctx.websearch.transform) to report a rate limit, so it gets the same cooldown and provider switching as the built-in providers.
Here's how the current code (packages/core/src/websearch.ts) behaves:
- Cooldown and switching only run when
websearch.provider is "random", and only when the failure is an HTTP client error with status 429 (Retry-After sets the cooldown). With a pinned provider, built-in or custom, any failure ends the search. So pinning fail429 would not fail over even with a proper 429.
- In
"random" mode, the selector does include plugin-registered providers. A provider is reused for the session until it is rate limited, so a few built-in picks in a row is probably chance plus that stickiness, not exclusion.
- The gap you found is real: an error thrown from a plugin's
execute() is never recognised as a rate limit, and the plugin API has no rate-limited error type or retryAfter field. Because the cooldown state lives inside core, a plugin can't fully fix this on its own. Your in-plugin fallback is the best workaround for now.
A possible addition to the plugin API would be an exported RateLimited error with an optional retryAfter, or having the promise adapter honour status: 429 / retryAfter on thrown errors, which the selector would then handle like a built-in 429. Documenting that failover only applies to "random" would also help. Maintainers will consider this.
Related:
nazerim commented on Oct 23, 2026 Thanks for the careful triage — two corrections to my report, on your read of the code:
- My repro overstates the failover story. I pinned
fail429 and read the hard-fail as "custom providers are excluded from failover", but a pinned provider never fails over whether built-in or custom — the switching is random-mode only. The title/summary should be read accordingly.
random does include plugin-registered providers. My "built-ins picked 4/4" observation was the session stickiness (first pick reused until a rate limit), not exclusion — the same confound websearch: V2 keyless search is undocumented and "random" can stick to a failing provider #54311 describes.
What remains, and what you confirmed is real: in random mode, a built-in's 429 cools down and switches, while a 429 from a plugin provider's execute() is opaque — wrapped as ServiceUnavailableError, search ends — and there is no typed signal or retryAfter a plugin can surface. An exported RateLimited { retryAfter? } (or the promise adapter honoring status: 429 / retryAfter on thrown errors) is exactly the shape I'd hope for, and documenting failover as random-only would help — I misread the semantics precisely because it isn't documented.
Question: is that contract in scope for #50938 (the web search errors/limits rework)? If so I'm happy to test that branch against the fail429 repro. Context: #58334 re-lands Brave as a built-in, which would solve our specific deployment, but the plugin gap stands for any out-of-tree provider.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|