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.

Recover Patrol after provider circuit failures

rcourtman73ce59a1ab57
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 0f2f675462..f4705d863f 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -6348,8 +6348,15 @@ a successful preflight with an observed tool call proves the configured
provider/model currently accepts Patrol's tool-call path. Either must clear the
synthetic `ai-service` runtime failure just as a successful full Patrol run
does, without loosening ordinary scoped finding reconciliation for
-infrastructure issues. A soft-warning preflight where the provider responds but
-the model does not emit a tool call is not sufficient recovery evidence.
+infrastructure issues. Full and scoped runs must account for the same circuit
+breaker lease around the actual provider call: successful scoped work records
+success, failed scoped work records its classified provider error, and
+collection or scope failures before inference never acquire a half-open probe.
+A successful current-generation preflight for the exactly configured Patrol
+route also resets stale circuit-open state and its corresponding blocked status,
+because it is direct tool-call recovery evidence. A successful override for a
+different route, a stale preflight generation, or a soft-warning response
+without a tool call cannot reset the configured route's breaker.
Because the synthetic runtime finding is seeded into scoped runs as Patrol-wide
health evidence, the run's finding adapter must also expose and accept a
terminal assessment for that finding even though `ai-service` is not part of
diff --git a/internal/ai/patrol_init.go b/internal/ai/patrol_init.go
index 22b834881f..ac42fb7cfd 100644
--- a/internal/ai/patrol_init.go
+++ b/internal/ai/patrol_init.go
@@ -217,6 +217,35 @@ func (p *PatrolService) SetCircuitBreaker(breaker *circuit.Breaker) {
log.Info().Msg("circuit breaker configured for patrol")
}
+// recoverCircuitBreakerAfterVerifiedPreflight closes stale provider-failure
+// state only after the configured Patrol route has completed a real tool-call
+// round trip. A provider/model setting change by itself is not recovery
+// evidence; the successful preflight is.
+func (p *PatrolService) recoverCircuitBreakerAfterVerifiedPreflight() bool {
+ if p == nil {
+ return false
+ }
+ p.mu.RLock()
+ breaker := p.circuitBreaker
+ p.mu.RUnlock()
+ if breaker == nil {
+ return false
+ }
+
+ wasDegraded := breaker.State() != circuit.StateClosed
+ breaker.Reset()
+
+ p.mu.Lock()
+ if p.lastBlockedCause == PatrolFailureCauseCircuitOpen {
+ p.lastBlockedReason = ""
+ p.lastBlockedCause = PatrolFailureCauseNone
+ p.lastBlockedAt = time.Time{}
+ wasDegraded = true
+ }
+ p.mu.Unlock()
+ return wasDegraded
+}
+
// SetRemediationEngine sets the governed plan store/executor for model-proposed fixes.
func (p *PatrolService) SetRemediationEngine(engine aicontracts.RemediationEngine) {
p.mu.Lock()
diff --git a/internal/ai/patrol_preflight.go b/internal/ai/patrol_preflight.go
index 11bffee481..5fa8c3c3a7 100644
--- a/internal/ai/patrol_preflight.go
+++ b/internal/ai/patrol_preflight.go
@@ -97,19 +97,21 @@ func (s *Service) CachedPatrolPreflight() (*PatrolPreflightResult, time.Time) {
// recordPatrolPreflight stores the result in the cache. Called after
// every RunPatrolToolPreflight invocation so the most recent outcome is
-// always observable, including failures.
-func (s *Service) recordPatrolPreflight(result PatrolPreflightResult, at time.Time, generation uint64) {
+// always observable, including failures. It returns false when a generation
+// or route fence rejects stale evidence.
+func (s *Service) recordPatrolPreflight(result PatrolPreflightResult, at time.Time, generation uint64) bool {
s.mu.RLock()
cfg := s.cfg
s.mu.RUnlock()
s.patrolPreflightCache.mu.Lock()
defer s.patrolPreflightCache.mu.Unlock()
if generation != s.patrolPreflightCache.generation || cfg != nil && !patrolPreflightMatchesConfig(&result, cfg) {
- return
+ return false
}
clone := result
s.patrolPreflightCache.result = &clone
s.patrolPreflightCache.recordedAt = at
+ return true
}
func (s *Service) patrolPreflightGeneration() uint64 {
@@ -306,8 +308,9 @@ func (s *Service) runPatrolToolPreflight(ctx context.Context, providerName, mode
result.Cause = PatrolFailureCauseNone
result.Title = "Pulse Patrol: Preflight succeeded"
result.Summary = "Provider accepted the preflight request and the model emitted a tool call."
- s.recordPatrolPreflight(result, time.Now(), generation)
- s.resolvePatrolRuntimeFailureAfterToolPreflight(result)
+ if s.recordPatrolPreflight(result, time.Now(), generation) {
+ s.recoverPatrolAfterToolPreflight(result)
+ }
return result
}
@@ -323,7 +326,7 @@ func (s *Service) runPatrolToolPreflight(ctx context.Context, providerName, mode
return result
}
-func (s *Service) resolvePatrolRuntimeFailureAfterToolPreflight(result PatrolPreflightResult) bool {
+func (s *Service) recoverPatrolAfterToolPreflight(result PatrolPreflightResult) bool {
if s == nil || !result.Success || !result.ToolCallObserved {
return false
}
@@ -331,7 +334,9 @@ func (s *Service) resolvePatrolRuntimeFailureAfterToolPreflight(result PatrolPre
if patrol == nil {
return false
}
- return patrol.resolvePatrolRuntimeFailureFinding("patrol_preflight_success")
+ breakerRecovered := patrol.recoverCircuitBreakerAfterVerifiedPreflight()
+ runtimeFindingResolved := patrol.resolvePatrolRuntimeFailureFinding("patrol_preflight_success")
+ return breakerRecovered || runtimeFindingResolved
}
func applyPatrolPreflightDiagnostic(result *PatrolPreflightResult, err error) {
diff --git a/internal/ai/patrol_preflight_test.go b/internal/ai/patrol_preflight_test.go
index 25ec65a762..081a146456 100644
--- a/internal/ai/patrol_preflight_test.go
+++ b/internal/ai/patrol_preflight_test.go
@@ -13,6 +13,7 @@ import (
"testing"
"time"
+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/circuit"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
)
@@ -220,6 +221,99 @@ func TestRunPatrolToolPreflight_SuccessResolvesPreviousRuntimeFailure(t *testing
}
}
+func TestRunPatrolToolPreflight_SuccessRecoversConfiguredRouteCircuit(t *testing.T) {
+ h := newPatrolPreflightTestService(t, "openai:gpt-4o-mini", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id":"x","model":"gpt-4o-mini","choices":[{"finish_reason":"tool_calls","message":{"role":"assistant","content":"","tool_calls":[{"id":"1","type":"function","function":{"name":"verify_pulse_patrol","arguments":"{\"ok\":true}"}}]}}]}`))
+ })
+ defer h.close()
+
+ patrol := NewPatrolService(h.svc, nil)
+ h.svc.patrolService = patrol
+ breaker := circuit.NewBreaker("patrol", circuit.Config{
+ FailureThreshold: 1,
+ SuccessThreshold: 1,
+ InitialBackoff: time.Hour,
+ })
+ breaker.RecordFailure(errors.New("provider unavailable"))
+ patrol.SetCircuitBreaker(breaker)
+ patrol.setBlockedReasonWithCause("circuit breaker is open", PatrolFailureCauseCircuitOpen)
+
+ result := h.svc.RunPatrolToolPreflight(context.Background(), "", "")
+ if !result.Success || !result.ToolCallObserved {
+ t.Fatalf("expected green preflight, got %+v", result)
+ }
+ if breaker.State() != circuit.StateClosed {
+ t.Fatalf("expected configured route circuit to recover, got %s", breaker.State())
+ }
+ status := patrol.GetStatus()
+ if status.BlockedReason != "" || status.BlockedCause != PatrolFailureCauseNone {
+ t.Fatalf("expected stale circuit block to clear, got reason=%q cause=%q", status.BlockedReason, status.BlockedCause)
+ }
+}
+
+func TestRunPatrolToolPreflight_OverrideRouteDoesNotRecoverConfiguredRouteCircuit(t *testing.T) {
+ h := newPatrolPreflightTestService(t, "openai:gpt-4o-mini", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id":"x","model":"other-model","choices":[{"finish_reason":"tool_calls","message":{"role":"assistant","content":"","tool_calls":[{"id":"1","type":"function","function":{"name":"verify_pulse_patrol","arguments":"{\"ok\":true}"}}]}}]}`))
+ })
+ defer h.close()
+
+ patrol := NewPatrolService(h.svc, nil)
+ h.svc.patrolService = patrol
+ breaker := circuit.NewBreaker("patrol", circuit.Config{
+ FailureThreshold: 1,
+ SuccessThreshold: 1,
+ InitialBackoff: time.Hour,
+ })
+ breaker.RecordFailure(errors.New("configured route unavailable"))
+ patrol.SetCircuitBreaker(breaker)
+ patrol.setBlockedReasonWithCause("circuit breaker is open", PatrolFailureCauseCircuitOpen)
+
+ result := h.svc.RunPatrolToolPreflight(context.Background(), config.AIProviderOpenAI, "other-model")
+ if !result.Success || !result.ToolCallObserved {
+ t.Fatalf("expected override route preflight to succeed, got %+v", result)
+ }
+ if breaker.State() != circuit.StateOpen {
+ t.Fatalf("override route must not recover configured route circuit, got %s", breaker.State())
+ }
+ status := patrol.GetStatus()
+ if status.BlockedCause != PatrolFailureCauseCircuitOpen {
+ t.Fatalf("override route must not clear configured route block, got %+v", status)
+ }
+}
+
+func TestRunPatrolToolPreflight_StaleGenerationDoesNotRecoverCircuit(t *testing.T) {
+ h := newPatrolPreflightTestService(t, "openai:gpt-4o-mini", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"id":"x","model":"gpt-4o-mini","choices":[{"finish_reason":"tool_calls","message":{"role":"assistant","content":"","tool_calls":[{"id":"1","type":"function","function":{"name":"verify_pulse_patrol","arguments":"{\"ok\":true}"}}]}}]}`))
+ })
+ defer h.close()
+
+ patrol := NewPatrolService(h.svc, nil)
+ h.svc.patrolService = patrol
+ breaker := circuit.NewBreaker("patrol", circuit.Config{
+ FailureThreshold: 1,
+ SuccessThreshold: 1,
+ InitialBackoff: time.Hour,
+ })
+ breaker.RecordFailure(errors.New("configured route unavailable"))
+ patrol.SetCircuitBreaker(breaker)
+ staleGeneration := h.svc.patrolPreflightGeneration()
+ h.svc.InvalidatePatrolPreflight()
+
+ result := h.svc.runPatrolToolPreflight(context.Background(), "", "", staleGeneration)
+ if !result.Success || !result.ToolCallObserved {
+ t.Fatalf("expected stale in-flight check itself to succeed, got %+v", result)
+ }
+ if breaker.State() != circuit.StateOpen {
+ t.Fatalf("stale preflight generation must not recover circuit, got %s", breaker.State())
+ }
+ if cached, _ := h.svc.CachedPatrolPreflight(); cached != nil {
+ t.Fatalf("stale preflight generation must not publish cache evidence, got %+v", cached)
+ }
+}
+
func TestRunPatrolToolPreflight_Success_NoToolCall(t *testing.T) {
// Provider accepts the request but the model returned plain text
// instead of calling the verify tool. Pulse soft-warns rather than
diff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.go
index e7e68cc09b..cc96b27d1b 100644
--- a/internal/ai/patrol_run.go
+++ b/internal/ai/patrol_run.go
@@ -399,12 +399,6 @@ func (p *PatrolService) runPatrolWithTriggerStart(ctx context.Context, trigger T
}
defer p.endRun()
- // Check if circuit breaker allows LLM calls.
- llmAllowed := breaker == nil || breaker.Allow()
- if !llmAllowed {
- log.Warn().Msg("AI Patrol: Circuit breaker is open (LLM calls blocked)")
- }
-
start := runStart.startedAt
runID := runStart.id
executionID := uuid.NewString()
@@ -571,8 +565,16 @@ func (p *PatrolService) runPatrolWithTriggerStart(ctx context.Context, trigger T
}
}
- // Determine if we can run LLM analysis (requires AI service + circuit breaker not open)
+ // Acquire a breaker probe only when this run is actually ready to call the
+ // provider. Early collection/scope exits must not strand a half-open probe.
aiServiceEnabled := p.aiService != nil && p.aiService.IsEnabled()
+ llmAllowed := true
+ if aiServiceEnabled && breaker != nil {
+ llmAllowed = breaker.Allow()
+ }
+ if !llmAllowed {
+ log.Warn().Msg("AI Patrol: Circuit breaker is open (LLM calls blocked)")
+ }
canRunLLM := aiServiceEnabled && llmAllowed
// Check if we can run LLM analysis (AI-only patrol)
@@ -809,17 +811,7 @@ func (p *PatrolService) runPatrolWithTriggerStart(ctx context.Context, trigger T
// canRunLLM is true only when AI is enabled, licensed, AND breaker allowed.
// Use error categorization so non-transient errors (auth failures, insufficient
// credits) don't trip the breaker — those won't be fixed by waiting.
- if breaker != nil && canRunLLM {
- if runStats.errors > 0 {
- aiErr := runStats.lastAIError
- if aiErr == nil {
- aiErr = fmt.Errorf("patrol completed with %d errors", runStats.errors)
- }
- breaker.RecordFailureWithCategory(aiErr, circuit.CategorizeError(aiErr))
- } else {
- breaker.RecordSuccess()
- }
- }
+ recordPatrolCircuitResult(breaker, canRunLLM, runStats.errors, runStats.lastAIError)
// Add to history store (handles persistence automatically)
p.runHistoryStore.Add(runRecord)
@@ -951,12 +943,6 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
}
defer p.endRun()
- // Check if circuit breaker allows LLM calls.
- llmAllowed := breaker == nil || breaker.Allow()
- if !llmAllowed {
- log.Warn().Msg("AI Patrol: Circuit breaker is open for scoped patrol (LLM calls blocked)")
- }
-
start := runStart.startedAt
runID := runStart.id
executionID := uuid.NewString()
@@ -979,6 +965,7 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
triageSkippedLLM bool
findingIDs []string
errors int
+ lastAIError error
errorSummary string
errorDetail string
aiAnalysis *AIAnalysisResult
@@ -1087,8 +1074,16 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
}
runStats.resourceCount = resourceCount
- // Determine if we can run LLM analysis
+ // Acquire a breaker probe only after the requested scope has resolved to
+ // real work. This keeps collection-only failures outside provider health.
aiServiceEnabled := p.aiService != nil && p.aiService.IsEnabled()
+ llmAllowed := true
+ if aiServiceEnabled && breaker != nil {
+ llmAllowed = breaker.Allow()
+ }
+ if !llmAllowed {
+ log.Warn().Msg("AI Patrol: Circuit breaker is open for scoped patrol (LLM calls blocked)")
+ }
canRunLLM := aiServiceEnabled && llmAllowed
if !canRunLLM {
@@ -1135,6 +1130,7 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
if aiErr != nil {
log.Warn().Err(aiErr).Msg("AI Patrol (scoped): LLM analysis failed")
runStats.errors++
+ runStats.lastAIError = aiErr
failure := patrolRuntimeFailureFromError(aiErr)
runStats.errorSummary = failure.Summary
runStats.errorDetail = failure.Detail
@@ -1266,6 +1262,8 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
p.errorCount = runStats.errors
p.mu.Unlock()
+ recordPatrolCircuitResult(breaker, canRunLLM, runStats.errors, runStats.lastAIError)
+
p.runHistoryStore.Add(runRecord)
log.Info().
@@ -1281,6 +1279,20 @@ func (p *PatrolService) runScopedPatrolWithStart(ctx context.Context, scope Patr
p.dispatchPatrolInvestigations(runStats.aiAnalysis)
}
+func recordPatrolCircuitResult(breaker *circuit.Breaker, attempted bool, errorCount int, runErr error) {
+ if breaker == nil || !attempted {
+ return
+ }
+ if errorCount == 0 {
+ breaker.RecordSuccess()
+ return
+ }
+ if runErr == nil {
+ runErr = fmt.Errorf("patrol completed with %d errors", errorCount)
+ }
+ breaker.RecordFailureWithCategory(runErr, circuit.CategorizeError(runErr))
+}
+
func (p *PatrolService) recordScopedPatrolScopeFailure(start time.Time, runID string, scope PatrolScope, resolution PatrolScopeResolution, summary, detail string) {
completedAt := time.Now()
record := PatrolRunRecord{
diff --git a/internal/ai/patrol_run_additional_test.go b/internal/ai/patrol_run_additional_test.go
index 56c399dfd6..3a00e1358d 100644
--- a/internal/ai/patrol_run_additional_test.go
+++ b/internal/ai/patrol_run_additional_test.go
@@ -2,11 +2,13 @@ package ai
import (
"context"
+ "errors"
"fmt"
"strings"
"testing"
"time"
+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/circuit"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/providers"
"github.com/rcourtman/pulse-go-rewrite/internal/alerts"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
@@ -20,6 +22,26 @@ type mockPatrolProvider struct {
calls int
}
+func TestRunPatrol_EarlyRuntimeFailureDoesNotAcquireHalfOpenProbe(t *testing.T) {
+ svc := NewService(config.NewConfigPersistence(t.TempDir()), nil)
+ svc.cfg = &config.AIConfig{Enabled: true, PatrolModel: "mock:model"}
+ ps := NewPatrolService(svc, nil)
+ ps.SetConfig(PatrolConfig{Enabled: true, AnalyzeNodes: true})
+ breaker := circuit.NewBreaker("patrol", circuit.Config{
+ FailureThreshold: 1,
+ SuccessThreshold: 1,
+ InitialBackoff: time.Nanosecond,
+ })
+ breaker.RecordFailure(errors.New("transient provider failure"))
+ ps.SetCircuitBreaker(breaker)
+
+ ps.runPatrolWithTrigger(context.Background(), TriggerReasonManual, nil)
+
+ if breaker.State() != circuit.StateOpen {
+ t.Fatalf("runtime-input failure must not acquire a half-open provider probe, got %s", breaker.State())
+ }
+}
+
func (m *mockPatrolProvider) Chat(ctx context.Context, req providers.ChatRequest) (*providers.ChatResponse, error) {
m.lastReq = req
m.calls++
diff --git a/internal/ai/patrol_scoped_run_test.go b/internal/ai/patrol_scoped_run_test.go
index 2f673e9842..fddc96d0c8 100644
--- a/internal/ai/patrol_scoped_run_test.go
+++ b/internal/ai/patrol_scoped_run_test.go
@@ -2,9 +2,12 @@ package ai
import (
"context"
+ "errors"
+ "strings"
"testing"
"time"
+ "github.com/rcourtman/pulse-go-rewrite/internal/ai/circuit"
"github.com/rcourtman/pulse-go-rewrite/internal/ai/tools"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
"github.com/rcourtman/pulse-go-rewrite/internal/models"
@@ -109,6 +112,98 @@ func TestRunScopedPatrol_StoresEffectiveScopeResourceIDs(t *testing.T) {
}
}
+func TestRunScopedPatrol_RecordsSuccessfulHalfOpenProbe(t *testing.T) {
+ persistence := config.NewConfigPersistence(t.TempDir())
+ svc := NewService(persistence, nil)
+ svc.cfg = &config.AIConfig{Enabled: true, PatrolModel: "mock:model"}
+ svc.provider = &mockProvider{}
+ svc.SetChatService(&mockChatService{
+ executor: tools.NewPulseToolExecutor(tools.ExecutorConfig{}),
+ executePatrolStreamFunc: func(ctx context.Context, req PatrolExecuteRequest, callback ChatStreamCallback) (*PatrolStreamResponse, error) {
+ return &PatrolStreamResponse{Content: "no issues"}, nil
+ },
+ })
+ ps := NewPatrolService(svc, &mockStateProvider{state: models.StateSnapshot{
+ Nodes: []models.Node{{ID: "node-1", Name: "pve-1", Status: "online"}},
+ }})
+ ps.SetConfig(PatrolConfig{Enabled: true, AnalyzeNodes: true})
+ breaker := circuit.NewBreaker("patrol", circuit.Config{
+ FailureThreshold: 1,
+ SuccessThreshold: 1,
+ InitialBackoff: time.Nanosecond,
+ })
+ breaker.RecordFailure(errors.New("transient provider failure"))
+ ps.SetCircuitBreaker(breaker)
+
+ ps.runScopedPatrol(context.Background(), PatrolScope{
+ ResourceIDs: []string{"node-1"},
+ Reason: TriggerReasonManual,
+ NoStream: true,
+ })
+
+ if breaker.State() != circuit.StateClosed {
+ t.Fatalf("successful scoped provider call must close half-open circuit, got %s", breaker.State())
+ }
+ if got := breaker.GetStatus().TotalSuccesses; got != 1 {
+ t.Fatalf("successful scoped provider call recorded %d successes, want 1", got)
+ }
+}
+
+func TestRunScopedPatrol_RecordsProviderFailure(t *testing.T) {
+ persistence := config.NewConfigPersistence(t.TempDir())
+ svc := NewService(persistence, nil)
+ svc.cfg = &config.AIConfig{Enabled: true, PatrolModel: "mock:model"}
+ svc.provider = &mockProvider{}
+ providerErr := errors.New("provider connection reset")
+ svc.SetChatService(&mockChatService{
+ executor: tools.NewPulseToolExecutor(tools.ExecutorConfig{}),
+ executePatrolStreamFunc: func(ctx context.Context, req PatrolExecuteRequest, callback ChatStreamCallback) (*PatrolStreamResponse, error) {
+ return nil, providerErr
+ },
+ })
+ ps := NewPatrolService(svc, &mockStateProvider{state: models.StateSnapshot{
+ Nodes: []models.Node{{ID: "node-1", Name: "pve-1", Status: "online"}},
+ }})
+ ps.SetConfig(PatrolConfig{Enabled: true, AnalyzeNodes: true})
+ breaker := circuit.NewBreaker("patrol", circuit.Config{FailureThreshold: 3})
+ ps.SetCircuitBreaker(breaker)
+
+ ps.runScopedPatrol(context.Background(), PatrolScope{
+ ResourceIDs: []string{"node-1"},
+ Reason: TriggerReasonManual,
+ NoStream: true,
+ })
+
+ status := breaker.GetStatus()
+ if status.TotalFailures != 1 || status.ConsecutiveFailures != 1 {
+ t.Fatalf("scoped provider failure was not recorded exactly once: %+v", status)
+ }
+ if !strings.Contains(status.LastError, providerErr.Error()) {
+ t.Fatalf("scoped circuit error = %q, want underlying cause %q", status.LastError, providerErr)
+ }
+}
+
+func TestRunScopedPatrol_EarlyCollectionFailureDoesNotAcquireHalfOpenProbe(t *testing.T) {
+ ps := NewPatrolService(nil, mockPatrolStateProvider{state: models.StateSnapshot{}})
+ ps.SetConfig(PatrolConfig{Enabled: true, AnalyzeNodes: true})
+ breaker := circuit.NewBreaker("patrol", circuit.Config{
+ FailureThreshold: 1,
+ SuccessThreshold: 1,
+ InitialBackoff: time.Nanosecond,
+ })
+ breaker.RecordFailure(errors.New("transient provider failure"))
+ ps.SetCircuitBreaker(breaker)
+
+ ps.runScopedPatrol(context.Background(), PatrolScope{
+ ResourceIDs: []string{"missing-node"},
+ Reason: TriggerReasonManual,
+ })
+
+ if breaker.State() != circuit.StateOpen {
+ t.Fatalf("collection-only failure must not acquire a half-open provider probe, got %s", breaker.State())
+ }
+}
+
func TestRunScopedPatrol_PhysicalDiskScopeRuns(t *testing.T) {
persistence := config.NewConfigPersistence(t.TempDir())
svc := NewService(persistence, nil)