From 9cdf55073b2e676672e40b8e6de048ee8472d592 Mon Sep 17 00:00:00 2001 From: lc6464 <64722907+lc6464@users.noreply.github.com> Date: Wed, 1 Apr 2026 01:01:00 +0800 Subject: [PATCH] fix(api): reduce probe cache key fragmentation --- web/backend/api/model_status.go | 14 +------------- web/backend/api/model_status_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/web/backend/api/model_status.go b/web/backend/api/model_status.go index cb27a8207..98bd501f5 100644 --- a/web/backend/api/model_status.go +++ b/web/backend/api/model_status.go @@ -193,30 +193,18 @@ func runLocalModelProbe(m *config.ModelConfig) bool { func modelProbeCacheKey(m *config.ModelConfig) string { protocol, modelID := splitModel(m.Model) - modelName := strings.ToLower(strings.TrimSpace(m.ModelName)) apiBaseRaw := modelProbeAPIBase(m) apiBase := strings.ToLower(strings.TrimRight(strings.TrimSpace(apiBaseRaw), "/")) - authMethod := strings.ToLower(strings.TrimSpace(m.AuthMethod)) - connectMode := strings.ToLower(strings.TrimSpace(m.ConnectMode)) apiKeyFingerprint := modelProbeAPIKeyFingerprint(m.APIKey()) var b strings.Builder - b.Grow( - len(modelName) + len(protocol) + len(modelID) + len(apiBase) + len(authMethod) + - len(connectMode) + len(apiKeyFingerprint) + 8, - ) - b.WriteString(modelName) - b.WriteByte('|') + b.Grow(len(protocol) + len(modelID) + len(apiBase) + len(apiKeyFingerprint) + 8) b.WriteString(protocol) b.WriteByte('|') b.WriteString(modelID) b.WriteByte('|') b.WriteString(apiBase) b.WriteByte('|') - b.WriteString(authMethod) - b.WriteByte('|') - b.WriteString(connectMode) - b.WriteByte('|') b.WriteString(apiKeyFingerprint) return b.String() diff --git a/web/backend/api/model_status_test.go b/web/backend/api/model_status_test.go index 848c59aeb..d5463a856 100644 --- a/web/backend/api/model_status_test.go +++ b/web/backend/api/model_status_test.go @@ -129,6 +129,29 @@ func TestModelProbeCacheKey_NormalizesTrailingSlashInAPIBase(t *testing.T) { } } +func TestModelProbeCacheKey_IgnoresDisplayAndConnectionFields(t *testing.T) { + base := &config.ModelConfig{ + ModelName: "vllm-one", + Model: "vllm/custom-model", + APIBase: "http://127.0.0.1:8000/v1", + AuthMethod: "none", + ConnectMode: "http", + } + changed := &config.ModelConfig{ + ModelName: "vllm-two", + Model: "vllm/custom-model", + APIBase: "http://127.0.0.1:8000/v1", + AuthMethod: "token", + ConnectMode: "ws", + } + + k1 := modelProbeCacheKey(base) + k2 := modelProbeCacheKey(changed) + if k1 != k2 { + t.Fatalf("modelProbeCacheKey() should ignore non-probe fields, got %q vs %q", k1, k2) + } +} + func TestProbeLocalModelAvailability_SuccessBackoff(t *testing.T) { resetModelProbeHooks(t)