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
fix(ai): skip orphaned tool calls when pruning messages
rcourtmana1fd2c4ddc7a
diff --git a/internal/ai/chat/agentic.go b/internal/ai/chat/agentic.goindex 2ff0263b63..c50546a796 100644--- a/internal/ai/chat/agentic.go+++ b/internal/ai/chat/agentic.go@@ -1251,10 +1251,23 @@ func pruneMessagesForModel(messages []Message) []Message {start := len(messages) - MaxContextMessagesLimitpruned := messages[start:]++ // Skip leading tool results (orphaned from pruned tool calls)for len(pruned) > 0 && pruned[0].ToolResult != nil {pruned = pruned[1:]}+ // If we start with an assistant message that has tool calls,+ // skip it and its following tool results — we've pruned the+ // user message that preceded it, so the sequence is broken.+ for len(pruned) > 0 && pruned[0].Role == "assistant" && len(pruned[0].ToolCalls) > 0 {+ pruned = pruned[1:]+ // Also skip the tool results that followed+ for len(pruned) > 0 && pruned[0].ToolResult != nil {+ pruned = pruned[1:]+ }+ }+return pruned}