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.

Preserve canonical resource IDs in Patrol queries

rcourtman2774744b11b9
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index a8dd7892fe..65bb2d62be 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -3983,6 +3983,15 @@ transcript before the model recovers with the numeric id. The type is recovered
from the trailing hex hash segment (no type word is all-hex); a bare numeric
VMID still requires an explicit `resource_type`.
+For a resource resolved through the unified-resource provider, every
+`pulse_query` `get`, `list`, and `search` response must keep `id` equal to the
+canonical unified resource ID. Provider-native identifiers such as a Docker
+container ID remain accepted lookup aliases and internal execution targets,
+but they must not replace the canonical ID in model-visible resource results.
+Otherwise a model can faithfully copy Pulse-provided evidence into a Patrol
+finding and still mis-link that finding to a source record instead of the
+canonical resource selected by the operator or scorer.
+
When the model runs tools but returns no final narrative, the deterministic
fallback summary (`buildAutomaticFallbackSummary` in
`internal/ai/chat/agentic_final.go`) must read as a clean operator message, not a
diff --git a/internal/ai/tools/tools_query.go b/internal/ai/tools/tools_query.go
index bfe3204700..561f49f04d 100644
--- a/internal/ai/tools/tools_query.go
+++ b/internal/ai/tools/tools_query.go
@@ -2171,7 +2171,7 @@ func (e *PulseToolExecutor) registerQueryTools() {
},
"resource_id": {
Type: "string",
- Description: "Resource identifier (VMID or name) (for action: get, config)",
+ Description: "Canonical resource identifier (for action: get, config). Provider-native IDs and names are accepted as lookup aliases, but canonical unified resources are returned with their canonical ID.",
},
"type": {
Type: "string",
@@ -2474,13 +2474,20 @@ func resourceAgentConnected(resource unifiedresources.Resource, connected map[st
return false
}
-func canonicalAppContainerID(resource unifiedresources.Resource) string {
+func appContainerProviderID(resource unifiedresources.Resource) string {
if resource.Docker != nil && strings.TrimSpace(resource.Docker.ContainerID) != "" {
return strings.TrimSpace(resource.Docker.ContainerID)
}
return strings.TrimSpace(resource.ID)
}
+func canonicalAppContainerID(resource unifiedresources.Resource) string {
+ if resourceID := strings.TrimSpace(resource.ID); resourceID != "" {
+ return resourceID
+ }
+ return appContainerProviderID(resource)
+}
+
func canonicalAppContainerState(resource unifiedresources.Resource) string {
if resource.Docker != nil && strings.TrimSpace(resource.Docker.ContainerState) != "" {
return strings.TrimSpace(resource.Docker.ContainerState)
@@ -2505,12 +2512,13 @@ func matchCanonicalAppContainerResource(resource unifiedresources.Resource, reso
if query == "" {
return "", false
}
- containerID := canonicalAppContainerID(resource)
- if strings.EqualFold(containerID, query) ||
+ canonicalID := canonicalAppContainerID(resource)
+ providerID := appContainerProviderID(resource)
+ if strings.EqualFold(canonicalID, query) ||
+ strings.EqualFold(providerID, query) ||
strings.EqualFold(resourceDisplayName(resource), query) ||
- strings.EqualFold(strings.TrimSpace(resource.ID), query) ||
- strings.HasPrefix(strings.ToLower(containerID), strings.ToLower(query)) {
- return containerID, true
+ strings.HasPrefix(strings.ToLower(providerID), strings.ToLower(query)) {
+ return providerID, true
}
return "", false
}
@@ -3411,7 +3419,7 @@ func canonicalAppContainerActions(resource unifiedresources.Resource) []string {
}
func resolvedAppContainerRegistration(resource unifiedresources.Resource) (ResourceRegistration, bool) {
- containerID := strings.TrimSpace(canonicalAppContainerID(resource))
+ containerID := strings.TrimSpace(appContainerProviderID(resource))
name := strings.TrimSpace(resourceDisplayName(resource))
host := strings.TrimSpace(canonicalAppContainerHost(resource))
adapter := strings.TrimSpace(canonicalAppContainerAdapter(resource))
@@ -3865,7 +3873,7 @@ func (e *PulseToolExecutor) executeListInfrastructure(_ context.Context, args ma
}
summary := canonicalAppContainerSummaryFromResource(resource)
- summary.GovernedResourceMetadata = governance.Resolve(resourceDisplayName(resource), resource.ID, canonicalAppContainerID(resource))
+ summary.GovernedResourceMetadata = governance.Resolve(resourceDisplayName(resource), canonicalAppContainerID(resource), appContainerProviderID(resource))
response.AppContainers = append(response.AppContainers, summary)
count++
}
@@ -4911,9 +4919,9 @@ func (e *PulseToolExecutor) executeGetResource(_ context.Context, args map[strin
case "app-container":
if resource, containerID, ok := findCanonicalAppContainerResource(e.unifiedResourceProvider, resourceID); ok {
response := EmptyResourceResponse()
- response.GovernedResourceMetadata = governance.Resolve(resourceDisplayName(resource), resource.ID, containerID)
+ response.GovernedResourceMetadata = governance.Resolve(resourceDisplayName(resource), canonicalAppContainerID(resource), containerID)
response.Type = "app-container"
- response.ID = containerID
+ response.ID = canonicalAppContainerID(resource)
response.Name = resourceDisplayName(resource)
response.Status = canonicalAppContainerState(resource)
response.Platform = canonicalResourcePlatform(resource)
@@ -5720,10 +5728,11 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
continue
}
- containerID := canonicalAppContainerID(resource)
+ canonicalID := canonicalAppContainerID(resource)
+ containerID := appContainerProviderID(resource)
candidates := []string{
resourceDisplayName(resource),
- resource.ID,
+ canonicalID,
containerID,
canonicalAppContainerHost(resource),
canonicalResourcePlatform(resource),
@@ -5744,7 +5753,7 @@ func (e *PulseToolExecutor) executeSearchResources(_ context.Context, args map[s
summary := canonicalAppContainerSummaryFromResource(resource)
addMatch(ResourceMatch{
- GovernedResourceMetadata: governance.Resolve(resourceDisplayName(resource), resource.ID, containerID),
+ GovernedResourceMetadata: governance.Resolve(resourceDisplayName(resource), canonicalID, containerID),
Type: "app-container",
ID: summary.ID,
Name: summary.Name,
diff --git a/internal/ai/tools/tools_query_test.go b/internal/ai/tools/tools_query_test.go
index 75d4410a51..b4044d8304 100644
--- a/internal/ai/tools/tools_query_test.go
+++ b/internal/ai/tools/tools_query_test.go
@@ -924,6 +924,16 @@ func TestExecuteGetResource(t *testing.T) {
func TestExecuteQuery_UsesCanonicalTrueNASUnifiedResources(t *testing.T) {
provider := newTrueNASUnifiedQueryProvider(t)
+ expectedNextcloudID := ""
+ for _, resource := range provider.GetByType(unifiedresources.ResourceTypeAppContainer) {
+ if resourceDisplayName(resource) == "Nextcloud" {
+ expectedNextcloudID = resource.ID
+ break
+ }
+ }
+ if expectedNextcloudID == "" {
+ t.Fatal("expected canonical Nextcloud resource ID")
+ }
executor := NewPulseToolExecutor(ExecutorConfig{
UnifiedResourceProvider: provider,
})
@@ -964,7 +974,7 @@ func TestExecuteQuery_UsesCanonicalTrueNASUnifiedResources(t *testing.T) {
continue
}
foundNextcloud = true
- if app.Platform != "truenas" || app.Host != "truenas-main" || app.ID != "nextcloud" {
+ if app.Platform != "truenas" || app.Host != "truenas-main" || app.ID != expectedNextcloudID {
t.Fatalf("unexpected Nextcloud summary: %+v", app)
}
}
@@ -1079,6 +1089,77 @@ func TestExecuteQuery_UsesCanonicalTrueNASUnifiedResources(t *testing.T) {
}
}
+func TestExecuteQuery_AppContainerPreservesCanonicalResourceIDAcrossAliases(t *testing.T) {
+ const canonicalID = "app-container-e5593f5074d6cd7f"
+ providerID := strings.Repeat("3", 64)
+ provider := &stubUnifiedResourceProvider{resources: []unifiedresources.Resource{{
+ ID: canonicalID,
+ Type: unifiedresources.ResourceTypeAppContainer,
+ Technology: "docker",
+ Name: "worker",
+ Status: unifiedresources.StatusOnline,
+ ParentName: "colima",
+ Docker: &unifiedresources.DockerData{
+ ContainerID: providerID,
+ ContainerState: "running",
+ Image: "alpine:3.20",
+ RestartCount: 6,
+ },
+ }}}
+ executor := NewPulseToolExecutor(ExecutorConfig{
+ StateProvider: &mockStateProvider{state: models.StateSnapshot{}},
+ UnifiedResourceProvider: provider,
+ })
+
+ for _, lookup := range []string{canonicalID, providerID, providerID[:12], "worker"} {
+ t.Run("get_"+lookup, func(t *testing.T) {
+ result, err := executor.executeGetResource(context.Background(), map[string]interface{}{
+ "resource_type": "app-container",
+ "resource_id": lookup,
+ })
+ if err != nil {
+ t.Fatalf("get app-container by %q: %v", lookup, err)
+ }
+ var response ResourceResponse
+ if err := json.Unmarshal([]byte(result.Content[0].Text), &response); err != nil {
+ t.Fatalf("decode app-container response: %v", err)
+ }
+ if response.ID != canonicalID {
+ t.Fatalf("response id = %q, want canonical id %q", response.ID, canonicalID)
+ }
+ })
+ }
+
+ listResult, err := executor.executeListInfrastructure(context.Background(), map[string]interface{}{
+ "type": "app-containers",
+ })
+ if err != nil {
+ t.Fatalf("list app-containers: %v", err)
+ }
+ var listResponse InfrastructureResponse
+ if err := json.Unmarshal([]byte(listResult.Content[0].Text), &listResponse); err != nil {
+ t.Fatalf("decode app-container list response: %v", err)
+ }
+ if len(listResponse.AppContainers) != 1 || listResponse.AppContainers[0].ID != canonicalID {
+ t.Fatalf("list response did not preserve canonical id: %+v", listResponse.AppContainers)
+ }
+
+ searchResult, err := executor.executeSearchResources(context.Background(), map[string]interface{}{
+ "query": providerID,
+ "type": "app-container",
+ })
+ if err != nil {
+ t.Fatalf("search app-container by provider id: %v", err)
+ }
+ var searchResponse ResourceSearchResponse
+ if err := json.Unmarshal([]byte(searchResult.Content[0].Text), &searchResponse); err != nil {
+ t.Fatalf("decode app-container search response: %v", err)
+ }
+ if len(searchResponse.Matches) != 1 || searchResponse.Matches[0].ID != canonicalID {
+ t.Fatalf("search response did not preserve canonical id: %+v", searchResponse.Matches)
+ }
+}
+
func TestExecuteGetResource_RegistersTrueNASAppContainerForCanonicalControl(t *testing.T) {
provider := newTrueNASUnifiedQueryProvider(t)
resolved := &mockResolvedContext{