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
Ground Patrol fallback summaries in evidence
rcourtman3a99f72a5c95
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 6d6684c34e..0f2f675462 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -7405,3 +7405,16 @@ findings read or a failed lifecycle write in an ephemeral callback. Exactfinding-lifecycle retries suppressed before canonical invocation are runtimeloop-control decisions rather than tool executions and do not create a secondtool-start/tool-end pair.++### Patrol investigation fallback summaries remain evidence-grounded++When a provider completes an investigation tool loop but fails to emit the+final narrative, `internal/ai/chat/agentic_final.go` must not replace the+operator's evidence with a generic retry request. The deterministic fallback+projects only bounded finding fields from the core-authored investigation+handoff plus successful tool identities. It names the recorded symptom and+canonical affected resource, distinguishes missing narrative from confirmed+root cause, discloses failed tool-call count without treating failures as+evidence, and describes a successful typed proposal only as a governed+proposal. It never dumps raw tool output, infers execution, or upgrades the+finding to resolved. A failed proposal remains absent from the receipt.diff --git a/internal/ai/chat/agentic_additional_test.go b/internal/ai/chat/agentic_additional_test.goindex 08b8b11a30..00e9b2486e 100644--- a/internal/ai/chat/agentic_additional_test.go+++ b/internal/ai/chat/agentic_additional_test.go@@ -1843,6 +1843,87 @@ func TestBuildAutomaticFallbackSummary_UsesToolNamesNotCallIDsOrRawOutput(t *tes}}+func TestBuildAutomaticFallbackSummary_InvestigationUsesGroundedReceipt(t *testing.T) {+ summary := buildAutomaticFallbackSummary([]Message{+ {+ Role: "user",+ Content: `You are investigating a finding from Pulse Patrol.++## Finding Details+- **Title**: Container health check reported unhealthy while running+- **Severity**: warning+- **Category**: reliability+- **Resource display name**: inventory-api+- **Canonical resource ID**: app-container-123+- **Resource type**: app-container+- **Description**: The container is running, but its health check is unhealthy.++## Evidence Completion Contract`,+ },+ {Role: "assistant", ToolCalls: []ToolCall{+ {ID: "call-query", Name: "pulse_query", Input: map[string]interface{}{"resource_id": "app-container-123"}},+ {ID: "call-proposal", Name: "patrol_propose_action", Input: map[string]interface{}{+ "resource_id": "app-container-123",+ "capability_name": "restart",+ }},+ }},+ {Role: "user", ToolResult: &ToolResult{ToolUseID: "call-query", Content: `{"private_raw_output":"must not leak"}`}},+ {Role: "user", ToolResult: &ToolResult{ToolUseID: "call-proposal", Content: `{"ok":true}`}},+ })++ for _, want := range []string{+ "### Investigation Summary",+ "health check reported unhealthy",+ "### Root Cause",+ "inventory-api",+ "app-container-123",+ "governed restart proposal",+ "### Conclusion",+ "NEEDS_ATTENTION:",+ "No resolution is being inferred",+ } {+ if !strings.Contains(summary, want) {+ t.Fatalf("grounded fallback missing %q:\n%s", want, summary)+ }+ }+ for _, forbidden := range []string{"private_raw_output", "must not leak", "Ask me again"} {+ if strings.Contains(summary, forbidden) {+ t.Fatalf("grounded fallback leaked or deferred with %q:\n%s", forbidden, summary)+ }+ }+}++func TestBuildAutomaticFallbackSummary_InvestigationDoesNotTreatFailedProposalAsRecorded(t *testing.T) {+ summary := buildAutomaticFallbackSummary([]Message{+ {Role: "user", Content: `## Finding Details+- **Title**: Disk is filling up+- **Severity**: warning+- **Category**: capacity+- **Resource display name**: storage-a+- **Canonical resource ID**: storage-123+- **Resource type**: storage+- **Description**: Free space is below the configured threshold.++## Evidence Completion Contract`},+ {Role: "assistant", ToolCalls: []ToolCall{{+ ID: "call-proposal",+ Name: "patrol_propose_action",+ Input: map[string]interface{}{+ "resource_id": "storage-123",+ "capability_name": "delete",+ },+ }}},+ {Role: "user", ToolResult: &ToolResult{ToolUseID: "call-proposal", Content: "policy refused", IsError: true}},+ })++ if strings.Contains(summary, "governed delete proposal was recorded") {+ t.Fatalf("failed proposal must not be presented as recorded:\n%s", summary)+ }+ if !strings.Contains(summary, "nothing was authorized by this fallback") {+ t.Fatalf("failed proposal fallback must stay fail-closed:\n%s", summary)+ }+}+func TestExecuteToolSafely_RecoversPanic(t *testing.T) {exec := tools.NewPulseToolExecutor(tools.ExecutorConfig{})exec.RegisterTool(tools.RegisteredTool{diff --git a/internal/ai/chat/agentic_final.go b/internal/ai/chat/agentic_final.goindex dc0bb96e54..9bfd27244b 100644--- a/internal/ai/chat/agentic_final.go+++ b/internal/ai/chat/agentic_final.go@@ -194,16 +194,20 @@ func buildAutomaticFallbackSummary(resultMessages []Message) string {// Resolve provider tool-call ids to the real tool name so the summary names// the checks (query, metrics, ...) instead of leaking raw `call_…` ids.idToName := make(map[string]string)+ idToCall := make(map[string]ToolCall)for _, msg := range resultMessages {for _, call := range msg.ToolCalls {id := strings.TrimSpace(call.ID)name := strings.TrimSpace(call.Name)if id != "" && name != "" {idToName[id] = name+ idToCall[id] = call}}}+ var proposal *automaticFallbackProposal+for _, msg := range resultMessages {if msg.ToolResult == nil {continue@@ -213,9 +217,15 @@ func buildAutomaticFallbackSummary(resultMessages []Message) string {continue}successCount++- if name := fallbackToolDisplayName(msg.ToolResult.ToolUseID, idToName); name != "" {+ name := fallbackToolDisplayName(msg.ToolResult.ToolUseID, idToName)+ if name != "" {toolCounts[name]++}+ if strings.EqualFold(name, "patrol_propose_action") {+ if call, ok := idToCall[strings.TrimSpace(msg.ToolResult.ToolUseID)]; ok {+ proposal = automaticFallbackProposalFromToolCall(call)+ }+ }}if successCount == 0 && errorCount == 0 {@@ -250,6 +260,10 @@ func buildAutomaticFallbackSummary(resultMessages []Message) string {toolList = strings.Join(names, ", ")}+ if finding, ok := automaticFallbackFindingFromMessages(resultMessages); ok {+ return buildInvestigationFallbackSummary(finding, proposal, successCount, errorCount, toolList)+ }+checkWord := "checks"if successCount == 1 {checkWord = "check"@@ -268,6 +282,170 @@ func buildAutomaticFallbackSummary(resultMessages []Message) string {return summary}+type automaticFallbackFinding struct {+ Title string+ Severity string+ Category string+ ResourceName string+ ResourceID string+ ResourceType string+ Description string+}++type automaticFallbackProposal struct {+ CapabilityName string+ ResourceID string+}++func automaticFallbackFindingFromMessages(resultMessages []Message) (automaticFallbackFinding, bool) {+ for i := len(resultMessages) - 1; i >= 0; i-- {+ msg := resultMessages[i]+ if msg.Role != "user" || msg.ToolResult != nil {+ continue+ }+ if finding, ok := parseAutomaticFallbackFinding(msg.Content); ok {+ return finding, true+ }+ }+ return automaticFallbackFinding{}, false+}++func parseAutomaticFallbackFinding(prompt string) (automaticFallbackFinding, bool) {+ const sectionHeader = "## Finding Details"+ sectionStart := strings.Index(prompt, sectionHeader)+ if sectionStart < 0 {+ return automaticFallbackFinding{}, false+ }++ finding := automaticFallbackFinding{}+ for _, rawLine := range strings.Split(prompt[sectionStart+len(sectionHeader):], "\n") {+ line := strings.TrimSpace(rawLine)+ if strings.HasPrefix(line, "## ") {+ break+ }+ value := func(label string) (string, bool) {+ prefix := "- **" + label + "**:"+ if !strings.HasPrefix(line, prefix) {+ return "", false+ }+ return automaticFallbackFact(strings.TrimSpace(strings.TrimPrefix(line, prefix))), true+ }+ if v, ok := value("Title"); ok && finding.Title == "" {+ finding.Title = v+ } else if v, ok := value("Severity"); ok && finding.Severity == "" {+ finding.Severity = v+ } else if v, ok := value("Category"); ok && finding.Category == "" {+ finding.Category = v+ } else if v, ok := value("Resource display name"); ok && finding.ResourceName == "" {+ finding.ResourceName = v+ } else if v, ok := value("Canonical resource ID"); ok && finding.ResourceID == "" {+ finding.ResourceID = v+ } else if v, ok := value("Resource type"); ok && finding.ResourceType == "" {+ finding.ResourceType = v+ } else if v, ok := value("Description"); ok && finding.Description == "" {+ finding.Description = v+ }+ }++ if finding.Title == "" || finding.ResourceID == "" {+ return automaticFallbackFinding{}, false+ }+ return finding, true+}++func automaticFallbackFact(value string) string {+ value = cleanToolCallArtifacts(value)+ value = strings.Join(strings.Fields(value), " ")+ const maxRunes = 320+ runes := []rune(value)+ if len(runes) > maxRunes {+ value = string(runes[:maxRunes-1]) + "…"+ }+ return value+}++func automaticFallbackProposalFromToolCall(call ToolCall) *automaticFallbackProposal {+ capabilityName, _ := call.Input["capability_name"].(string)+ resourceID, _ := call.Input["resource_id"].(string)+ capabilityName = automaticFallbackFact(capabilityName)+ resourceID = automaticFallbackFact(resourceID)+ if capabilityName == "" || resourceID == "" {+ return nil+ }+ return &automaticFallbackProposal{CapabilityName: capabilityName, ResourceID: resourceID}+}++func buildInvestigationFallbackSummary(finding automaticFallbackFinding, proposal *automaticFallbackProposal, successCount, errorCount int, toolList string) string {+ resourceName := finding.ResourceName+ if resourceName == "" {+ resourceName = finding.ResourceID+ }+ resourceDetails := finding.ResourceID+ if finding.ResourceType != "" {+ resourceDetails += "; " + finding.ResourceType+ }++ checkWord := "tool calls"+ if successCount == 1 {+ checkWord = "tool call"+ }+ errorNote := ""+ if errorCount > 0 {+ errorWord := "errors"+ if errorCount == 1 {+ errorWord = "error"+ }+ errorNote = fmt.Sprintf(" %d tool %s were also recorded; they are not being treated as evidence.", errorCount, errorWord)+ }++ symptom := finding.Description+ if symptom == "" {+ symptom = finding.Title+ }+ classification := ""+ if finding.Severity != "" || finding.Category != "" {+ classification = strings.Trim(strings.Join([]string{finding.Severity, finding.Category}, " / "), " / ")+ if classification != "" {+ classification = " Classification: " + classification + "."+ }+ }++ recommendation := "Review the recorded evidence before choosing a manual next step."+ proposalConclusion := "No governed action proposal was recorded, so nothing was authorized by this fallback."+ if proposal != nil {+ recommendation = fmt.Sprintf("A governed %s proposal was recorded for %s. Core policy—not this fallback—decides whether it needs approval or may run automatically.", proposal.CapabilityName, proposal.ResourceID)+ proposalConclusion = "The proposal remains traceable through its governed action receipt; this fallback does not infer execution or resolution."+ }++ return fmt.Sprintf(`### Investigation Summary+Patrol investigated %s on %s. It completed %d successful %s using %s.%s The model did not return a final narrative, so this deterministic receipt uses only the recorded finding and successful tool outcomes.++### Root Cause+Patrol cannot claim a confirmed root cause without the missing final narrative. The recorded symptom was: %s%s++### Affected Resources+- %s (%s)++### Recommendation+%s++### Conclusion+NEEDS_ATTENTION: %s No resolution is being inferred.`,+ finding.Title,+ resourceName,+ successCount,+ checkWord,+ toolList,+ errorNote,+ symptom,+ classification,+ resourceName,+ resourceDetails,+ recommendation,+ proposalConclusion,+ )+}+// fallbackToolDisplayName resolves an operator-facing tool name for the// automatic fallback summary. It prefers the real tool name from the assistant's// tool call (idToName), and only falls back to the tool-use id when that id