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.

Canonicalize container health finding vocabulary

rcourtman9f23d40c43ad
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 80b364b223..e73ac692b0 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -3562,11 +3562,11 @@ resolve canonical/source IDs and unique aliases before collection, reject
verification lifecycle.
1. Update this contract when canonical AI runtime or transport entry points move, including transport-level provider request-shape changes such as OpenAI-compatible `tool_choice` handling, runtime-failure classification splits (for example separating tool-choice request rejection, no tool-capable endpoint, and generic model-level lack of tool support into distinct causes), Patrol-specific verification surfaces such as `POST /api/ai/patrol/preflight` that exercise the full chat-completions path with a minimal tool definition rather than only listing models, Patrol-preflight cache observability where the AI Service caches the most recent preflight outcome (success, soft warning, or classified failure) and the AI settings response surfaces it as `patrol_preflight` so the UI can hydrate a "last verified" indicator without forcing operators to re-run preflight on every page load, the auto-trigger contract on `HandleUpdateAISettings` where the save handler runs `TriggerPatrolPreflightAsync` only when the change actually moved Patrol transport (model swap, provider key for that model changed, or assistant just enabled with a Patrol model) so routine settings saves do not burn provider tokens, the startup-seed contract where the AI Service handler dispatches the same async preflight on Pulse boot when assistant is enabled and a Patrol model is configured so the cache is populated for the first `/api/settings/ai` poll after a restart instead of blanking back to "never verified", the readiness-integration contract where the `tools` check in the Patrol readiness payload consults the cached preflight and surfaces the classified evidence (success, soft warning, or failure with classified summary plus "last preflight <age>") for the configured provider+model when available (falling back to the static `PatrolToolReadinessForModel` classifier only when the cache is empty or holds a result for a different model), the preflight-runtime-recovery contract where a successful Patrol preflight with an observed tool call resolves the synthetic Patrol runtime failure finding while failed or no-tool-call preflights leave it active, the stateless-Patrol-input contract where `ExecutePatrolStream` must pass only the current run's user prompt into the agentic loop rather than reloading the persisted `patrol-main` session history (so a prior run that ended with orphan `tool_calls` cannot poison every subsequent run with malformed conversation structure), and the deterministic-resolve-gate contract where the `patrol_resolve_finding` tool adapter rejects LLM-driven resolves of event/persistent category findings (`backup`, `reliability`, `security`, `general`) when a deterministic verifier exists for the finding's key and that verifier either still detects the failure signal **or returns an inconclusive result** — preventing the LLM from optimistically resolving a finding its current investigation simply didn't re-surface, which was the source of the "Backup failed" flap (detected → auto-resolved → re-detected ten times in a day before this gate). The fail-closed-on-inconclusive policy treats verifier errors (timeouts, executor unavailability, transport faults) as "we don't know" rather than "go ahead": resolution of an event/persistent finding is effectively permanent (next detection registers as a regression and inflates counters), so the safe default is to refuse and require either a successful re-verification or operator action. The gate has a symmetric counterpart, the verified stale-resolve contract: `reconcileStaleFindings` (`internal/ai/patrol_ai.go`) may auto-resolve an event/persistent finding that was seeded but neither re-reported nor resolved ONLY when the finding's key has a deterministic verifier and that verifier affirmatively confirms the failure signal is gone — absence of a re-report remains insufficient evidence for these categories, "still present" or inconclusive verification leaves the finding active (the same fail-closed default), and verifications are capped per reconcile pass (`maxVerifiedStaleResolvesPerRun`) with deferred candidates logged and retried on the next successful full patrol. Without this counterpart the lifecycle was asymmetric: a genuinely fixed backup or recovered service stayed an active finding indefinitely unless the LLM happened to call `patrol_resolve_finding`. `hasDeterministicVerifierForKey` (`internal/ai/patrol_findings.go`) is the single source of truth for which keys have verifiers, consulted by both the gate and the reconcile pass, and must stay aligned with the dispatch switch in `verifyFixDeterministically` (it previously listed two of the seven dispatch keys, silently skipping verification that existed). Finding keys normalize onto the canonical verifier vocabulary in `normalizeFindingKey` via an alias map of unambiguous directional synonyms (`high-cpu` → `cpu-high`, `high-memory` → `memory-high`, `high-disk` → `disk-high`) so deduplication and deterministic verification meet on one key, and the `patrol_report_finding` key guidance (`internal/ai/tools/tools_patrol.go`) teaches the canonical vocabulary; semantically distinct keys (`pbs-job-failed`, `node-offline`) must not be aliased onto verifier keys whose resource model they do not match, the assessment-recovery contract where the overall-health "Recent Patrol errors" coverage factor in `summarizeRecentPatrolCoverage` suppresses the score penalty once three consecutive trailing successful full Patrol runs exist at the most-recent end of the recent-runs window — so the grade reflects current reality after a Patrol-affecting bug is fixed rather than dragging stale failures forward for the ~9 hours it takes scheduled runs to age them out of the trailing-10 ratio, the orphan-tool-call-repair contract where `convertToProviderMessages` injects synthetic is_error tool result messages for any `tool_call_id` in an assistant message that has no matching downstream tool result, so a chat session that ended mid-tool-call (network drop, ctx timeout, browser crash) cannot poison its next message with the structural-violation error the provider rejects — the synthetic content is marked is_error=true and explains the interruption so the model can retry the call or proceed without the data, and the patrol-session-bound contract where `ExecutePatrolStream` calls `SessionStore.TrimMessages` after persisting each run's messages to cap the patrol-main session at 200 messages (roughly two recent runs' worth) — without the bound the file grew unbounded at every scheduled run, reaching 16 MB and 3,593 messages within a month and making every `AddMessage` rewrite linearly more expensive; the canonical Patrol forensic log is the `PatrolRunRecord` history surfaced at `/api/ai/patrol/runs`, not the chat-session-shaped file
- Container-health finding variants such as `app-container-unhealthy`,
- `app-container-health-check-failed`, `container-health-unhealthy`,
- `container-health-failing`, `container-unhealthy`, and
- `failing-health-check` must normalize to the canonical
- `health-check-failed` key before finding identity is generated.
+ The bounded container-health failure vocabulary, including resource-family
+ modifiers, health/check terms, and failed/failing/failure/unhealthy terms,
+ must normalize independent of token order to the canonical
+ `health-check-failed` key before finding identity is generated. Unrelated
+ host-health, degraded, timeout, and unknown-token keys remain distinct.
Existing-finding reconfirmation therefore converges on one durable issue
even when the model changes an unambiguous key spelling between runs.
2. Keep AI runtime and shared API proof routing aligned in `registry.json`
diff --git a/internal/ai/patrol_findings.go b/internal/ai/patrol_findings.go
index a471543503..29e19668b9 100644
--- a/internal/ai/patrol_findings.go
+++ b/internal/ai/patrol_findings.go
@@ -1446,6 +1446,30 @@ var findingKeyAliases = map[string]string{
"unhealthy-container": "health-check-failed",
}
+func isContainerHealthFailureKey(key string) bool {
+ hasHealth := false
+ hasContainerOrCheck := false
+ hasFailure := false
+ for _, token := range strings.Split(key, "-") {
+ switch token {
+ case "app", "docker":
+ // Bounded resource-family modifiers.
+ case "container", "check":
+ hasContainerOrCheck = true
+ case "healthcheck":
+ hasHealth = true
+ hasContainerOrCheck = true
+ case "health":
+ hasHealth = true
+ case "failed", "failing", "failure", "unhealthy":
+ hasFailure = true
+ default:
+ return false
+ }
+ }
+ return hasHealth && hasContainerOrCheck && hasFailure
+}
+
func normalizeFindingKey(key string) string {
if key == "" {
return ""
@@ -1463,6 +1487,9 @@ func normalizeFindingKey(key string) string {
}
}
normalized := strings.Trim(b.String(), "-")
+ if isContainerHealthFailureKey(normalized) {
+ return "health-check-failed"
+ }
if canonical, ok := findingKeyAliases[normalized]; ok {
return canonical
}
diff --git a/internal/ai/patrol_findings_additional_test.go b/internal/ai/patrol_findings_additional_test.go
index 504ac65d26..17972a5eb3 100644
--- a/internal/ai/patrol_findings_additional_test.go
+++ b/internal/ai/patrol_findings_additional_test.go
@@ -1778,7 +1778,7 @@ func TestPatrolFindingAdapterCanonicalizesContainerHealthKeyVariantsAcrossRuns(t
t.Fatalf("first report = (%q, %t, %v), want a new finding", findingID, isNew, err)
}
- for _, variant := range []string{"container-health-failing", "app-container-unhealthy", "app-container-health-check-failed", "container-health-unhealthy"} {
+ for _, variant := range []string{"container-health-failing", "app-container-unhealthy", "app-container-health-check-failed", "container-health-unhealthy", "health-check-unhealthy", "unhealthy-health-check", "docker-health-check-failure"} {
secondInput := firstInput
secondInput.Key = variant
secondInput.Title = "Container health is failing while running"
diff --git a/internal/ai/patrol_reconcile_test.go b/internal/ai/patrol_reconcile_test.go
index 3db6560b99..a4caf04635 100644
--- a/internal/ai/patrol_reconcile_test.go
+++ b/internal/ai/patrol_reconcile_test.go
@@ -458,12 +458,18 @@ func TestNormalizeFindingKey_CanonicalAliases(t *testing.T) {
"container-health-failing": "health-check-failed",
"container-health-check-failed": "health-check-failed",
"container-health-unhealthy": "health-check-failed",
+ "health-check-unhealthy": "health-check-failed",
+ "unhealthy-health-check": "health-check-failed",
+ "docker-health-check-failure": "health-check-failed",
"healthcheck-failed": "health-check-failed",
"failing-health-check": "health-check-failed",
"container-unhealthy": "health-check-failed",
"unhealthy-container": "health-check-failed",
// Non-aliased keys pass through normalization unchanged.
- "pbs-job-failed": "pbs-job-failed",
+ "pbs-job-failed": "pbs-job-failed",
+ "host-health-unhealthy": "host-health-unhealthy",
+ "container-health-degraded": "container-health-degraded",
+ "health-check-timeout": "health-check-timeout",
}
for in, want := range cases {
if got := normalizeFindingKey(in); got != want {