Repository navigation
[ENG-21224] feat(web-search): add explicit fallbackProvider recovery - #290
william-antoline-boon wants to merge 3 commits into
Conversation
DuckDuckGo's bot-detection wall (unofficial HTML scrape, flagged by AWS hosting-range IPs) throws with zero recovery today: the moment a web_search provider is explicitly named, hasExplicitWebSearchSelection disables ALL fallback, by upstream design (key-free providers require explicit naming; an explicit choice is honored, not silently overridden). That's correct for respecting an operator's choice, but leaves no path to recover from a transient upstream failure on the chosen provider when a second, working provider is configured and available. Add a new, separately opt-in `fallbackProvider` config field: when the explicit primary throws, give exactly one named fallback provider one recovery attempt before failing. Naming a provider here is its own explicit consent, same principle as naming the primary, so this does not reopen general auto-detect-style fallback. If the fallback also fails, the error reported is the ORIGINAL primary's, not the fallback's, so operators still see the root cause. Zero behavior change when fallbackProvider is unset (regression-tested). Co-Authored-By: Claude Sonnet 5 <[email protected]>
…d scope Three independent adversarial reviews (plus manual verification against a red/green test) found a critical bug: when an explicit `provider` has known manifest ownership (true for every bundled provider in production), candidate loading is scoped to ONLY that provider's owning plugin (`onlyPluginIds`) before runWebSearch's loop ever runs. The fallback-recovery logic added in the prior commit never accounted for this — `fallbackProvider`'s owning plugin was never added to that scope, so a cross-plugin fallback (the PR's own flagship example: DuckDuckGo primary, Brave fallback) was silently filtered out before it ever reached `candidates`, making the whole feature dead code for exactly the case it was built for. Fix: resolveExplicitWebSearchProviderPluginIds now also resolves fallbackProvider's owning plugin and includes it in onlyPluginIds. Unknown ownership for either id now falls back to unscoped loading (the existing safe default) rather than risking a silent drop. Also fixes a second, related gap the reviews surfaced: fallbackProvider had no config-time validation, unlike provider, so a typo'd fallback id passed validation cleanly and then silently did nothing at runtime -- directly undercutting the field's own point of keeping failures visible. validateWebSearchProvider is now parameterized and runs for both fields. New tests: - runtime.test.ts: a scoping-fix regression test using a mock that actually filters by onlyPluginIds (unlike the existing fallback tests' fixed-return mocks, which could not have caught this) -- verified red (fails without the fix) / green (passes with it) by hand before committing. - config.web-search-provider.test.ts: fallbackProvider typo validation, mirroring the existing provider typo test. 69/69 tests passing, oxlint clean. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Update: 3 independent adversarial reviews found and fixed a critical bug before this went anywhere near real review. The original version of this PR had the fallback logic correctly written in isolation, but missed something upstream: Caught this via 3 independent fresh-context review agents (not just re-reading my own code), all three converging on the same root cause independently. Fixed in the latest commit:
69/69 tests passing, oxlint clean. Still a draft, same reasoning as before — ready once the team decides. |
…I overrides A 4th round of independent review (3 more agents) traced every real call site that can pass an explicit providerId directly into runWebSearch and found a genuine gap: `openclaw capability web search --provider <id>` is a real operator diagnostic command whose entire purpose is observing one specific provider's actual behavior. Because the fallback-recovery added in the prior commits didn't distinguish "primary came from config" from "primary came from a one-off caller override", a configured fallbackProvider would silently substitute a different provider's success for that command too -- masking exactly the failure an on-call engineer is trying to isolate during an incident. Fix: fallbackProvider is now only consulted when the primary came from config (tools.web.search.provider), not from a direct providerId call parameter. New test, verified red (fails without the guard) / green (passes with it) by hand. Also tightens the existing typo-validation test to assert exactly one validation issue, after review found its primary provider id wasn't itself registered in that test file's mocked manifest, which could produce a second, unasserted issue alongside the intended one. 70/70 tests passing, oxlint clean. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
Round 2: 3 more independent reviews, one more real bug found and fixed. This pass specifically targeted the two fixes from the last round (new code = new bug surface) plus a fresh angle: every real call site that can pass Found: Fixed: Also: tightened the typo-validation test to assert exactly one issue, after review found its primary provider id wasn't itself registered in that test file's mock manifest (a second, unasserted issue could've been hiding alongside the intended one). Everything else from this round came back clean: the "unset = unchanged behavior" claim re-traced and confirmed airtight, the unscoped-fallback-on-unknown-ownership behavior confirmed as a deliberate new-field-only tradeoff (can't regress anyone who predates this PR), and a repo-wide grep confirmed no other test asserts the validation message strings this PR's refactor touches. 70/70 tests passing, oxlint clean. Still draft. (Aside, unrelated to correctness: one of the parallel review agents hit a stash-index race against a concurrent session sharing this checkout mid-verification — recovered cleanly, no work lost, worktree left in the state it was found. Flagging only for the record, not a PR concern.) |
Related: ENG-21224 (DuckDuckGo bot-detection breaking web_search on the boon-agent fleet)
STATUS: draft, do not merge yet. This is ready to merge once the team confirms the fallback-provider approach for ENG-21224 (vs. an alternative like a straight provider swap) and the final fallback provider is picked. The code is provider-agnostic — nothing here hardcodes a specific vendor — but the concrete tests below demonstrate the currently-favored target (DuckDuckGo primary, Brave fallback).
See the pinned comments below for two critical bugs found and fixed across two rounds of independent adversarial review (6 agents total) before this went to a human reviewer.
What Problem This Solves
Resolves a problem where an operator who explicitly names a
web_searchprovider has zero recovery when that provider has a transient upstream failure — even when a second, working provider is configured. On the boon-agent fleet this surfaces as DuckDuckGo's bot-detection wall (an unofficial HTML scrape, flagged by anti-bot systems for coming from AWS hosting-range IPs) failing everyweb_searchcall for the rest of that turn, with the agent unable to look up current information, even though nothing else was tried.Why This Change Was Made
hasExplicitWebSearchSelectiondisables all fallback the moment a provider is named explicitly — correct behavior for honoring an operator's deliberate choice (and required, since key-free providers like DuckDuckGo can only be used via explicit naming), but it leaves no recovery path at all. This change adds one new, separately opt-in config field,tools.web.search.fallbackProvider: when the explicit primary throws, give exactly one named fallback provider one recovery attempt before failing. Naming a provider here is its own explicit consent — the same principle as naming the primary — so this does not reopen general auto-detect-style fallback for every other explicit-selection user. If the fallback also fails, the error surfaced is the original primary's, not the fallback's, so operators still see the real root cause in logs/Sentry. It also only applies when the primary came from config, not from a one-offproviderIdoverride (e.g. a diagnostic CLI command), so it can't mask the exact failure an operator is deliberately trying to isolate.Unset, behavior is byte-for-byte unchanged (regression-tested below).
User Impact
Operators can configure a safety-net provider for an explicit
web_searchselection, without giving up the "respect my explicit choice" guarantee for every other provider failure mode, and without that safety net interfering with one-off diagnostic provider overrides. No UI change; config + docs only (docs/tools/web.md).Evidence
src/web-search/runtime.test.ts: 6 fallback-specific tests covering recovery, both failure-reporting paths (thrown error and structured{error: ...}return), the unset no-op case, the cross-plugin scoping fix, and the CLI-override scoping fix.src/config/config.web-search-provider.test.ts: typo validation forfallbackProvider, mirroring the existingprovidertypo test.oxlintclean on all touched files.Before merging
inventory.yaml:fleet_desired_config, a real API key) happens separately ingandalf-manager, after this merges and releases