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
Make Narrative / FleetOutlier JSON shape consistent with prompt schema
rcourtmanc3319b630460
diff --git a/pkg/reporting/fleet_narrative.go b/pkg/reporting/fleet_narrative.goindex 24e9ff86b9..2c5fcc40ff 100644--- a/pkg/reporting/fleet_narrative.go+++ b/pkg/reporting/fleet_narrative.go@@ -59,26 +59,29 @@ type FleetAggregate struct {}// FleetNarrative is the cross-resource interpretation rendered into-// the fleet summary cover. Source values mirror Narrative.+// the fleet summary cover. Source values mirror Narrative. JSON tags+// keep the shape consistent with NarrativeBullet — without them the+// chat tool returns capital-letter keys for the same fields that+// appear lowercase in the AI narrator's system prompt schema.type FleetNarrative struct {- Source string- HealthStatus string- HealthMessage string- ExecutiveSummary string- Outliers []FleetOutlier- Patterns []NarrativeBullet- Recommendations []string- PeriodComparison string- Disclaimer string+ Source string `json:"source"`+ HealthStatus string `json:"health_status"`+ HealthMessage string `json:"health_message"`+ ExecutiveSummary string `json:"executive_summary,omitempty"`+ Outliers []FleetOutlier `json:"outliers,omitempty"`+ Patterns []NarrativeBullet `json:"patterns,omitempty"`+ Recommendations []string `json:"recommendations,omitempty"`+ PeriodComparison string `json:"period_comparison,omitempty"`+ Disclaimer string `json:"disclaimer,omitempty"`}// FleetOutlier names a single resource the operator should pay// attention to and why. The Reason is rendered verbatim in the PDF.type FleetOutlier struct {- ResourceID string- ResourceName string- Reason string- Severity string+ ResourceID string `json:"resource_id"`+ ResourceName string `json:"resource_name,omitempty"`+ Reason string `json:"reason"`+ Severity string `json:"severity"`}// FleetNarrator produces a FleetNarrative from a FleetNarrativeInput.diff --git a/pkg/reporting/narrative.go b/pkg/reporting/narrative.goindex 5ed1cb242c..370f13085b 100644--- a/pkg/reporting/narrative.go+++ b/pkg/reporting/narrative.go@@ -25,21 +25,26 @@ const (// produced either by the heuristic narrator (deterministic thresholds) or// by an AI narrator that reads the same NarrativeInput.type Narrative struct {- Source string // NarrativeSourceHeuristic or NarrativeSourceAI- HealthStatus string // HEALTHY / WARNING / CRITICAL- HealthMessage string // one-line summary shown next to HealthStatus- ExecutiveSummary string // optional prose (AI populates, heuristic leaves empty)- Observations []NarrativeBullet // ordered list rendered as bullets- Recommendations []string // ordered list rendered as numbered actions- PeriodComparison string // optional prose summarising deltas vs PriorPeriod- Disclaimer string // optional footer (e.g. AI provenance note)+ Source string `json:"source"` // NarrativeSourceHeuristic or NarrativeSourceAI+ HealthStatus string `json:"health_status"` // HEALTHY / WARNING / CRITICAL+ HealthMessage string `json:"health_message"` // one-line summary shown next to HealthStatus+ ExecutiveSummary string `json:"executive_summary,omitempty"` // optional prose (AI populates, heuristic leaves empty)+ Observations []NarrativeBullet `json:"observations,omitempty"` // ordered list rendered as bullets+ Recommendations []string `json:"recommendations,omitempty"` // ordered list rendered as numbered actions+ PeriodComparison string `json:"period_comparison,omitempty"` // optional prose summarising deltas vs PriorPeriod+ Disclaimer string `json:"disclaimer,omitempty"` // optional footer (e.g. AI provenance note)}// NarrativeBullet is a single observation entry with a severity classification-// the renderer maps to a colour swatch.+// the renderer maps to a colour swatch. JSON tags use lowercase keys to+// match the shape the AI narrator's system prompt asks for and the chat+// tool consumers expect — without them the embedded type serialises with+// capital field names, which is inconsistent with the rest of the JSON+// surface and confuses downstream models that get back a different shape+// than the schema they were taught.type NarrativeBullet struct {- Text string- Severity string+ Text string `json:"text"`+ Severity string `json:"severity"`}// NarrativeInput is the data passed to a Narrator. It is denormalised fromdiff --git a/pkg/reporting/narrative_json_test.go b/pkg/reporting/narrative_json_test.gonew file mode 100644index 0000000000..392b769d4b--- /dev/null+++ b/pkg/reporting/narrative_json_test.go@@ -0,0 +1,88 @@+package reporting++import (+ "encoding/json"+ "strings"+ "testing"+)++// TestNarrativeBullet_JSONUsesLowercaseKeys pins the wire shape that+// the pulse_summarize chat tool returns. Without JSON tags the+// embedded struct serialises with capital field names (Text/Severity),+// which is inconsistent with the lowercase schema the AI narrator's+// system prompt asks for. A downstream model consuming the tool+// response then has to handle two different cases for the same+// shape. Caught by exercising the chat path against a real model.+func TestNarrativeBullet_JSONUsesLowercaseKeys(t *testing.T) {+ b, err := json.Marshal(NarrativeBullet{Text: "hello", Severity: "ok"})+ if err != nil {+ t.Fatalf("marshal: %v", err)+ }+ got := string(b)+ if !strings.Contains(got, `"text":"hello"`) {+ t.Errorf("expected lowercase 'text' key, got %s", got)+ }+ if !strings.Contains(got, `"severity":"ok"`) {+ t.Errorf("expected lowercase 'severity' key, got %s", got)+ }+ if strings.Contains(got, `"Text"`) || strings.Contains(got, `"Severity"`) {+ t.Errorf("capital-case keys leaked into JSON: %s", got)+ }+}++// TestFleetOutlier_JSONUsesLowercaseKeys is the fleet counterpart.+// FleetOutlier appears in summarizeFleetResponse.Outliers and feeds+// the same chat-tool path that surfaced the casing inconsistency.+func TestFleetOutlier_JSONUsesLowercaseKeys(t *testing.T) {+ b, err := json.Marshal(FleetOutlier{+ ResourceID: "node-a",+ ResourceName: "alpha",+ Reason: "memory at 92%",+ Severity: "warning",+ })+ if err != nil {+ t.Fatalf("marshal: %v", err)+ }+ got := string(b)+ wants := []string{+ `"resource_id":"node-a"`,+ `"resource_name":"alpha"`,+ `"reason":"memory at 92%"`,+ `"severity":"warning"`,+ }+ for _, w := range wants {+ if !strings.Contains(got, w) {+ t.Errorf("expected key %q in %s", w, got)+ }+ }+ if strings.Contains(got, `"ResourceID"`) || strings.Contains(got, `"Severity"`) {+ t.Errorf("capital-case keys leaked: %s", got)+ }+}++// TestNarrative_JSONUsesSnakeCaseKeys verifies the parent Narrative+// envelope also serialises with the documented schema. The chat tool+// doesn't currently return the whole Narrative directly (it copies+// fields into summarizeResourceResponse), but if a future caller+// marshals the type directly the wire shape should match the+// system-prompt schema.+func TestNarrative_JSONUsesSnakeCaseKeys(t *testing.T) {+ b, err := json.Marshal(Narrative{+ Source: NarrativeSourceAI,+ HealthStatus: "HEALTHY",+ HealthMessage: "ok",+ })+ if err != nil {+ t.Fatalf("marshal: %v", err)+ }+ got := string(b)+ if !strings.Contains(got, `"source":"ai"`) {+ t.Errorf("expected source key: %s", got)+ }+ if !strings.Contains(got, `"health_status":"HEALTHY"`) {+ t.Errorf("expected health_status key: %s", got)+ }+ if !strings.Contains(got, `"health_message":"ok"`) {+ t.Errorf("expected health_message key: %s", got)+ }+}