Skip to content

feat(ai): search the web through a chain of providers #3925

Closed

Description

@dan-petty

Problem

Web search has one backend in main: firecrawl_search (HTTP 402 since the credit ran out). PR #3900 (#3876) adds a DuckDuckGo fallback but keeps Firecrawl first and adds a second counter. The owner asked on 2026-11-07 for a local SearXNG. Each provider added as one more except branch makes the code worse. The owner chose not to use the Brave Search API (its terms forbid storing results and it has no free tier), so the chain has no keyed provider for now.

Expected

One entry point web_search(query, *, limit) over a list of providers, in a new module of src/devops_cli/ai/. A SearchHit with url, title, snippet and provider. A SearchProvider protocol with name, configured(settings) and search(query, *, limit). Providers in this item: duckduckgo (the function duckduckgo_search of #3900, moved) and firecrawl (the function firecrawl_search, moved). The next item adds searxng. A later provider with a key needs only a new class and a name in the list.

Settings: new section search with providers (default [searxng, duckduckgo, firecrawl], an unknown name is a validation error) and language (default en). The section joins the section table in config/constants.py. search.searxng_url comes with its provider item.

Order and failover: a provider that is not configured is skipped; a provider that fails (timeout, connect error, 402, 429, 5xx, 401, 403, other 4xx, a reply that is not JSON or has no list) passes the search on at once, with no retry and no sleep; a healthy empty reply also passes it on; the first provider with at least one hit wins; if none answered, SearchFailed is raised; if some answered empty and the rest failed, the result is an empty list. A total deadline of 60 s ends the chain. Dedup of one answer by the normalized URL (the key function of alternatives.py, moved here), the URL scheme must be http or https.

Guard on the query before any provider: refuse an empty query, a query over 400 characters or 50 words, a query that starts with ! or :, and a query that holds a secret (mask_secrets), an e-mail address, a private IP address or an internal host name. SearchQueryRefused is raised and no provider runs.

Callers: cited_web_search, InvestigationTools, AlternativesTools, WebSearch and web_search_of lose the key argument (a provider reads its own credential). The gate: web search is on for a public repository when at least one provider is configured. request_plan.py lists the request of the first configured provider in the dry run and makes no request.

Metric: one counter devops_cli_web_searches_total{backend,result} replaces devops_cli_firecrawl_searches_total and devops_cli_web_search_fallbacks_total (no shim). backend is a provider name or none; result is ok, empty, degraded, error, refused, exhausted or an HTTP status. Change in the same pull request: the alerts RoadmapServiceFirecrawlRefused (rename to RoadmapServiceWebSearchRefused) and RoadmapServiceAlternativesNotSearching, their rule tests, docs/TELEMETRY.md, k8s/README.md, docs/roadmap/alternatives.md, docs/roadmap/refine.md, the messages in lang/en/messages.py, and any dashboard that reads the old names.

Acceptance criteria

  • Tests with the HTTP fake fail on the base: the first provider answers and the others do not run; a 402, a 429, a 5xx and a timeout each pass the search to the next provider and count the backend and the result; a healthy empty reply passes on; all providers fail and SearchFailed is raised; an empty list returns when one answered empty and the rest failed.
  • A test: an unconfigured provider is skipped and not counted.
  • A test: each refused query (secret, e-mail address, private address, leading !, over the cap) raises SearchQueryRefused and sends no request.
  • A test: a caller (cited_web_search) turns SearchFailed and SearchQueryRefused into a text answer and does not stop the run.
  • A test: a log line of a failed attempt holds the backend and the status or class, and never the key or the query.
  • tests/roadmap/test_roadmap_dry_runs.py still passes: the dry run makes zero requests.
  • The Prometheus rule tests for the renamed and changed alerts fail on the base and pass; git grep finds no devops_cli_firecrawl_searches_total and no devops_cli_web_search_fallbacks_total outside openspec/changes/archive.
  • The generated docs (devops docs generate --sync-readme) list the section search, its environment variables and the counter.

Existing tool considered

The code of #3900 (ddgs engine parts through http_client) and the existing firecrawl_search are moved, not rewritten. pydantic-ai search tools are not used: they take no transport, so they skip the egress check (the finding of the #3876 comment of 2026-11-07, SECURITY.md rule 2). No failover library: the rules are 30 lines and the project's HTTP entry point already gives timeouts and the egress check.

Related

Related: #3876 (merge PR #3900 first), #2398, #2650, #3243, #3915, #3877, #2475. Next: the SearXNG provider item.

Part of the search provider plan of 2026-11-07 (SearXNG; the Brave Search API was dropped by the owner on 2026-11-07).

Activity

  1. added
    source/agent
    type/feature
    scope/ai
    status/new
    value/high
    effort/high
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. The current single backend is degraded (HTTP 402), but the system still runs. This is a planned architectural improvement, not a blocking defect.
    • Value: High. Multiple providers with failover make web search reliable and ready for future providers such as SearXNG and Brave.
    • Effort: High. New module, protocol, settings section, failover logic, query guards, metrics migration, caller updates, alert renames, and tests span many files.
    • Related: feat(ai): web search falls back to DuckDuckGo after Firecrawl #3876, which asks for a different change. Both change web search in src/devops_cli/ai/. #3876 adds a single fallback; the candidate builds a full provider chain with protocol, settings, failover, guards, and metrics.
  3. added
    priority/p2-medium
    owner/agent
    status/in-review
    and removed
    status/new
    on Nov 7, 2026
  4. removed
    status/in-review
    owner/agent
    on Nov 7, 2026
  5. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-07 13:09 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p2-mediumscope/aisource/agenttype/featurevalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions