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.

Keep new Patrol findings out of reassessment

rcourtman611e9a0227d0
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index ba8e487bd9..d78d4f3e2c 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -124,6 +124,11 @@ further investigation and new findings, accepts `uncertain` as a complete
honest verdict, and is capped at the missing-finding count plus two turns,
never more than twelve. Verdicts still missing after the sweep keep the
existing run-level incomplete-assessment error.
+Findings first created by an accepted `patrol_report_finding` in the current
+run are already complete structured new-issue outcomes and never join that
+run's assessment sweep, even if a concurrent or later `patrol_get_findings`
+call observes them. Re-reported pre-existing findings remain subject to the
+existing-finding verdict contract.
Investigation and interactive profiles retain a tool-free final summary; a
Watch finding write at the deadline is followed only by the existing bounded
summary path. A capability-unavailable
diff --git a/internal/ai/patrol_ai.go b/internal/ai/patrol_ai.go
index 5692567059..51fa853cd7 100644
--- a/internal/ai/patrol_ai.go
+++ b/internal/ai/patrol_ai.go
@@ -43,6 +43,7 @@ type AIAnalysisResult struct {
OutputTokens int
ToolCalls []ToolCallRecord // Tool invocations during this analysis
ReportedIDs []string // Finding IDs reported (created/re-reported) this run
+ NewFindingIDs []string // Finding IDs first created during this run
ResolvedIDs []string // Finding IDs explicitly resolved by LLM this run
Assessments []PatrolFindingAssessment // Explicit verdicts for existing findings this run
SeededFindingIDs []string // Finding IDs that were presented in seed context
@@ -385,7 +386,7 @@ func patrolMissingAssessmentIDs(result *AIAnalysisResult) []string {
if result == nil || len(result.SeededFindingIDs)+len(result.QueriedFindingIDs) == 0 {
return nil
}
- completed := make(map[string]bool, len(result.Assessments)+len(result.ResolvedIDs))
+ completed := make(map[string]bool, len(result.Assessments)+len(result.ResolvedIDs)+len(result.NewFindingIDs))
for _, assessment := range result.Assessments {
completed[assessment.FindingID] = true
}
@@ -395,6 +396,13 @@ func patrolMissingAssessmentIDs(result *AIAnalysisResult) []string {
for _, findingID := range result.ResolvedIDs {
completed[findingID] = true
}
+ // A finding first created during this run is already the model's accepted
+ // structured verdict for that issue. It can appear in a concurrent or later
+ // patrol_get_findings result, but must not be immediately re-litigated by the
+ // existing-finding assessment sweep.
+ for _, findingID := range result.NewFindingIDs {
+ completed[findingID] = true
+ }
missing := make([]string, 0)
runtimeFindingID := generateFindingID(patrolRuntimeResourceID, "reliability", patrolRuntimeFindingKey)
seen := make(map[string]bool)
@@ -804,6 +812,7 @@ func (p *PatrolService) runAIAnalysisState(ctx context.Context, snap patrolRunti
OutputTokens: outputTokens,
ToolCalls: append([]ToolCallRecord(nil), toolCalls...),
ReportedIDs: adapter.getReportedFindingIDs(),
+ NewFindingIDs: adapter.getNewFindingIDs(),
ResolvedIDs: adapter.getResolvedIDs(),
Assessments: adapter.getAssessments(),
SeededFindingIDs: seededFindingIDs,
diff --git a/internal/ai/patrol_ai_additional_test.go b/internal/ai/patrol_ai_additional_test.go
index 86bf66ae19..549d9756f3 100644
--- a/internal/ai/patrol_ai_additional_test.go
+++ b/internal/ai/patrol_ai_additional_test.go
@@ -318,13 +318,15 @@ func TestPatrolService_SeedPreviousRun(t *testing.T) {
func TestPatrolMissingAssessmentIDsIncludesSeededAndQueriedFindings(t *testing.T) {
result := &AIAnalysisResult{
- SeededFindingIDs: []string{"seeded", "resolved-direct", "duplicate"},
- QueriedFindingIDs: []string{"queried", "duplicate"},
+ SeededFindingIDs: []string{"seeded", "resolved-direct", "duplicate", "reported-existing"},
+ QueriedFindingIDs: []string{"queried", "duplicate", "new-this-run", "reported-existing"},
+ ReportedIDs: []string{"new-this-run", "reported-existing"},
+ NewFindingIDs: []string{"new-this-run"},
Assessments: []PatrolFindingAssessment{{FindingID: "seeded", Verdict: "present"}},
ResolvedIDs: []string{"resolved-direct"},
}
missing := patrolMissingAssessmentIDs(result)
- if len(missing) != 2 || missing[0] != "duplicate" || missing[1] != "queried" {
- t.Fatalf("missing assessments = %v, want [duplicate queried]", missing)
+ if len(missing) != 3 || missing[0] != "duplicate" || missing[1] != "queried" || missing[2] != "reported-existing" {
+ t.Fatalf("missing assessments = %v, want [duplicate queried reported-existing]", missing)
}
}
diff --git a/internal/ai/patrol_findings.go b/internal/ai/patrol_findings.go
index d19e469c65..87a987778a 100644
--- a/internal/ai/patrol_findings.go
+++ b/internal/ai/patrol_findings.go
@@ -514,6 +514,7 @@ type patrolFindingCreatorAdapter struct {
findingScope map[string]bool
findingsMu sync.Mutex
findings []*Finding
+ newFindingIDs []string
assessments []PatrolFindingAssessment
queriedFindingIDs []string
queriedFindings []tools.PatrolFindingInfo
@@ -651,6 +652,9 @@ func (a *patrolFindingCreatorAdapter) CreateFinding(input tools.PatrolFindingInp
// Track for run stats
a.trackCollectedFinding(finding)
+ if isNew {
+ a.trackNewFindingID(id)
+ }
return id, isNew, nil
}
@@ -681,6 +685,20 @@ func (a *patrolFindingCreatorAdapter) trackCollectedFinding(finding *Finding) {
a.findings = append(a.findings, finding)
}
+func (a *patrolFindingCreatorAdapter) trackNewFindingID(findingID string) {
+ if findingID == "" {
+ return
+ }
+ a.findingsMu.Lock()
+ defer a.findingsMu.Unlock()
+ for _, existingID := range a.newFindingIDs {
+ if existingID == findingID {
+ return
+ }
+ }
+ a.newFindingIDs = append(a.newFindingIDs, findingID)
+}
+
// AssessFinding records the model's explicit terminal verdict for an existing
// finding in this run. Present refreshes the durable finding heartbeat and
// current evidence, resolved delegates to the existing fail-closed verifier,
@@ -1134,6 +1152,17 @@ func (a *patrolFindingCreatorAdapter) getReportedFindingIDs() []string {
return ids
}
+// getNewFindingIDs returns findings whose durable lifecycle began in this run.
+// Re-reported findings are intentionally excluded because they still require
+// an explicit existing-finding verdict.
+func (a *patrolFindingCreatorAdapter) getNewFindingIDs() []string {
+ a.findingsMu.Lock()
+ defer a.findingsMu.Unlock()
+ result := make([]string, len(a.newFindingIDs))
+ copy(result, a.newFindingIDs)
+ return result
+}
+
// getResolvedIDs returns the IDs of findings explicitly resolved by the LLM this run.
func (a *patrolFindingCreatorAdapter) getResolvedIDs() []string {
a.findingsMu.Lock()
diff --git a/internal/ai/patrol_findings_additional_test.go b/internal/ai/patrol_findings_additional_test.go
index 70f82bb423..2e6e298abc 100644
--- a/internal/ai/patrol_findings_additional_test.go
+++ b/internal/ai/patrol_findings_additional_test.go
@@ -1556,3 +1556,51 @@ func TestPatrolFindingAdapterSeparatesRequestedLifecycleScopeFromEvidenceScope(t
t.Fatalf("context-only finding must be rejected by lifecycle scope, got %v", err)
}
}
+
+func TestPatrolFindingAdapterDistinguishesSameRunCreationFromExistingRereport(t *testing.T) {
+ ps := NewPatrolService(nil, nil)
+ input := tools.PatrolFindingInput{
+ ResourceID: "camera-1", ResourceName: "Camera 1", ResourceType: "host",
+ Key: "camera-offline", Severity: "warning", Category: "reliability",
+ Title: "Camera is unavailable", Description: "The camera is offline.",
+ Impact: "Recording is unavailable.", Recommendation: "Restore availability.",
+ Evidence: "Current status is offline.",
+ }
+
+ firstRun := newPatrolFindingCreatorAdapterState(ps, patrolRuntimeState{})
+ if active := firstRun.GetActiveFindings("", ""); len(active) != 0 {
+ t.Fatalf("initial active findings = %+v, want none", active)
+ }
+ findingID, isNew, err := firstRun.CreateFinding(input)
+ if err != nil || !isNew {
+ t.Fatalf("first report = (%q, %t, %v), want a new finding", findingID, isNew, err)
+ }
+ // This models a findings read racing with or following the accepted report.
+ // The new finding may be returned, but it is not an existing-finding verdict
+ // candidate in the run that created it.
+ firstRun.GetActiveFindings("", "")
+ firstResult := &AIAnalysisResult{
+ ReportedIDs: firstRun.getReportedFindingIDs(),
+ NewFindingIDs: firstRun.getNewFindingIDs(),
+ QueriedFindingIDs: firstRun.getQueriedFindingIDs(),
+ }
+ if missing := patrolMissingAssessmentIDs(firstResult); len(missing) != 0 {
+ t.Fatalf("same-run new finding unexpectedly needs assessment: %v", missing)
+ }
+
+ secondRun := newPatrolFindingCreatorAdapterState(ps, patrolRuntimeState{})
+ secondRun.GetActiveFindings("", "")
+ reportedID, isNew, err := secondRun.CreateFinding(input)
+ if err != nil || isNew || reportedID != findingID {
+ t.Fatalf("second report = (%q, %t, %v), want existing %q", reportedID, isNew, err, findingID)
+ }
+ secondResult := &AIAnalysisResult{
+ ReportedIDs: secondRun.getReportedFindingIDs(),
+ NewFindingIDs: secondRun.getNewFindingIDs(),
+ QueriedFindingIDs: secondRun.getQueriedFindingIDs(),
+ }
+ missing := patrolMissingAssessmentIDs(secondResult)
+ if len(missing) != 1 || missing[0] != findingID {
+ t.Fatalf("re-reported existing finding missing assessments = %v, want [%s]", missing, findingID)
+ }
+}