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 qualification artifacts for bounded transcripts

rcourtman728d09769c88
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 6718f863c2..114d909935 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -5637,6 +5637,12 @@ Qualification scoring must keep synthetic Patrol runtime findings on the
Provider/runtime failure remains an unconditional qualification hard failure,
but its synthetic service finding must not be reported as an infrastructure
false positive or matched to scenario ground truth.
+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
+or malformed, report generation must preserve the report, replay diagnostic,
+Markdown, and checksums, mark the run failed, and refuse to present that capture
+as executable deterministic replay.
That same provider-transport boundary owns OpenAI-compatible tool protocol
adaptation. Pulse must keep normal tool selection automatic/model-owned for
OpenAI-compatible providers, including direct DeepSeek paths. Text-only
diff --git a/internal/ai/patrol.go b/internal/ai/patrol.go
index a8f07cdd03..a3188c1844 100644
--- a/internal/ai/patrol.go
+++ b/internal/ai/patrol.go
@@ -403,9 +403,12 @@ func (r *PatrolRunRecord) UnmarshalJSON(data []byte) error {
const MaxPatrolRunHistory = 100
const (
- MaxToolInputSize = 1024 // max chars for tool input in persisted record
- MaxToolOutputSize = 2048 // max chars for tool output in persisted record
- MaxToolCallsPerRun = 100 // max tool calls stored per run (oldest dropped)
+ // Finding reports routinely carry several independently grounded prose fields.
+ // Keep the persisted input bounded, but large enough to preserve the complete
+ // structured call for qualification replay instead of cutting JSON mid-token.
+ MaxToolInputSize = 16 * 1024 // max chars for tool input in persisted record
+ MaxToolOutputSize = 2048 // max chars for tool output in persisted record
+ MaxToolCallsPerRun = 100 // max tool calls stored per run (oldest dropped)
)
// LearningProvider provides learned preferences for patrol context
diff --git a/internal/ai/patrol_ai_additional_test.go b/internal/ai/patrol_ai_additional_test.go
index 7a6538a878..86bf66ae19 100644
--- a/internal/ai/patrol_ai_additional_test.go
+++ b/internal/ai/patrol_ai_additional_test.go
@@ -1,6 +1,7 @@
package ai
import (
+ "encoding/json"
"strings"
"testing"
"time"
@@ -10,6 +11,21 @@ import (
ur "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
)
+func TestPersistedPatrolToolInputKeepsExpectedFindingJSONComplete(t *testing.T) {
+ payload, err := json.Marshal(map[string]string{
+ "description": strings.Repeat("d", 4*1024),
+ "evidence": strings.Repeat("e", 4*1024),
+ "recommendation": strings.Repeat("r", 2*1024),
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ persisted := truncateString(string(payload), MaxToolInputSize)
+ if persisted != string(payload) || !json.Valid([]byte(persisted)) {
+ t.Fatalf("expected finding input (%d bytes) was not preserved as complete JSON", len(payload))
+ }
+}
+
func TestSeedFormattingHelpers(t *testing.T) {
t.Run("formatBytes", func(t *testing.T) {
cases := []struct {
diff --git a/internal/ai/qualification/replay.go b/internal/ai/qualification/replay.go
index d4c9d72635..409aec57a1 100644
--- a/internal/ai/qualification/replay.go
+++ b/internal/ai/qualification/replay.go
@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
+ "strings"
"time"
)
@@ -28,6 +29,8 @@ type ReplayBundle struct {
Exchanges []ToolExchange `json:"tool_exchanges"`
AIAnalysis string `json:"ai_analysis,omitempty"`
Findings []Finding `json:"findings"`
+ Replayable bool `json:"replayable"`
+ ReplayIssues []string `json:"replay_issues,omitempty"`
}
type ToolExchange struct {
@@ -48,12 +51,21 @@ func BuildReplayBundle(report RunReport) (ReplayBundle, error) {
SchemaVersion: ReplaySchemaVersion, CapturedAt: time.Now().UTC(), RunID: report.RunID,
ManifestID: report.Manifest.ID, ManifestDigest: digest, Model: report.Environment.Model,
GroundTruth: report.GroundTruth, AIAnalysis: report.PatrolRun.AIAnalysis,
- Findings: append([]Finding(nil), report.Findings...),
+ Findings: append([]Finding(nil), report.Findings...),
+ Replayable: true,
}
for index, call := range report.PatrolRun.ToolCalls {
input, err := canonicalToolInput(call.Input)
if err != nil {
- return ReplayBundle{}, fmt.Errorf("canonicalize tool call %s input: %w", call.ID, err)
+ bundle.Replayable = false
+ bundle.ReplayIssues = append(bundle.ReplayIssues, fmt.Sprintf("tool call %s input is not complete JSON: %v", call.ID, err))
+ // Preserve the captured bytes as valid JSON so the artifact remains
+ // inspectable and checksumable. It is deliberately not executable replay.
+ opaque, marshalErr := json.Marshal(map[string]string{"captured_raw_input": call.Input})
+ if marshalErr != nil {
+ return ReplayBundle{}, marshalErr
+ }
+ input = string(opaque)
}
bundle.Exchanges = append(bundle.Exchanges, ToolExchange{
Sequence: index + 1, ToolCallID: call.ID, ToolName: call.ToolName,
@@ -100,6 +112,9 @@ func NewReplaySession(bundle ReplayBundle) (*ReplaySession, error) {
if bundle.SchemaVersion != ReplaySchemaVersion {
return nil, fmt.Errorf("unsupported replay schema %q", bundle.SchemaVersion)
}
+ if len(bundle.ReplayIssues) > 0 {
+ return nil, fmt.Errorf("replay capture is incomplete: %s", strings.Join(bundle.ReplayIssues, "; "))
+ }
for index, exchange := range bundle.Exchanges {
if exchange.Sequence != index+1 || exchange.ToolName == "" || exchange.CanonicalInput == "" {
return nil, fmt.Errorf("invalid replay exchange at index %d", index)
diff --git a/internal/ai/qualification/replay_test.go b/internal/ai/qualification/replay_test.go
index 18c00b1a22..d0fcbecf62 100644
--- a/internal/ai/qualification/replay_test.go
+++ b/internal/ai/qualification/replay_test.go
@@ -1,6 +1,9 @@
package qualification
-import "testing"
+import (
+ "strings"
+ "testing"
+)
func TestReplaySessionRequiresExactOrderedCanonicalCalls(t *testing.T) {
report := RunReport{
@@ -36,6 +39,28 @@ func TestReplaySessionRequiresExactOrderedCanonicalCalls(t *testing.T) {
}
}
+func TestBuildReplayBundleMarksMalformedCapturedInputNonReplayable(t *testing.T) {
+ report := RunReport{
+ RunID: "q-truncated-input", Manifest: validTestManifest(),
+ PatrolRun: PatrolRun{ToolCalls: []ToolCall{{
+ ID: "truncated", ToolName: "patrol_report_finding", Input: `{"description":"cut...`, Success: true,
+ }}},
+ }
+ bundle, err := BuildReplayBundle(report)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if bundle.Replayable || len(bundle.ReplayIssues) != 1 {
+ t.Fatalf("malformed capture must be explicit and non-replayable: %+v", bundle)
+ }
+ if !strings.Contains(bundle.Exchanges[0].CanonicalInput, "captured_raw_input") {
+ t.Fatalf("opaque captured bytes not preserved: %+v", bundle.Exchanges[0])
+ }
+ if _, err := NewReplaySession(bundle); err == nil || !strings.Contains(err.Error(), "incomplete") {
+ t.Fatalf("expected deterministic replay rejection, got %v", err)
+ }
+}
+
func TestReplaySessionRejectsMissingCall(t *testing.T) {
session, err := NewReplaySession(ReplayBundle{SchemaVersion: ReplaySchemaVersion, Exchanges: []ToolExchange{{Sequence: 1, ToolName: "get_resource", CanonicalInput: `{}`}}})
if err != nil {
diff --git a/internal/ai/qualification/report.go b/internal/ai/qualification/report.go
index 2fd2143cb2..d2109c2c2f 100644
--- a/internal/ai/qualification/report.go
+++ b/internal/ai/qualification/report.go
@@ -159,14 +159,18 @@ func WriteReport(dir string, report RunReport) error {
if err := os.MkdirAll(dir, 0o700); err != nil {
return err
}
- if err := writeJSONFile(filepath.Join(dir, "ground-truth.json"), report.GroundTruth); err != nil {
+ replay, err := BuildReplayBundle(report)
+ if err != nil {
return err
}
- if err := writeJSONFile(filepath.Join(dir, "report.json"), report); err != nil {
+ if !replay.Replayable {
+ report.Passed = false
+ report.Errors = append(report.Errors, "deterministic replay capture incomplete: "+strings.Join(replay.ReplayIssues, "; "))
+ }
+ if err := writeJSONFile(filepath.Join(dir, "ground-truth.json"), report.GroundTruth); err != nil {
return err
}
- replay, err := BuildReplayBundle(report)
- if err != nil {
+ if err := writeJSONFile(filepath.Join(dir, "report.json"), report); err != nil {
return err
}
if err := writeJSONFile(filepath.Join(dir, "replay.json"), replay); err != nil {
diff --git a/internal/ai/qualification/report_test.go b/internal/ai/qualification/report_test.go
index 8e8b7c0950..6797c33c10 100644
--- a/internal/ai/qualification/report_test.go
+++ b/internal/ai/qualification/report_test.go
@@ -97,6 +97,32 @@ func TestWriteComparisonReportPublishesOnlyQualifiedRecommendation(t *testing.T)
}
}
+func TestWriteReportPreservesArtifactsWhenReplayCaptureIsIncomplete(t *testing.T) {
+ dir := t.TempDir()
+ report := RunReport{
+ SchemaVersion: ReportSchemaVersion, RunID: "q-incomplete-replay", Passed: true,
+ Manifest: validTestManifest(),
+ PatrolRun: PatrolRun{ToolCalls: []ToolCall{{
+ ID: "truncated", ToolName: "patrol_report_finding", Input: `{"description":"cut...`, Success: true,
+ }}},
+ }
+ if err := WriteReport(dir, report); err != nil {
+ t.Fatal(err)
+ }
+ for _, name := range []string{"ground-truth.json", "report.json", "report.md", "replay.json", "SHA256SUMS"} {
+ if _, err := os.Stat(filepath.Join(dir, name)); err != nil {
+ t.Fatalf("missing %s: %v", name, err)
+ }
+ }
+ written, err := LoadReport(filepath.Join(dir, "report.json"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if written.Passed || !strings.Contains(strings.Join(written.Errors, "\n"), "replay capture incomplete") {
+ t.Fatalf("incomplete capture must fail explicitly without losing artifacts: %+v", written)
+ }
+}
+
func TestApplyQualificationGatesRejectsIncomparableRuns(t *testing.T) {
manifest := validTestManifest()
manifest.Repeat.Qualification = 1