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.

Normalize pulse_read native log denial paths

rcourtman046a0e92c083
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 17229f9b43..065c825676 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -236,6 +236,11 @@ agent-routed platforms. Shared AI context should carry canonical
`resource_id` guidance for those resources, and `pulse_read action=logs` may
only be suggested when the runtime has an explicit native resource read path
such as supported TrueNAS `app-container` logs.
+If a caller still targets `pulse_read action=logs` with `resource_id` for a
+resource that lacks that native log path, the shared tool boundary must fail
+as a structured blocked response with a governed recovery hint toward the
+correct shared path, such as `pulse_query action=get` for API-backed read-only
+resources or `target_host` plus `container` for agent-routed app logs.
That same VMware AI rule also now includes mention resolution. Frontend
Assistant mention payloads for VMware-backed `agent`, `vm`, `storage`, and
canonical `app-container` resources must preserve the shared unified resource
diff --git a/internal/ai/tools/tools_read.go b/internal/ai/tools/tools_read.go
index cc58e021da..0f6645d273 100644
--- a/internal/ai/tools/tools_read.go
+++ b/internal/ai/tools/tools_read.go
@@ -459,10 +459,6 @@ func (e *PulseToolExecutor) executeReadLogs(ctx context.Context, args map[string
}
func (e *PulseToolExecutor) executeNativeAppContainerReadLogs(ctx context.Context, resourceRef, container string, lines int) (CallToolResult, error) {
- if e.appContainerReadProvider == nil {
- return NewErrorResult(fmt.Errorf("native app-container read provider is not available")), nil
- }
-
validation := e.validateResolvedResource(resourceRef, "query", false)
if validation.IsBlocked() {
return NewToolResponseResult(validation.StrictError.ToToolResponse()), nil
@@ -482,10 +478,13 @@ func (e *PulseToolExecutor) executeNativeAppContainerReadLogs(ctx context.Contex
resolved := validation.Resource
if resolved.GetKind() != "app-container" {
- return NewErrorResult(fmt.Errorf("resource '%s' of kind %q does not support native logs through pulse_read", resourceRef, resolved.GetKind())), nil
+ return blockedNativeReadLogsResult(resolved, resourceRef, container), nil
}
if !strings.EqualFold(strings.TrimSpace(resolved.GetAdapter()), "truenas") {
- return NewErrorResult(fmt.Errorf("resource '%s' uses unsupported read adapter %q", resourceRef, resolved.GetAdapter())), nil
+ return blockedNativeReadLogsResult(resolved, resourceRef, container), nil
+ }
+ if e.appContainerReadProvider == nil {
+ return NewErrorResult(fmt.Errorf("native app-container read provider is not available")), nil
}
resourceName := resolvedResourceDisplayName(resolved)
@@ -526,6 +525,73 @@ func (e *PulseToolExecutor) executeNativeAppContainerReadLogs(ctx context.Contex
return NewTextResult(fmt.Sprintf("%s:\n%s", title, output)), nil
}
+func blockedNativeReadLogsResult(resolved ResolvedResourceInfo, resourceRef, container string) CallToolResult {
+ resourceRef = strings.TrimSpace(resourceRef)
+ if resolved == nil {
+ return NewErrorResult(fmt.Errorf("resource '%s' does not support native logs through pulse_read", resourceRef))
+ }
+
+ resourceName := resolvedResourceDisplayName(resolved)
+ if resourceName == "" {
+ resourceName = resourceRef
+ }
+ kind := strings.TrimSpace(resolved.GetKind())
+ if kind == "" {
+ kind = strings.TrimSpace(resolved.GetResourceType())
+ }
+ adapter := strings.TrimSpace(resolved.GetAdapter())
+ canonicalResourceID := strings.TrimSpace(resolved.GetResourceID())
+ details := map[string]interface{}{
+ "resource_ref": resourceRef,
+ "resource_id": canonicalResourceID,
+ "resource_type": kind,
+ "adapter": adapter,
+ "allowed_actions": resolved.GetAllowedActions(),
+ "native_logs_path": false,
+ }
+
+ if kind == "app-container" {
+ targetHost := strings.TrimSpace(resolved.GetTargetHost())
+ containerName := strings.TrimSpace(container)
+ if containerName == "" {
+ containerName = resourceName
+ }
+ if targetHost != "" {
+ details["target_host"] = targetHost
+ details["container"] = containerName
+ details["recovery_hint"] = fmt.Sprintf(
+ "Use pulse_read action=logs target_host=%q container=%q for app logs on this platform.",
+ targetHost,
+ containerName,
+ )
+ return NewToolResponseResult(NewToolBlockedError(
+ ErrCodeActionNotAllowed,
+ fmt.Sprintf("Resource %q does not expose native app logs through pulse_read resource_id on adapter %q.", resourceName, adapter),
+ details,
+ ))
+ }
+ }
+
+ queryType := kind
+ if queryType == "" {
+ queryType = "resource"
+ }
+ queryResourceID := canonicalResourceID
+ if queryResourceID == "" {
+ queryResourceID = resourceRef
+ }
+ details["recovery_hint"] = fmt.Sprintf(
+ "Use pulse_query action=get resource_type=%q resource_id=%q to inspect status, alerts, activity, and metrics for this resource.",
+ queryType,
+ queryResourceID,
+ )
+ return NewToolResponseResult(NewToolBlockedError(
+ ErrCodeActionNotAllowed,
+ fmt.Sprintf("Resource %q does not expose native logs through pulse_read for adapter %q.", resourceName, adapter),
+ details,
+ ))
+}
+
// truncateCommand truncates a command for display/logging
func truncateCommand(cmd string, maxLen int) string {
if len(cmd) <= maxLen {
diff --git a/internal/ai/tools/tools_read_test.go b/internal/ai/tools/tools_read_test.go
index f09ac83c8c..eaa381c25c 100644
--- a/internal/ai/tools/tools_read_test.go
+++ b/internal/ai/tools/tools_read_test.go
@@ -2,6 +2,7 @@ package tools
import (
"context"
+ "encoding/json"
"strings"
"testing"
@@ -229,3 +230,110 @@ func TestExecuteReadLogs_TrueNASAppUsesNativeReadProvider(t *testing.T) {
t.Fatalf("unexpected native app read request: %+v", call)
}
}
+
+func TestExecuteReadLogs_VMwareResourcesReturnStructuredQueryGuidance(t *testing.T) {
+ tests := []struct {
+ name string
+ resourceType string
+ resourceID string
+ resourceRef string
+ wantKind string
+ }{
+ {name: "vm", resourceType: "vm", resourceID: "app-01", resourceRef: "app-01", wantKind: "vm"},
+ {name: "agent", resourceType: "agent", resourceID: "esxi-01.lab.local", resourceRef: "esxi-01.lab.local", wantKind: "agent"},
+ {name: "storage", resourceType: "storage", resourceID: "nvme-primary", resourceRef: "nvme-primary", wantKind: "storage"},
+ }
+
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ provider := newVMwareUnifiedQueryProvider(t)
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ exec := NewPulseToolExecutor(ExecutorConfig{
+ UnifiedResourceProvider: provider,
+ ReadState: provider.ResourceRegistry,
+ })
+ exec.SetResolvedContext(resolved)
+
+ _, err := exec.executeGetResource(context.Background(), map[string]interface{}{
+ "resource_type": tc.resourceType,
+ "resource_id": tc.resourceID,
+ })
+ require.NoError(t, err)
+
+ result, err := exec.executeReadLogs(context.Background(), map[string]interface{}{
+ "action": "logs",
+ "resource_id": tc.resourceRef,
+ })
+ require.NoError(t, err)
+ assert.True(t, result.IsError)
+
+ payload := decodeToolResponse(t, result)
+ require.NotNil(t, payload.Error)
+ assert.Equal(t, ErrCodeActionNotAllowed, payload.Error.Code)
+ assert.True(t, payload.Error.Blocked)
+ assert.Contains(t, payload.Error.Message, "does not expose native logs through pulse_read")
+ assert.Equal(t, tc.wantKind, payload.Error.Details["resource_type"])
+ assert.Equal(t, "vmware-vsphere", payload.Error.Details["adapter"])
+
+ hint, ok := payload.Error.Details["recovery_hint"].(string)
+ require.True(t, ok)
+ assert.Contains(t, hint, `pulse_query action=get`)
+ assert.Contains(t, hint, `resource_type="`+tc.wantKind+`"`)
+ })
+ }
+}
+
+func TestExecuteReadLogs_NonNativeAppContainersReturnStructuredTargetHostGuidance(t *testing.T) {
+ resolved := &mockResolvedContext{
+ resources: make(map[string]ResolvedResourceInfo),
+ aliases: make(map[string]ResolvedResourceInfo),
+ }
+ resource := &mockResource{
+ resourceID: "app-container:docker-host:homepage",
+ resourceType: "app-container",
+ targetHost: "docker-host",
+ adapter: "docker",
+ allowedActions: []string{"query", "get", "start", "stop", "restart"},
+ providerUID: "homepage",
+ kind: "app-container",
+ aliases: []string{"homepage"},
+ }
+ resolved.resources[resource.resourceID] = resource
+ resolved.aliases["homepage"] = resource
+
+ exec := NewPulseToolExecutor(ExecutorConfig{})
+ exec.SetResolvedContext(resolved)
+
+ result, err := exec.executeReadLogs(context.Background(), map[string]interface{}{
+ "action": "logs",
+ "resource_id": "homepage",
+ })
+ require.NoError(t, err)
+ assert.True(t, result.IsError)
+
+ payload := decodeToolResponse(t, result)
+ require.NotNil(t, payload.Error)
+ assert.Equal(t, ErrCodeActionNotAllowed, payload.Error.Code)
+ assert.True(t, payload.Error.Blocked)
+ assert.Contains(t, payload.Error.Message, "does not expose native app logs through pulse_read resource_id")
+ assert.Equal(t, "app-container", payload.Error.Details["resource_type"])
+ assert.Equal(t, "docker-host", payload.Error.Details["target_host"])
+ assert.Equal(t, "homepage", payload.Error.Details["container"])
+
+ hint, ok := payload.Error.Details["recovery_hint"].(string)
+ require.True(t, ok)
+ assert.Contains(t, hint, `target_host="docker-host"`)
+ assert.Contains(t, hint, `container="homepage"`)
+}
+
+func decodeToolResponse(t *testing.T, result CallToolResult) ToolResponse {
+ t.Helper()
+ require.NotEmpty(t, result.Content)
+
+ var payload ToolResponse
+ require.NoError(t, json.Unmarshal([]byte(result.Content[0].Text), &payload))
+ return payload
+}