RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(go-models): harden LongCat default transport handling (#15340)
glorydavid03023ff9aa4e2c7d5
diff --git a/internal/entity/models/longcat.go b/internal/entity/models/longcat.goindex 1f9c17571d..c4644a58bf 100644--- a/internal/entity/models/longcat.go+++ b/internal/entity/models/longcat.go@@ -60,7 +60,15 @@ type LongCatModel struct {// long-lived SSE streams in ChatStreamlyWithSender. Non-streaming// callers wrap each request with context.WithTimeout instead.func NewLongCatModel(baseURL map[string]string, urlSuffix URLSuffix) *LongCatModel {- transport := http.DefaultTransport.(*http.Transport).Clone()+ defaultTransport, ok := http.DefaultTransport.(*http.Transport)+ var transport *http.Transport+ if ok {+ transport = defaultTransport.Clone()+ } else {+ transport = &http.Transport{+ Proxy: http.ProxyFromEnvironment,+ }+ }transport.MaxIdleConns = 100transport.MaxIdleConnsPerHost = 10transport.IdleConnTimeout = 90 * time.Seconddiff --git a/internal/entity/models/longcat_test.go b/internal/entity/models/longcat_test.goindex d5d02717b8..00c6cfda7d 100644--- a/internal/entity/models/longcat_test.go+++ b/internal/entity/models/longcat_test.go@@ -9,6 +9,12 @@ import ("testing")+type roundTripperFunc func(*http.Request) (*http.Response, error)++func (f roundTripperFunc) RoundTrip(r *http.Request) (*http.Response, error) {+ return f(r)+}+func newLongCatServer(t *testing.T, expectedPath string, handler func(t *testing.T, r *http.Request, body map[string]interface{}, w http.ResponseWriter)) *httptest.Server {t.Helper()return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {@@ -85,6 +91,20 @@ func TestLongCatName(t *testing.T) {}}+func TestLongCatNewModelWithCustomDefaultTransport(t *testing.T) {+ original := http.DefaultTransport+ http.DefaultTransport = roundTripperFunc(func(*http.Request) (*http.Response, error) {+ return nil, nil+ })+ t.Cleanup(func() {+ http.DefaultTransport = original+ })++ if model := NewLongCatModel(map[string]string{"default": "http://unused"}, URLSuffix{}); model == nil {+ t.Fatal("NewLongCatModel returned nil")+ }+}+func TestLongCatChatHappyPath(t *testing.T) {srv := newLongCatServer(t, "/openai/v1/chat/completions", func(t *testing.T, _ *http.Request, body map[string]interface{}, w http.ResponseWriter) {if body["model"] != "LongCat-Flash-Chat" {