p3: tavily parse errors degrade; retry DNS on search

A 200 with a bad Tavily body is tavily: error, not an empty success
that would cache for the hour. Upstream clients stay in the source
list if DNS is down at boot and retry the pin on Search; /healthz
lists them as unresolved until a pin lands.
This commit is contained in:
2026-09-23 12:22:31 -07:00
parent f748e695b1
commit 429f6b207e
8 changed files with 177 additions and 51 deletions
+18 -2
View File
@@ -30,6 +30,16 @@ func warnErr(name string, err error) string {
return name + ": error"
}
func pinErr(ctx context.Context, c *dial.Client, name string) string {
if c == nil {
return name + ": error"
}
if err := c.Ensure(ctx); err != nil {
return warnErr(name, err)
}
return ""
}
func readJSON(resp *http.Response, dest any) error {
defer resp.Body.Close()
if resp.StatusCode != 200 {
@@ -46,12 +56,16 @@ type SearxNG struct {
}
func (s *SearxNG) Name() string { return NameSearxNG }
func (s *SearxNG) Ready() bool { return s != nil && s.Client.Ready() }
func (s *BraveLLM) Ready() bool { return s != nil && s.Client.Ready() }
func (s *SearxNG) Search(ctx context.Context, query string, k int) SourceOut {
if s == nil || s.Client == nil {
return SourceOut{Warn: NameSearxNG + ": error"}
}
_ = s.Client.RefreshIfStale(ctx)
if w := pinErr(ctx, s.Client, NameSearxNG); w != "" {
return SourceOut{Warn: w}
}
base := strings.TrimRight(s.Client.URL.String(), "/")
u, err := url.Parse(base + "/search")
if err != nil {
@@ -110,7 +124,9 @@ func (s *BraveLLM) Search(ctx context.Context, query string, k int) SourceOut {
if s == nil || s.Client == nil {
return SourceOut{Warn: NameBraveLLM + ": error"}
}
_ = s.Client.RefreshIfStale(ctx)
if w := pinErr(ctx, s.Client, NameBraveLLM); w != "" {
return SourceOut{Warn: w}
}
u, err := url.Parse(s.Client.URL.String())
if err != nil {
return SourceOut{Warn: warnErr(NameBraveLLM, err)}