Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Align DeepSeek V4 Patrol readiness
rcourtmanf88f0fcf1a77
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex ff81787426..8ae96f5fb8 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -1347,19 +1347,23 @@ process the buffered frame set and route tool-call assembly plus final doneevent emission through the same canonical finalizer used for `[DONE]` insteadof dropping the last chunk or leaving tool calls unfinalized on clean close.That same provider-transport boundary owns OpenAI-compatible tool protocol-adaptation. When a direct provider such as DeepSeek accepts tools but rejects-forced specific or required `tool_choice` values, the shared OpenAI-compatible-client must degrade offered-tool requests to provider-supported auto tool-selection instead of surfacing a raw provider protocol error to Assistant or-Patrol. Reasoning-backed provider turns that return tool calls with-`reasoning_content` must preserve that reasoning state on the following-tool-result turn when the provider requires it, so Assistant and Patrol can-complete multi-turn tool use against live BYOK providers.+adaptation. For direct DeepSeek provider paths, the shared OpenAI-compatible+client must preserve specific or required `tool_choice` values for current+DeepSeek V4 tool-capable models and the legacy aliases that currently route to+that V4 contract. Unknown direct DeepSeek model IDs must still degrade offered+tool requests to provider-supported auto tool selection so provider errors+remain model/readiness diagnostics instead of forced-tool protocol noise.+Reasoning-backed provider turns that return tool calls with `reasoning_content`+must preserve that reasoning state on the following tool-result turn when the+provider requires it, so Assistant and Patrol can complete multi-turn tool use+against live BYOK providers.Readiness classification for the same provider path must be model-aware, not-provider-only. Known live-proven DeepSeek V4 tool-capable models may report-Patrol readiness as ready; unknown DeepSeek aliases may still warn until-proved, and known reasoning-only families must continue to fail closed before-Patrol work is admitted.+provider-only. Current official DeepSeek V4 tool-capable models may report+Patrol readiness as ready; legacy DeepSeek aliases may only warn with the+alias-retirement posture and a recommendation to select the current V4 model+IDs; unknown direct DeepSeek model IDs must be not-ready with+`model_unavailable`; and known reasoning-only families must continue to fail+closed before Patrol work is admitted.That same browser-owned chat read model must keep target normalization helper-driven. Assistant shells may still derive legacy VM identifiers or displaylabels for read-only targeting, but they must do so through shared helpers anddiff --git a/internal/ai/patrol_readiness.go b/internal/ai/patrol_readiness.goindex 4ea57b9bc0..86593df480 100644--- a/internal/ai/patrol_readiness.go+++ b/internal/ai/patrol_readiness.go@@ -77,8 +77,8 @@ func EvaluatePatrolConfigReadiness(cfg *config.AIConfig) PatrolConfigReadiness {func PatrolToolReadinessForModel(provider, model string) (string, PatrolFailureCause, string) {normalizedModel := strings.ToLower(strings.TrimSpace(model))switch {- case provider == config.AIProviderDeepSeek && patrolDeepSeekModelSupportsTools(normalizedModel):- return PatrolReadinessReady, PatrolFailureCauseNone, "The selected DeepSeek model supports Patrol's tool-backed analysis contract."+ case provider == config.AIProviderDeepSeek:+ return patrolDeepSeekToolReadiness(normalizedModel)case strings.Contains(normalizedModel, "deepseek-r1") ||strings.Contains(normalizedModel, "/r1") ||strings.Contains(normalizedModel, ":r1") ||@@ -89,18 +89,38 @@ func PatrolToolReadinessForModel(provider, model string) (string, PatrolFailureCreturn PatrolReadinessWarning, PatrolFailureCauseModelToolSupportUnverified, "OpenRouter routes vary by model and endpoint. Patrol will fail closed if the routed model rejects tools or tool_choice."case provider == config.AIProviderOllama:return PatrolReadinessWarning, PatrolFailureCauseModelToolSupportUnverified, "Ollama connectivity alone does not prove tool support. Use an Ollama model that returns tool_calls for Patrol verification."- case provider == config.AIProviderDeepSeek:- return PatrolReadinessWarning, PatrolFailureCauseModelToolSupportUnverified, "DeepSeek model capability varies by model. Patrol requires a model that supports tool calling."default:return PatrolReadinessReady, PatrolFailureCauseNone, "The selected provider path supports Patrol's tool-backed analysis contract."}}+func patrolDeepSeekToolReadiness(normalizedModel string) (string, PatrolFailureCause, string) {+ model := patrolDeepSeekModelName(normalizedModel)+ switch {+ case patrolDeepSeekModelSupportsTools(model):+ return PatrolReadinessReady, PatrolFailureCauseNone, "The selected DeepSeek model supports Patrol's tool-backed analysis contract."+ case patrolDeepSeekLegacyAlias(model):+ return PatrolReadinessWarning, PatrolFailureCauseModelToolSupportUnverified, "The selected DeepSeek legacy alias currently routes to V4 Flash, but DeepSeek will retire legacy aliases on July 24, 2026. Select deepseek-v4-flash or deepseek-v4-pro for Patrol."+ default:+ return PatrolReadinessNotReady, PatrolFailureCauseModelUnavailable, "The selected DeepSeek model is not in the current official DeepSeek API catalog. Patrol supports deepseek-v4-flash or deepseek-v4-pro."+ }+}++func patrolDeepSeekModelName(normalizedModel string) string {+ model := strings.ToLower(strings.TrimSpace(normalizedModel))+ return strings.TrimPrefix(model, string(config.AIProviderDeepSeek)+":")+}+func patrolDeepSeekModelSupportsTools(normalizedModel string) bool {- model := strings.TrimPrefix(normalizedModel, string(config.AIProviderDeepSeek)+":")+ model := patrolDeepSeekModelName(normalizedModel)return model == "deepseek-v4-flash" || model == "deepseek-v4-pro"}+func patrolDeepSeekLegacyAlias(normalizedModel string) bool {+ model := patrolDeepSeekModelName(normalizedModel)+ return model == "deepseek-chat" || model == "deepseek-reasoner"+}+func patrolConfigReadiness(provider, model, status string, cause PatrolFailureCause, summary string) PatrolConfigReadiness {if cause == "" {cause = PatrolFailureCauseNonediff --git a/internal/ai/patrol_readiness_test.go b/internal/ai/patrol_readiness_test.goindex 96da2e18b8..72c79c9d68 100644--- a/internal/ai/patrol_readiness_test.go+++ b/internal/ai/patrol_readiness_test.go@@ -91,6 +91,26 @@ func TestEvaluatePatrolConfigReadiness_AssignsStableCause(t *testing.T) {cfg.PatrolModel = "deepseek:deepseek-v4-pro"},},+ {+ name: "deepseek legacy alias warns",+ wantCause: PatrolFailureCauseModelToolSupportUnverified,+ wantReady: true,+ configure: func(cfg *config.AIConfig) {+ cfg.Enabled = true+ cfg.DeepSeekAPIKey = "sk-test"+ cfg.PatrolModel = "deepseek:deepseek-chat"+ },+ },+ {+ name: "deepseek typo is not ready",+ wantCause: PatrolFailureCauseModelUnavailable,+ wantReady: false,+ configure: func(cfg *config.AIConfig) {+ cfg.Enabled = true+ cfg.DeepSeekAPIKey = "sk-test"+ cfg.PatrolModel = "deepseek:deepseek-v4-flush7pro"+ },+ },{name: "ready",wantCause: PatrolFailureCauseNone,diff --git a/internal/ai/patrol_runtime_failure.go b/internal/ai/patrol_runtime_failure.goindex f78e75f719..b36915c80a 100644--- a/internal/ai/patrol_runtime_failure.go+++ b/internal/ai/patrol_runtime_failure.go@@ -109,7 +109,9 @@ func patrolRuntimeFailureFromError(err error) patrolRuntimeFailure {case strings.Contains(lower, "model") && (strings.Contains(lower, "not available") ||strings.Contains(lower, "not found") ||strings.Contains(lower, "does not exist") ||- strings.Contains(lower, "no such model")):+ strings.Contains(lower, "no such model") ||+ strings.Contains(lower, "invalid model") ||+ strings.Contains(lower, "unsupported model")):failure.Title = "Pulse Patrol: Selected model unavailable"failure.Summary = "Selected model unavailable"failure.Cause = PatrolFailureCauseModelUnavailable@@ -203,6 +205,13 @@ func summarizePatrolRuntimeFailureDetail(raw string) string {return "Provider rejected Patrol tool calls. Choose a Patrol model and endpoint with tool-call support."case strings.Contains(lower, "reasoning_content"):return "Provider rejected Patrol reasoning state. Retry with a provider route that supports the selected model's reasoning and tool protocol."+ case strings.Contains(lower, "model") && (strings.Contains(lower, "not available") ||+ strings.Contains(lower, "not found") ||+ strings.Contains(lower, "does not exist") ||+ strings.Contains(lower, "no such model") ||+ strings.Contains(lower, "invalid model") ||+ strings.Contains(lower, "unsupported model")):+ return "Selected provider model is not available from this provider path."case strings.Contains(lower, "insufficient balance") ||strings.Contains(lower, "402") ||strings.Contains(lower, "payment required") ||diff --git a/internal/ai/patrol_runtime_failure_test.go b/internal/ai/patrol_runtime_failure_test.goindex 205bda6c9c..636a809b31 100644--- a/internal/ai/patrol_runtime_failure_test.go+++ b/internal/ai/patrol_runtime_failure_test.go@@ -57,6 +57,22 @@ func TestPatrolRuntimeFailureFromError_ClassifiesUnavailableModel(t *testing.T)}}+func TestPatrolRuntimeFailureFromError_ClassifiesInvalidProviderModel(t *testing.T) {+ err := errors.New(`agentic patrol failed: API error (400): invalid model "deepseek-v4-flush7pro"`)++ failure := patrolRuntimeFailureFromError(err)++ if failure.Cause != PatrolFailureCauseModelUnavailable {+ t.Fatalf("unexpected cause %q", failure.Cause)+ }+ if strings.Contains(failure.Evidence, "deepseek-v4-flush7pro") {+ t.Fatalf("evidence leaked raw provider model detail: %q", failure.Evidence)+ }+ if !strings.Contains(failure.Evidence, "Selected provider model is not available") {+ t.Fatalf("expected safe model-unavailable evidence, got %q", failure.Evidence)+ }+}+func TestClassifyPatrolRuntimeFailureOmitsRawProviderEvidence(t *testing.T) {diagnostic := ClassifyPatrolRuntimeFailure(errors.New(`API error (401): {"error":"raw upstream credential body"}`))diff --git a/internal/ai/providers/openai.go b/internal/ai/providers/openai.goindex 2bcc099f0e..100f633140 100644--- a/internal/ai/providers/openai.go+++ b/internal/ai/providers/openai.go@@ -181,7 +181,15 @@ func (c *OpenAIClient) shouldSendReasoningContent() bool {}func (c *OpenAIClient) supportsForcedToolChoice(model string) bool {- return !c.isDeepSeek()+ if !c.isDeepSeek() {+ return true+ }+ switch normalizeOpenAICompatibleModelName(model) {+ case "deepseek-v4-flash", "deepseek-v4-pro", "deepseek-chat", "deepseek-reasoner":+ return true+ default:+ return false+ }}func (c *OpenAIClient) toolChoiceForModel(model string, choice *ToolChoice) interface{} {@@ -191,6 +199,14 @@ func (c *OpenAIClient) toolChoiceForModel(model string, choice *ToolChoice) intereturn convertToolChoiceToOpenAI(choice)}+func normalizeOpenAICompatibleModelName(model string) string {+ model = strings.ToLower(strings.TrimSpace(model))+ for _, prefix := range []string{"openai:", "openrouter:", "deepseek:"} {+ model = strings.TrimPrefix(model, prefix)+ }+ return model+}+func (c *OpenAIClient) applyProviderHeaders(req *http.Request) {if !c.isOpenRouter() {return@@ -353,9 +369,9 @@ func (c *OpenAIClient) Chat(ctx context.Context, req ChatRequest) (*ChatResponseif len(openaiReq.Tools) > 0 {// Map ToolChoice to OpenAI format// OpenAI uses "required" instead of Anthropic's "any"- // DeepSeek's direct API accepts tools with auto choice, but rejects- // forced specific/required tool_choice values for reasoning-backed- // models such as V4 Flash/Pro.+ // DeepSeek V4 supports the OpenAI tool_choice contract. Unknown+ // direct DeepSeek model IDs fall back to auto so provider errors+ // become model/readiness diagnostics instead of forced-tool noise.openaiReq.ToolChoice = c.toolChoiceForModel(model, req.ToolChoice)}}@@ -759,9 +775,9 @@ func (c *OpenAIClient) ChatStream(ctx context.Context, req ChatRequest, callback}if len(openaiReq.Tools) > 0 {// Map ToolChoice to OpenAI format (same as non-streaming)- // DeepSeek's direct API accepts tools with auto choice, but rejects- // forced specific/required tool_choice values for reasoning-backed- // models such as V4 Flash/Pro.+ // DeepSeek V4 supports the OpenAI tool_choice contract. Unknown+ // direct DeepSeek model IDs fall back to auto so provider errors+ // become model/readiness diagnostics instead of forced-tool noise.openaiReq.ToolChoice = c.toolChoiceForModel(model, req.ToolChoice)}}diff --git a/internal/ai/providers/openai_test.go b/internal/ai/providers/openai_test.goindex e6a5ff11c0..288a4ec74b 100644--- a/internal/ai/providers/openai_test.go+++ b/internal/ai/providers/openai_test.go@@ -400,12 +400,17 @@ func TestOpenAIClient_ChatStream_ToolChoiceNone_DropsTools(t *testing.T) {assert.True(t, doneCalled)}-func TestOpenAIClient_Chat_DeepSeekCoercesForcedToolChoiceToAuto(t *testing.T) {+func TestOpenAIClient_Chat_DeepSeekV4PreservesForcedToolChoice(t *testing.T) {server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {var got map[string]interface{}require.NoError(t, json.NewDecoder(r.Body).Decode(&got))assert.Equal(t, "deepseek-v4-flash", got["model"])- assert.Equal(t, "auto", got["tool_choice"])+ assert.Equal(t, map[string]interface{}{+ "type": "function",+ "function": map[string]interface{}{+ "name": "ping",+ },+ }, got["tool_choice"])require.Len(t, got["tools"], 1)_ = json.NewEncoder(w).Encode(openaiResponse{@@ -434,12 +439,12 @@ func TestOpenAIClient_Chat_DeepSeekCoercesForcedToolChoiceToAuto(t *testing.T) {require.NoError(t, err)}-func TestOpenAIClient_ChatStream_DeepSeekCoercesForcedToolChoiceToAuto(t *testing.T) {+func TestOpenAIClient_ChatStream_DeepSeekV4PreservesRequiredToolChoice(t *testing.T) {server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {var got map[string]interface{}require.NoError(t, json.NewDecoder(r.Body).Decode(&got))assert.Equal(t, "deepseek-v4-flash", got["model"])- assert.Equal(t, "auto", got["tool_choice"])+ assert.Equal(t, "required", got["tool_choice"])require.Len(t, got["tools"], 1)w.Header().Set("Content-Type", "text/event-stream")@@ -463,6 +468,40 @@ func TestOpenAIClient_ChatStream_DeepSeekCoercesForcedToolChoiceToAuto(t *testinrequire.NoError(t, err)}+func TestOpenAIClient_Chat_UnknownDeepSeekModelCoercesForcedToolChoiceToAuto(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ var got map[string]interface{}+ require.NoError(t, json.NewDecoder(r.Body).Decode(&got))+ assert.Equal(t, "deepseek-v4-flush7pro", got["model"])+ assert.Equal(t, "auto", got["tool_choice"])+ require.Len(t, got["tools"], 1)++ _ = json.NewEncoder(w).Encode(openaiResponse{+ ID: "chatcmpl-deepseek-unknown-tools",+ Model: "deepseek-v4-flush7pro",+ Choices: []openaiChoice{+ {+ Message: openaiRespMsg{Role: "assistant", Content: "ok"},+ FinishReason: "stop",+ },+ },+ })+ }))+ defer server.Close()++ client := NewOpenAIClient("sk-test", "deepseek-v4-flush7pro", server.URL, 0)+ client.baseURL = strings.TrimSuffix(server.URL, "/") + "/v1/chat/completions#deepseek.com"++ _, err := client.Chat(context.Background(), ChatRequest{+ Messages: []Message{{Role: "user", Content: "Use the tool"}},+ Tools: []Tool{+ {Name: "ping", Description: "Ping", InputSchema: map[string]interface{}{"type": "object"}},+ },+ ToolChoice: &ToolChoice{Type: ToolChoiceTool, Name: "ping"},+ })+ require.NoError(t, err)+}+func TestOpenAIClient_Chat_DeepSeekPreservesReasoningContentForToolTurns(t *testing.T) {server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {var got openaiRequestdiff --git a/internal/api/ai_handlers_test.go b/internal/api/ai_handlers_test.goindex 6f5577a331..bd55529cdf 100644--- a/internal/api/ai_handlers_test.go+++ b/internal/api/ai_handlers_test.go@@ -297,13 +297,27 @@ func TestAISettingsHandler_PatrolReadinessBranches(t *testing.T) {},},{- name: "deepseek aliases warn instead of silently ready",+ name: "deepseek legacy aliases warn instead of silently ready",patrolAvailable: true,wantStatus: patrolReadinessWarning,wantReady: true,wantCheckID: "tools",wantCheck: patrolReadinessWarning,- wantSummary: "DeepSeek model capability varies",+ wantSummary: "legacy alias currently routes to V4 Flash",+ configure: func(aiCfg *config.AIConfig) {+ aiCfg.Enabled = true+ aiCfg.Model = "deepseek:deepseek-chat"+ aiCfg.DeepSeekAPIKey = "test-key"+ },+ },+ {+ name: "deepseek typo blocks before Patrol runtime",+ patrolAvailable: true,+ wantStatus: patrolReadinessNotReady,+ wantReady: false,+ wantCheckID: "tools",+ wantCheck: patrolReadinessNotReady,+ wantSummary: "current official DeepSeek API catalog",configure: func(aiCfg *config.AIConfig) {aiCfg.Enabled = trueaiCfg.Model = "deepseek:deepseek-v4-flush7pro"