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
Correct the DeepSeek tool_choice coercion rationale
rcourtman9329258f8bdf
diff --git a/internal/ai/providers/openai.go b/internal/ai/providers/openai.goindex 1ce2d773d0..08d9a3f394 100644--- a/internal/ai/providers/openai.go+++ b/internal/ai/providers/openai.go@@ -181,10 +181,26 @@ func (c *OpenAIClient) shouldSendReasoningContent() bool {}func (c *OpenAIClient) supportsForcedToolChoice(model string) bool {- // DeepSeek's API server-side aliases v4-flash/v4-pro to deepseek-reasoner,- // which rejects forced tool_choice with HTTP 400. Always coerce to "auto"- // for any DeepSeek model so Patrol stays functional regardless of how- // DeepSeek routes the requested id.+ // Empirical: DeepSeek's API returns HTTP 400 ("provider rejected+ // forced tool selection") when tool_choice=required is sent against+ // the canonical chat models, including deepseek-v4-flash. DeepSeek's+ // official chat-completion docs list `required` as a supported value+ // with no model-specific restriction (verified at+ // https://api-docs.deepseek.com/api/create-chat-completion on+ // 2026-05-11), but their server behavior disagrees with their docs.+ // A live preflight against deepseek-v4-flash with required produced+ // `cause: tool_choice_rejected` in 275ms — a deterministic 400, not+ // a transient. The legacy `deepseek-reasoner` id is documented as a+ // thinking-mode alias for v4-flash on the pricing page and shares+ // the same behavior.+ //+ // Until DeepSeek's API matches their docs, coerce forced tool_choice+ // to "auto" for any DeepSeek model so Patrol stays functional. With+ // auto, the model is free to skip the tool call and preflight may+ // record tool_call_observed=false; that is handled as a soft warning+ // ("Model did not emit a tool call during preflight") rather than a+ // hard failure, which is the correct surface for a model that+ // supports tools but is not under forced selection.return !c.isDeepSeek()}diff --git a/internal/ai/providers/openai_test.go b/internal/ai/providers/openai_test.goindex bb1de9bd13..ec4894f937 100644--- a/internal/ai/providers/openai_test.go+++ b/internal/ai/providers/openai_test.go@@ -401,10 +401,13 @@ func TestOpenAIClient_ChatStream_ToolChoiceNone_DropsTools(t *testing.T) {}func TestOpenAIClient_Chat_DeepSeekCoercesForcedToolChoiceToAuto(t *testing.T) {- // DeepSeek's API server-side aliases v4-flash/v4-pro to deepseek-reasoner,- // which rejects forced tool_choice with HTTP 400. Pulse coerces any DeepSeek- // forced tool_choice to "auto" so Patrol stays functional regardless of how- // DeepSeek routes the requested id.+ // Empirical: DeepSeek's API rejects tool_choice=required with HTTP 400+ // for the canonical chat models (verified via live preflight against+ // deepseek-v4-flash on 2026-05-11, deterministic 400 in 275ms). DeepSeek's+ // official docs claim required is supported, but server behavior+ // disagrees. Pulse coerces forced tool_choice to "auto" for any DeepSeek+ // model so Patrol stays functional; the soft "model did not emit a tool+ // call" warning surface handles auto-mode preflight outcomes correctly.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))@@ -439,9 +442,8 @@ func TestOpenAIClient_Chat_DeepSeekCoercesForcedToolChoiceToAuto(t *testing.T) {}func TestOpenAIClient_ChatStream_DeepSeekCoercesAnyToolChoiceToAuto(t *testing.T) {- // DeepSeek's API server-side aliases v4-flash/v4-pro to deepseek-reasoner,- // which rejects forced tool_choice with HTTP 400. Pulse coerces any DeepSeek- // forced tool_choice to "auto" on streaming requests as well.+ // Streaming variant of the same coercion. See the non-streaming test+ // for the empirical-evidence note.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))@@ -471,6 +473,9 @@ func TestOpenAIClient_ChatStream_DeepSeekCoercesAnyToolChoiceToAuto(t *testing.T}func TestOpenAIClient_Chat_UnknownDeepSeekModelCoercesForcedToolChoiceToAuto(t *testing.T) {+ // Unknown DeepSeek model ids share the canonical-models' coercion+ // behavior. Until DeepSeek's documented tool_choice=required support+ // actually works server-side, every DeepSeek request gets auto.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))