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.

Add impact and rollback to investigation records

rcourtmane7b5650233fc
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 3415194388..c5fa957bbe 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -227,7 +227,15 @@ runtime cost control, and shared AI transport surfaces.
`InvestigationSession` as execution detail, but Assistant handoff,
unified findings, persistence, and approval/remediation context must use
the durable investigation record when they need operator-facing
- investigation context. When `/api/ai/chat` receives `finding_id`, the
+ investigation context. The durable record carries top-level `impact`
+ and `rollback` strings alongside the existing `verification` array, so
+ Assistant `/api/ai/chat` enrichment surfaces consequence-if-ignored and
+ undo intent when Patrol has populated them and remains silent when the
+ fields are empty rather than fabricating placeholder analysis through
+ the model. The TS API client must keep its `InvestigationRecord` and
+ `InvestigationRecordTrigger` mirrors aligned with the Go struct,
+ including the `trigger.cause` string, so frontend handoff context does
+ not lose backend-attributed failure cause. When `/api/ai/chat` receives `finding_id`, the
runtime must enrich the provider turn from that durable record while
preserving the user's authored prompt as the persisted conversation
message; the model-only handoff may persist as session metadata so
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 1e72b1210b..a0313c6ed5 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -946,7 +946,16 @@ the canonical monitored-system blocked payload.
investigation-record contract, so unified findings may
expose `investigation_record` only through the shared
`aicontracts.InvestigationRecord` payload shape, with frontend API types
- and backend contract tests updated in the same slice as any field change
+ and backend contract tests updated in the same slice as any field change.
+ That shared shape carries top-level `impact` and `rollback` fields
+ alongside the existing `verification` array so paid Patrol responses
+ can name the consequence of operator inaction and the undo intent for a
+ proposed fix at the record root rather than buried inside per-step fix
+ payload, and `trigger.cause` mirrors the Go failure-cause string in the
+ TS API client so frontend consumers see the same patrol-failure
+ attribution the backend persists. Both `impact` and `rollback` are
+ omitempty/normalize-empty and must remain absent rather than fabricated
+ when Patrol has not yet populated them
and the Assistant finding-context request contract, so `/api/ai/chat`
payloads carrying `finding_id` may hydrate a structured investigation
summary from the unified finding, but raw proposed-fix commands must stay
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 253177cdd4..42a6d243f7 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -942,7 +942,14 @@ prompt explain the same operator-facing priority.
investigation-record framing must derive that prompt copy through
`frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts`
so shared drawer primitives stay shell-owned rather than becoming a
- Patrol-specific prompt formatter. Patrol assessment-level handoffs must use
+ Patrol-specific prompt formatter. That feature-owned presentation
+ helper is the single emitter for investigation-record `impact` and
+ `rollback` fields: when an investigation record exists but those fields
+ are empty, the helper emits explicit `Impact not assessed` and
+ `Rollback not specified` lines into the model-only Patrol finding
+ prompt context so the operator-visible gap is surfaced to Assistant
+ rather than hidden, and shared chat primitives stay free of that
+ placeholder logic. Patrol assessment-level handoffs must use
that same feature helper to attach bounded model-only assessment,
verification, latest-run, supporting-context evidence, active-finding, and
resource reference context while forcing request-local approval-required
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 343ef13ef1..c7fca4c01a 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -239,7 +239,19 @@ Patrol-specific presentation helpers.
timeline summary. The inline Patrol investigation surface must also treat a
structured `investigationRecord` as investigation data, even when the legacy
investigation-detail endpoint has no separate session payload, so it must not
- render empty-state copy above a durable Patrol record.
+ render empty-state copy above a durable Patrol record. The Patrol-owned
+ investigation surface must also expose the durable record's `impact`
+ and `rollback` fields: the shared
+ `frontend-modern/src/components/patrol/InvestigationSection.tsx`
+ renderer surfaces an explicit `Impact not assessed` placeholder whenever
+ an investigation record exists with no impact text, and a parallel
+ `Rollback not specified` placeholder whenever rollback is empty, so the
+ operator-visible gap is conspicuous rather than hidden. The Patrol
+ operator briefing card built by
+ `frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts`
+ may include populated impact text in its bounded detail lines but must
+ omit the placeholder copy from that compact card so it stays tight,
+ leaving placeholder rendering to the full investigation surface.
The primary Patrol assessment summary may open Assistant as a whole-surface
review handoff, but that handoff must also flow through
`frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts`.
diff --git a/frontend-modern/src/api/__tests__/ai.test.ts b/frontend-modern/src/api/__tests__/ai.test.ts
index 6269b167ad..fc98149176 100644
--- a/frontend-modern/src/api/__tests__/ai.test.ts
+++ b/frontend-modern/src/api/__tests__/ai.test.ts
@@ -77,6 +77,7 @@ describe('AIAPI', () => {
status: 'completed',
evidence: [],
verification: [],
+ rollback: [],
tools_used: [],
started_at: '2026-03-01T00:00:00Z',
},
@@ -96,6 +97,55 @@ describe('AIAPI', () => {
});
});
+ it('preserves the structured investigation-record shape including impact, rollback, and trigger cause', async () => {
+ apiFetchJSONMock.mockResolvedValue({
+ findings: [
+ {
+ id: 'f-impact',
+ resource_id: 'vm-101',
+ source: 'threshold',
+ severity: 'critical',
+ category: 'storage',
+ title: 'Datastore quota exhausted',
+ detected_at: '2026-05-08T12:00:00Z',
+ alert_identifier: 'canonical-alert-impact',
+ investigation_record: {
+ id: 'investigation-impact',
+ finding_id: 'f-impact',
+ subject: { resource_id: 'vm-101' },
+ trigger: {
+ detected_at: '2026-05-08T12:00:00Z',
+ title: 'Datastore quota exhausted',
+ cause: 'storage_quota_exceeded',
+ },
+ status: 'completed',
+ outcome: 'fix_queued',
+ confidence: 'medium',
+ conclusion: 'Datastore quota exhausted.',
+ impact: 'Nightly backups will be skipped; recovery window grows by one day per skip.',
+ recommended_action: 'Free 200GB before the next backup window.',
+ evidence: [{ kind: 'metrics', summary: 'datastore 99% full' }],
+ verification: ['Backup job exits 0 on next run'],
+ rollback: ['Restore prior retention policy'],
+ tools_used: [],
+ started_at: '2026-05-08T12:00:00Z',
+ },
+ },
+ ],
+ count: 1,
+ } as any);
+
+ const result = await AIAPI.getUnifiedFindings();
+ const record = result.findings[0].investigation_record;
+
+ expect(record).toBeDefined();
+ expect(record!.impact).toBe(
+ 'Nightly backups will be skipped; recovery window grows by one day per skip.',
+ );
+ expect(record!.rollback).toEqual(['Restore prior retention policy']);
+ expect(record!.trigger.cause).toBe('storage_quota_exceeded');
+ });
+
it('encodes dynamic provider, approval, finding, and plan identifiers', async () => {
apiFetchJSONMock.mockResolvedValue({} as any);
diff --git a/frontend-modern/src/api/ai.ts b/frontend-modern/src/api/ai.ts
index d67f5abf39..ca3baaa58e 100644
--- a/frontend-modern/src/api/ai.ts
+++ b/frontend-modern/src/api/ai.ts
@@ -367,6 +367,7 @@ export interface InvestigationRecordTrigger {
title?: string;
detected_at: string;
description?: string;
+ cause?: string;
}
export interface InvestigationRecordEvidence {
@@ -396,9 +397,11 @@ export interface InvestigationRecord {
confidence?: 'low' | 'medium' | 'high';
evidence: InvestigationRecordEvidence[];
conclusion?: string;
+ impact?: string;
recommended_action?: string;
proposed_fix?: InvestigationRecordFix;
verification: string[];
+ rollback: string[];
tools_used: string[];
started_at: string;
completed_at?: string;
diff --git a/frontend-modern/src/components/patrol/InvestigationSection.tsx b/frontend-modern/src/components/patrol/InvestigationSection.tsx
index 51c2e857a8..7345eeb661 100644
--- a/frontend-modern/src/components/patrol/InvestigationSection.tsx
+++ b/frontend-modern/src/components/patrol/InvestigationSection.tsx
@@ -219,6 +219,21 @@ export const InvestigationSection: Component<InvestigationSectionProps> = (props
)}
</Show>
+ <Show when={investigationRecord().hasRecord}>
+ <div class="mt-2">
+ <div class="text-[10px] font-medium uppercase text-muted">Impact</div>
+ <p
+ class="mt-1 text-xs"
+ classList={{
+ 'text-muted': Boolean(investigationRecord().impact),
+ 'italic text-muted/70': !investigationRecord().impact,
+ }}
+ >
+ {investigationRecord().impact || 'Impact not assessed'}
+ </p>
+ </div>
+ </Show>
+
<Show when={investigationRecord().evidenceSummaries.length > 0}>
<div class="mt-2">
<div class="text-[10px] font-medium uppercase text-muted">Evidence</div>
@@ -241,6 +256,24 @@ export const InvestigationSection: Component<InvestigationSectionProps> = (props
</div>
</Show>
+ <Show when={investigationRecord().hasRecord}>
+ <div class="mt-2">
+ <div class="text-[10px] font-medium uppercase text-muted">Rollback</div>
+ <Show
+ when={investigationRecord().rollbackSummaries.length > 0}
+ fallback={
+ <p class="mt-1 text-xs italic text-muted/70">Rollback not specified</p>
+ }
+ >
+ <ul class="mt-1 space-y-1 text-xs text-muted">
+ <For each={investigationRecord().rollbackSummaries}>
+ {(item) => <li>{item}</li>}
+ </For>
+ </ul>
+ </Show>
+ </div>
+ </Show>
+
<Show when={investigationRecord().toolsUsed.length > 0}>
<div class="mt-2 flex flex-wrap gap-1">
<For each={investigationRecord().toolsUsed}>
diff --git a/frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx b/frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx
index a713373653..08fc38b36f 100644
--- a/frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx
+++ b/frontend-modern/src/components/patrol/__tests__/InvestigationSection.test.tsx
@@ -112,6 +112,7 @@ describe('InvestigationSection', () => {
target_host: 'pve-1',
},
verification: ['CPU returned below 50%'],
+ rollback: [],
tools_used: ['metrics.history'],
started_at: '2026-05-06T12:00:00Z',
};
diff --git a/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts b/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts
index 0644e0b031..624dfa588e 100644
--- a/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts
+++ b/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts
@@ -294,6 +294,7 @@ describe('patrolInvestigationContextModel', () => {
destructive: false,
},
verification: ['CPU returned below 50%'],
+ rollback: [],
tools_used: ['ssh.exec'],
started_at: '2026-05-06T12:00:00Z',
},
@@ -849,6 +850,7 @@ describe('patrolInvestigationContextModel', () => {
rationale: 'The process is wedged after backup IO pressure.',
},
verification: ['CPU returned below 50%'],
+ rollback: [],
tools_used: ['metrics.history', 'ssh.exec'],
started_at: '2026-05-06T12:00:00Z',
});
@@ -870,6 +872,36 @@ describe('patrolInvestigationContextModel', () => {
},
});
expect(JSON.stringify(presentation)).not.toContain('systemctl restart workload.service');
+ expect(presentation.rollbackSummaries).toEqual([]);
+ expect(presentation.impact).toBe('');
+ });
+
+ it('surfaces investigation impact and rollback when the backend record carries them', () => {
+ const presentation = buildPatrolInvestigationRecordPresentation({
+ id: 'record-2',
+ finding_id: 'finding-2',
+ subject: { resource_id: 'vm-101' },
+ trigger: { title: 'Backup job failing', detected_at: '2026-05-06T12:00:00Z' },
+ status: 'completed',
+ outcome: 'fix_queued',
+ confidence: 'medium',
+ conclusion: 'Datastore quota exhausted.',
+ impact: 'Nightly backups will be skipped; recovery window grows by one day per skip.',
+ recommended_action: 'Free 200GB on the datastore before the next backup window.',
+ evidence: [{ kind: 'metrics', summary: 'datastore 99% full' }],
+ verification: ['Backup job exits 0 on next run'],
+ rollback: ['Restore prior retention policy', 'Re-pin previous datastore mount'],
+ tools_used: [],
+ started_at: '2026-05-06T12:00:00Z',
+ });
+
+ expect(presentation.impact).toBe(
+ 'Nightly backups will be skipped; recovery window grows by one day per skip.',
+ );
+ expect(presentation.rollbackSummaries).toEqual([
+ 'Restore prior retention policy',
+ 'Re-pin previous datastore mount',
+ ]);
});
it('normalizes safe proposed-fix briefing metadata without command text', () => {
@@ -936,6 +968,7 @@ describe('patrolInvestigationContextModel', () => {
status: 'completed',
evidence: [],
verification: [],
+ rollback: [],
tools_used: [],
started_at: '2026-05-06T12:00:00Z',
},
@@ -1182,6 +1215,7 @@ describe('patrolInvestigationContextModel', () => {
destructive: true,
},
verification: ['CPU returned below 50%'],
+ rollback: [],
tools_used: [],
started_at: '2026-05-06T12:00:00Z',
approval_id: 'approval-1',
@@ -1303,6 +1337,7 @@ describe('patrolInvestigationContextModel', () => {
destructive: false,
},
verification: [],
+ rollback: [],
tools_used: [],
started_at: '2026-05-06T12:00:00Z',
},
diff --git a/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts b/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts
index 4e66bb12a9..c478fbc70a 100644
--- a/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts
+++ b/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts
@@ -56,9 +56,11 @@ export interface PatrolInvestigationRecordPresentation {
outcomeLabel?: string;
confidenceLabel?: string;
conclusion?: string;
+ impact?: string;
recommendedAction?: string;
evidenceSummaries: string[];
verificationSummaries: string[];
+ rollbackSummaries: string[];
toolsUsed: string[];
proposedFix?: {
description: string;
@@ -394,6 +396,7 @@ export function buildPatrolInvestigationRecordPresentation(
statusLabel: '',
evidenceSummaries: [],
verificationSummaries: [],
+ rollbackSummaries: [],
toolsUsed: [],
};
}
@@ -410,6 +413,7 @@ export function buildPatrolInvestigationRecordPresentation(
? `${formatIdentifierLabel(record.confidence)} confidence`
: undefined,
conclusion: normalizeText(record.conclusion),
+ impact: normalizeText(record.impact),
recommendedAction: normalizeText(record.recommended_action),
evidenceSummaries: (record.evidence || [])
.map((item) => normalizeText(item.summary || item.kind || item.id))
@@ -419,6 +423,10 @@ export function buildPatrolInvestigationRecordPresentation(
.map(normalizeText)
.filter(Boolean)
.slice(0, 3),
+ rollbackSummaries: (record.rollback || [])
+ .map(normalizeText)
+ .filter(Boolean)
+ .slice(0, 3),
toolsUsed: (record.tools_used || []).map(formatToolLabel).filter(Boolean).slice(0, 4),
proposedFix:
proposedFix && proposedFix.description
@@ -2205,6 +2213,10 @@ function buildPatrolAssistantFindingModelContext(
formatContextLine('Investigation Outcome', record.outcomeLabel),
formatContextLine('Investigation Confidence', record.confidenceLabel),
formatContextLine('Conclusion', record.conclusion),
+ formatContextLine(
+ 'Impact',
+ record.hasRecord ? record.impact || 'Impact not assessed' : record.impact,
+ ),
formatContextLine('Recommended Action', record.recommendedAction),
...record.evidenceSummaries.map((summary, index) =>
formatContextLine(`Evidence ${index + 1}`, summary),
@@ -2212,6 +2224,13 @@ function buildPatrolAssistantFindingModelContext(
...record.verificationSummaries.map((summary, index) =>
formatContextLine(`Verification ${index + 1}`, summary),
),
+ ...(record.rollbackSummaries.length > 0
+ ? record.rollbackSummaries.map((summary, index) =>
+ formatContextLine(`Rollback ${index + 1}`, summary),
+ )
+ : record.hasRecord
+ ? [formatContextLine('Rollback', 'Rollback not specified')]
+ : []),
formatContextLine('Tools Used', record.toolsUsed.join(', ')),
formatContextLine('Approval', pendingApproval.id),
formatContextLine('Approval Status', pendingApproval.status),
@@ -2440,6 +2459,7 @@ export function buildPatrolAssistantFindingBriefing(
const detailLines = [
attentionReason ? `Attention: ${attentionReason}` : undefined,
record.conclusion,
+ record.impact ? `Impact: ${record.impact}` : undefined,
record.recommendedAction,
proposedFixDetail,
operatorDecision ? `Decision: ${operatorDecision}` : undefined,
diff --git a/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts b/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts
index 5e4b61bd68..c9fb064090 100644
--- a/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts
+++ b/frontend-modern/src/stores/__tests__/aiIntelligence.test.ts
@@ -82,6 +82,7 @@ describe('aiIntelligenceStore', () => {
confidence: 'medium',
evidence: [],
verification: [],
+ rollback: [],
tools_used: [],
started_at: '2026-03-05T00:00:00Z',
},
diff --git a/internal/ai/investigation_records_test.go b/internal/ai/investigation_records_test.go
index 9b98b0556c..418a6c2c94 100644
--- a/internal/ai/investigation_records_test.go
+++ b/internal/ai/investigation_records_test.go
@@ -90,6 +90,19 @@ func TestBuildFindingInvestigationRecord_FromSession(t *testing.T) {
if record.ApprovalID != "approval-1" {
t.Fatalf("approval ID = %q", record.ApprovalID)
}
+ if record.Impact != "" {
+ t.Fatalf("expected empty default impact, got %q", record.Impact)
+ }
+ if record.Rollback == nil || len(record.Rollback) != 0 {
+ t.Fatalf("expected normalized empty rollback slice, got %#v", record.Rollback)
+ }
+}
+
+func TestEmptyInvestigationRecord_NormalizesRollback(t *testing.T) {
+ record := aicontracts.EmptyInvestigationRecord()
+ if record.Rollback == nil || len(record.Rollback) != 0 {
+ t.Fatalf("expected empty rollback slice on empty record, got %#v", record.Rollback)
+ }
}
func TestFindingsStore_UpdateInvestigationRecord(t *testing.T) {
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index df63a9e2ca..804918367d 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -2873,6 +2873,7 @@ func TestContract_FindingJSONSnapshot(t *testing.T) {
Conclusion: "CPU sustained above 95%",
RecommendedAction: "Investigate processes and load",
Verification: []string{},
+ Rollback: []string{},
ToolsUsed: []string{"ssh.exec"},
StartedAt: now,
ApprovalID: "approval-1",
@@ -2931,7 +2932,7 @@ func TestContract_FindingJSONSnapshot(t *testing.T) {
"investigation_outcome":"fix_queued",
"last_investigated_at":"2026-02-08T13:29:15Z",
"investigation_attempts":2,
- "investigation_record":{"id":"investigation-1","finding_id":"finding-1","subject":{"resource_id":"vm-100","resource_name":"web-server","resource_type":"vm","node":"pve-1"},"trigger":{"finding_key":"cpu-high","source":"ai-analysis","severity":"critical","category":"performance","title":"High CPU usage","detected_at":"2026-02-08T13:14:15Z","description":"CPU sustained above 95%"},"status":"completed","outcome":"fix_queued","confidence":"medium","evidence":[{"kind":"finding_evidence","summary":"cpu=96%"}],"conclusion":"CPU sustained above 95%","recommended_action":"Investigate processes and load","verification":[],"tools_used":["ssh.exec"],"started_at":"2026-02-08T13:14:15Z","approval_id":"approval-1"},
+ "investigation_record":{"id":"investigation-1","finding_id":"finding-1","subject":{"resource_id":"vm-100","resource_name":"web-server","resource_type":"vm","node":"pve-1"},"trigger":{"finding_key":"cpu-high","source":"ai-analysis","severity":"critical","category":"performance","title":"High CPU usage","detected_at":"2026-02-08T13:14:15Z","description":"CPU sustained above 95%"},"status":"completed","outcome":"fix_queued","confidence":"medium","evidence":[{"kind":"finding_evidence","summary":"cpu=96%"}],"conclusion":"CPU sustained above 95%","recommended_action":"Investigate processes and load","verification":[],"rollback":[],"tools_used":["ssh.exec"],"started_at":"2026-02-08T13:14:15Z","approval_id":"approval-1"},
"loop_state":"remediation_planned",
"lifecycle":[{"at":"2026-02-08T13:14:15Z","type":"state_change","message":"Moved to investigating","from":"detected","to":"investigating","metadata":{"from":"detected","to":"investigating"}}],
"regression_count":1,
diff --git a/pkg/aicontracts/investigation.go b/pkg/aicontracts/investigation.go
index 6a83124f66..df622dbf4c 100644
--- a/pkg/aicontracts/investigation.go
+++ b/pkg/aicontracts/investigation.go
@@ -150,9 +150,11 @@ type InvestigationRecord struct {
Confidence InvestigationRecordConfidence `json:"confidence,omitempty"`
Evidence []InvestigationRecordEvidence `json:"evidence"`
Conclusion string `json:"conclusion,omitempty"`
+ Impact string `json:"impact,omitempty"`
RecommendedAction string `json:"recommended_action,omitempty"`
ProposedFix *InvestigationRecordFix `json:"proposed_fix,omitempty"`
Verification []string `json:"verification"`
+ Rollback []string `json:"rollback"`
ToolsUsed []string `json:"tools_used"`
StartedAt time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
@@ -213,6 +215,9 @@ func (r InvestigationRecord) NormalizeCollections() InvestigationRecord {
if r.Verification == nil {
r.Verification = []string{}
}
+ if r.Rollback == nil {
+ r.Rollback = []string{}
+ }
if r.ToolsUsed == nil {
r.ToolsUsed = []string{}
}