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.

Isolate Patrol investigation dispatch from Watch runs

rcourtmancde850c6868a
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 0982c5da76..f4105284fd 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -3214,7 +3214,13 @@ resolve canonical/source IDs and unique aliases before collection, reject
for runtime zero-match races, record requested and effective identities,
and summarize only findings within the effective scope. Watch may mutate
only finding lifecycle state; Pro investigation remains structurally
- read-only. Its finding resource is an observation anchor, never a search
+ read-only. A Watch model-reported finding must not dispatch Pro
+ investigation from inside the finding tool call: Pulse first persists the
+ completed Watch run and unwinds its run-scoped finding adapter, then
+ dispatches the accepted findings into Pro investigation. Investigation may
+ clone the shared executor only after that boundary; it must never inherit or
+ mutate the active Watch run's finding-lifecycle adapter. Its finding resource
+ is an observation anchor, never a search
fence: the Pro prompt must explicitly require evidence-led expansion,
competing-hypothesis testing, and a distinction between affected and causal
resources. When evidence selects a different remediation target, the
diff --git a/internal/ai/patrol_findings.go b/internal/ai/patrol_findings.go
index ff6849f1ab..1294978ec2 100644
--- a/internal/ai/patrol_findings.go
+++ b/internal/ai/patrol_findings.go
@@ -38,6 +38,19 @@ func patrolRuntimeFindingManualActionError(action string) error {
// recordFinding stores a finding, syncs it to the unified store, and triggers follow-up actions.
func (p *PatrolService) recordFinding(f *Finding) bool {
+ return p.recordFindingWithInvestigation(f, true)
+}
+
+// recordFindingDuringPatrol records a model-reported finding without starting
+// Pro investigation while the Watch run's finding adapter is still installed
+// on the shared chat executor. The completed run dispatches investigation only
+// after its durable run record has been written and the adapter has been
+// cleared.
+func (p *PatrolService) recordFindingDuringPatrol(f *Finding) bool {
+ return p.recordFindingWithInvestigation(f, false)
+}
+
+func (p *PatrolService) recordFindingWithInvestigation(f *Finding, investigate bool) bool {
if p == nil || p.findings == nil || f == nil {
return false
}
@@ -83,8 +96,10 @@ func (p *PatrolService) recordFinding(f *Finding) bool {
p.unifiedFindingCallback(stored)
}
- // Trigger autonomous investigation if enabled and finding warrants it
- p.MaybeInvestigateFinding(stored)
+ if investigate {
+ // Trigger autonomous investigation if enabled and finding warrants it.
+ p.MaybeInvestigateFinding(stored)
+ }
return isNew
}
@@ -552,7 +567,7 @@ func (a *patrolFindingCreatorAdapter) CreateFinding(input tools.PatrolFindingInp
}
// Record finding via PatrolService
- isNew := a.patrol.recordFinding(finding)
+ isNew := a.patrol.recordFindingDuringPatrol(finding)
// Track for run stats
a.trackCollectedFinding(finding)
@@ -997,6 +1012,25 @@ func (a *patrolFindingCreatorAdapter) getQueriedFindingIDs() []string {
return result
}
+// dispatchPatrolInvestigations advances model-reported findings from the
+// completed Watch stage into Pro investigation. It must be called only after
+// the Watch run record is durable and run-scoped executor state has unwound.
+func (p *PatrolService) dispatchPatrolInvestigations(result *AIAnalysisResult) {
+ if p == nil || p.findings == nil || result == nil {
+ return
+ }
+ seen := make(map[string]bool, len(result.Findings))
+ for _, candidate := range result.Findings {
+ if candidate == nil || candidate.ID == "" || seen[candidate.ID] {
+ continue
+ }
+ seen[candidate.ID] = true
+ if stored := p.findings.Get(candidate.ID); stored != nil {
+ p.MaybeInvestigateFinding(stored)
+ }
+ }
+}
+
// findingKeyAliases maps directional synonyms the LLM plausibly assigns onto
// the canonical verifier vocabulary (the verifyFixDeterministically switch),
// so deduplication and deterministic verification meet on one key. Only
diff --git a/internal/ai/patrol_integration_test.go b/internal/ai/patrol_integration_test.go
index c2be06de18..f8af477900 100644
--- a/internal/ai/patrol_integration_test.go
+++ b/internal/ai/patrol_integration_test.go
@@ -19,6 +19,7 @@ type integrationOrchestrator struct {
canStart bool
investigated []string // finding IDs passed to InvestigateFinding
investigateCh chan string
+ canStartCh chan struct{}
runningCount int32
}
@@ -26,6 +27,7 @@ func newIntegrationOrchestrator(canStart bool) *integrationOrchestrator {
return &integrationOrchestrator{
canStart: canStart,
investigateCh: make(chan string, 10),
+ canStartCh: make(chan struct{}, 10),
}
}
@@ -42,6 +44,10 @@ func (o *integrationOrchestrator) GetRunningCount() int {
}
func (o *integrationOrchestrator) GetFixedCount() int { return 0 }
func (o *integrationOrchestrator) CanStartInvestigation() bool {
+ select {
+ case o.canStartCh <- struct{}{}:
+ default:
+ }
return o.canStart
}
func (o *integrationOrchestrator) ReinvestigateFinding(_ context.Context, _, _ string) error {
@@ -69,6 +75,7 @@ func TestIntegration_PatrolRunCreatesFindings(t *testing.T) {
svc.provider = &mockProvider{}
executor := tools.NewPulseToolExecutor(tools.ExecutorConfig{})
+ orch := newIntegrationOrchestrator(true)
mockCS := &patrolMockChatService{
executor: executor,
executePatrolStreamFunc: func(ctx context.Context, req PatrolExecuteRequest, callback ChatStreamCallback) (*PatrolStreamResponse, error) {
@@ -91,6 +98,11 @@ func TestIntegration_PatrolRunCreatesFindings(t *testing.T) {
if err != nil {
return nil, fmt.Errorf("create finding: %w", err)
}
+ select {
+ case <-orch.canStartCh:
+ return nil, fmt.Errorf("investigation admission started before the Watch model turn completed")
+ default:
+ }
return &PatrolStreamResponse{Content: "Found high CPU on web-server"}, nil
},
}
@@ -116,7 +128,6 @@ func TestIntegration_PatrolRunCreatesFindings(t *testing.T) {
})
// Set up orchestrator to record investigation triggers
- orch := newIntegrationOrchestrator(true)
ps.SetInvestigationOrchestrator(orch)
// Provide a mock config that returns "approval" autonomy level
@@ -160,9 +171,15 @@ func TestIntegration_PatrolRunCreatesFindings(t *testing.T) {
if findingID == "" {
t.Fatal("investigation triggered with empty finding ID")
}
+ if creator := executor.GetPatrolFindingCreator(); creator != nil {
+ t.Fatal("investigation inherited the completed Watch run's finding adapter")
+ }
case <-time.After(3 * time.Second):
t.Fatal("expected investigation to be triggered within 3 seconds")
}
+ if ps.runHistoryStore.Count() == 0 {
+ t.Fatal("investigation was dispatched before the Watch run record was stored")
+ }
}
// TestIntegration_FindingRejectedByThreshold verifies that findings for resources
diff --git a/internal/ai/patrol_run.go b/internal/ai/patrol_run.go
index 14e7d0aa71..471cd46eb1 100644
--- a/internal/ai/patrol_run.go
+++ b/internal/ai/patrol_run.go
@@ -743,6 +743,8 @@ func (p *PatrolService) runPatrolWithTrigger(ctx context.Context, trigger Trigge
Int("warning", summary.Warning).
Int("watch", summary.Watch).
Msg("AI Patrol: Completed patrol run")
+
+ p.dispatchPatrolInvestigations(runStats.aiAnalysis)
}
func patrolFindingSummaryForState(findings []*Finding, state patrolRuntimeState) FindingsSummary {
@@ -1137,6 +1139,8 @@ func (p *PatrolService) runScopedPatrol(ctx context.Context, scope PatrolScope)
Int("resources", resourceCount).
Str("reason", string(scope.Reason)).
Msg("AI Patrol: Scoped patrol complete")
+
+ p.dispatchPatrolInvestigations(runStats.aiAnalysis)
}
func (p *PatrolService) recordScopedPatrolScopeFailure(start time.Time, runID string, scope PatrolScope, resolution PatrolScopeResolution, summary, detail string) {