fix(web_search): add diagnostic logging for Brave empty results

When the Brave Search API returns HTTP 200 with zero results, log a
warning with the response body preview to help diagnose silent failures.
This addresses cases where the API response format has changed or a
non-standard error response is misinterpreted as a successful empty
result, leaving the LLM with a misleading "No results" message.

Previously, empty results were silently returned to the LLM as "No
results for: <query>", making it impossible to distinguish between
genuinely empty results and API format mismatches or silent errors.

Closes #3125
This commit is contained in:
徐金城0668000897 2026-06-17 15:50:28 +08:00
parent a16a1e1535
commit b2fbe83565

View file

@ -350,6 +350,19 @@ func (p *BraveSearchProvider) Search(
results := searchResp.Web.Results
if len(results) == 0 {
// Log a warning when the API returned 200 but no results.
// This helps diagnose API format changes or silent errors
// where the response body does not match the expected structure.
bodyPreview := string(body)
if len(bodyPreview) > 300 {
bodyPreview = bodyPreview[:300]
}
logger.WarnCF("web_search", "Brave API returned empty results",
map[string]any{
"query": query,
"status": resp.StatusCode,
"body_preview": bodyPreview,
})
return fmt.Sprintf("No results for: %s", query), nil
}