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 scoped Patrol investigations grounded

rcourtman857af3e3ccf7
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index fa3ce77e3a..779a025f17 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -65,7 +65,9 @@ verification remain core-owned and fail closed.
An investigation cannot complete or submit a typed action proposal before the
model has made at least one structured call to an advertised evidence tool.
Until then, core withholds proposal authority while leaving evidence-tool
-selection model-owned. If the provider returns prose without a tool call, core
+selection model-owned. The side-effect-free action-capability lookup is planning
+metadata, not infrastructure evidence: it neither consumes the evidence budget
+nor satisfies this grounding gate. If the provider returns prose without a tool call, core
must discard that prose as a durable conclusion and allow one bounded repair
turn that requires a structured call from the same advertised evidence
manifest. The repair is generic and carries no platform-, incident-, or
@@ -7374,10 +7376,12 @@ core-satisfied active-finding read. An explicitly scoped Watch whose exact
resource identity resolves to known canonical resource types receives the
least evidence manifest for those types plus the detection-owned finding
lifecycle. `internal/agentcapabilities/patrol_scope_tools.go` owns that mapping:
-generic canonical query/read operations remain available for evidence-led
-cross-resource causality, while unrelated subsystem schemas are removed. The
-mapping consumes only caller-supplied or core-resolved typed scope, never prompt
-text. An empty or unknown type keeps the full governed profile instead of
+canonical query and relevant subsystem reads remain available for evidence-led
+cross-resource causality, while unrelated subsystem schemas are removed. Watch
+does not receive the optional agent-routed `pulse_read` deep-inspection schema;
+root-cause log, file, and bounded exec evidence belongs to the separate finding
+investigation. The mapping consumes only caller-supplied or core-resolved typed
+scope, never prompt text. An empty or unknown type keeps the full governed profile instead of
guessing and silently blinding Patrol; the allowlist is applied after profile
projection and therefore can remove tools but cannot add authority.
@@ -7447,7 +7451,13 @@ Core uses the same scoped evidence mapping to project generic query/read tools,
the relevant subsystem evidence tool, and only the investigation-owned
capability lookup and typed proposal sink. The type is not model-authored and
cannot add a tool outside the already-projected investigation profile. Unknown
-types keep the full safe investigation profile. This keeps focused Patrol
+types keep the full safe investigation profile. Known types intersect their
+evidence ceiling with tools that are actually available after profile
+projection, so a deployment without an agent-routed or native `pulse_read`
+adapter still investigates from canonical query and subsystem evidence. At
+least one structured evidence tool plus both the capability lookup and proposal
+sink remain mandatory; missing proposal authority or a zero-evidence manifest
+fails before inference. This keeps focused Patrol
usable with smaller local models without replacing model judgment with a
diagnostic script or weakening proposal, policy, approval, execution, or
verification boundaries.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index bcb73fa7d3..ebe80a9595 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -9510,9 +9510,12 @@ and action approval semantics are unchanged.
Exact scoped Watch runs may now populate that internal allowlist from the
core-resolved canonical resource type set. The shared
`agentcapabilities.PatrolDetectionToolNamesForResourceTypes` mapping retains
-generic query/read evidence and only the relevant subsystem and detection
-lifecycle schemas. Investigations carry their finding `resource_type` over the
-public Pulse/Enterprise orchestrator dependency contract and use the companion
-investigation projection. Both paths are reductions after execution-profile
-projection; neither external clients nor model output can select or widen the
-surface.
+canonical query evidence and only the relevant subsystem and detection
+lifecycle schemas; optional agent-routed deep reads are deferred to the
+investigation boundary. Investigations carry their finding `resource_type` over
+the public Pulse/Enterprise orchestrator dependency contract and use the companion
+investigation projection. That projection intersects optional evidence tools
+with the runtime-available governed profile, while requiring at least one
+evidence tool plus the capability lookup and typed proposal sink. Both paths
+are reductions after execution-profile projection; neither external clients nor
+model output can select or widen the surface.
diff --git a/internal/agentcapabilities/patrol_scope_tools.go b/internal/agentcapabilities/patrol_scope_tools.go
index db953c7acc..66e075ea4c 100644
--- a/internal/agentcapabilities/patrol_scope_tools.go
+++ b/internal/agentcapabilities/patrol_scope_tools.go
@@ -12,14 +12,21 @@ import "strings"
// investigation can still follow canonical topology and inspect a causal
// dependency without receiving every subsystem-specific schema up front.
func PatrolEvidenceToolNamesForResourceTypes(resourceTypes []string) ([]string, bool) {
+ return patrolEvidenceToolNamesForResourceTypes(resourceTypes, true)
+}
+
+func patrolEvidenceToolNamesForResourceTypes(resourceTypes []string, includeDeepRead bool) ([]string, bool) {
if len(resourceTypes) == 0 {
return nil, false
}
- names := []string{PulseQueryToolName, PulseReadToolName}
+ names := []string{PulseQueryToolName}
seen := map[string]bool{
PulseQueryToolName: true,
- PulseReadToolName: true,
+ }
+ if includeDeepRead {
+ names = append(names, PulseReadToolName)
+ seen[PulseReadToolName] = true
}
add := func(name string) {
if !seen[name] {
@@ -63,7 +70,10 @@ func PatrolEvidenceToolNamesForResourceTypes(resourceTypes []string) ([]string,
// surface with the finding lifecycle owned by the detection profile. It may
// only reduce the already-governed profile manifest.
func PatrolDetectionToolNamesForResourceTypes(resourceTypes []string) ([]string, bool) {
- names, ok := PatrolEvidenceToolNamesForResourceTypes(resourceTypes)
+ // Watch owns symptom detection from the canonical seed and provider reads.
+ // Agent-routed file/log/exec inspection belongs to the separate finding
+ // investigation, where runtime availability can be evaluated explicitly.
+ names, ok := patrolEvidenceToolNamesForResourceTypes(resourceTypes, false)
if !ok {
return nil, false
}
diff --git a/internal/agentcapabilities/patrol_scope_tools_test.go b/internal/agentcapabilities/patrol_scope_tools_test.go
index c5bc675039..261fd7e1ae 100644
--- a/internal/agentcapabilities/patrol_scope_tools_test.go
+++ b/internal/agentcapabilities/patrol_scope_tools_test.go
@@ -47,11 +47,14 @@ func TestPatrolScopedToolProjectionComposesProfileOwnedTools(t *testing.T) {
if !ok {
t.Fatal("network-endpoint scope was not recognized")
}
- for _, required := range []string{PulseQueryToolName, PulseReadToolName, PulseDiscoveryToolName, PatrolGetFindingsToolName, PatrolReportFindingToolName, PatrolAssessFindingToolName, PatrolResolveFindingToolName} {
+ for _, required := range []string{PulseQueryToolName, PulseDiscoveryToolName, PatrolGetFindingsToolName, PatrolReportFindingToolName, PatrolAssessFindingToolName, PatrolResolveFindingToolName} {
if !slices.Contains(detection, required) {
t.Fatalf("detection surface missing %q: %v", required, detection)
}
}
+ if slices.Contains(detection, PulseReadToolName) {
+ t.Fatalf("detection surface included optional deep-read authority: %v", detection)
+ }
if slices.Contains(detection, PatrolProposeActionToolName) {
t.Fatalf("detection surface gained investigation proposal authority: %v", detection)
}
diff --git a/internal/agentcapabilities/types_test.go b/internal/agentcapabilities/types_test.go
index 0ff1809c9f..73b4973cc0 100644
--- a/internal/agentcapabilities/types_test.go
+++ b/internal/agentcapabilities/types_test.go
@@ -2,10 +2,31 @@ package agentcapabilities
import (
"net/http"
+ "slices"
"strings"
"testing"
)
+func TestPatrolScopedDetectionDefersOptionalDeepReadsToInvestigation(t *testing.T) {
+ detection, ok := PatrolDetectionToolNamesForResourceTypes([]string{"vm"})
+ if !ok {
+ t.Fatal("vm scope was not recognized")
+ }
+ if slices.Contains(detection, PulseReadToolName) {
+ t.Fatalf("Watch detection surface included optional agent-routed deep read: %v", detection)
+ }
+ for _, required := range []string{PulseQueryToolName, PulseMetricsToolName, PatrolReportFindingToolName, PatrolAssessFindingToolName} {
+ if !slices.Contains(detection, required) {
+ t.Fatalf("VM detection surface missing %q: %v", required, detection)
+ }
+ }
+
+ investigation, ok := PatrolInvestigationToolNamesForResourceTypes([]string{"vm"})
+ if !ok || !slices.Contains(investigation, PulseReadToolName) {
+ t.Fatalf("VM investigation surface lost optional deep-read preference: %v, ok=%v", investigation, ok)
+ }
+}
+
func TestDefaultApprovalPolicyDescriptionUsesSharedPolicyVocabulary(t *testing.T) {
cases := []struct {
policy ApprovalPolicy
diff --git a/internal/ai/chat/agentic_additional_test.go b/internal/ai/chat/agentic_additional_test.go
index 64e48b223d..926637a19a 100644
--- a/internal/ai/chat/agentic_additional_test.go
+++ b/internal/ai/chat/agentic_additional_test.go
@@ -133,12 +133,15 @@ func TestInvestigationEvidenceBudgetHelpers(t *testing.T) {
if isInvestigationEvidenceTool(agentcapabilities.PatrolProposeActionToolName) {
t.Fatal("terminal proposal must not consume evidence budget")
}
+ if isInvestigationEvidenceTool(agentcapabilities.PatrolActionCapabilitiesToolName) {
+ t.Fatal("capability lookup must not count as infrastructure evidence")
+ }
if got := investigationEvidenceCheckpoint(15); got != 8 {
t.Fatalf("checkpoint(15) = %d, want 8", got)
}
evidenceOnly := investigationEvidenceTools(available)
- if len(evidenceOnly) != 2 || evidenceOnly[0].Name != agentcapabilities.PulseQueryToolName || evidenceOnly[1].Name != agentcapabilities.PatrolActionCapabilitiesToolName {
- t.Fatalf("evidence tools = %+v, want proposal excluded", evidenceOnly)
+ if len(evidenceOnly) != 1 || evidenceOnly[0].Name != agentcapabilities.PulseQueryToolName {
+ t.Fatalf("evidence tools = %+v, want only infrastructure evidence", evidenceOnly)
}
}
diff --git a/internal/ai/chat/agentic_investigation_budget.go b/internal/ai/chat/agentic_investigation_budget.go
index b7c45254b9..2479375100 100644
--- a/internal/ai/chat/agentic_investigation_budget.go
+++ b/internal/ai/chat/agentic_investigation_budget.go
@@ -43,7 +43,12 @@ func applyInvestigationOutputLimitRecoveryRequest(req *providers.ChatRequest, pr
}
func isInvestigationEvidenceTool(name string) bool {
- return strings.TrimSpace(name) != agentcapabilities.PatrolProposeActionToolName
+ switch strings.TrimSpace(name) {
+ case "", agentcapabilities.PatrolProposeActionToolName, agentcapabilities.PatrolActionCapabilitiesToolName:
+ return false
+ default:
+ return true
+ }
}
func investigationEvidenceTools(available []providers.Tool) []providers.Tool {
diff --git a/internal/ai/chat/agentic_investigation_budget_w0716_coverage_test.go b/internal/ai/chat/agentic_investigation_budget_w0716_coverage_test.go
index 281e7f7635..49f04610c0 100644
--- a/internal/ai/chat/agentic_investigation_budget_w0716_coverage_test.go
+++ b/internal/ai/chat/agentic_investigation_budget_w0716_coverage_test.go
@@ -57,10 +57,11 @@ func Test_w0716_budget_IsInvestigationEvidenceTool(t *testing.T) {
}{
{name: "read-only query consumes evidence budget", in: agentcapabilities.PulseQueryToolName, want: true},
{name: "arbitrary evidence tool consumes budget", in: "pulse_read", want: true},
+ {name: "capability lookup is planning not evidence", in: agentcapabilities.PatrolActionCapabilitiesToolName, want: false},
{name: "terminal proposal does not consume budget", in: agentcapabilities.PatrolProposeActionToolName, want: false},
{name: "whitespace-padded proposal still not evidence", in: " " + agentcapabilities.PatrolProposeActionToolName + "\t", want: false},
- {name: "empty name treated as evidence tool", in: "", want: true},
- {name: "only-whitespace name treated as evidence tool", in: " ", want: true},
+ {name: "empty name is not evidence", in: "", want: false},
+ {name: "only-whitespace name is not evidence", in: " ", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/internal/ai/chat/service_filter_test.go b/internal/ai/chat/service_filter_test.go
index e44e8ac025..75762965ae 100644
--- a/internal/ai/chat/service_filter_test.go
+++ b/internal/ai/chat/service_filter_test.go
@@ -2,6 +2,7 @@ package chat
import (
"reflect"
+ "strings"
"testing"
"github.com/rcourtman/pulse-go-rewrite/internal/agentcapabilities"
@@ -53,6 +54,64 @@ func TestRestrictInvestigationProviderToolsForResourceType(t *testing.T) {
}
}
+func TestRestrictInvestigationProviderToolsAllowsUnavailableOptionalDeepRead(t *testing.T) {
+ providerTools := []providers.Tool{
+ {Name: agentcapabilities.PulseQueryToolName},
+ {Name: agentcapabilities.PulseMetricsToolName},
+ {Name: agentcapabilities.PatrolActionCapabilitiesToolName},
+ {Name: agentcapabilities.PatrolProposeActionToolName},
+ }
+ filtered, err := restrictInvestigationProviderToolsForResourceType(providerTools, "vm")
+ if err != nil {
+ t.Fatalf("restrict VM investigation without agent deep-read adapter: %v", err)
+ }
+ var names []string
+ for _, tool := range filtered {
+ names = append(names, tool.Name)
+ }
+ want := []string{
+ agentcapabilities.PulseQueryToolName,
+ agentcapabilities.PulseMetricsToolName,
+ agentcapabilities.PatrolActionCapabilitiesToolName,
+ agentcapabilities.PatrolProposeActionToolName,
+ }
+ if !reflect.DeepEqual(names, want) {
+ t.Fatalf("VM investigation tools = %v, want %v", names, want)
+ }
+}
+
+func TestRestrictInvestigationProviderToolsRequiresEvidenceAndProposalBoundary(t *testing.T) {
+ tests := []struct {
+ name string
+ tools []providers.Tool
+ want string
+ }{
+ {
+ name: "missing proposal sink",
+ tools: []providers.Tool{
+ {Name: agentcapabilities.PulseQueryToolName},
+ {Name: agentcapabilities.PatrolActionCapabilitiesToolName},
+ },
+ want: agentcapabilities.PatrolProposeActionToolName,
+ },
+ {
+ name: "missing evidence",
+ tools: []providers.Tool{
+ {Name: agentcapabilities.PatrolActionCapabilitiesToolName},
+ {Name: agentcapabilities.PatrolProposeActionToolName},
+ },
+ want: "no evidence tool",
+ },
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ if _, err := restrictInvestigationProviderToolsForResourceType(tc.tools, "vm"); err == nil || !strings.Contains(err.Error(), tc.want) {
+ t.Fatalf("error = %v, want %q", err, tc.want)
+ }
+ })
+ }
+}
+
func TestFilterToolsForPatrol_ConfigFlags(t *testing.T) {
svc := &Service{
cfg: &config.AIConfig{
diff --git a/internal/ai/chat/service_investigation.go b/internal/ai/chat/service_investigation.go
index f841035d9e..81ce4ec8c9 100644
--- a/internal/ai/chat/service_investigation.go
+++ b/internal/ai/chat/service_investigation.go
@@ -256,9 +256,46 @@ func restrictInvestigationProviderToolsForResourceType(providerTools []providers
if !ok {
return append([]providers.Tool(nil), providerTools...), nil
}
- filtered, err := restrictPatrolProviderTools(providerTools, scopedNames)
- if err != nil {
- return nil, fmt.Errorf("failed to project scoped investigation tools: %w", err)
+
+ // The typed map is a least-manifest ceiling, not a claim that every
+ // deployment has every optional evidence adapter. In particular,
+ // pulse_read exists only when an agent-routed or native log adapter is
+ // available. Intersect evidence with the already-governed runtime profile,
+ // while keeping the investigation-owned proposal boundary mandatory.
+ scoped := make(map[string]bool, len(scopedNames))
+ for _, name := range scopedNames {
+ name = strings.TrimSpace(name)
+ if name == "" {
+ return nil, fmt.Errorf("failed to project scoped investigation tools: scoped tool name must not be empty")
+ }
+ scoped[name] = true
+ }
+
+ filtered := make([]providers.Tool, 0, len(scoped))
+ present := make(map[string]bool, len(scoped))
+ evidenceCount := 0
+ for _, tool := range providerTools {
+ name := strings.TrimSpace(tool.Name)
+ if !scoped[name] {
+ continue
+ }
+ filtered = append(filtered, tool)
+ present[name] = true
+ if isInvestigationEvidenceTool(name) {
+ evidenceCount++
+ }
+ }
+
+ for _, required := range []string{
+ agentcapabilities.PatrolActionCapabilitiesToolName,
+ agentcapabilities.PatrolProposeActionToolName,
+ } {
+ if !present[required] {
+ return nil, fmt.Errorf("failed to project scoped investigation tools: required tool unavailable after profile projection: %s", required)
+ }
+ }
+ if evidenceCount == 0 {
+ return nil, fmt.Errorf("failed to project scoped investigation tools: no evidence tool is available for resource type %q", strings.TrimSpace(resourceType))
}
return filtered, nil
}
diff --git a/internal/ai/patrol_objective_mission_test.go b/internal/ai/patrol_objective_mission_test.go
index 0da6f359e7..fcace99d27 100644
--- a/internal/ai/patrol_objective_mission_test.go
+++ b/internal/ai/patrol_objective_mission_test.go
@@ -70,7 +70,6 @@ func TestScopedPatrolUsesCoreResolvedResourceTypeForLeastManifest(t *testing.T)
allowed := patrolAllowedToolNamesForScope(scope)
for _, required := range []string{
agentcapabilities.PulseQueryToolName,
- agentcapabilities.PulseReadToolName,
agentcapabilities.PulseDockerToolName,
agentcapabilities.PatrolReportFindingToolName,
} {
@@ -79,6 +78,7 @@ func TestScopedPatrolUsesCoreResolvedResourceTypeForLeastManifest(t *testing.T)
}
}
for _, forbidden := range []string{
+ agentcapabilities.PulseReadToolName,
agentcapabilities.PulseStorageToolName,
agentcapabilities.PulseKubernetesToolName,
agentcapabilities.PulsePMGToolName,