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.

Infer resource_type from a canonical handle in pulse_query get

rcourtmanaccebfb305b6
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index a458aacbb6..31ab154486 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -2370,6 +2370,16 @@ Pulse already inventories. Tool selection stays model-owned: offer the tools and
let the model decide whether to use them, rather than pre-deciding from prompt
keywords/length that no tools are needed.
+The `pulse_query` `get` action (`executeGetResource` in
+`internal/ai/tools/tools_query.go`) must accept a canonical resource handle
+(`<type>-<hash>`, e.g. `system-container-599a2e3…`) as `resource_id` without a
+separate `resource_type` and infer the type from the handle, because that is how
+a model naturally references a resource it read from context. Failing such a call
+with "resource_type is required" burns visibly-failed tool calls in the
+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`.
+
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 e63c3136e7..ec0b0fa916 100644
--- a/internal/ai/tools/tools_query.go
+++ b/internal/ai/tools/tools_query.go
@@ -4556,6 +4556,30 @@ func (e *PulseToolExecutor) executeGetTopology(_ context.Context, args map[strin
return NewJSONResult(response), nil
}
+// resourceTypeFromCanonicalID extracts the resource type from a canonical
+// resource id of the form "<type>-<hex hash>" (unifiedresources/ids.go builds
+// ids as "<type>-<hex(sha256[:8])>"). The hash segment is unambiguous because no
+// resource-type word is all-hex, so the type is everything before the trailing
+// hex segment. Returns "" when the id is not a canonical handle (e.g. a bare
+// numeric VMID), in which case the caller still requires an explicit type.
+func resourceTypeFromCanonicalID(id string) string {
+ id = strings.TrimSpace(id)
+ idx := strings.LastIndex(id, "-")
+ if idx <= 0 || idx >= len(id)-1 {
+ return ""
+ }
+ suffix := id[idx+1:]
+ if len(suffix) < 7 || len(suffix) > 64 {
+ return ""
+ }
+ for _, r := range suffix {
+ if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f')) {
+ return ""
+ }
+ }
+ return id[:idx]
+}
+
func (e *PulseToolExecutor) executeGetResource(_ context.Context, args map[string]interface{}) (CallToolResult, error) {
resourceType, _ := args["resource_type"].(string)
resourceID, _ := args["resource_id"].(string)
@@ -4572,6 +4596,19 @@ func (e *PulseToolExecutor) executeGetResource(_ context.Context, args map[strin
resourceID = canonicalQueryIDForResolvedResource(resource)
}
+ if resourceType == "" {
+ // Models often pass a single canonical handle ("system-container-<hash>")
+ // as resource_id without a separate resource_type, because the handle
+ // already encodes the type (unifiedresources/ids.go: "<type>-<hash>").
+ // Infer the type from it instead of failing the call — otherwise the model
+ // burns one or more visibly-failed "resource_type is required" tool calls
+ // before recovering with the numeric id.
+ if inferred := resourceTypeFromCanonicalID(resourceID); inferred != "" {
+ resourceType = canonicalQueryResourceType(inferred)
+ resourceTypeRaw = inferred
+ }
+ }
+
if resourceType == "" {
return NewErrorResult(fmt.Errorf("resource_type is required")), nil
}
diff --git a/internal/ai/tools/tools_query_test.go b/internal/ai/tools/tools_query_test.go
index d64e2f726b..9b9d0dec5f 100644
--- a/internal/ai/tools/tools_query_test.go
+++ b/internal/ai/tools/tools_query_test.go
@@ -1969,3 +1969,23 @@ func TestExecuteGetGuestConfig_RejectsLegacyResourceTypes(t *testing.T) {
})
}
}
+
+func TestResourceTypeFromCanonicalID(t *testing.T) {
+ // Canonical handles are "<type>-<hex hash>"; the type must be recoverable so a
+ // `get` call that passes only the handle (no separate resource_type) succeeds
+ // instead of failing visibly with "resource_type is required".
+ cases := map[string]string{
+ "system-container-599a2e3f1b2c4d5e": "system-container",
+ "vm-0123456789abcdef": "vm",
+ "docker-container-deadbeefcafe1234": "docker-container",
+ "network-share-aabbccddeeff0011": "network-share",
+ "102": "", // bare numeric VMID still needs a type
+ "esphome": "", // a plain name is not a canonical handle
+ "": "",
+ }
+ for id, want := range cases {
+ if got := resourceTypeFromCanonicalID(id); got != want {
+ t.Fatalf("resourceTypeFromCanonicalID(%q) = %q, want %q", id, got, want)
+ }
+ }
+}