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.

Refresh Assistant handoff session summaries

rcourtman8594297b1852
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 32966a903a..c709832589 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -286,6 +286,12 @@ runtime cost control, and shared AI transport surfaces.
`autonomous_mode:false` even when the summary is context-only and has no
queued action, while the visible badge/action copy must still reflect the
actual last-known action state instead of inventing a pending approval.
+ Before `/api/ai/sessions` returns summaries with stored handoff action
+ references, the chat runtime must refresh their safe approval/action status
+ from the canonical approval store and action-audit store. Session listing is
+ an operator decision surface, so it must not leave stale pending/approval
+ labels in the drawer after the governed action moved on, and it must still
+ omit raw commands, preflight bodies, and execution output.
Proposed-fix command text must stay out of both the persisted chat message
and the model-only handoff context, and command payloads remain
approval-context data, not conversational copy.
diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.go
index 4e445a2e2c..26423b848b 100644
--- a/internal/ai/chat/service.go
+++ b/internal/ai/chat/service.go
@@ -2073,15 +2073,62 @@ func (s *Service) ListAvailableTools(ctx context.Context, prompt string) []strin
func (s *Service) ListSessions(ctx context.Context) ([]Session, error) {
s.mu.RLock()
sessions := s.sessions
+ actionAuditStore := s.actionAuditStore
+ orgID := s.orgID
s.mu.RUnlock()
if sessions == nil {
return nil, fmt.Errorf("service not started")
}
+ refreshSessionHandoffActionSummaries(sessions, orgID, actionAuditStore)
return sessions.List()
}
+func refreshSessionHandoffActionSummaries(sessions *SessionStore, orgID string, actionStore unifiedresources.ResourceStore) {
+ if sessions == nil {
+ return
+ }
+
+ list, err := sessions.List()
+ if err != nil {
+ log.Debug().Err(err).Msg("[ChatService] Failed to list sessions for handoff action refresh")
+ return
+ }
+
+ for _, session := range list {
+ if session.HandoffSummary == nil || session.HandoffSummary.ActionCount == 0 {
+ continue
+ }
+ actions, err := sessions.GetModelHandoffActions(session.ID)
+ if err != nil {
+ log.Debug().Err(err).Str("session_id", session.ID).Msg("[ChatService] Failed to load session handoff actions for summary refresh")
+ continue
+ }
+ refreshed := refreshHandoffActionStatus(actions, orgID, actionStore)
+ if handoffActionsEqual(actions, refreshed) {
+ continue
+ }
+ if err := sessions.SetModelHandoffActions(session.ID, refreshed); err != nil {
+ log.Debug().Err(err).Str("session_id", session.ID).Msg("[ChatService] Failed to persist refreshed session handoff action summary")
+ }
+ }
+}
+
+func handoffActionsEqual(a, b []HandoffAction) bool {
+ a = normalizeHandoffActions(a)
+ b = normalizeHandoffActions(b)
+ if len(a) != len(b) {
+ return false
+ }
+ for idx := range a {
+ if a[idx] != b[idx] {
+ return false
+ }
+ }
+ return true
+}
+
// CreateSession creates a new session
func (s *Service) CreateSession(ctx context.Context) (*Session, error) {
s.mu.RLock()
diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.go
index 44ad852572..e9a4e9a949 100644
--- a/internal/ai/chat/service_execute_additional_test.go
+++ b/internal/ai/chat/service_execute_additional_test.go
@@ -192,6 +192,103 @@ func seedHandoffActionAudit(t *testing.T, store unifiedresources.ResourceStore,
}
}
+func TestService_ListSessionsRefreshesHandoffActionSummary(t *testing.T) {
+ now := time.Now().UTC().Add(-2 * time.Minute)
+ decidedAt := now.Add(2 * time.Minute)
+ actionPlan := testHandoffActionPlan(now)
+ 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,
+ Status: approval.StatusApproved,
+ RequestedAt: now,
+ DecidedAt: &decidedAt,
+ ExpiresAt: now.Add(10 * time.Minute),
+ Plan: &actionPlan,
+ })
+ if _, err := approval.GetStore().Approve("approval-123", "[email protected]"); err != nil {
+ t.Fatalf("Approve failed: %v", err)
+ }
+
+ tmpDir := t.TempDir()
+ store, err := NewSessionStore(tmpDir)
+ 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)
+ }
+ if err := store.SetModelHandoffFindingID(session.ID, "finding-123"); err != nil {
+ t.Fatalf("SetModelHandoffFindingID failed: %v", err)
+ }
+ if err := store.SetModelHandoffActions(session.ID, []HandoffAction{{
+ FindingID: "finding-123",
+ ApprovalID: "approval-123",
+ ApprovalStatus: "pending",
+ ActionID: actionPlan.ActionID,
+ ActionState: "awaiting_approval",
+ ActionRequiresApproval: true,
+ ActionPreflight: "systemctl restart workload.service",
+ ActionResult: "raw command output",
+ RiskLevel: "medium",
+ TargetResourceID: "vm-100",
+ TargetResourceName: "web-server",
+ TargetResourceType: "vm",
+ }}); err != nil {
+ t.Fatalf("SetModelHandoffActions failed: %v", err)
+ }
+
+ actionStore := unifiedresources.NewMemoryStore()
+ seedHandoffActionAudit(t, actionStore, actionPlan, unifiedresources.ActionStateCompleted, &unifiedresources.ExecutionResult{
+ Success: true,
+ Output: "raw command output",
+ })
+ svc := &Service{
+ sessions: store,
+ actionAuditStore: actionStore,
+ started: true,
+ }
+
+ sessions, err := svc.ListSessions(context.Background())
+ if err != nil {
+ t.Fatalf("ListSessions failed: %v", err)
+ }
+ if len(sessions) != 1 || sessions[0].HandoffSummary == nil {
+ t.Fatalf("sessions = %#v, want one handoff summary", sessions)
+ }
+ summary := sessions[0].HandoffSummary
+ if summary.LastKnownApprovalStatus != "approved" {
+ t.Fatalf("approval status = %q, want approved", summary.LastKnownApprovalStatus)
+ }
+ if summary.LastKnownActionState != string(unifiedresources.ActionStateCompleted) {
+ t.Fatalf("action state = %q, want completed", summary.LastKnownActionState)
+ }
+ if !summary.RequiresApproval || summary.ActionCount != 1 {
+ t.Fatalf("action summary = %#v, want approval-required action context", summary)
+ }
+
+ actions, err := store.GetModelHandoffActions(session.ID)
+ if err != nil {
+ t.Fatalf("GetModelHandoffActions failed: %v", err)
+ }
+ if len(actions) != 1 {
+ t.Fatalf("actions = %#v, want one refreshed action", actions)
+ }
+ safeContext := strings.Join([]string{
+ actions[0].ActionPreflight,
+ actions[0].ActionDryRunSummary,
+ actions[0].ActionResult,
+ }, " ")
+ if strings.Contains(safeContext, "systemctl restart workload.service") || strings.Contains(safeContext, "raw command output") {
+ t.Fatalf("refreshed handoff action leaked command details: %#v", actions[0])
+ }
+}
+
func (s *stubServiceProvider) Chat(ctx context.Context, req providers.ChatRequest) (*providers.ChatResponse, error) {
return &providers.ChatResponse{Content: "ok", Model: req.Model}, nil
}