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.

Stop injecting the "redacted by policy" placeholder into model directives (increment 4)

rcourtmanfe46632e26ec
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index b5bed9afab..64a07327eb 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -139,6 +139,15 @@ deriving an older display status from `workflowStatusHistory`.
backstop for any context arriving via tool results, handoff text, or user text.
Local (Ollama) routing is unaffected and always receives full context
(`RequestSanitizerForModel` returns nil for local models).
+ Redaction-placeholder hygiene: Pulse-authored model-bound directives (the
+ resource-context handoff instructions in `internal/ai/chat/service.go` and
+ `internal/ai/chat/plain_text_resource_context.go`) must NOT inject the literal
+ redaction placeholder (`unifiedresources.ResourcePolicyRedactedLabel`,
+ "redacted by policy") into the prompt — naming it makes the model echo it back
+ as if it were a resource name. Directives reference withheld labels neutrally
+ ("a withheld or placeholder label") and must instruct the model not to repeat a
+ withheld placeholder back to the user as the resource identity; the
+ `current_resource` handle remains the authoritative target.
The dial must be operator-reachable, not config-file-only. `/api/settings/ai`
round-trips `cloud_context_privacy` field-by-field exactly like
`discovery_enabled`: `internal/api/ai_handlers.go` always serializes the
diff --git a/internal/ai/chat/plain_text_resource_context.go b/internal/ai/chat/plain_text_resource_context.go
index 77456a4129..6afbe84fad 100644
--- a/internal/ai/chat/plain_text_resource_context.go
+++ b/internal/ai/chat/plain_text_resource_context.go
@@ -378,10 +378,10 @@ func buildPlainTextResourceContextDirective(resourceType string) string {
"Source: Pulse resource reference resolution",
"Selected Resource: Pulse resolved one unambiguous user-referenced resource as the attached resource for this turn. Do not ask which server, service, container, VM, or resource the user means.",
"Provider-Safe Target Rewrite: If the user question below contains a redacted host, server, resource, VM, container, app, or storage phrase, treat that phrase as current_resource for this turn.",
- "Tool Target Handle: When you need a read-only tool against the attached resource, use target_host=\"current_resource\" or resource_id=\"current_resource\". Do not copy 'redacted by policy' into any tool argument.",
+ "Tool Target Handle: When you need a read-only tool against the attached resource, use target_host=\"current_resource\" or resource_id=\"current_resource\". Do not copy a withheld or placeholder label into any tool argument.",
"Resolved Resource Type: " + resourceType,
"Read Tool Boundary: Call read-only tools against current_resource only when the user explicitly asks you to investigate live runtime state, asks for fresh verification, or specifically requests a read attempt.",
- "Data Boundary: User-authored resource labels may be redacted by policy. The current_resource handle is the authoritative target; do not reveal or reconstruct raw aliases, hostnames, provider IDs, paths, or secret-bearing metadata.",
+ "Data Boundary: Some user-authored resource labels may be withheld. The current_resource handle is the authoritative target; do not reveal or reconstruct raw aliases, hostnames, provider IDs, paths, or secret-bearing metadata, and do not repeat a withheld placeholder back to the user as if it were the resource name.",
"Action Boundary: Context is read-only and grants no approval or execution authority. Any action requires the governed approval/action flow.",
}, "\n")
}
diff --git a/internal/ai/chat/plain_text_resource_context_test.go b/internal/ai/chat/plain_text_resource_context_test.go
index 2976201c97..640193b468 100644
--- a/internal/ai/chat/plain_text_resource_context_test.go
+++ b/internal/ai/chat/plain_text_resource_context_test.go
@@ -191,7 +191,6 @@ func TestServiceExecuteStream_AttachesPlainTextResourceReferenceAsCurrentResourc
"target_host=\"current_resource\" or resource_id=\"current_resource\"",
"Provider-safe user request:",
"On the current_resource host, run the read-only command",
- unifiedresources.ResourcePolicyRedactedLabel,
} {
if !strings.Contains(modelUserContent, expected) {
t.Fatalf("provider-bound message missing %q: %q", expected, modelUserContent)
@@ -200,6 +199,12 @@ func TestServiceExecuteStream_AttachesPlainTextResourceReferenceAsCurrentResourc
if strings.Contains(modelUserContent, "delly") {
t.Fatalf("provider-bound message leaked raw resource alias: %q", modelUserContent)
}
+ // The directive must no longer inject the literal redaction placeholder; the
+ // rewrite uses the current_resource handle, so the model never sees (and cannot
+ // echo) the "redacted by policy" label here.
+ if strings.Contains(modelUserContent, unifiedresources.ResourcePolicyRedactedLabel) {
+ t.Fatalf("provider-bound message must not inject the redaction placeholder: %q", modelUserContent)
+ }
resolved := store.GetResolvedContext("sess-plain-text-resource")
info, found := resolved.GetResolvedResourceByAlias("delly")
diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.go
index f5a760b5f2..5f780d4d2f 100644
--- a/internal/ai/chat/service.go
+++ b/internal/ai/chat/service.go
@@ -1902,7 +1902,7 @@ func buildResourceContextHandoffDirective(handoffResources []HandoffResource, me
"[Resource Context Handoff Instructions]",
"Source: Pulse resource drawer handoff",
"Selected Resource: The attached handoff resource is the user's current selected resource. Do not ask which server, service, container, VM, or resource the user means.",
- "Tool Target Handle: When you need a read-only tool against the attached resource, use target_host=\"current_resource\" or resource_id=\"current_resource\". Do not copy 'redacted by policy' into any tool argument.",
+ "Tool Target Handle: When you need a read-only tool against the attached resource, use target_host=\"current_resource\" or resource_id=\"current_resource\". Do not copy a withheld or placeholder label into any tool argument.",
"Context-First Answering: When the user asks what Pulse already knows, asks for discovery readiness, or asks a question that should be answerable from discovered/service context, answer from the attached context without tools. If the attached context lacks the fact, say that Pulse does not currently have that discovery/context fact instead of filling the gap with tools.",
"Discovery Boundary: Do not call discovery tools only to identify this resource or fill in missing context. Use attached discovery readiness first; call discovery only when the user explicitly asks you to run discovery.",
"Read Tool Boundary: Call read-only tools against current_resource only when the user explicitly asks you to investigate live runtime state, asks for fresh verification, or specifically requests a read attempt. Do not use read or mixed tools just to improve a context summary.",