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
Sanitise double-pipe DeepSeek DSML tool-call markers in chat
rcourtman2a9afb111200
diff --git a/internal/ai/chat/agentic_sanitize.go b/internal/ai/chat/agentic_sanitize.goindex f6cac34863..a2d7ab57dd 100644--- a/internal/ai/chat/agentic_sanitize.go+++ b/internal/ai/chat/agentic_sanitize.go@@ -18,6 +18,16 @@ var (// MiniMax-style markers: minimax:tool_call followed by JSON-like contentminimaxMarkerRe = regexp.MustCompile(`(?m)^minimax:tool_call\b`)++ // DeepSeek DSML markers with arbitrary pipe-count variants. The+ // fast-path string list below covers the single- and double-pipe+ // forms we've actually observed in the wild+ // (`<|DSML|...>` and `<||DSML||...>` — the latter from+ // deepseek-v4-flash). This regex is the catch-all backstop for any+ // pipe-count variant the model might emit so the chat orchestrator+ // never falls through to showing raw DSML to the user as the+ // assistant's "final response."+ dsmlRe = regexp.MustCompile(`</?[\||]+/?DSML[\||]*`))// cleanToolCallArtifacts removes LLM-internal tool call format leakage from content.@@ -29,14 +39,24 @@ func cleanToolCallArtifacts(content string) string {return content}- // Fast-path: DeepSeek DSML markers (literal string checks, no regex needed)+ // Fast-path: DeepSeek DSML markers (literal string checks, no regex needed).+ // Includes both single- and double-pipe variants — deepseek-v4-flash+ // emits the double-pipe form ("<||DSML||tool_calls>"). The single-pipe+ // list alone left the double-pipe form unsanitised, so users saw the+ // raw DSML in chat as the assistant's "final response."dsmlMarkers := []string{- "<|DSML|", // Unicode pipe variant (opening)- "</|DSML|", // Unicode pipe variant (closing)- "<|DSML|", // ASCII pipe variant (opening)- "</|DSML|", // ASCII pipe variant (closing)- "<|/DSML|", // Alternative Unicode closing- "<|/DSML|", // Alternative ASCII closing+ "<|DSML|", // Unicode single pipe (opening)+ "</|DSML|", // Unicode single pipe (closing)+ "<||DSML||", // Unicode double pipe (opening) — deepseek-v4-flash+ "</||DSML||", // Unicode double pipe (closing)+ "<|DSML|", // ASCII single pipe (opening)+ "</|DSML|", // ASCII single pipe (closing)+ "<||DSML||", // ASCII double pipe (opening)+ "</||DSML||", // ASCII double pipe (closing)+ "<|/DSML|", // Alternative Unicode closing+ "<||/DSML||", // Alternative Unicode double-pipe closing+ "<|/DSML|", // Alternative ASCII closing+ "<||/DSML||", // Alternative ASCII double-pipe closing}for _, marker := range dsmlMarkers {@@ -45,6 +65,12 @@ func cleanToolCallArtifacts(content string) string {}}+ // Backstop regex catches arbitrary pipe-count variants the fast-path+ // list above might miss as new model behaviours surface.+ if loc := dsmlRe.FindStringIndex(content); loc != nil {+ content = strings.TrimSpace(content[:loc[0]])+ }+// Structural patterns: XML-style envelopesif loc := xmlToolCallRe.FindStringIndex(content); loc != nil {content = strings.TrimSpace(content[:loc[0]])@@ -66,10 +92,15 @@ func cleanToolCallArtifacts(content string) string {// containsToolCallMarker checks if content contains any known LLM-internal tool call markers.// Used during streaming to detect when to stop forwarding content chunks.func containsToolCallMarker(content string) bool {- // Fast-path: DeepSeek DSML literal checks+ // Fast-path: DeepSeek DSML literal checks. Covers single- and+ // double-pipe variants. deepseek-v4-flash uses double-pipe; older+ // deepseek variants use single. Both leak into content as text+ // rather than going through the tool-call channel.dsmlMarkers := []string{- "<|DSML|", // Unicode pipe variant- "<|DSML|", // ASCII pipe variant+ "<|DSML|", // Unicode single pipe+ "<||DSML||", // Unicode double pipe (deepseek-v4-flash)+ "<|DSML|", // ASCII single pipe+ "<||DSML||", // ASCII double pipe}for _, marker := range dsmlMarkers {if strings.Contains(content, marker) {@@ -78,6 +109,9 @@ func containsToolCallMarker(content string) bool {}// Structural patterns+ if dsmlRe.MatchString(content) {+ return true+ }if xmlToolCallRe.MatchString(content) {return true}diff --git a/internal/ai/chat/agentic_sanitize_test.go b/internal/ai/chat/agentic_sanitize_test.goindex a3af9ab7b9..1e2ac4004c 100644--- a/internal/ai/chat/agentic_sanitize_test.go+++ b/internal/ai/chat/agentic_sanitize_test.go@@ -12,6 +12,13 @@ func TestCleanToolCallArtifacts(t *testing.T) {{"clean content unchanged", "Hello, how can I help?", "Hello, how can I help?"},{"DeepSeek DSML unicode", "Here is my answer<|DSML|function_calls>...", "Here is my answer"},{"DeepSeek DSML ascii", "Response text<|DSML|invoke>...", "Response text"},+ // deepseek-v4-flash emits the double-pipe variant. Found by+ // exercising pulse_summarize in real chat — the user saw the+ // raw DSML as the assistant's "final response" because the+ // fast-path only listed single-pipe.+ {"DeepSeek DSML double-pipe unicode", "Summary done<||DSML||tool_calls>more", "Summary done"},+ {"DeepSeek DSML double-pipe ascii", "Result<||DSML||tool_calls>extra", "Result"},+ {"DeepSeek DSML triple-pipe regex backstop", "Output<|||DSML|||function_call>", "Output"},{"XML tool_call envelope", "My response\n<tool_call>{\"name\":\"foo\"}</tool_call>", "My response"},{"XML tool_calls envelope", "Answer here\n<tool_calls>\n{\"name\":\"bar\"}\n</tool_calls>", "Answer here"},{"XML function_call envelope", "Done.\n<function_call>test</function_call>", "Done."},@@ -45,6 +52,8 @@ func TestContainsToolCallMarker(t *testing.T) {{"normal angle brackets", "<div>html</div>", false},{"DeepSeek DSML unicode", "text<|DSML|func>", true},{"DeepSeek DSML ascii", "text<|DSML|func>", true},+ {"DeepSeek DSML double-pipe unicode", "text<||DSML||func>", true},+ {"DeepSeek DSML double-pipe ascii", "text<||DSML||func>", true},{"tool_call tag", "<tool_call>json</tool_call>", true},{"tool_calls tag", "<tool_calls>json</tool_calls>", true},{"function_call tag", "<function_call>json</function_call>", true},