Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Mark Patrol queued fixes as Patrol actions

rcourtmanf563adf1368f
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 2f2d57f1f5..7126078ded 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -657,8 +657,10 @@ planning contract.
Patrol investigation-fix approvals must use that same action-audit boundary:
when the orchestrator queues a fix approval, `internal/api/ai_handlers.go` must
attach a governed action plan, seed the shared action-audit store as planned
-and pending, and leave later execution or approval decisions to the governed
-action/approval paths instead of creating Patrol-only execution context.
+and pending with `pulse_patrol` as the requester/actor, and leave later
+execution or approval decisions to the governed action/approval paths instead
+of creating Patrol-only execution context or collapsing Patrol proposals into
+generic Assistant-origin actions.
The same ownership includes the Pulse query tool schema under
`internal/ai/tools/`: topology-query input names must stay canonical inside
the AI runtime itself, so new tool arguments such as `max_proxmox_nodes`
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index c550019c5d..0e37551dd1 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -851,7 +851,10 @@ approval/action-audit model instead of storing Patrol-only execution context.
The investigation approval adapter must seed the unified action-audit store
with planned and pending lifecycle evidence when it creates the approval, so
Assistant handoffs and resource timelines can hydrate the same canonical
-action record before any operator decision or execution occurs.
+action record before any operator decision or execution occurs. Those queued
+fix records must carry `pulse_patrol` as the requester and lifecycle actor so
+resource timelines preserve the product source of the proposal instead of
+flattening proactive Patrol work into generic Assistant chat activity.
That same store now owns the Patrol dashboard load bundle as well, so the
page refresh path stays aligned on a single orchestrated AI bundle instead of
repeating the individual summary, findings, approval, and correlation fetches
diff --git a/internal/ai/approval/store.go b/internal/ai/approval/store.go
index f15fc393dd..45c5cbaf40 100644
--- a/internal/ai/approval/store.go
+++ b/internal/ai/approval/store.go
@@ -29,7 +29,16 @@ const (
StatusExpired ApprovalStatus = "expired"
)
-const DefaultOrgID = "default"
+const (
+ DefaultOrgID = "default"
+
+ // RequesterPulseAssistant identifies approvals proposed from the interactive
+ // Assistant control surface.
+ RequesterPulseAssistant = "pulse_assistant"
+ // RequesterPulsePatrol identifies approvals produced by Patrol's structured
+ // investigation loop.
+ RequesterPulsePatrol = "pulse_patrol"
+)
// RiskLevel indicates the potential impact of a command.
type RiskLevel string
@@ -117,6 +126,18 @@ func BelongsToOrg(req *ApprovalRequest, orgID string) bool {
return requestOrg == normalizedOrg
}
+// RequesterForRequest returns the canonical producer identity for an approval.
+func RequesterForRequest(req *ApprovalRequest) string {
+ if req == nil {
+ return RequesterPulseAssistant
+ }
+ if strings.TrimSpace(req.ToolID) == "investigation_fix" ||
+ strings.TrimSpace(req.TargetType) == "investigation" {
+ return RequesterPulsePatrol
+ }
+ return RequesterPulseAssistant
+}
+
// ExecutionState stores the AI conversation state for resumption after approval.
type ExecutionState struct {
ID string `json:"id"`
@@ -264,7 +285,7 @@ func (s *Store) CreateApproval(req *ApprovalRequest) error {
ResourceID: approvalResourceID(req.TargetType, req.TargetID, req.TargetName),
CapabilityName: approvalCapabilityName(req.TargetType),
Reason: req.Context,
- RequestedBy: "pulse_assistant",
+ RequestedBy: RequesterForRequest(req),
}, *req.Plan)
req.Preflight = req.Plan.Preflight
}
diff --git a/internal/ai/approval/store_test.go b/internal/ai/approval/store_test.go
index ed0523afd7..e4a0c34e0c 100644
--- a/internal/ai/approval/store_test.go
+++ b/internal/ai/approval/store_test.go
@@ -252,6 +252,52 @@ func TestCreateApproval_PopulatesActionPlanPreflightWhenMissing(t *testing.T) {
}
}
+func TestCreateApproval_UsesPatrolRequesterForInvestigationFixPreflight(t *testing.T) {
+ tmpDir, err := os.MkdirTemp("", "approval-test-*")
+ if err != nil {
+ t.Fatalf("Failed to create temp dir: %v", err)
+ }
+ defer os.RemoveAll(tmpDir)
+
+ store, _ := NewStore(StoreConfig{
+ DataDir: tmpDir,
+ DefaultTimeout: 1 * time.Minute,
+ DisablePersistence: true,
+ })
+
+ req := &ApprovalRequest{
+ ID: "approval-patrol",
+ ToolID: "investigation_fix",
+ Command: "systemctl restart nginx",
+ TargetType: "investigation",
+ TargetID: "finding-123",
+ Context: "Restart nginx after Patrol investigation",
+ Plan: &unifiedresources.ActionPlan{
+ ActionID: "action-patrol",
+ Allowed: true,
+ RequiresApproval: true,
+ ApprovalPolicy: unifiedresources.ApprovalAdmin,
+ PlannedAt: time.Now().UTC(),
+ },
+ }
+
+ if err := store.CreateApproval(req); err != nil {
+ t.Fatalf("CreateApproval() error = %v", err)
+ }
+ if got := RequesterForRequest(req); got != RequesterPulsePatrol {
+ t.Fatalf("RequesterForRequest = %q, want %q", got, RequesterPulsePatrol)
+ }
+ if req.Plan.Preflight == nil {
+ t.Fatal("expected normalized action preflight")
+ }
+ if req.Plan.Preflight.Target != "investigation:finding-123" {
+ t.Fatalf("preflight target = %q, want investigation:finding-123", req.Plan.Preflight.Target)
+ }
+ if len(req.Plan.Preflight.VerificationSteps) == 0 {
+ t.Fatalf("expected request-context normalized preflight: %#v", req.Plan.Preflight)
+ }
+}
+
func TestCreateApproval_RejectsUnsupportedHostTargetType(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "approval-test-*")
if err != nil {
diff --git a/internal/ai/tools/action_audit.go b/internal/ai/tools/action_audit.go
index d079900d8e..0006b23915 100644
--- a/internal/ai/tools/action_audit.go
+++ b/internal/ai/tools/action_audit.go
@@ -16,7 +16,7 @@ import (
"github.com/rs/zerolog/log"
)
-const approvalAuditActor = "pulse_assistant"
+const approvalAuditActor = approval.RequesterPulseAssistant
func (e *PulseToolExecutor) executeCommandWithAudit(
ctx context.Context,
@@ -578,23 +578,27 @@ func RecordPendingApprovalAction(store unifiedresources.ResourceStore, req *appr
if store == nil || req == nil || req.Plan == nil {
return
}
- record := actionAuditRecordFromApproval(req, unifiedresources.ActionStatePending, approvalAuditActor)
+ actor := approval.RequesterForRequest(req)
+ record := actionAuditRecordFromApproval(req, unifiedresources.ActionStatePending, actor)
if err := store.RecordActionAudit(record); err != nil {
log.Warn().Err(err).Str("action_id", record.ID).Msg("failed to persist pending approval action")
return
}
- recordApprovalLifecycle(store, req.Plan.ActionID, unifiedresources.ActionStatePlanned, strings.TrimSpace(req.Context))
- recordApprovalLifecycle(store, req.Plan.ActionID, unifiedresources.ActionStatePending, "waiting for approval")
+ recordApprovalLifecycle(store, req.Plan.ActionID, unifiedresources.ActionStatePlanned, actor, strings.TrimSpace(req.Context))
+ recordApprovalLifecycle(store, req.Plan.ActionID, unifiedresources.ActionStatePending, actor, "waiting for approval")
}
-func recordApprovalLifecycle(store unifiedresources.ResourceStore, actionID string, state unifiedresources.ActionState, message string) {
+func recordApprovalLifecycle(store unifiedresources.ResourceStore, actionID string, state unifiedresources.ActionState, actor, message string) {
event := unifiedresources.ActionLifecycleEvent{
ActionID: strings.TrimSpace(actionID),
State: state,
Timestamp: time.Now().UTC(),
- Actor: approvalAuditActor,
+ Actor: strings.TrimSpace(actor),
Message: strings.TrimSpace(message),
}
+ if event.Actor == "" {
+ event.Actor = approvalAuditActor
+ }
if err := store.RecordActionLifecycleEvent(event); err != nil {
log.Warn().Err(err).Str("action_id", actionID).Str("state", string(state)).Msg("failed to persist pending approval lifecycle event")
}
diff --git a/internal/ai/tools/action_audit_execution_test.go b/internal/ai/tools/action_audit_execution_test.go
index f74866366e..ccfa1aceef 100644
--- a/internal/ai/tools/action_audit_execution_test.go
+++ b/internal/ai/tools/action_audit_execution_test.go
@@ -141,7 +141,7 @@ func TestAttachApprovalActionPlanRecordsPendingActionAudit(t *testing.T) {
if audit.Request.ResourceID != "investigation:finding-123" {
t.Fatalf("audit resource id = %q", audit.Request.ResourceID)
}
- if audit.Request.RequestedBy != approvalAuditActor {
+ if audit.Request.RequestedBy != approval.RequesterPulsePatrol {
t.Fatalf("audit requested by = %q", audit.Request.RequestedBy)
}
@@ -152,6 +152,9 @@ func TestAttachApprovalActionPlanRecordsPendingActionAudit(t *testing.T) {
states := map[unifiedresources.ActionState]bool{}
for _, event := range events {
states[event.State] = true
+ if event.Actor != approval.RequesterPulsePatrol {
+ t.Fatalf("lifecycle actor = %q, want %q", event.Actor, approval.RequesterPulsePatrol)
+ }
}
if !states[unifiedresources.ActionStatePlanned] || !states[unifiedresources.ActionStatePending] {
t.Fatalf("expected planned and pending lifecycle states, got %#v", events)
diff --git a/internal/api/ai_handlers_test.go b/internal/api/ai_handlers_test.go
index 27855f6c91..fcaa0c24de 100644
--- a/internal/api/ai_handlers_test.go
+++ b/internal/api/ai_handlers_test.go
@@ -2780,7 +2780,7 @@ func TestOrchestratorApprovalAdapterRecordsPendingActionAudit(t *testing.T) {
require.Equal(t, unifiedresources.ActionStatePending, audit.State)
require.Equal(t, req.ID, audit.Request.RequestID)
require.Equal(t, "investigation:finding-123", audit.Request.ResourceID)
- require.Equal(t, "pulse_assistant", audit.Request.RequestedBy)
+ require.Equal(t, "pulse_patrol", audit.Request.RequestedBy)
require.NotNil(t, audit.Plan.Preflight)
events, err := actionStore.GetActionLifecycleEvents(req.Plan.ActionID, time.Time{}, 10)
@@ -2788,6 +2788,7 @@ func TestOrchestratorApprovalAdapterRecordsPendingActionAudit(t *testing.T) {
states := map[unifiedresources.ActionState]bool{}
for _, event := range events {
states[event.State] = true
+ require.Equal(t, "pulse_patrol", event.Actor)
}
require.True(t, states[unifiedresources.ActionStatePlanned], "missing planned lifecycle event: %#v", events)
require.True(t, states[unifiedresources.ActionStatePending], "missing pending lifecycle event: %#v", events)