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
Hydrate Assistant handoff approval status
rcourtman8c60e48f0912
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 7b9b1b9048..c68935bd27 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -364,7 +364,9 @@ profile and assignment columns, but embedded table framing must route throughAssistant handoff action references from the same Patrol finding remainAI/runtime review metadata only; lifecycle code must not treat approval IDs,fix IDs, risk, or target-resource labels from that handoff as agent command- grants, enrollment proof, or auto-approval policy.+ grants, enrollment proof, or auto-approval policy. Any approval status+ snapshot refreshed for Assistant review remains read-only AI/runtime context+ and must not become command-websocket authority or lifecycle execution state.The same isolation rule applies to CSRF token-store behavior in`internal/api/csrf_store.go`: lifecycle-adjacent browser flows may rely onthe shared API/security layer to keep parallel replacement-token retriesdiff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex af264d032a..7635555e44 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -189,7 +189,10 @@ runtime cost control, and shared AI transport surfaces.references from the same investigation record as model-context metadata, butthose references are review context only: they must not include raw commandtext, must not grant approval or execution authority, and must route any- operator decision back through the governed approval/remediation flow.+ operator decision back through the governed approval/remediation flow. When+ those references include an approval ID, Assistant runtime may refresh a+ current status snapshot from the canonical approval store on each turn, but+ it must enforce org scoping and still omit the approval command payload.Proposed-fix command text must stay out of both the persisted chat messageand the model-only handoff context, and command payloads remainapproval-context data, not conversational copy.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 40c7c4245c..bb638964a0 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -760,9 +760,12 @@ the canonical monitored-system blocked payload.and approval references from the investigation record into chat execution,but those references must omit raw proposed-fix commands, remain model-onlyreview context, and leave approval/execution authority with the governed- approval and remediation APIs. Frontend handoff briefings must derive from- the same shared investigation payload rather than inventing a second- finding-context transport shape.+ approval and remediation APIs. Chat execution may refresh approval status+ snapshots for those references from the canonical approval store, but that+ snapshot is read-only, org-scoped, and must not expose or infer the raw+ command. Frontend handoff briefings must derive from the same shared+ investigation payload rather than inventing a second finding-context+ transport shape.7. Keep Patrol summary payload consumers aligned on one assessment hierarchy: transport-driven Patrol summary surfaces may show supporting counts and outcomes, but the canonical assessment and verification states must remain singular and not be repeated as a second compact verdict strip8. Keep Patrol verification and activity facts unified on one transport-backed secondary status area: when frontend consumers combine Patrol status payloads (`runtime_state`, `last_patrol_at`, `last_activity_at`, `trigger_status`) with run-history transport, the latest run result, activity mix, scoped-trigger state, and circuit-breaker context must read as one supporting explanation beneath the primary assessment instead of being re-expanded into a separate full-width status strip plus duplicate summary layersand the main Patrol page composition boundary, so once that governeddiff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.mdindex 203b607e30..3fd8fab41f 100644--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md@@ -105,7 +105,10 @@ Patrol-specific presentation helpers.hands a pending fix or approval into Assistant, the shared handoff may retainonly structured action references such as approval ID, fix ID, risk, target,and resource identity; approval and execution authority stays with the- governed approval/remediation surfaces.+ governed approval/remediation surfaces. Assistant may refresh the referenced+ approval's current status for review, but Patrol presentation must still keep+ command payloads inside governed approval/remediation context rather than+ rendering them as handoff copy.## Current Statediff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 24278c33d1..634b682d50 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -420,7 +420,10 @@ bypass the API fail-closed execution gate.are also adjacent AI/runtime review metadata only; storage and recoverysurfaces must not reinterpret approval IDs, fix IDs, risk, or target labelsas restore support, backup freshness, recovery execution authority, or a- storage-local approval bypass.+ storage-local approval bypass. Any refreshed approval status snapshot in+ Assistant handoff context is still read-only AI/runtime context and must not+ become recovery freshness, restore eligibility, or storage-local execution+ state.That same adjacent `internal/api/` boundary still carries Patrol-runexecution identity. Storage and recovery may observe shared Patroltransport through `internal/api/chat_service_adapter.go`, but they must notdiff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.goindex 97fa2eb4cf..d776453132 100644--- a/internal/ai/chat/service.go+++ b/internal/ai/chat/service.go@@ -12,6 +12,7 @@ import ("github.com/google/uuid""github.com/rcourtman/pulse-go-rewrite/internal/agentexec"+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/approval""github.com/rcourtman/pulse-go-rewrite/internal/ai/modelboundary""github.com/rcourtman/pulse-go-rewrite/internal/ai/providers""github.com/rcourtman/pulse-go-rewrite/internal/ai/tools"@@ -517,6 +518,12 @@ func (s *Service) ExecuteStream(ctx context.Context, req ExecuteRequest, callbacInt("message_count", len(messages)).Msg("[ChatService] Got messages, calling agentic loop")+ handoffActions = refreshHandoffActionApprovalStatus(handoffActions, s.orgID)+ if len(handoffActions) > 0 {+ if err := sessions.SetModelHandoffActions(session.ID, handoffActions); err != nil {+ log.Warn().Err(err).Str("session_id", session.ID).Msg("[ChatService] Failed to persist refreshed handoff action status")+ }+ }handoffContext = mergeHandoffActionContext(handoffContext, handoffActions)injectHandoffContextIntoLatestUserMessage(messages, handoffContext)@@ -861,6 +868,13 @@ func buildHandoffActionContext(handoffActions []HandoffAction) string {appendHandoffActionLine(&b, label+" Finding ID", action.FindingID)appendHandoffActionLine(&b, label+" Record ID", action.RecordID)appendHandoffActionLine(&b, label+" Approval ID", action.ApprovalID)+ appendHandoffActionLine(&b, label+" Approval Status", action.ApprovalStatus)+ appendHandoffActionLine(&b, label+" Approval Requested At", action.ApprovalRequestedAt)+ appendHandoffActionLine(&b, label+" Approval Expires At", action.ApprovalExpiresAt)+ appendHandoffActionLine(&b, label+" Approval Decided At", action.ApprovalDecidedAt)+ if action.ApprovalConsumed {+ appendHandoffActionLine(&b, label+" Approval Consumed", "true")+ }appendHandoffActionLine(&b, label+" Fix ID", action.FixID)appendHandoffActionLine(&b, label+" Proposed Fix", action.Description)appendHandoffActionLine(&b, label+" Risk", action.RiskLevel)@@ -874,6 +888,66 @@ func buildHandoffActionContext(handoffActions []HandoffAction) string {return strings.TrimSpace(b.String())}+func refreshHandoffActionApprovalStatus(handoffActions []HandoffAction, orgID string) []HandoffAction {+ actions := normalizeHandoffActions(handoffActions)+ if len(actions) == 0 {+ return nil+ }++ store := approval.GetStore()+ normalizedOrgID := approval.NormalizeOrgID(orgID)+ for idx := range actions {+ clearHandoffActionApprovalStatus(&actions[idx])+ approvalID := strings.TrimSpace(actions[idx].ApprovalID)+ if approvalID == "" || store == nil {+ continue+ }+ req, ok := store.GetApproval(approvalID)+ if !ok || !approval.BelongsToOrg(req, normalizedOrgID) {+ continue+ }++ actions[idx].ApprovalStatus = string(req.Status)+ actions[idx].ApprovalRequestedAt = formatHandoffActionTime(req.RequestedAt)+ actions[idx].ApprovalExpiresAt = formatHandoffActionTime(req.ExpiresAt)+ if req.DecidedAt != nil {+ actions[idx].ApprovalDecidedAt = formatHandoffActionTime(*req.DecidedAt)+ }+ actions[idx].ApprovalConsumed = req.Consumed+ if strings.TrimSpace(actions[idx].RiskLevel) == "" {+ actions[idx].RiskLevel = string(req.RiskLevel)+ }+ if strings.TrimSpace(actions[idx].TargetResourceID) == "" {+ actions[idx].TargetResourceID = strings.TrimSpace(req.TargetID)+ }+ if strings.TrimSpace(actions[idx].TargetResourceName) == "" {+ actions[idx].TargetResourceName = strings.TrimSpace(req.TargetName)+ }+ if strings.TrimSpace(actions[idx].TargetResourceType) == "" {+ actions[idx].TargetResourceType = strings.TrimSpace(req.TargetType)+ }+ }+ return normalizeHandoffActions(actions)+}++func clearHandoffActionApprovalStatus(action *HandoffAction) {+ if action == nil {+ return+ }+ action.ApprovalStatus = ""+ action.ApprovalRequestedAt = ""+ action.ApprovalExpiresAt = ""+ action.ApprovalDecidedAt = ""+ action.ApprovalConsumed = false+}++func formatHandoffActionTime(value time.Time) string {+ if value.IsZero() {+ return ""+ }+ return value.UTC().Format(time.RFC3339)+}+func appendHandoffActionLine(b *strings.Builder, label, value string) {value = strings.TrimSpace(value)if value == "" {diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.goindex 7238dd9d9e..e23decd5b2 100644--- a/internal/ai/chat/service_execute_additional_test.go+++ b/internal/ai/chat/service_execute_additional_test.go@@ -6,6 +6,7 @@ import ("testing""time"+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/approval""github.com/rcourtman/pulse-go-rewrite/internal/ai/providers""github.com/rcourtman/pulse-go-rewrite/internal/ai/tools""github.com/rcourtman/pulse-go-rewrite/internal/config"@@ -18,6 +19,28 @@ type stubServiceProvider struct {streamFn func(ctx context.Context, req providers.ChatRequest, callback providers.StreamCallback) error}+func installTestApprovalStore(t *testing.T, req *approval.ApprovalRequest) {+ t.Helper()+ previous := approval.GetStore()+ store, err := approval.NewStore(approval.StoreConfig{+ DataDir: t.TempDir(),+ DefaultTimeout: 10 * time.Minute,+ DisablePersistence: true,+ })+ if err != nil {+ t.Fatalf("failed to create approval store: %v", err)+ }+ approval.SetStore(store)+ t.Cleanup(func() {+ approval.SetStore(previous)+ })+ if req != nil {+ if err := store.CreateApproval(req); err != nil {+ t.Fatalf("failed to create approval: %v", err)+ }+ }+}+func (s *stubServiceProvider) Chat(ctx context.Context, req providers.ChatRequest) (*providers.ChatResponse, error) {return &providers.ChatResponse{Content: "ok", Model: req.Model}, nil}@@ -95,6 +118,17 @@ func TestService_ExecuteStream_Success(t *testing.T) {}func TestService_ExecuteStream_HandoffContextIsModelOnly(t *testing.T) {+ installTestApprovalStore(t, &approval.ApprovalRequest{+ ID: "approval-123",+ OrgID: approval.DefaultOrgID,+ Command: "systemctl restart workload.service",+ TargetType: "vm",+ TargetID: "vm-100",+ TargetName: "web-server",+ RiskLevel: approval.RiskMedium,+ ExpiresAt: time.Now().Add(10 * time.Minute),+ })+tmpDir := t.TempDir()store, err := NewSessionStore(tmpDir)if err != nil {@@ -183,12 +217,26 @@ func TestService_ExecuteStream_HandoffContextIsModelOnly(t *testing.T) {if !strings.Contains(modelUserContent, "Pending Action Approval ID: approval-123") {t.Fatalf("model user content missing approval reference: %q", modelUserContent)}+ if !strings.Contains(modelUserContent, "Pending Action Approval Status: pending") {+ t.Fatalf("model user content missing approval status: %q", modelUserContent)+ }if strings.Contains(modelUserContent, "systemctl restart workload.service") {t.Fatalf("model user content must not infer raw command text: %q", modelUserContent)}}func TestService_ExecuteStream_ReusesModelHandoffContextAcrossFollowUps(t *testing.T) {+ installTestApprovalStore(t, &approval.ApprovalRequest{+ ID: "approval-123",+ OrgID: approval.DefaultOrgID,+ Command: "systemctl restart workload.service",+ TargetType: "vm",+ TargetID: "vm-100",+ TargetName: "web-server",+ RiskLevel: approval.RiskMedium,+ ExpiresAt: time.Now().Add(10 * time.Minute),+ })+tmpDir := t.TempDir()store, err := NewSessionStore(tmpDir)if err != nil {@@ -295,6 +343,9 @@ func TestService_ExecuteStream_ReusesModelHandoffContextAcrossFollowUps(t *testiif !strings.Contains(firstModelUserContent, "Pending Action Approval ID: approval-123") {t.Fatalf("first provider turn missing approval reference: %q", firstModelUserContent)}+ if !strings.Contains(firstModelUserContent, "Pending Action Approval Status: pending") {+ t.Fatalf("first provider turn missing approval status: %q", firstModelUserContent)+ }secondModelUserContent := latestProviderUserContent(t, capturedRequests[1])if !strings.Contains(secondModelUserContent, "[Finding Context]") {t.Fatalf("follow-up provider turn missing stored handoff context: %q", secondModelUserContent)@@ -308,11 +359,49 @@ func TestService_ExecuteStream_ReusesModelHandoffContextAcrossFollowUps(t *testiif !strings.Contains(secondModelUserContent, "Pending Action Approval ID: approval-123") {t.Fatalf("follow-up provider turn missing stored approval reference: %q", secondModelUserContent)}+ if !strings.Contains(secondModelUserContent, "Pending Action Approval Status: pending") {+ t.Fatalf("follow-up provider turn missing refreshed approval status: %q", secondModelUserContent)+ }if strings.Contains(firstModelUserContent+secondModelUserContent, "systemctl restart workload.service") {t.Fatalf("provider turns must not include raw command text")}}+func TestRefreshHandoffActionApprovalStatusRejectsCrossOrgApproval(t *testing.T) {+ installTestApprovalStore(t, &approval.ApprovalRequest{+ ID: "approval-cross-org",+ OrgID: "org-a",+ Command: "systemctl restart workload.service",+ TargetType: "vm",+ TargetID: "vm-100",+ TargetName: "web-server",+ RiskLevel: approval.RiskHigh,+ ExpiresAt: time.Now().Add(10 * time.Minute),+ })++ actions := refreshHandoffActionApprovalStatus([]HandoffAction{{+ ApprovalID: "approval-cross-org",+ ApprovalStatus: "pending",+ ApprovalRequestedAt: "2026-01-01T00:00:00Z",+ FixID: "fix-123",+ Description: "Restart the workload service",+ }}, "org-b")++ if len(actions) != 1 {+ t.Fatalf("actions = %#v, want one retained action reference", actions)+ }+ if actions[0].ApprovalStatus != "" || actions[0].ApprovalRequestedAt != "" {+ t.Fatalf("cross-org approval status should be cleared, got %#v", actions[0])+ }+ contextText := buildHandoffActionContext(actions)+ if strings.Contains(contextText, "Approval Status") {+ t.Fatalf("cross-org approval status leaked into action context: %q", contextText)+ }+ if strings.Contains(contextText, "systemctl restart workload.service") {+ t.Fatalf("raw command leaked into action context: %q", contextText)+ }+}+func TestService_ExecuteStream_HandoffResourceHydratesResolvedContext(t *testing.T) {tmpDir := t.TempDir()store, err := NewSessionStore(tmpDir)diff --git a/internal/ai/chat/session.go b/internal/ai/chat/session.goindex 62531aa6f8..2a74f377c5 100644--- a/internal/ai/chat/session.go+++ b/internal/ai/chat/session.go@@ -96,6 +96,10 @@ func normalizeHandoffActions(actions []HandoffAction) []HandoffAction {action.FindingID = strings.TrimSpace(action.FindingID)action.RecordID = strings.TrimSpace(action.RecordID)action.ApprovalID = strings.TrimSpace(action.ApprovalID)+ action.ApprovalStatus = strings.TrimSpace(action.ApprovalStatus)+ action.ApprovalRequestedAt = strings.TrimSpace(action.ApprovalRequestedAt)+ action.ApprovalExpiresAt = strings.TrimSpace(action.ApprovalExpiresAt)+ action.ApprovalDecidedAt = strings.TrimSpace(action.ApprovalDecidedAt)action.FixID = strings.TrimSpace(action.FixID)action.Description = strings.TrimSpace(action.Description)action.RiskLevel = strings.TrimSpace(action.RiskLevel)diff --git a/internal/ai/chat/types.go b/internal/ai/chat/types.goindex ffa0c2f034..2fece9dddb 100644--- a/internal/ai/chat/types.go+++ b/internal/ai/chat/types.go@@ -104,18 +104,23 @@ type HandoffResource struct {// It is context for review only: it carries no command text and grants no// authority to approve, execute, or replay a remediation.type HandoffAction struct {- FindingID string `json:"finding_id,omitempty"`- RecordID string `json:"record_id,omitempty"`- ApprovalID string `json:"approval_id,omitempty"`- FixID string `json:"fix_id,omitempty"`- Description string `json:"description,omitempty"`- RiskLevel string `json:"risk_level,omitempty"`- Destructive bool `json:"destructive,omitempty"`- TargetHost string `json:"target_host,omitempty"`- TargetResourceID string `json:"target_resource_id,omitempty"`- TargetResourceName string `json:"target_resource_name,omitempty"`- TargetResourceType string `json:"target_resource_type,omitempty"`- TargetNode string `json:"target_node,omitempty"`+ FindingID string `json:"finding_id,omitempty"`+ RecordID string `json:"record_id,omitempty"`+ ApprovalID string `json:"approval_id,omitempty"`+ ApprovalStatus string `json:"approval_status,omitempty"`+ ApprovalRequestedAt string `json:"approval_requested_at,omitempty"`+ ApprovalExpiresAt string `json:"approval_expires_at,omitempty"`+ ApprovalDecidedAt string `json:"approval_decided_at,omitempty"`+ ApprovalConsumed bool `json:"approval_consumed,omitempty"`+ FixID string `json:"fix_id,omitempty"`+ Description string `json:"description,omitempty"`+ RiskLevel string `json:"risk_level,omitempty"`+ Destructive bool `json:"destructive,omitempty"`+ TargetHost string `json:"target_host,omitempty"`+ TargetResourceID string `json:"target_resource_id,omitempty"`+ TargetResourceName string `json:"target_resource_name,omitempty"`+ TargetResourceType string `json:"target_resource_type,omitempty"`+ TargetNode string `json:"target_node,omitempty"`}// ExecuteRequest represents a chat execution requestdiff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex fbb3006611..c467bb2feb 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -166,9 +166,11 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {"sessions.GetModelHandoffResources(session.ID)","sessions.SetModelHandoffActions(session.ID, handoffActions)","sessions.GetModelHandoffActions(session.ID)",+ "refreshHandoffActionApprovalStatus(handoffActions, s.orgID)","handoffContext = mergeHandoffActionContext(handoffContext, handoffActions)","s.hydrateHandoffResources(session.ID, handoffResources, sessions, unifiedResourceProvider)","injectHandoffContextIntoLatestUserMessage(messages, handoffContext)",+ "Approval Status","Action Boundary","User message: ",} {@@ -200,6 +202,7 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {"HandoffResources []HandoffResource","type HandoffAction struct","HandoffActions []HandoffAction",+ "ApprovalStatus string",} {if !strings.Contains(chatTypesText, required) {t.Fatalf("chat request must carry structured handoff resource scope outside messages: missing %q", required)