Skip to content

[ENG-21224] feat(web-search): add explicit fallbackProvider recovery - #290

Draft
william-antoline-boon wants to merge 3 commits into
boonfrom
eng-21224-websearch-fallback-provider
Draft

william-antoline-boon wants to merge 3 commits into
boonfrom
eng-21224-websearch-fallback-provider

Conversation

@william-antoline-boon

@william-antoline-boon william-antoline-boon commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

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_search provider 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 every web_search call 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

hasExplicitWebSearchSelection disables 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-off providerId override (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_search selection, 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 for fallbackProvider, mirroring the existing provider typo test.
  • Full suite: 70/70 passing, 0 regressions. oxlint clean on all touched files.
  • Two of the above (the cross-plugin scoping test and the CLI-override test) were hand-verified red (fail without the fix) → green (pass with it) before committing.
  • Live-validated separately (outside this PR, on a non-customer canary host through the real production LLM/gateway path) that an alternative provider genuinely recovers a DuckDuckGo bot-detection failure end-to-end — this PR is the generalized, reviewed version of that same mechanism.

Before merging

  • Team confirms the fallback-chain approach (vs. switching the primary provider outright) for ENG-21224
  • Final fallback provider decided (tests currently target Brave — the leading candidate pending a vendor/data-handling review)
  • Fleet-side config wiring (inventory.yaml:fleet_desired_config, a real API key) happens separately in gandalf-manager, after this merges and releases

william-antoline-boon and others added 2 commits October 14, 2026 17:03
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]>
@william-antoline-boon

Copy link
Copy Markdown
Collaborator Author

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: runWebSearch scopes which plugins even get loaded into candidates (onlyPluginIds) based on the primary provider's owning plugin — before the new fallback code ever runs. That scope never accounted for fallbackProvider, so a cross-plugin fallback (DuckDuckGo primary → Brave fallback, this PR's own flagship example) was silently filtered out before it ever reached the candidate list. The feature was dead code for exactly the case it was built for. The original 3 new tests all passed anyway, because their mocks returned a fixed provider list regardless of the onlyPluginIds they were called with — they didn't simulate the real scoping filter.

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:

  • resolveExplicitWebSearchProviderPluginIds now also resolves fallbackProvider's owning plugin and includes it in scope (falls back to unscoped loading if either id's ownership is unknown, rather than risk a silent drop).
  • Added a second gap found in the same pass: fallbackProvider had no config-time typo validation (unlike provider) — fixed by parameterizing validateWebSearchProvider to cover both fields.
  • New regression test verified red (fails without the fix) → green (passes with it) by hand before committing, using a mock that actually filters by onlyPluginIds instead of ignoring it.

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]>
@william-antoline-boon

Copy link
Copy Markdown
Collaborator Author

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 providerId directly into runWebSearch.

Found: openclaw capability web search --provider <id> is a real operator diagnostic command — its entire purpose is observing one specific provider's actual behavior (e.g. during an incident: "is Google actually down right now?"). The fallback logic didn't distinguish "primary came from config" from "primary came from this one-off CLI override," so a fleet-wide fallbackProvider policy would silently substitute a different provider's success for that diagnostic command too — masking exactly the failure the engineer was trying to isolate.

Fixed: fallbackProvider is now only consulted when the primary came from config (tools.web.search.provider), never from a direct providerId call parameter. New test, verified red/green by hand.

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.)

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.

1 participant