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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
A.1: close the proposal-channel contract breaks before Commit B
rcourtman956f5749d6a9
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex f9b26c3456..5c1207f9ce 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -4683,11 +4683,28 @@ canonical exposure projector(`RedactToolCallArgumentsForExposure`) redacts them from the durablechat transcript and every tool_start/tool_progress/tool_end streamevent, while the action audit remains their canonical durable home.+Proposal validation reuses the planner's canonical exported rules+(`actionplanner.FindCapability` exact-name matching and+`actionplanner.ValidateParams` for declared/required/typed/enum/pattern+parameters and malformed schemas), so proposal acceptance and planning+can never drift; the sensitive-parameter rejection stays a+proposal-specific ratchet on top. Captured proposals are immutable:+params and evidence identity are deep-cloned on capture and again on+outcome, and fingerprint serialization failures are errors, never a+shared sentinel value. Provider-streamed RawInput overrides on progress+events are discarded for exposure-restricted tools - the override is+unredacted model output and would reintroduce exactly what the+projector removed. An investigation run refuses to start without+finding and investigation identity, and any run error nils the+proposal while preserving simultaneous proposal errors via errors.Join:+a non-nil proposal exists only from a completely successful run.Proofs: `internal/ai/tools/proposal_capture_test.go` (concurrentambiguity with nil proposal, replay/integrity semantics by tool-use ID,failed-attempts typed error, sensitive rejection without echo,-profile-only projection and execution) and the end-to-end loop-redaction proof in `internal/ai/chat/service_tooling_test.go`. A blocked question call is persisted to+profile-only projection and execution, caller-mutation immunity,+exact-name matching, canonical planner validation) and the end-to-end+loop redaction and progress-override proofs in+`internal/ai/chat/service_tooling_test.go`. A blocked question call is persisted tothe durable transcript paired with its refusal result (the assistantmessage records the call, so the transcript must never retain anunanswered call). Profile proofs live indiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 21cabcfecb..21ed6a8a88 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -1870,8 +1870,14 @@ a new API state machine, queue contract, or verification-accounting field.the model supplying only resource/capability/params/reason and allcorrelation identity injected from trusted orchestration context.Proposal parameter values are redacted from durable transcripts and- stream events by the shared exposure projector; the action audit is- their canonical durable home once the broker plans the proposal.+ stream events by the shared exposure projector (including+ provider-streamed raw-input overrides, which are discarded for+ exposure-restricted tools); the action audit is their canonical+ durable home once the broker plans the proposal. Proposal acceptance+ validates through the planner's exported canonical rules+ (`actionplanner.FindCapability` / `actionplanner.ValidateParams`),+ so a proposal that validates is exactly a proposal the planner will+ accept.Executor-owned live readiness is part of planning, not a UI precheck:after planner validation and before audit persistence, the lifecycleservice must askdiff --git a/internal/actionplanner/planner.go b/internal/actionplanner/planner.goindex f638bf6702..761d51fb58 100644--- a/internal/actionplanner/planner.go+++ b/internal/actionplanner/planner.go@@ -211,6 +211,13 @@ func validateRequest(req unified.ActionRequest) error {return nil}+// FindCapability resolves a capability by its exact (trimmed) name -+// the same matching planning uses, exported so proposal validation and+// planning can never drift on name resolution.+func FindCapability(capabilities []unified.ResourceCapability, name string) (unified.ResourceCapability, bool) {+ return findCapability(capabilities, name)+}+func findCapability(capabilities []unified.ResourceCapability, name string) (unified.ResourceCapability, bool) {name = strings.TrimSpace(name)for _, capability := range capabilities {@@ -221,6 +228,15 @@ func findCapability(capabilities []unified.ResourceCapability, name string) (unireturn unified.ResourceCapability{}, false}+// ValidateParams checks concrete parameter values against a capability's+// declared parameter specs: declared/duplicate/trimmed names, required+// presence with empty-value detection, types, enums, and patterns. It is+// the single canonical validation for both planning and proposal+// acceptance, exported so the two can never drift.+func ValidateParams(params map[string]any, specs []unified.CapabilityParam) error {+ return validateParams(params, specs)+}+func validateParams(params map[string]any, specs []unified.CapabilityParam) error {specByName := make(map[string]unified.CapabilityParam, len(specs))for _, spec := range specs {diff --git a/internal/actionplanner/planner_test.go b/internal/actionplanner/planner_test.goindex 9aba66d4b6..3d595f1d2f 100644--- a/internal/actionplanner/planner_test.go+++ b/internal/actionplanner/planner_test.go@@ -226,3 +226,39 @@ func TestPlannerReturnsCapabilityNotFound(t *testing.T) {t.Fatalf("Plan() error = %v, want ErrCapabilityNotFound", err)}}++func TestExportedValidationMatchesPlanningExactly(t *testing.T) {+ capabilities := []unified.ResourceCapability{{+ Name: "restart",+ Params: []unified.CapabilityParam{+ {Name: "mode", Type: "string", Required: true, Enum: []string{"graceful", "force"}},+ },+ }}++ // FindCapability is the planner's exact-name matcher, exported so+ // proposal acceptance can never drift on resolution.+ if _, ok := FindCapability(capabilities, "restart"); !ok {+ t.Fatal("exact name must resolve")+ }+ if _, ok := FindCapability(capabilities, "Restart"); ok {+ t.Fatal("case-mismatched name must not resolve; planning matches exactly")+ }+ if _, ok := FindCapability(capabilities, " restart "); !ok {+ t.Fatal("trimmed name must resolve like planning")+ }++ // ValidateParams is the canonical parameter validation shared with+ // proposal acceptance.+ if err := ValidateParams(map[string]any{"mode": "graceful"}, capabilities[0].Params); err != nil {+ t.Fatalf("valid params rejected: %v", err)+ }+ if err := ValidateParams(map[string]any{"mode": " "}, capabilities[0].Params); err == nil {+ t.Fatal("whitespace-only required value must fail")+ }+ if err := ValidateParams(map[string]any{"mode": 42}, capabilities[0].Params); err == nil {+ t.Fatal("wrong-typed value must fail")+ }+ if err := ValidateParams(map[string]any{"mode": "graceful", "extra": "x"}, capabilities[0].Params); err == nil {+ t.Fatal("undeclared parameter must fail")+ }+}diff --git a/internal/agentcapabilities/invocation.go b/internal/agentcapabilities/invocation.goindex 71f90dc70a..8e213450ae 100644--- a/internal/agentcapabilities/invocation.go+++ b/internal/agentcapabilities/invocation.go@@ -278,6 +278,14 @@ func ClassifyRegisteredInvocation(toolName string, args map[string]interface{})// durable or user-visible exposure of a patrol_propose_action call.const RedactedProposalParamsMarker = "[redacted-proposal-params]"+// ToolHasRestrictedExposure reports whether a tool's raw arguments are+// exposure-restricted: durable and user-visible surfaces must use only+// the projected form and must never substitute provider-streamed raw+// argument text.+func ToolHasRestrictedExposure(toolName string) bool {+ return strings.TrimSpace(toolName) == PatrolProposeActionToolName+}+// RedactToolCallArgumentsForExposure is the canonical exposure projector// for tool-call arguments: everything durable or user-visible (chat// transcripts, tool_start/tool_progress/tool_end stream events) must routediff --git a/internal/agentcapabilities/invocation_test.go b/internal/agentcapabilities/invocation_test.goindex d1f35b7f7b..a61b59067c 100644--- a/internal/agentcapabilities/invocation_test.go+++ b/internal/agentcapabilities/invocation_test.go@@ -150,3 +150,22 @@ func TestInvocationBlockedResultCoversAllMutationTargets(t *testing.T) {}}}++func TestRestrictedExposureVocabulary(t *testing.T) {+ if !ToolHasRestrictedExposure(PatrolProposeActionToolName) {+ t.Fatal("patrol_propose_action must be exposure-restricted")+ }+ for _, name := range []string{PulseQueryToolName, PulseDockerToolName, PulseReadToolName} {+ if ToolHasRestrictedExposure(name) {+ t.Fatalf("%s must not be exposure-restricted", name)+ }+ }+ // Restricted exposure implies raw provider overrides are discarded;+ // the projected form is the only exposable one.+ projected := RedactToolCallArgumentsForExposure(PatrolProposeActionToolName, map[string]interface{}{+ "params": map[string]interface{}{"token": "secret"},+ })+ if projected["params"] != RedactedProposalParamsMarker {+ t.Fatalf("projector must redact params, got %#v", projected["params"])+ }+}diff --git a/internal/ai/chat/agentic.go b/internal/ai/chat/agentic.goindex 00a49781ac..06e2b50a9c 100644--- a/internal/ai/chat/agentic.go+++ b/internal/ai/chat/agentic.go@@ -261,7 +261,10 @@ func emitToolProgressEventWithRawInput(callback StreamCallback, id, name string,return}inputStr, rawInput := formatToolInputForFrontend(name, input, false)- if rawInputOverride != "" {+ // The provider-streamed raw override is unredacted model output;+ // exposure-restricted tools must never surface it, or the override+ // would reintroduce exactly the values the projector removed.+ if rawInputOverride != "" && !agentcapabilities.ToolHasRestrictedExposure(name) {rawInput = rawInputOverride}jsonData, _ := json.Marshal(ToolProgressData{diff --git a/internal/ai/chat/service_investigation.go b/internal/ai/chat/service_investigation.goindex 025b3135fb..8bcb9f2df1 100644--- a/internal/ai/chat/service_investigation.go+++ b/internal/ai/chat/service_investigation.go@@ -2,6 +2,7 @@ package chatimport ("context"+ "errors""fmt""strings""time"@@ -52,6 +53,13 @@ type InvestigationRunResult struct {// Proposal-channel violations (ambiguity, integrity, failed-only// attempts) return the result alongside the typed proposal error.func (s *Service) ExecuteInvestigationStream(ctx context.Context, req InvestigationRunRequest, callback StreamCallback) (*InvestigationRunResult, error) {+ // Correlation identity is a precondition: without it a captured+ // proposal could never be reconciled, so the run refuses before any+ // provider call or session exists.+ if strings.TrimSpace(req.Identity.FindingID) == "" || strings.TrimSpace(req.Identity.InvestigationID) == "" {+ return nil, fmt.Errorf("investigation run requires finding and investigation identity before it can start")+ }+s.mu.RLock()if !s.started {s.mu.RUnlock()@@ -163,11 +171,12 @@ func (s *Service) ExecuteInvestigationStream(ctx context.Context, req InvestigatInputTokens: loop.GetTotalInputTokens(),OutputTokens: loop.GetTotalOutputTokens(),}- if runErr != nil {- return result, runErr- }- if proposalErr != nil {- return result, proposalErr+ if runErr != nil || proposalErr != nil {+ // A proposal is actionable only from a completely successful+ // run: any error nils it, and simultaneous run/proposal errors+ // are both preserved.+ result.Proposal = nil+ return result, errors.Join(runErr, proposalErr)}return result, nil}diff --git a/internal/ai/chat/service_tooling_test.go b/internal/ai/chat/service_tooling_test.goindex 2e10d85725..884a49049e 100644--- a/internal/ai/chat/service_tooling_test.go+++ b/internal/ai/chat/service_tooling_test.go@@ -1274,3 +1274,54 @@ func TestInvestigationLoopRedactsProposalParamsEverywhereDurable(t *testing.T) {t.Fatalf("captured proposal = %#v", proposal)}}++func TestProposalRawInputOverrideNeverLeaksThroughProgressEvents(t *testing.T) {+ var events []string+ callback := func(event StreamEvent) { events = append(events, string(event.Data)) }++ // Providers stream the accumulating raw tool-call JSON as a+ // RawInput override on progress events; for exposure-restricted+ // tools that override must be discarded, not substituted back in+ // after projection.+ secret := `{"params":{"join_token":"super-secret-value"}}`+ emitToolProgressEventWithRawInput(callback, "p-1",+ agentcapabilities.PatrolProposeActionToolName,+ map[string]interface{}{+ "resource_id": "vm:42",+ "params": map[string]interface{}{"join_token": "super-secret-value"},+ },+ secret, "streaming", "Receiving tool call.")++ if len(events) != 1 {+ t.Fatalf("expected one event, got %d", len(events))+ }+ if strings.Contains(events[0], "super-secret-value") {+ t.Fatalf("progress event leaked raw proposal params: %s", events[0])+ }+ if !strings.Contains(events[0], agentcapabilities.RedactedProposalParamsMarker) {+ t.Fatalf("progress event should carry the projected form, got %s", events[0])+ }++ // Unrestricted tools keep the provider's raw override.+ events = nil+ emitToolProgressEventWithRawInput(callback, "q-1", "pulse_query",+ map[string]interface{}{"action": "health"},+ `{"action":"health","extra":"raw-override"}`, "streaming", "Receiving tool call.")+ if len(events) != 1 {+ t.Fatalf("expected one event, got %d", len(events))+ }+ if !strings.Contains(events[0], "raw-override") {+ t.Fatalf("unrestricted tools should keep the raw override, got %s", events[0])+ }+}++func TestInvestigationRunRequiresIdentityBeforeStarting(t *testing.T) {+ svc := &Service{}+ _, err := svc.ExecuteInvestigationStream(context.Background(), InvestigationRunRequest{+ Prompt: "investigate",+ Identity: tools.ProposalIdentity{FindingID: "f-1"}, // missing investigation ID+ }, func(StreamEvent) {})+ if err == nil || !strings.Contains(err.Error(), "identity") {+ t.Fatalf("expected identity precondition error, got %v", err)+ }+}diff --git a/internal/ai/tools/proposal_capture.go b/internal/ai/tools/proposal_capture.goindex 2a50ab371d..f4cae90501 100644--- a/internal/ai/tools/proposal_capture.go+++ b/internal/ai/tools/proposal_capture.go@@ -7,10 +7,10 @@ import ("encoding/json""errors""fmt"- "sort""strings""sync"+ "github.com/rcourtman/pulse-go-rewrite/internal/actionplanner"unified "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources")@@ -109,13 +109,38 @@ type ProposalCapture struct {failedAttempts int}+func (i ProposalIdentity) clone() ProposalIdentity {+ i.EvidenceIDs = append([]string(nil), i.EvidenceIDs...)+ return i+}+// NewProposalCapture builds the sink with trusted identity and the-// capability catalog used for validation.+// capability catalog used for validation. The identity is deep-cloned so+// later caller-side mutation cannot alter captured correlation.func NewProposalCapture(identity ProposalIdentity, catalog ProposalCatalog) *ProposalCapture {- return &ProposalCapture{identity: identity, catalog: catalog}+ return &ProposalCapture{identity: identity.clone(), catalog: catalog}+}++// cloneParams deep-clones a parameter map via JSON round-trip (the values+// arrived as decoded JSON, so the round-trip is lossless). The sink never+// retains or returns the caller's map: mutation after validation must not+// be able to change the actionable proposal.+func cloneParams(params map[string]interface{}) (map[string]interface{}, error) {+ if params == nil {+ return map[string]interface{}{}, nil+ }+ encoded, err := json.Marshal(params)+ if err != nil {+ return nil, fmt.Errorf("proposal parameters are not serializable")+ }+ clone := map[string]interface{}{}+ if err := json.Unmarshal(encoded, &clone); err != nil {+ return nil, fmt.Errorf("proposal parameters are not serializable")+ }+ return clone, nil}-func proposalFingerprint(resourceID, capabilityName, reason string, params map[string]interface{}) string {+func proposalFingerprint(resourceID, capabilityName, reason string, params map[string]interface{}) (string, error) {payload := struct {ResourceID string `json:"resourceId"`CapabilityName string `json:"capabilityName"`@@ -124,10 +149,10 @@ func proposalFingerprint(resourceID, capabilityName, reason string, params map[s}{resourceID, capabilityName, reason, params}encoded, err := json.Marshal(payload)if err != nil {- return "unfingerprintable"+ return "", fmt.Errorf("proposal payload is not fingerprintable")}sum := sha256.Sum256(encoded)- return hex.EncodeToString(sum[:])+ return hex.EncodeToString(sum[:]), nil}// RecordFailedAttempt tallies a proposal call that failed validation.@@ -156,7 +181,20 @@ func (c *ProposalCapture) Submit(invocationID, resourceID, capabilityName, reasoc.mu.Unlock()return fmt.Errorf("proposal call carries no tool-use id; cannot establish call identity")}- fingerprint := proposalFingerprint(resourceID, capabilityName, reason, params)+ params, cloneErr := cloneParams(params)+ if cloneErr != nil {+ c.mu.Lock()+ c.failedAttempts+++ c.mu.Unlock()+ return cloneErr+ }+ fingerprint, fingerprintErr := proposalFingerprint(resourceID, capabilityName, reason, params)+ if fingerprintErr != nil {+ c.mu.Lock()+ c.failedAttempts+++ c.mu.Unlock()+ return fingerprintErr+ }c.mu.Lock()defer c.mu.Unlock()@@ -170,7 +208,7 @@ func (c *ProposalCapture) Submit(invocationID, resourceID, capabilityName, reasoc.fingerprint = fingerprintc.proposal = &CapturedProposal{InvocationID: invocationID,- Identity: c.identity,+ Identity: c.identity.clone(),ResourceID: resourceID,CapabilityName: capabilityName,Params: params,@@ -207,6 +245,14 @@ func (c *ProposalCapture) Outcome() (*CapturedProposal, int, error) {return nil, c.failedAttempts, ErrProposalIntegritycase proposalCaptureHeld:proposal := *c.proposal+ proposal.Identity = proposal.Identity.clone()+ clonedParams, err := cloneParams(proposal.Params)+ if err != nil {+ // Unreachable in practice (params cloned on capture), but a+ // proposal that cannot be copied must not be actionable.+ return nil, c.failedAttempts, err+ }+ proposal.Params = clonedParamsreturn &proposal, c.failedAttempts, nildefault:if c.failedAttempts > 0 {@@ -228,58 +274,27 @@ func validateProposalAgainstCatalog(ctx context.Context, catalog ProposalCatalogif err != nil {return fmt.Errorf("capability catalog lookup failed for resource %q", resourceID)}- var capability *unified.ResourceCapability- for i := range capabilities {- if strings.EqualFold(strings.TrimSpace(capabilities[i].Name), capabilityName) {- capability = &capabilities[i]- break- }- }- if capability == nil {+ // Exact-name resolution and full parameter validation are the+ // planner's canonical implementations, so proposal acceptance and+ // planning can never drift on matching, types, enums, patterns,+ // required presence, or malformed capability schemas.+ capability, found := actionplanner.FindCapability(capabilities, capabilityName)+ if !found {return fmt.Errorf("resource %q does not advertise capability %q", resourceID, capabilityName)}-- declared := map[string]unified.CapabilityParam{}- for _, param := range capability.Params {- declared[param.Name] = param- }- var missing []string+ // Proposal-specific ratchet on top of planning: investigations must+ // never carry sensitive values (operators supply those at approval+ // time on the canonical surface).for _, param := range capability.Params {- if !param.Required {+ if !param.IsSensitive {continue}- if _, ok := params[param.Name]; !ok {- missing = append(missing, param.Name)+ if value, ok := params[param.Name]; ok && value != nil {+ return fmt.Errorf("parameter %q is sensitive and must be supplied by an operator on the canonical approval surface, never by an investigation", param.Name)}}- sort.Strings(missing)- if len(missing) > 0 {- return fmt.Errorf("proposal is missing required parameter(s) %v for capability %q", missing, capabilityName)- }- for name, value := range params {- param, ok := declared[name]- if !ok {- return fmt.Errorf("parameter %q is not declared by capability %q", name, capabilityName)- }- if param.IsSensitive && value != nil {- return fmt.Errorf("parameter %q is sensitive and must be supplied by an operator on the canonical approval surface, never by an investigation", name)- }- if len(param.Enum) > 0 {- text, isString := value.(string)- if !isString {- return fmt.Errorf("parameter %q must be one of the declared enum values", name)- }- allowed := false- for _, candidate := range param.Enum {- if candidate == text {- allowed = true- break- }- }- if !allowed {- return fmt.Errorf("parameter %q must be one of the declared enum values", name)- }- }+ if err := actionplanner.ValidateParams(params, capability.Params); err != nil {+ return fmt.Errorf("proposal parameters are invalid for capability %q: %s", capabilityName, err.Error())}return nil}diff --git a/internal/ai/tools/proposal_capture_test.go b/internal/ai/tools/proposal_capture_test.goindex b938b4547f..0317bff8c3 100644--- a/internal/ai/tools/proposal_capture_test.go+++ b/internal/ai/tools/proposal_capture_test.go@@ -225,3 +225,70 @@ func TestProposalExposureProjectorRedactsParams(t *testing.T) {t.Fatal("non-proposal tools must not be redacted")}}++func TestCapturedProposalIsImmuneToCallerMutation(t *testing.T) {+ capture := NewProposalCapture(ProposalIdentity{InvestigationID: "inv-1", EvidenceIDs: []string{"ev-1"}}, testProposalCatalog())+ args := proposeArgs()+ params := args["params"].(map[string]interface{})++ require.NoError(t, capture.Submit("call-a", "vm:42", "restart", "recover", params))++ // Mutating the caller's map after validation must not change the+ // actionable proposal (or its fingerprint identity).+ params["mode"] = "force"++ proposal, _, err := capture.Outcome()+ require.NoError(t, err)+ require.NotNil(t, proposal)+ assert.Equal(t, "graceful", proposal.Params["mode"])++ // Mutating the returned copy must not affect a later outcome read.+ proposal.Params["mode"] = "force"+ proposal.Identity.EvidenceIDs[0] = "tampered"+ again, _, err := capture.Outcome()+ require.NoError(t, err)+ assert.Equal(t, "graceful", again.Params["mode"])+ assert.Equal(t, "ev-1", again.Identity.EvidenceIDs[0])+}++func TestProposalCapabilityMatchingIsExactLikePlanning(t *testing.T) {+ capture := NewProposalCapture(ProposalIdentity{}, testProposalCatalog())+ exec := newInvestigationExecutor(t, capture)++ // The catalog advertises "restart"; a case-mismatched proposal must+ // fail exactly as planning would, so acceptance and planning never+ // drift on name resolution.+ args := proposeArgs()+ args["capability_name"] = "Restart"+ result := executePropose(t, exec, "call-a", args)+ assert.Contains(t, result.Content[0].Text, "does not advertise")++ _, failed, err := capture.Outcome()+ assert.Equal(t, 1, failed)+ if !errors.Is(err, ErrProposalAttemptsFailed) {+ t.Fatalf("outcome error = %v, want ErrProposalAttemptsFailed", err)+ }+}++func TestProposalValidationUsesCanonicalPlannerRules(t *testing.T) {+ capture := NewProposalCapture(ProposalIdentity{}, testProposalCatalog())+ exec := newInvestigationExecutor(t, capture)++ // Empty required value: planner treats whitespace as missing.+ args := proposeArgs()+ args["params"] = map[string]interface{}{"mode": " "}+ result := executePropose(t, exec, "call-a", args)+ assert.Contains(t, result.Content[0].Text, "invalid for capability")++ // Wrong type for an enum string parameter.+ args = proposeArgs()+ args["params"] = map[string]interface{}{"mode": 42}+ result = executePropose(t, exec, "call-b", args)+ assert.Contains(t, result.Content[0].Text, "invalid for capability")++ _, failed, err := capture.Outcome()+ assert.Equal(t, 2, failed)+ if !errors.Is(err, ErrProposalAttemptsFailed) {+ t.Fatalf("outcome error = %v, want ErrProposalAttemptsFailed", err)+ }+}