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.

Suppress assessment error penalty after trailing-success recovery

rcourtmane657f6ace9b0
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index f991e2e3fb..9c18ab940b 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -108,7 +108,7 @@ runtime cost control, and shared AI transport surfaces.
## Completion Obligations
-1. Update this contract when canonical AI runtime or transport entry points move, including transport-level provider request-shape changes such as DeepSeek `tool_choice` coercion, runtime-failure classification splits (for example separating forced tool selection 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 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 still detects the failure signal — 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)
+1. Update this contract when canonical AI runtime or transport entry points move, including transport-level provider request-shape changes such as DeepSeek `tool_choice` coercion, runtime-failure classification splits (for example separating forced tool selection 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 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 still detects the failure signal — 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), and 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
2. Keep AI runtime and shared API proof routing aligned in `registry.json`
3. Preserve explicit coverage for chat, Patrol, remediation, and cost-control behavior when AI runtime changes
Patrol runtime failures are part of that runtime contract: provider, model,
diff --git a/internal/ai/intelligence.go b/internal/ai/intelligence.go
index 929b9d23f3..f913533083 100644
--- a/internal/ai/intelligence.go
+++ b/internal/ai/intelligence.go
@@ -1092,6 +1092,26 @@ func summarizeRecentPatrolCoverage(
}
}
+ // Count trailing successful full Patrol runs starting from the most
+ // recent (relevant is newest-first per GetAll), skipping non-full
+ // runs. When Pulse has recovered from a run of errors — N
+ // consecutive successful full runs at the leading edge of the
+ // window — the score should reflect current reality, not drag stale
+ // failures forward. Without this, fixing a Patrol-affecting bug
+ // keeps the grade depressed for ~9 hours (the time it takes 3
+ // scheduled runs at 3-hour cadence to age out the failures).
+ trailingFullSuccesses := 0
+ for _, r := range relevant {
+ if !isFullPatrolRun(r) {
+ continue
+ }
+ if isSuccessfulFullPatrolRun(r) {
+ trailingFullSuccesses++
+ continue
+ }
+ break
+ }
+
limitedActivityLabel := describeLimitedPatrolActivity(relevant)
switch {
@@ -1114,6 +1134,19 @@ func summarizeRecentPatrolCoverage(
impact: 20,
}, true
case recentErrors > 0:
+ // Recovery suppression: if Pulse has had a clean stretch of
+ // consecutive successful full Patrol runs at the END of the
+ // window, the score should reflect current reality rather than
+ // drag forward stale failures. Three successful full runs is
+ // roughly a 9-hour window at the default 3-hour cadence — long
+ // enough that "we've genuinely stabilized" beats "we still
+ // have errors in the recent-10 ratio." Without this, fixing a
+ // Patrol-affecting bug kept the assessment depressed for hours
+ // after the actual problem was resolved.
+ const recoveredTrailingSuccessThreshold = 3
+ if trailingFullSuccesses >= recoveredTrailingSuccessThreshold {
+ return patrolCoverageFactor{}, false
+ }
// Tier the impact by error ratio so the score actually reflects how
// unreliable recent runs have been. The previous flat 10-point impact
// could not separate "1 error in 10 runs" (mostly healthy) from
diff --git a/internal/ai/intelligence_coverage_test.go b/internal/ai/intelligence_coverage_test.go
index 841b480282..c3e4cdb501 100644
--- a/internal/ai/intelligence_coverage_test.go
+++ b/internal/ai/intelligence_coverage_test.go
@@ -899,6 +899,101 @@ func TestIntelligence_GetResourceIntelligence_WithAllSubsystems(t *testing.T) {
}
}
+// TestIntelligence_GetSummary_RecoversAfterTrailingSuccessfulFullRuns
+// guards the recovery-suppression introduced after the
+// malformed-history Patrol bug: when a Patrol-affecting bug causes a
+// run of errors and the fix lands, three consecutive successful full
+// runs at the END of the recent-runs window should drop the error
+// penalty entirely so the health score reflects current reality. Before
+// this, fixing a bug kept the assessment depressed for ~9 hours while
+// the historical errors aged out of the trailing-10 ratio.
+func TestIntelligence_GetSummary_RecoversAfterTrailingSuccessfulFullRuns(t *testing.T) {
+ intel := NewIntelligence(IntelligenceConfig{})
+ runHistory := NewPatrolRunHistoryStore(20)
+ now := time.Now()
+
+ // Six older errored full runs.
+ for i := 0; i < 6; i++ {
+ runHistory.Add(PatrolRunRecord{
+ ID: fmt.Sprintf("error-%d", i),
+ Type: "full",
+ CompletedAt: now.Add(-time.Duration(20-i) * time.Hour),
+ ErrorCount: 1,
+ Status: "error",
+ ResourcesChecked: 1,
+ })
+ }
+ // Three trailing successful full runs (the "fix landed" sequence).
+ for i := 0; i < 3; i++ {
+ runHistory.Add(PatrolRunRecord{
+ ID: fmt.Sprintf("success-%d", i),
+ Type: "full",
+ CompletedAt: now.Add(-time.Duration(6-i*2) * time.Hour),
+ ErrorCount: 0,
+ Status: "issues_found",
+ ResourcesChecked: 50,
+ NewFindings: 1,
+ })
+ }
+ intel.SetRunHistoryStore(runHistory)
+
+ summary := intel.GetSummary()
+ for _, factor := range summary.OverallHealth.Factors {
+ if factor.Category == "coverage" {
+ t.Fatalf("expected coverage factor to be suppressed after trailing successes, got %+v", factor)
+ }
+ }
+ if strings.Contains(summary.OverallHealth.Prediction, "encountered errors") {
+ t.Fatalf("expected prediction to not mention historical errors after recovery, got %q", summary.OverallHealth.Prediction)
+ }
+}
+
+// TestIntelligence_GetSummary_KeepsPenaltyWhenRecoveryIncomplete guards
+// the inverse: two trailing successes after errors isn't yet "recovered"
+// — the threshold is three. This prevents premature trust restoration
+// from a transient single-run recovery.
+func TestIntelligence_GetSummary_KeepsPenaltyWhenRecoveryIncomplete(t *testing.T) {
+ intel := NewIntelligence(IntelligenceConfig{})
+ runHistory := NewPatrolRunHistoryStore(20)
+ now := time.Now()
+
+ for i := 0; i < 6; i++ {
+ runHistory.Add(PatrolRunRecord{
+ ID: fmt.Sprintf("error-%d", i),
+ Type: "full",
+ CompletedAt: now.Add(-time.Duration(15-i) * time.Hour),
+ ErrorCount: 1,
+ Status: "error",
+ ResourcesChecked: 1,
+ })
+ }
+ // Only two trailing successful runs — not yet a clean recovery.
+ for i := 0; i < 2; i++ {
+ runHistory.Add(PatrolRunRecord{
+ ID: fmt.Sprintf("success-%d", i),
+ Type: "full",
+ CompletedAt: now.Add(-time.Duration(4-i*2) * time.Hour),
+ ErrorCount: 0,
+ Status: "issues_found",
+ ResourcesChecked: 50,
+ NewFindings: 1,
+ })
+ }
+ intel.SetRunHistoryStore(runHistory)
+
+ summary := intel.GetSummary()
+ foundCoverage := false
+ for _, factor := range summary.OverallHealth.Factors {
+ if factor.Category == "coverage" {
+ foundCoverage = true
+ break
+ }
+ }
+ if !foundCoverage {
+ t.Fatal("expected coverage penalty to remain when trailing successes are below the recovery threshold")
+ }
+}
+
func TestIntelligence_GetResourceIntelligence_KnowledgeFallback(t *testing.T) {
intel := NewIntelligence(IntelligenceConfig{})
knowledgeStore, _ := knowledge.NewStore(t.TempDir())