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.

Bound Patrol finding summary turns

rcourtman44d861433043
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 61c89dcefa..d2b562ecb7 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -5669,6 +5669,11 @@ routes use exact model IDs and model-specific review dates from the public
OpenRouter Models API; aliases, fast variants, routers, and other unreviewed
routes remain unknown and therefore fail any non-zero qualification cost
budget until their actual route price is explicitly recorded.
+After a non-interactive Patrol finding lifecycle write succeeds, the structured
+tool result is authoritative and the remaining text-only provider turn is only
+for operator-facing summary prose. That turn must use a bounded summary system
+instruction rather than resending the full detection and investigation prompt;
+it may not invent findings, evidence, actions, verification, or remediation.
Persisted Patrol tool inputs must retain complete structured finding calls up
to the bounded 16 KiB record limit so normal evidence-rich findings remain
deterministically replayable. If any captured input is nevertheless incomplete
diff --git a/internal/ai/chat/agentic.go b/internal/ai/chat/agentic.go
index 80f153edca..36398e6051 100644
--- a/internal/ai/chat/agentic.go
+++ b/internal/ai/chat/agentic.go
@@ -382,6 +382,17 @@ func appendFSMVerificationPrompt(messages []providers.Message, prompt string) []
})
}
+const patrolFindingLifecycleSummarySystemPrompt = `You are Pulse Patrol completing a non-interactive run after its structured finding lifecycle operations succeeded. Return a concise operator summary grounded only in the supplied seed, tool calls, and tool results. Treat the structured tool results as authoritative. Do not invent new findings, evidence, actions, verification, or remediation claims.`
+
+func applyPatrolFindingLifecycleSummaryRequest(req *providers.ChatRequest) {
+ if req == nil {
+ return
+ }
+ req.Tools = nil
+ req.ToolChoice = nil
+ req.System = patrolFindingLifecycleSummarySystemPrompt
+}
+
// sanitizeProviderStreamErrorForUser turns a raw provider/transport error into a
// clean, human message safe to render in the chat. Upstream errors (especially
// from OpenAI-compatible gateways like OpenRouter) embed raw JSON bodies and
@@ -655,8 +666,9 @@ func (a *AgenticLoop) executeWithTools(ctx context.Context, sessionID string, me
var resultMessages []Message
turn := 0
- writeCompletedLastTurn := false // When true, request final text without offering tools
- toolBlockedLastTurn := false // When true, request final text after budget/loop block
+ writeCompletedLastTurn := false // When true, request final text without offering tools
+ patrolFindingWriteCompletedLastTurn := false // When true, use the bounded Patrol lifecycle summary contract
+ toolBlockedLastTurn := false // When true, request final text after budget/loop block
// Loop detection: track identical tool calls (name + serialized input).
// After maxIdenticalCalls identical invocations, the next one is blocked.
@@ -767,6 +779,16 @@ func (a *AgenticLoop) executeWithTools(ctx context.Context, sessionID string, me
Int("max_turns", maxTurns).
Str("session_id", sessionID).
Msg("[AgenticLoop] Approaching max turns — omitting tools for final response")
+ } else if patrolFindingWriteCompletedLastTurn {
+ // Structured finding lifecycle results are the source of truth. The final
+ // provider turn exists only to produce concise display prose, so do not
+ // resend Patrol's full detection/investigation instruction set.
+ applyPatrolFindingLifecycleSummaryRequest(&req)
+ textOnlySafetyBrake = true
+ patrolFindingWriteCompletedLastTurn = false
+ log.Debug().
+ Str("session_id", sessionID).
+ Msg("[AgenticLoop] Patrol finding lifecycle write completed — using bounded summary prompt")
} else if writeCompletedLastTurn {
// A write action completed successfully on the previous turn.
// Ask for the final response with the execution result already in context.
@@ -1853,7 +1875,11 @@ func (a *AgenticLoop) executeWithTools(ctx context.Context, sessionID string, me
// handler accepts it. It neither changes infrastructure nor proves
// verification of a preceding infrastructure change. Conclude on
// the next text-only turn.
- writeCompletedLastTurn = true
+ if a.currentExecutionProfile().NonInteractive() {
+ patrolFindingWriteCompletedLastTurn = true
+ } else {
+ writeCompletedLastTurn = true
+ }
log.Debug().
Str("tool", tc.Name).
Str("state", string(fsm.State)).
diff --git a/internal/ai/chat/agentic_additional_test.go b/internal/ai/chat/agentic_additional_test.go
index 04633edfd4..7d86ac6805 100644
--- a/internal/ai/chat/agentic_additional_test.go
+++ b/internal/ai/chat/agentic_additional_test.go
@@ -113,6 +113,31 @@ func TestAppendFSMVerificationPrompt_EndsWithUserInstruction(t *testing.T) {
}
}
+func TestPatrolFindingLifecycleSummaryPromptIsBoundedAndNonAuthoritative(t *testing.T) {
+ prompt := patrolFindingLifecycleSummarySystemPrompt
+ for _, required := range []string{"structured tool results as authoritative", "Do not invent", "remediation claims"} {
+ if !strings.Contains(prompt, required) {
+ t.Fatalf("bounded Patrol summary prompt missing %q: %s", required, prompt)
+ }
+ }
+ if len(prompt) >= 500 {
+ t.Fatalf("bounded Patrol summary prompt unexpectedly large: %d bytes", len(prompt))
+ }
+
+ req := providers.ChatRequest{
+ System: "full Patrol detection prompt",
+ Tools: []providers.Tool{{Name: agentcapabilities.PatrolReportFindingToolName}},
+ ToolChoice: &providers.ToolChoice{Type: providers.ToolChoiceRequired},
+ }
+ applyPatrolFindingLifecycleSummaryRequest(&req)
+ if req.System != patrolFindingLifecycleSummarySystemPrompt {
+ t.Fatalf("summary request retained full system prompt: %q", req.System)
+ }
+ if len(req.Tools) != 0 || req.ToolChoice != nil {
+ t.Fatalf("summary request retained tools or tool choice: tools=%d choice=%+v", len(req.Tools), req.ToolChoice)
+ }
+}
+
func TestPruneMessagesForModel_Stateless(t *testing.T) {
prev := StatelessContext
StatelessContext = true