From 540f81ff9e7e6e769c09c8576f0d6b339a072459 Mon Sep 17 00:00:00 2001
From: Alix-007
Date: Wed, 24 Jun 2026 18:30:44 +0800
Subject: [PATCH 1/3] fix(openai_compat): use structured logger for
native_search warning
---
pkg/providers/openai_compat/provider.go | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/pkg/providers/openai_compat/provider.go b/pkg/providers/openai_compat/provider.go
index c12a8348..317a4930 100644
--- a/pkg/providers/openai_compat/provider.go
+++ b/pkg/providers/openai_compat/provider.go
@@ -160,9 +160,12 @@ func (p *Provider) buildRequestBody(
// treat it as false — web_search_preview must not be injected
// when the caller cannot express a well-typed intent.
if _, present := options["native_search"]; present {
- log.Printf(
- "[openai_compat] native_search option has unexpected type %T, ignoring",
- options["native_search"],
+ logger.WarnCF(
+ "provider.openai_compat",
+ "native_search option has unexpected type, ignoring",
+ map[string]any{
+ "type": fmt.Sprintf("%T", options["native_search"]),
+ },
)
}
}
From 5e3fd4cd0fb0d5c9d8ae65593499cc6f46641e38 Mon Sep 17 00:00:00 2001
From: Alix-007
Date: Wed, 24 Jun 2026 23:29:46 +0800
Subject: [PATCH 2/3] fix(model): handle error response read failures
---
cmd/picoclaw/internal/model/add_test.go | 16 ++++++++++++++++
cmd/picoclaw/internal/model/online.go | 5 ++++-
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/cmd/picoclaw/internal/model/add_test.go b/cmd/picoclaw/internal/model/add_test.go
index 5da4d5e7..51a61124 100644
--- a/cmd/picoclaw/internal/model/add_test.go
+++ b/cmd/picoclaw/internal/model/add_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"net/http"
"net/http/httptest"
+ "strconv"
"strings"
"testing"
@@ -68,6 +69,21 @@ func TestFetchOpenAIModels_HTTPError(t *testing.T) {
assert.Contains(t, err.Error(), "HTTP 401")
}
+func TestFetchOpenAIModels_HTTPErrorReadFailure(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ body := "short"
+ w.Header().Set("Content-Length", strconv.Itoa(len(body)+1))
+ w.WriteHeader(http.StatusUnauthorized)
+ _, _ = w.Write([]byte(body))
+ }))
+ defer srv.Close()
+
+ _, err := fetchOpenAIModels(srv.URL, "bad")
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "read error response")
+ assert.Contains(t, err.Error(), "unexpected EOF")
+}
+
func TestFetchOpenAIModels_EmptyDataEnvelope(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = w.Write([]byte(`{"data":[]}`))
diff --git a/cmd/picoclaw/internal/model/online.go b/cmd/picoclaw/internal/model/online.go
index 9b8f7811..1d1a7453 100644
--- a/cmd/picoclaw/internal/model/online.go
+++ b/cmd/picoclaw/internal/model/online.go
@@ -45,7 +45,10 @@ func fetchOpenAIModels(baseURL, apiKey string) ([]modelEntry, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
+ body, err := io.ReadAll(io.LimitReader(resp.Body, 512))
+ if err != nil {
+ return nil, fmt.Errorf("read error response: %w", err)
+ }
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
}
From f53e6e68e26d500ef0589a8f1df5253060e711fd Mon Sep 17 00:00:00 2001
From: Alix-007
Date: Wed, 24 Jun 2026 23:35:06 +0800
Subject: [PATCH 3/3] fix(model): avoid shadowing response error
---
cmd/picoclaw/internal/model/online.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/cmd/picoclaw/internal/model/online.go b/cmd/picoclaw/internal/model/online.go
index 1d1a7453..d27a261f 100644
--- a/cmd/picoclaw/internal/model/online.go
+++ b/cmd/picoclaw/internal/model/online.go
@@ -45,9 +45,9 @@ func fetchOpenAIModels(baseURL, apiKey string) ([]modelEntry, error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- body, err := io.ReadAll(io.LimitReader(resp.Body, 512))
- if err != nil {
- return nil, fmt.Errorf("read error response: %w", err)
+ body, readErr := io.ReadAll(io.LimitReader(resp.Body, 512))
+ if readErr != nil {
+ return nil, fmt.Errorf("read error response: %w", readErr)
}
return nil, fmt.Errorf("HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
}