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.

Expose safe Assistant handoff session summaries

rcourtman7d28defe6ac1
diff --git a/docs/API.md b/docs/API.md
index f3ae9c423d..1ecb123c01 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -977,7 +977,7 @@ Streaming variant of execute (used by the UI for incremental responses).
### Assistant Chat & Sessions
- `GET /api/ai/status`
- `POST /api/ai/chat` (streaming)
-- `GET /api/ai/sessions`
+- `GET /api/ai/sessions` returns session summaries; scoped Assistant handoffs may include a safe `handoff_summary` marker without model-only context text or command payloads.
- `POST /api/ai/sessions`
- `DELETE /api/ai/sessions/{id}`
- `GET /api/ai/sessions/{id}/messages`
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 782433d19c..5cda02698e 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -269,6 +269,14 @@ runtime cost control, and shared AI transport surfaces.
rather than treating the original approval as the current action truth.
That action snapshot remains model-only review context and must expose
lifecycle status rather than raw execution output or command text.
+ The public chat session contract may expose only a bounded
+ `handoff_summary` for this private model-context metadata so reloaded
+ Assistant sessions can still be identified as scoped Patrol/product
+ handoffs. That summary may include the handoff kind, finding ID, resource
+ and action counts, a primary resource label, last-known approval/action
+ status, risk level, and timestamp, but it must not expose model-only
+ handoff text, action preflight/result bodies, remediation descriptions, raw
+ commands, or approval command payloads.
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/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index c028bc641a..dc08fdd9a3 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -1892,6 +1892,13 @@ handoff text and same-finding resource/action references as secondary
model-only review context, while dropping mismatched references and raw command
payload lines so the model cannot continue from stale or spoofed Patrol
authority.
+The `/api/ai/sessions` response may expose `handoff_summary` for sessions that
+carry private Assistant model-context metadata, but that payload is a safe
+reload marker only. It may carry the handoff kind, finding ID, counts,
+primary-resource label, last-known approval/action status, risk level, and
+summary timestamp; it must not serialize the model-only `handoff_context`,
+action preflight/result bodies, remediation descriptions, raw commands, or
+approval command payloads.
Patrol finding handoffs are stricter than ordinary chat requests: when
`finding_id` resolves to model-only Patrol briefing, resource, or action
context, `internal/api/ai_handler.go` must clamp the request-local autonomous
diff --git a/internal/ai/chat/session.go b/internal/ai/chat/session.go
index e525d2f271..f81d864116 100644
--- a/internal/ai/chat/session.go
+++ b/internal/ai/chat/session.go
@@ -146,6 +146,66 @@ func modelContextEmpty(modelContext *sessionModelContext) bool {
len(normalizeHandoffActions(modelContext.HandoffActions)) == 0
}
+const (
+ sessionHandoffKindPatrolFinding = "patrol_finding"
+ sessionHandoffKindScopedContext = "scoped_context"
+)
+
+func modelContextHandoffSummary(modelContext *sessionModelContext) *SessionHandoffSummary {
+ if modelContextEmpty(modelContext) {
+ return nil
+ }
+
+ resources := normalizeHandoffResources(modelContext.HandoffResources)
+ actions := normalizeHandoffActions(modelContext.HandoffActions)
+ findingID := strings.TrimSpace(modelContext.HandoffFindingID)
+ if findingID == "" {
+ for _, action := range actions {
+ if strings.TrimSpace(action.FindingID) != "" {
+ findingID = strings.TrimSpace(action.FindingID)
+ break
+ }
+ }
+ }
+
+ kind := sessionHandoffKindScopedContext
+ if findingID != "" {
+ kind = sessionHandoffKindPatrolFinding
+ }
+
+ summary := &SessionHandoffSummary{
+ Kind: kind,
+ FindingID: findingID,
+ HasModelContext: strings.TrimSpace(modelContext.HandoffContext) != "",
+ ResourceCount: len(resources),
+ ActionCount: len(actions),
+ }
+ if !modelContext.UpdatedAt.IsZero() {
+ updatedAt := modelContext.UpdatedAt
+ summary.UpdatedAt = &updatedAt
+ }
+ if len(resources) > 0 {
+ primaryResource := resources[0]
+ summary.PrimaryResource = &primaryResource
+ }
+ for _, action := range actions {
+ if !summary.RequiresApproval && (action.ActionRequiresApproval || strings.TrimSpace(action.ApprovalID) != "") {
+ summary.RequiresApproval = true
+ }
+ if summary.LastKnownApprovalStatus == "" {
+ summary.LastKnownApprovalStatus = strings.TrimSpace(action.ApprovalStatus)
+ }
+ if summary.LastKnownActionState == "" {
+ summary.LastKnownActionState = strings.TrimSpace(action.ActionState)
+ }
+ if summary.LastKnownActionRisk == "" {
+ summary.LastKnownActionRisk = strings.TrimSpace(action.RiskLevel)
+ }
+ }
+
+ return summary
+}
+
const maxSessionIDLength = 128
// NewSessionStore creates a new session store
@@ -250,11 +310,12 @@ func (s *SessionStore) List() ([]Session, error) {
}
sessions = append(sessions, Session{
- ID: data.ID,
- Title: data.Title,
- CreatedAt: data.CreatedAt,
- UpdatedAt: data.UpdatedAt,
- MessageCount: len(data.Messages),
+ ID: data.ID,
+ Title: data.Title,
+ CreatedAt: data.CreatedAt,
+ UpdatedAt: data.UpdatedAt,
+ MessageCount: len(data.Messages),
+ HandoffSummary: modelContextHandoffSummary(data.ModelContext),
})
}
@@ -303,11 +364,12 @@ func (s *SessionStore) Get(id string) (*Session, error) {
}
return &Session{
- ID: data.ID,
- Title: data.Title,
- CreatedAt: data.CreatedAt,
- UpdatedAt: data.UpdatedAt,
- MessageCount: len(data.Messages),
+ ID: data.ID,
+ Title: data.Title,
+ CreatedAt: data.CreatedAt,
+ UpdatedAt: data.UpdatedAt,
+ MessageCount: len(data.Messages),
+ HandoffSummary: modelContextHandoffSummary(data.ModelContext),
}, nil
}
diff --git a/internal/ai/chat/session_additional_test.go b/internal/ai/chat/session_additional_test.go
index 47a8c52c29..cbc8a8177a 100644
--- a/internal/ai/chat/session_additional_test.go
+++ b/internal/ai/chat/session_additional_test.go
@@ -1,6 +1,7 @@
package chat
import (
+ "encoding/json"
"os"
"path/filepath"
"strings"
@@ -318,6 +319,106 @@ func TestSessionStore_ModelHandoffContextLifecycle(t *testing.T) {
}
}
+func TestSessionStore_ListIncludesSafeHandoffSummary(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)
+ }
+
+ if err := store.SetModelHandoffFindingID(session.ID, " finding-123 "); err != nil {
+ t.Fatalf("SetModelHandoffFindingID failed: %v", err)
+ }
+ if err := store.SetModelHandoffContext(session.ID, "[Finding Context]\nID: finding-123\nConclusion: CPU saturated after backup."); err != nil {
+ t.Fatalf("SetModelHandoffContext failed: %v", err)
+ }
+ if err := store.SetModelHandoffResources(session.ID, []HandoffResource{{
+ ID: " vm-100 ",
+ Name: " web-server ",
+ Type: " vm ",
+ Node: " pve-1 ",
+ }}); err != nil {
+ t.Fatalf("SetModelHandoffResources failed: %v", err)
+ }
+ if err := store.SetModelHandoffActions(session.ID, []HandoffAction{{
+ FindingID: " finding-123 ",
+ ApprovalID: " approval-123 ",
+ ApprovalStatus: " pending ",
+ ActionID: " action-123 ",
+ ActionState: " awaiting_approval ",
+ ActionRequiresApproval: true,
+ ActionPreflight: "systemctl restart web-server",
+ ActionResult: "restart succeeded",
+ Description: "Restart the workload service",
+ RiskLevel: " medium ",
+ TargetResourceID: " vm-100 ",
+ TargetResourceName: " web-server ",
+ TargetResourceType: " vm ",
+ TargetNode: " pve-1 ",
+ }}); err != nil {
+ t.Fatalf("SetModelHandoffActions failed: %v", err)
+ }
+
+ sessions, err := store.List()
+ if err != nil {
+ t.Fatalf("List failed: %v", err)
+ }
+ if len(sessions) != 1 {
+ t.Fatalf("sessions = %#v, want one session", sessions)
+ }
+
+ summary := sessions[0].HandoffSummary
+ if summary == nil {
+ t.Fatalf("expected handoff summary")
+ }
+ if summary.Kind != sessionHandoffKindPatrolFinding {
+ t.Fatalf("handoff kind = %q, want %q", summary.Kind, sessionHandoffKindPatrolFinding)
+ }
+ if summary.FindingID != "finding-123" {
+ t.Fatalf("finding ID = %q, want finding-123", summary.FindingID)
+ }
+ if !summary.HasModelContext {
+ t.Fatalf("expected summary to report model context")
+ }
+ if summary.ResourceCount != 1 || summary.PrimaryResource == nil || summary.PrimaryResource.ID != "vm-100" || summary.PrimaryResource.Name != "web-server" {
+ t.Fatalf("resource summary = %#v, want normalized primary resource", summary)
+ }
+ if summary.ActionCount != 1 || !summary.RequiresApproval {
+ t.Fatalf("action summary = %#v, want one approval-required action", summary)
+ }
+ if summary.LastKnownApprovalStatus != "pending" || summary.LastKnownActionState != "awaiting_approval" || summary.LastKnownActionRisk != "medium" {
+ t.Fatalf("action status summary = %#v, want normalized last-known status fields", summary)
+ }
+
+ retrieved, err := store.Get(session.ID)
+ if err != nil {
+ t.Fatalf("Get failed: %v", err)
+ }
+ if retrieved.HandoffSummary == nil || retrieved.HandoffSummary.FindingID != "finding-123" {
+ t.Fatalf("retrieved handoff summary = %#v, want same safe finding summary", retrieved.HandoffSummary)
+ }
+
+ payload, err := json.Marshal(sessions)
+ if err != nil {
+ t.Fatalf("Marshal sessions failed: %v", err)
+ }
+ publicJSON := string(payload)
+ for _, forbidden := range []string{
+ "CPU saturated",
+ "systemctl restart",
+ "restart succeeded",
+ "Restart the workload service",
+ } {
+ if strings.Contains(publicJSON, forbidden) {
+ t.Fatalf("public session JSON leaked %q: %s", forbidden, publicJSON)
+ }
+ }
+}
+
func TestSessionStore_ClearModelHandoffContext(t *testing.T) {
store, err := NewSessionStore(t.TempDir())
if err != nil {
diff --git a/internal/ai/chat/types.go b/internal/ai/chat/types.go
index 7cbfd74c03..5240bd2463 100644
--- a/internal/ai/chat/types.go
+++ b/internal/ai/chat/types.go
@@ -13,11 +13,29 @@ import (
// Session represents a chat session
type Session struct {
- ID string `json:"id"`
- Title string `json:"title,omitempty"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- MessageCount int `json:"message_count,omitempty"`
+ ID string `json:"id"`
+ Title string `json:"title,omitempty"`
+ CreatedAt time.Time `json:"created_at"`
+ UpdatedAt time.Time `json:"updated_at"`
+ MessageCount int `json:"message_count,omitempty"`
+ HandoffSummary *SessionHandoffSummary `json:"handoff_summary,omitempty"`
+}
+
+// SessionHandoffSummary is the browser-safe public summary of private
+// 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"`
+ 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"`
}
// Message represents a chat message