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
Restore Patrol recommendation in Assistant sessions
rcourtmana5e8a1edb679
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 0132409dca..710e08ee31 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -329,7 +329,9 @@ runtime cost control, and shared AI transport surfaces.handoffs. That summary may include the handoff kind, finding ID, resourceand Patrol run ID, safe run type/status/runtime-failure flags, resource andaction counts, a primary resource label, last-known approval/action status,- risk level, and timestamp, but it must not expose model-only handoff text,+ risk level, timestamp, and Patrol assessment recommended next-step/action+ labels only when they can be safely extracted from the stored assessment+ handoff, but it must not expose model-only handoff text,runtime failure detail, action preflight/result bodies, remediationdescriptions, raw commands, or approval command payloads. Its`requires_approval` field is a current operator-decision flag only: pending@@ -341,7 +343,8 @@ runtime cost control, and shared AI transport surfaces.safe visible briefing: the next chat turn must carry`autonomous_mode:false` even when the summary is context-only and has noqueued action, while the visible badge/action copy must still reflect the- actual last-known action state instead of inventing a pending approval. That+ actual last-known action state or Patrol assessment recommendation instead+ of inventing a pending approval. Thatrestoration is success-bound: if the underlying session message load fails,the drawer must leave the current context untouched instead of applyingsummary-derived Patrol or approval state for a session the operator is notdiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 3aa81e7459..cd41f018c7 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -2006,7 +2006,9 @@ The `/api/ai/sessions` response may expose `handoff_summary` for sessions thatcarry private Assistant model-context metadata, but that payload is a safereload marker only. It may carry the handoff kind, finding ID, Patrol run ID,safe run type/status/runtime-failure flags, counts, primary-resource label,-last-known approval/action status, risk level, and summary timestamp; it must+last-known approval/action status, risk level, Patrol assessment recommended+next-step/action labels when safely extractable from the stored assessment+handoff, and summary timestamp; it mustnot serialize the model-only `handoff_context`, runtime failure detail, actionpreflight/result bodies, remediation descriptions, raw commands, or approvalcommand payloads.diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex cefa046255..c5d1962d2d 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -203,7 +203,10 @@ work extends shared components instead of creating new local variants.status badge, action label, and suggested prompts from `handoff_summary`, butit must not infer a finding target from bounded action references orreconstruct hidden model context, provider details, retry payloads, commands,- preflight output, or action results in the browser.+ preflight output, or action results in the browser. If the safe summary+ includes a Patrol assessment recommended next step or action label, restored+ drawer briefing and action copy must use that recommendation rather than+ falling back to generic assessment copy.Session-load and new-conversation transitions must be success-bound: if theunderlying session operation fails, the shared drawer store must not clear orreplace the current scoped handoff context.diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex 331d022be1..8209367b31 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -259,7 +259,11 @@ Patrol-specific presentation helpers.`handoff_metadata.kind=patrol_assessment` so saved Assistant sessions restoreas current-assessment context instead of becoming generic scoped context oran accidental single-finding session because one bounded action reference- names a finding.+ names a finding. Saved assessment sessions may expose the Patrol-owned+ recommended next step/action through the safe `handoff_summary` only after+ command-like and secret-like text is withheld; the browser must use those+ fields for restored drawer copy without receiving the private model-only+ handoff context.When the current Patrol assessment is coverage-incomplete with no activeinfrastructure finding, the same handoff model must frame the briefing as averification gap: the prompt leads with what scoped activity did and did notdiff --git a/frontend-modern/src/api/__tests__/aiChat.test.ts b/frontend-modern/src/api/__tests__/aiChat.test.tsindex a67aef236c..19c9b74787 100644--- a/frontend-modern/src/api/__tests__/aiChat.test.ts+++ b/frontend-modern/src/api/__tests__/aiChat.test.ts@@ -50,6 +50,8 @@ describe('AIChatAPI', () => {last_known_approval_status: 'pending',last_known_action_state: 'awaiting_approval',last_known_action_risk: 'high',+ recommended_next_step: 'Review pending Patrol approval',+ recommended_next_step_action: 'Review approvals',updated_at: '2026-05-06T12:08:00Z',},};diff --git a/frontend-modern/src/api/aiChat.ts b/frontend-modern/src/api/aiChat.tsindex 9cfdc58876..b32c9af54b 100644--- a/frontend-modern/src/api/aiChat.ts+++ b/frontend-modern/src/api/aiChat.ts@@ -53,6 +53,8 @@ export interface ChatSessionHandoffSummary {last_known_approval_status?: string;last_known_action_state?: string;last_known_action_risk?: string;+ recommended_next_step?: string;+ recommended_next_step_action?: string;updated_at?: string;}diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsxindex 5c71e37f3c..2ebbe53911 100644--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx@@ -887,6 +887,8 @@ describe('AIChat', () => {resource_count: 2,action_count: 0,requires_approval: false,+ recommended_next_step: 'Verify full coverage',+ recommended_next_step_action: 'Run Patrol',},},]);@@ -914,12 +916,17 @@ describe('AIChat', () => {context: expect.objectContaining({kind: 'patrol_assessment',findingId: undefined,+ recommendedNextStep: 'Verify full coverage',+ recommendedNextStepAction: 'Run Patrol',}),briefing: expect.objectContaining({sourceLabel: 'Pulse Patrol',title: 'Patrol assessment handoff',subject: 'Current Patrol assessment',- actionLabel: 'Review Patrol assessment',+ actionLabel: 'Recommended: Run Patrol',+ detailLines: expect.arrayContaining([+ 'Recommended next step: Verify full coverage',+ ]),}),}),);diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsxindex d186161972..559bdf0531 100644--- a/frontend-modern/src/components/AI/Chat/index.tsx+++ b/frontend-modern/src/components/AI/Chat/index.tsx@@ -153,6 +153,8 @@ const buildSessionHandoffContext = (session?: ChatSession): AIChatContext | undeconst resourceLabel = formatSessionHandoffResourceLabel(summary);const resourceDetail = formatSessionHandoffResourceDetail(summary);const statusLabel = formatSessionHandoffStatus(summary);+ const recommendedNextStep = summary.recommended_next_step?.trim() || '';+ const recommendedNextStepAction = summary.recommended_next_step_action?.trim() || '';const actionCount = summary.action_count ?? 0;const resourceCount = summary.resource_count ?? 0;const findingId = summary.finding_id?.trim() || undefined;@@ -211,6 +213,8 @@ const buildSessionHandoffContext = (session?: ChatSession): AIChatContext | undelastKnownApprovalStatus: summary.last_known_approval_status,lastKnownActionState: summary.last_known_action_state,lastKnownActionRisk: summary.last_known_action_risk,+ recommendedNextStep,+ recommendedNextStepAction,updatedAt: summary.updated_at,},findingId,@@ -238,6 +242,9 @@ const buildSessionHandoffContext = (session?: ChatSession): AIChatContext | underesourceCount > 1? pluralizeCount(resourceCount, 'linked resource', 'linked resources'): undefined,+ isPatrolAssessment && recommendedNextStep+ ? `Recommended next step: ${recommendedNextStep}`+ : undefined,actionCount > 0? pluralizeCount(actionCount, 'governed action', 'governed actions'): undefined,@@ -246,11 +253,15 @@ const buildSessionHandoffContext = (session?: ChatSession): AIChatContext | undeactionLabel: summary.requires_approval? 'Approval required': isPatrolConfigurationFailure- ? 'Review Patrol configuration issue'- : isPatrolAssessment- ? 'Review Patrol assessment'- : isPatrolRun && summary.runtime_failure- ? 'Review Patrol runtime issue'+ ? 'Review Patrol configuration issue'+ : isPatrolAssessment+ ? recommendedNextStepAction+ ? `Recommended: ${recommendedNextStepAction}`+ : recommendedNextStep+ ? `Recommended: ${recommendedNextStep}`+ : 'Review Patrol assessment'+ : isPatrolRun && summary.runtime_failure+ ? 'Review Patrol runtime issue': isPatrolRun? 'Review Patrol run': actionCount > 0diff --git a/frontend-modern/src/types/ai.ts b/frontend-modern/src/types/ai.tsindex d1cfe5f514..72511d8ac1 100644--- a/frontend-modern/src/types/ai.ts+++ b/frontend-modern/src/types/ai.ts@@ -392,6 +392,8 @@ export interface AIChatSessionHandoffSummary {last_known_approval_status?: string;last_known_action_state?: string;last_known_action_risk?: string;+ recommended_next_step?: string;+ recommended_next_step_action?: string;updated_at?: string;}diff --git a/internal/ai/chat/session.go b/internal/ai/chat/session.goindex 653e510316..70c7dd55d7 100644--- a/internal/ai/chat/session.go+++ b/internal/ai/chat/session.go@@ -223,6 +223,114 @@ func inferPatrolRunHandoffMetadata(handoffContext string) HandoffMetadata {return NormalizeHandoffMetadata(metadata)}+func patrolAssessmentRecommendedNextStepSummary(kind string, handoffContext string) (string, string) {+ if kind != sessionHandoffKindPatrolAssessment {+ return "", ""+ }++ lines := strings.Split(strings.TrimSpace(handoffContext), "\n")+ if len(lines) == 0 {+ return "", ""+ }++ sawAssessmentContext := false+ sawPatrolSource := false+ var recommendedNextStep string+ var recommendedNextStepAction string+ for _, line := range lines {+ line = strings.TrimSpace(line)+ if line == "[Patrol Assessment Context]" {+ sawAssessmentContext = true+ continue+ }+ if !sawAssessmentContext {+ continue+ }++ label, value, ok := strings.Cut(line, ":")+ if !ok {+ continue+ }+ label = strings.ToLower(strings.TrimSpace(label))+ value = strings.TrimSpace(value)+ switch label {+ case "source":+ if strings.EqualFold(value, "Pulse Patrol current assessment") {+ sawPatrolSource = true+ }+ case "recommended next step":+ recommendedNextStep = safeSessionHandoffSummaryText(value, 160)+ case "recommended next step action":+ recommendedNextStepAction = safePatrolAssessmentRecommendationAction(value)+ }+ }++ if !sawAssessmentContext || !sawPatrolSource {+ return "", ""+ }+ if recommendedNextStep == "" && recommendedNextStepAction != "" {+ recommendedNextStep = recommendedNextStepAction+ }+ return recommendedNextStep, recommendedNextStepAction+}++func safePatrolAssessmentRecommendationAction(value string) string {+ action := safeSessionHandoffSummaryText(value, 120)+ if action == "" {+ return ""+ }+ for _, suffix := range []string{+ " (discuss_assessment)",+ " (open_provider_settings)",+ " (review_approvals)",+ " (review_findings)",+ " (run_patrol)",+ } {+ if strings.HasSuffix(action, suffix) {+ return strings.TrimSpace(strings.TrimSuffix(action, suffix))+ }+ }+ return action+}++func safeSessionHandoffSummaryText(value string, maxRunes int) string {+ normalized := trimHandoffMetadataField(value, maxRunes)+ if normalized == "" || sessionHandoffSummaryTextShouldBeWithheld(normalized) {+ return ""+ }+ return normalized+}++func sessionHandoffSummaryTextShouldBeWithheld(value string) bool {+ normalized := strings.ToLower(value)+ for _, marker := range []string{+ "password",+ "secret",+ "token",+ "api key",+ "api_key",+ "api-key",+ "credential",+ "private key",+ "private_key",+ "private-key",+ "systemctl",+ "sudo ",+ "bash ",+ "sh -c",+ "curl ",+ "wget ",+ "kubectl ",+ "docker ",+ "ssh ",+ } {+ if strings.Contains(normalized, marker) {+ return true+ }+ }+ return false+}+func modelContextEmpty(modelContext *sessionModelContext) bool {if modelContext == nil {return true@@ -288,17 +396,23 @@ func modelContextHandoffSummary(modelContext *sessionModelContext) *SessionHando} else if findingID != "" {kind = sessionHandoffKindPatrolFinding}+ recommendedNextStep, recommendedNextStepAction := patrolAssessmentRecommendedNextStepSummary(+ kind,+ modelContext.HandoffContext,+ )summary := &SessionHandoffSummary{- Kind: kind,- FindingID: findingID,- RunID: metadata.RunID,- RunType: metadata.RunType,- RunStatus: metadata.RunStatus,- RuntimeFailure: metadata.RuntimeFailure,- HasModelContext: strings.TrimSpace(modelContext.HandoffContext) != "",- ResourceCount: len(resources),- ActionCount: len(actions),+ Kind: kind,+ FindingID: findingID,+ RunID: metadata.RunID,+ RunType: metadata.RunType,+ RunStatus: metadata.RunStatus,+ RuntimeFailure: metadata.RuntimeFailure,+ HasModelContext: strings.TrimSpace(modelContext.HandoffContext) != "",+ ResourceCount: len(resources),+ ActionCount: len(actions),+ RecommendedNextStep: recommendedNextStep,+ RecommendedNextStepAction: recommendedNextStepAction,}if kind != sessionHandoffKindPatrolRun {summary.RunID = ""diff --git a/internal/ai/chat/session_additional_test.go b/internal/ai/chat/session_additional_test.goindex ab1ee3d6fc..0b2dfbd5c4 100644--- a/internal/ai/chat/session_additional_test.go+++ b/internal/ai/chat/session_additional_test.go@@ -525,7 +525,14 @@ func TestSessionStore_ListKeepsPatrolAssessmentHandoffIdentity(t *testing.T) {t.Fatalf("failed to create session: %v", err)}- if err := store.SetModelHandoffEnvelope(session.ID, "", "[Patrol Assessment Context]\nSource: Pulse Patrol current assessment", nil, []HandoffAction{{+ handoffContext := strings.Join([]string{+ "[Patrol Assessment Context]",+ "Source: Pulse Patrol current assessment",+ "Assessment: Coverage incomplete",+ "Recommended Next Step: Verify full coverage",+ "Recommended Next Step Action: Run Patrol (run_patrol)",+ }, "\n")+ if err := store.SetModelHandoffEnvelope(session.ID, "", handoffContext, nil, []HandoffAction{{FindingID: "finding-123",ApprovalID: "approval-123",ApprovalStatus: "pending",@@ -560,6 +567,60 @@ func TestSessionStore_ListKeepsPatrolAssessmentHandoffIdentity(t *testing.T) {if summary.LastKnownApprovalStatus != "pending" || summary.LastKnownActionRisk != "high" {t.Fatalf("approval posture = %#v, want safe action summary", summary)}+ if summary.RecommendedNextStep != "Verify full coverage" || summary.RecommendedNextStepAction != "Run Patrol" {+ t.Fatalf("recommended next step summary = %#v, want safe Patrol recommendation", summary)+ }+ payload, err := json.Marshal(sessions)+ if err != nil {+ t.Fatalf("Marshal sessions failed: %v", err)+ }+ publicJSON := string(payload)+ for _, forbidden := range []string{+ "Coverage incomplete",+ "Restart the workload service",+ "vm-100",+ } {+ if strings.Contains(publicJSON, forbidden) {+ t.Fatalf("public session JSON leaked %q: %s", forbidden, publicJSON)+ }+ }+}++func TestSessionStore_ListWithholdsUnsafePatrolAssessmentRecommendationSummary(t *testing.T) {+ store, err := NewSessionStore(t.TempDir())+ if err != nil {+ t.Fatalf("failed to create session store: %v", err)+ }++ session, err := store.Create()+ if err != nil {+ t.Fatalf("failed to create session: %v", err)+ }++ handoffContext := strings.Join([]string{+ "[Patrol Assessment Context]",+ "Source: Pulse Patrol current assessment",+ "Recommended Next Step: Run sudo systemctl restart workload.service",+ "Recommended Next Step Action: sudo restart (run_patrol)",+ }, "\n")+ if err := store.SetModelHandoffEnvelope(session.ID, "", handoffContext, nil, nil, HandoffMetadata{+ Kind: "patrol_assessment",+ }); err != nil {+ t.Fatalf("SetModelHandoffEnvelope failed: %v", err)+ }++ sessions, err := store.List()+ if err != nil {+ t.Fatalf("List failed: %v", err)+ }+ if len(sessions) != 1 || sessions[0].HandoffSummary == nil {+ t.Fatalf("sessions = %#v, want one session with handoff summary", sessions)+ }++ summary := sessions[0].HandoffSummary+ if summary.RecommendedNextStep != "" || summary.RecommendedNextStepAction != "" {+ t.Fatalf("unsafe recommendation summary = %#v, want withheld recommendation fields", summary)+ }}func TestSessionStore_ListKeepsPatrolConfigurationFailureHandoffIdentity(t *testing.T) {diff --git a/internal/ai/chat/types.go b/internal/ai/chat/types.goindex 3366576dc1..139a3b5a8e 100644--- a/internal/ai/chat/types.go+++ b/internal/ai/chat/types.go@@ -25,21 +25,23 @@ type Session struct {// session-scoped model handoff metadata. It intentionally omits model-only// context text and raw remediation details.type SessionHandoffSummary struct {- Kind string `json:"kind,omitempty"`- FindingID string `json:"finding_id,omitempty"`- RunID string `json:"run_id,omitempty"`- RunType string `json:"run_type,omitempty"`- RunStatus string `json:"run_status,omitempty"`- RuntimeFailure bool `json:"runtime_failure,omitempty"`- HasModelContext bool `json:"has_model_context"`- ResourceCount int `json:"resource_count,omitempty"`- PrimaryResource *HandoffResource `json:"primary_resource,omitempty"`- ActionCount int `json:"action_count,omitempty"`- RequiresApproval bool `json:"requires_approval,omitempty"`- LastKnownApprovalStatus string `json:"last_known_approval_status,omitempty"`- LastKnownActionState string `json:"last_known_action_state,omitempty"`- LastKnownActionRisk string `json:"last_known_action_risk,omitempty"`- UpdatedAt *time.Time `json:"updated_at,omitempty"`+ Kind string `json:"kind,omitempty"`+ FindingID string `json:"finding_id,omitempty"`+ RunID string `json:"run_id,omitempty"`+ RunType string `json:"run_type,omitempty"`+ RunStatus string `json:"run_status,omitempty"`+ RuntimeFailure bool `json:"runtime_failure,omitempty"`+ HasModelContext bool `json:"has_model_context"`+ ResourceCount int `json:"resource_count,omitempty"`+ PrimaryResource *HandoffResource `json:"primary_resource,omitempty"`+ ActionCount int `json:"action_count,omitempty"`+ RequiresApproval bool `json:"requires_approval,omitempty"`+ LastKnownApprovalStatus string `json:"last_known_approval_status,omitempty"`+ LastKnownActionState string `json:"last_known_action_state,omitempty"`+ LastKnownActionRisk string `json:"last_known_action_risk,omitempty"`+ RecommendedNextStep string `json:"recommended_next_step,omitempty"`+ RecommendedNextStepAction string `json:"recommended_next_step_action,omitempty"`+ UpdatedAt *time.Time `json:"updated_at,omitempty"`}// Message represents a chat message