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.

Treat repeated container restarts as actionable evidence

rcourtmanf8aac166b6b3
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 23fc804180..85e3618bca 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -5880,12 +5880,16 @@ calm-day evidence and does not spend platform or inventory tool calls merely
reconfirming the same state. Exact scoped app-container rows carry the canonical
restart count from normal collection. A non-zero count is a concrete signal
that prevents the calm-day shortcut and may justify one targeted current
-resource read. In Watch detection, a current `restarting` state or a count that
-increased from the scoped snapshot confirms the operational symptom. The model
-reports it immediately and does not spend logs, discovery, Docker-service, or
-other root-cause tool calls after confirmation; causal analysis belongs to the
-separate Pro investigation track. Quiet triage is not a deterministic
-replacement for model-owned assessment.
+resource read. A provider-observed count of at least three deterministically
+flags repeated exits as model context. The model may report that grounded
+reliability warning even when the sampled lifecycle state is `running`, but it
+must not call the container an active restart loop from that snapshot alone. A
+current `restarting` state or a count that increased from the scoped snapshot
+confirms the active-loop symptom. The model does not spend logs, discovery,
+Docker-service, or other root-cause tool calls after the repeated-restart
+symptom is established; causal analysis belongs to the separate Pro
+investigation track. Quiet triage is not a deterministic replacement for
+model-owned assessment.
Model-authored structured findings remain concise for continuous operation:
description uses at most three short sentences, impact one sentence, evidence
three concrete facts, and recommendation two short sentences, without
diff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.go
index 8d9cb58929..4501839f96 100644
--- a/internal/ai/patrol_ai.go
+++ b/internal/ai/patrol_ai.go
@@ -1296,7 +1296,7 @@ Your job is to assess the provided evidence and decide which items, if any, requ
When deterministic triage is quiet, the current exact scoped inventory shows the scoped resources running and healthy with no restart evidence, and there are no active alerts or findings, treat the supplied snapshot as sufficient for a calm-day assessment. Call patrol_get_findings exactly once, then return the all-clear without using platform or inventory tools merely to reconfirm the same healthy state. A quiet result does not prohibit a targeted read when the snapshot, surrounding evidence, or an active finding contains a concrete signal that needs investigation.
-A non-zero container restart count is such a signal. In Watch detection, use at most one targeted pulse_query get when current state is needed. If it shows the container currently restarting or the count increasing from the scoped snapshot, the restart-loop symptom is confirmed: report it immediately from that provider evidence. Do not call logs, discovery, Docker services, or other root-cause tools after confirming the Watch symptom; root-cause analysis belongs to a separate Pro investigation.
+A non-zero container restart count is such a signal. A provider-observed count at or above the repeated-restart warning threshold is sufficient evidence that repeated exits occurred, even when one sampled lifecycle state says running; report that grounded reliability warning without claiming the container is currently in a restart loop. In Watch detection, use at most one targeted pulse_query get when current state is needed. If it shows the container currently restarting or the count increasing from the scoped snapshot, an active restart-loop symptom is confirmed. Do not call logs, discovery, Docker services, or other root-cause tools after the repeated-restart symptom is established; root-cause analysis belongs to a separate Pro investigation.
## Direct Provider-State Flags
diff --git a/internal/ai/patrol_ai_more_test.go b/internal/ai/patrol_ai_more_test.go
index 7a8cc41c1a..2f5e73cac3 100644
--- a/internal/ai/patrol_ai_more_test.go
+++ b/internal/ai/patrol_ai_more_test.go
@@ -348,8 +348,10 @@ func TestGetPatrolSystemPromptForTriage_IncludesQuietRunEfficiencyContract(t *te
"treat the supplied snapshot as sufficient for a calm-day assessment",
"without using platform or inventory tools merely to reconfirm the same healthy state",
"does not prohibit a targeted read",
+ "sufficient evidence that repeated exits occurred",
+ "without claiming the container is currently in a restart loop",
"use at most one targeted pulse_query get",
- "Do not call logs, discovery, Docker services, or other root-cause tools after confirming the Watch symptom",
+ "Do not call logs, discovery, Docker services, or other root-cause tools after the repeated-restart symptom is established",
} {
if !strings.Contains(prompt, want) {
t.Fatalf("triage patrol system prompt missing %q", want)
diff --git a/internal/ai/patrol_triage.go b/internal/ai/patrol_triage.go
index be3591d6b2..79e8b6c27a 100644
--- a/internal/ai/patrol_triage.go
+++ b/internal/ai/patrol_triage.go
@@ -72,6 +72,7 @@ func (p *PatrolService) runDeterministicTriageState(
flags = append(flags, triageBackupChecksState(snap, scopedSet)...)
flags = append(flags, triageDiskHealthChecksState(snap, scopedSet)...)
flags = append(flags, triageContainerHealthChecksState(snap, scopedSet)...)
+ flags = append(flags, triageContainerRestartChecksState(snap, scopedSet)...)
flags = append(flags, triageAlertChecksState(snap, scopedSet)...)
flags = append(flags, triageConnectivityChecksState(snap, guestIntel, scopedSet)...)
flags = append(flags, triageRecentChanges(intel)...)
@@ -101,6 +102,42 @@ func (p *PatrolService) runDeterministicTriageState(
}
}
+const patrolRepeatedRestartWarningThreshold = 3
+
+func triageContainerRestartChecksState(snap patrolRuntimeState, scopedSet map[string]bool) []TriageFlag {
+ rows := patrolAppContainerRows(snap, scopedSet)
+ flags := make([]TriageFlag, 0)
+ for _, row := range rows {
+ if row.restartCount < patrolRepeatedRestartWarningThreshold {
+ continue
+ }
+
+ state := strings.ToLower(strings.TrimSpace(row.status))
+ detail := fmt.Sprintf("Provider reported %d restarts", row.restartCount)
+ if state != "" {
+ detail += fmt.Sprintf("; current sampled state is %s", state)
+ }
+ if state == "restarting" {
+ detail += "; active restart-loop state is confirmed"
+ } else {
+ detail += "; repeated exits are confirmed but this snapshot alone does not prove an active loop"
+ }
+
+ flags = append(flags, TriageFlag{
+ ResourceID: row.id,
+ ResourceName: triageResourceName(row.name, row.id),
+ ResourceType: "app-container",
+ Category: "reliability",
+ Severity: "warning",
+ Reason: detail,
+ Metric: "restart_count",
+ Value: float64(row.restartCount),
+ Threshold: patrolRepeatedRestartWarningThreshold,
+ })
+ }
+ return flags
+}
+
func triageContainerHealthChecksState(snap patrolRuntimeState, scopedSet map[string]bool) []TriageFlag {
rows := patrolAppContainerRows(snap, scopedSet)
flags := make([]TriageFlag, 0)
diff --git a/internal/ai/patrol_triage_test.go b/internal/ai/patrol_triage_test.go
index 8fcedca976..fe3c471563 100644
--- a/internal/ai/patrol_triage_test.go
+++ b/internal/ai/patrol_triage_test.go
@@ -427,6 +427,69 @@ func TestTriageContainerHealthChecksState_UsesReadState(t *testing.T) {
}
}
+func TestTriageContainerRestartChecksState_DistinguishesRepeatedRestartsFromActiveLoop(t *testing.T) {
+ state := patrolRuntimeState{
+ DockerHosts: []models.DockerHost{{
+ ID: "docker-host-1",
+ Hostname: "tower",
+ Containers: []models.DockerContainer{
+ {ID: "app-container:tower:historical", Name: "historical", State: "running", RestartCount: 2},
+ {ID: "app-container:tower:repeated", Name: "repeated", State: "running", RestartCount: 3},
+ {ID: "app-container:tower:looping", Name: "looping", State: "restarting", RestartCount: 5},
+ },
+ }},
+ }
+
+ flags := triageContainerRestartChecksState(state, nil)
+ if len(flags) != 2 {
+ t.Fatalf("expected repeated and active restart flags only, got %#v", flags)
+ }
+ if flags[0].ResourceID != "app-container:tower:repeated" || flags[0].Category != "reliability" || flags[0].Severity != "warning" {
+ t.Fatalf("expected grounded repeated-restart warning, got %#v", flags[0])
+ }
+ if !strings.Contains(flags[0].Reason, "3 restarts") || !strings.Contains(flags[0].Reason, "does not prove an active loop") {
+ t.Fatalf("expected non-overstated repeated-restart evidence, got %#v", flags[0])
+ }
+ if flags[1].ResourceID != "app-container:tower:looping" || !strings.Contains(flags[1].Reason, "active restart-loop state is confirmed") {
+ t.Fatalf("expected confirmed active-loop evidence, got %#v", flags[1])
+ }
+}
+
+func TestTriageContainerRestartChecksState_UsesScopedReadState(t *testing.T) {
+ parentID := "docker-host-1"
+ repeated := unifiedresources.NewDockerContainerView(&unifiedresources.Resource{
+ ID: "app-container:tower:worker",
+ Name: "worker",
+ Type: unifiedresources.ResourceTypeAppContainer,
+ Status: unifiedresources.StatusOnline,
+ ParentID: &parentID,
+ Docker: &unifiedresources.DockerData{
+ ContainerState: "running",
+ RestartCount: 5,
+ },
+ })
+ other := unifiedresources.NewDockerContainerView(&unifiedresources.Resource{
+ ID: "app-container:tower:other",
+ Name: "other",
+ Type: unifiedresources.ResourceTypeAppContainer,
+ Status: unifiedresources.StatusOnline,
+ ParentID: &parentID,
+ Docker: &unifiedresources.DockerData{
+ ContainerState: "restarting",
+ RestartCount: 8,
+ },
+ })
+ state := patrolRuntimeState{readState: &mockReadState{dockerCtrs: []*unifiedresources.DockerContainerView{&repeated, &other}}}
+
+ flags := triageContainerRestartChecksState(state, map[string]bool{"app-container:tower:worker": true})
+ if len(flags) != 1 || flags[0].ResourceID != "app-container:tower:worker" {
+ t.Fatalf("expected one scoped read-state restart warning, got %#v", flags)
+ }
+ if flags[0].Metric != "restart_count" || flags[0].Value != 5 || flags[0].Threshold != patrolRepeatedRestartWarningThreshold {
+ t.Fatalf("expected exact restart evidence, got %#v", flags[0])
+ }
+}
+
func TestTriageAlertChecks(t *testing.T) {
state := patrolRuntimeState{
ActiveAlerts: []models.Alert{