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
add verification outcome and capability postcondition substrate
rcourtman006821327f36
diff --git a/internal/agentexec/verifier_postconditions.go b/internal/agentexec/verifier_postconditions.gonew file mode 100644index 0000000000..f1bbc09ac9--- /dev/null+++ b/internal/agentexec/verifier_postconditions.go@@ -0,0 +1,184 @@+package agentexec++import (+ "sort"+ "strings"+ "time"+)++// PostconditionField names the field on the post-write read that must be+// inspected to decide whether the action's intended state landed. Field+// values are exec-language-agnostic strings - the verifier substrate is+// responsible for mapping them to the right provider read.+//+// Closed enum to keep drift detectable in tests; the postcondition map+// below is the only place these are allowed to appear.+type PostconditionField string++const (+ // VM and container status as reported by Proxmox.+ FieldVMStatus PostconditionField = "status"+ FieldContainerStatus PostconditionField = "status"++ // Systemd unit fields read via DBus or systemctl show.+ FieldUnitActiveState PostconditionField = "ActiveState"+ FieldUnitSubState PostconditionField = "SubState"+ FieldUnitActiveEnterTimestamp PostconditionField = "ActiveEnterTimestamp"++ // Docker container fields.+ FieldDockerStatus PostconditionField = "status"+ FieldDockerLastStarted PostconditionField = "last_started"++ // Kubernetes deployment fields.+ FieldDeploymentReadyReplicas PostconditionField = "readyReplicas"+ FieldDeploymentDesiredReplicas PostconditionField = "desiredReplicas"+)++// PostconditionComparator names the comparison the verifier applies between+// the observed value and the expected target. The closed set keeps the wire+// format inspectable instead of pushing free-form expressions into the audit+// trail.+type PostconditionComparator string++const (+ // Equals: observed value must equal Expected (case-insensitive for strings).+ CompareEquals PostconditionComparator = "equals"+ // AfterOrEqual: observed timestamp must be >= action_started_at + offset.+ // Used for the "did the unit actually restart, not just stay up" check.+ CompareAfterOrEqualActionStart PostconditionComparator = "after_or_equal_action_start"+ // EqualsField: observed value must equal another observed field on the+ // same read (e.g. readyReplicas == desiredReplicas).+ CompareEqualsField PostconditionComparator = "equals_field"+)++// PostconditionCheck is one assertion the verifier evaluates against the+// post-write read. A capability's postcondition is the AND of its checks -+// all must hold for the outcome to be VerificationVerified.+type PostconditionCheck struct {+ // Field is the dotted-path or named field on the verification read.+ Field PostconditionField `json:"field"`+ // Comparator names how Expected is interpreted.+ Comparator PostconditionComparator `json:"comparator"`+ // Expected is the literal value (CompareEquals) or the peer field name+ // (CompareEqualsField). Empty for CompareAfterOrEqualActionStart.+ Expected string `json:"expected,omitempty"`+}++// CapabilityPostcondition describes how to verify a single tool capability.+// Window is the maximum wall-clock window the verifier waits for the+// postcondition to be observed; capabilities with no natural settle+// (a single-shot status read) use the default.+type CapabilityPostcondition struct {+ Capability string `json:"capability"`+ VerifyRead string `json:"verifyRead"`+ Window time.Duration `json:"window"`+ Description string `json:"description"`+ Checks []PostconditionCheck `json:"checks"`+}++// defaultVerifyWindow is the per-capability fallback window. The agentexec+// policy carries an operator-tunable verify_window that overrides this; the+// per-capability values here are the substrate's "what is reasonable for+// this surface" hint.+const defaultVerifyWindow = 2 * time.Minute++// CapabilityPostconditions returns the canonical capability -> postcondition+// map for the verifier substrate. The returned map is a copy so callers+// cannot mutate the shared substrate.+//+// Capabilities not present in this map have no automated postcondition and+// will surface as VerificationUnknown on the audit record.+func CapabilityPostconditions() map[string]CapabilityPostcondition {+ out := make(map[string]CapabilityPostcondition, len(capabilityPostconditions))+ for k, v := range capabilityPostconditions {+ copyChecks := make([]PostconditionCheck, len(v.Checks))+ copy(copyChecks, v.Checks)+ v.Checks = copyChecks+ out[k] = v+ }+ return out+}++// LookupCapabilityPostcondition returns the postcondition for the given+// capability name, or false if no postcondition is registered.+func LookupCapabilityPostcondition(capability string) (CapabilityPostcondition, bool) {+ capability = strings.TrimSpace(capability)+ if capability == "" {+ return CapabilityPostcondition{}, false+ }+ p, ok := capabilityPostconditions[capability]+ if !ok {+ return CapabilityPostcondition{}, false+ }+ copyChecks := make([]PostconditionCheck, len(p.Checks))+ copy(copyChecks, p.Checks)+ p.Checks = copyChecks+ return p, true+}++// CapabilityPostconditionNames returns the sorted list of capabilities with+// registered postconditions. Useful for diagnostics and tests that need a+// deterministic order.+func CapabilityPostconditionNames() []string {+ names := make([]string, 0, len(capabilityPostconditions))+ for k := range capabilityPostconditions {+ names = append(names, k)+ }+ sort.Strings(names)+ return names+}++// capabilityPostconditions is the closed registry of postconditions the+// verifier substrate knows how to evaluate. New tool capabilities must add+// an entry here AND a corresponding test in verifier_postconditions_test.go+// so a missing wiring shows up immediately.+var capabilityPostconditions = map[string]CapabilityPostcondition{+ "qm.start": {+ Capability: "qm.start",+ VerifyRead: "qm status <vmid>",+ Window: defaultVerifyWindow,+ Description: "Proxmox VM transitioned to running after start command",+ Checks: []PostconditionCheck{+ {Field: FieldVMStatus, Comparator: CompareEquals, Expected: "running"},+ },+ },+ "pct.start": {+ Capability: "pct.start",+ VerifyRead: "pct status <vmid>",+ Window: defaultVerifyWindow,+ Description: "Proxmox CT transitioned to running after start command",+ Checks: []PostconditionCheck{+ {Field: FieldContainerStatus, Comparator: CompareEquals, Expected: "running"},+ },+ },+ "docker.restart": {+ Capability: "docker.restart",+ VerifyRead: "docker inspect <container>",+ Window: defaultVerifyWindow,+ Description: "Docker container is running and last_started is no earlier than the action start",+ Checks: []PostconditionCheck{+ {Field: FieldDockerStatus, Comparator: CompareEquals, Expected: "running"},+ {Field: FieldDockerLastStarted, Comparator: CompareAfterOrEqualActionStart},+ },+ },+ "systemctl.restart": {+ Capability: "systemctl.restart",+ VerifyRead: "systemctl show <unit>",+ Window: defaultVerifyWindow,+ Description: "Systemd unit is active/running and ActiveEnterTimestamp is no earlier than the action start",+ Checks: []PostconditionCheck{+ {Field: FieldUnitActiveState, Comparator: CompareEquals, Expected: "active"},+ {Field: FieldUnitSubState, Comparator: CompareEquals, Expected: "running"},+ {Field: FieldUnitActiveEnterTimestamp, Comparator: CompareAfterOrEqualActionStart},+ },+ },+ "kubectl.rollout": {+ Capability: "kubectl.rollout",+ VerifyRead: "kubectl get deployment <name> -o json",+ Window: defaultVerifyWindow,+ Description: "Deployment's readyReplicas matches desiredReplicas after the rollout window",+ Checks: []PostconditionCheck{+ {Field: FieldDeploymentReadyReplicas, Comparator: CompareEqualsField, Expected: string(FieldDeploymentDesiredReplicas)},+ },+ },+}diff --git a/internal/agentexec/verifier_postconditions_test.go b/internal/agentexec/verifier_postconditions_test.gonew file mode 100644index 0000000000..24e64ab279--- /dev/null+++ b/internal/agentexec/verifier_postconditions_test.go@@ -0,0 +1,136 @@+package agentexec++import (+ "reflect"+ "sort"+ "strings"+ "testing"+ "time"+)++// TestCapabilityPostconditionsCoversRequiredCapabilities pins the closed set+// of capabilities the verifier substrate must understand. Drift either way+// (missing entry, drift in field/comparator) breaks the verifier contract.+func TestCapabilityPostconditionsCoversRequiredCapabilities(t *testing.T) {+ required := []string{"qm.start", "pct.start", "docker.restart", "systemctl.restart", "kubectl.rollout"}+ sort.Strings(required)+ got := CapabilityPostconditionNames()+ if !reflect.DeepEqual(got, required) {+ t.Fatalf("capability postcondition names = %v, want %v", got, required)+ }+}++// TestCapabilityPostconditionLookupReturnsCopy ensures callers cannot mutate+// the shared substrate by editing the returned slice.+func TestCapabilityPostconditionLookupReturnsCopy(t *testing.T) {+ first, ok := LookupCapabilityPostcondition("qm.start")+ if !ok {+ t.Fatalf("qm.start not registered")+ }+ first.Checks[0].Expected = "definitely-not-running"++ second, _ := LookupCapabilityPostcondition("qm.start")+ if second.Checks[0].Expected != "running" {+ t.Fatalf("mutation leaked into substrate: %q", second.Checks[0].Expected)+ }+}++// TestCapabilityPostconditionEntriesParse exercises every entry's checks so+// missing or unrecognized fields/comparators are caught.+func TestCapabilityPostconditionEntriesParse(t *testing.T) {+ cases := []struct {+ capability string+ minChecks int+ expectFields []PostconditionField+ expectCompare []PostconditionComparator+ expectWindow time.Duration+ mustReferenceCmd string+ }{+ {+ capability: "qm.start",+ minChecks: 1,+ expectFields: []PostconditionField{FieldVMStatus},+ expectCompare: []PostconditionComparator{CompareEquals},+ expectWindow: 2 * time.Minute,+ mustReferenceCmd: "qm status",+ },+ {+ capability: "pct.start",+ minChecks: 1,+ expectFields: []PostconditionField{FieldContainerStatus},+ expectCompare: []PostconditionComparator{CompareEquals},+ expectWindow: 2 * time.Minute,+ mustReferenceCmd: "pct status",+ },+ {+ capability: "docker.restart",+ minChecks: 2,+ expectFields: []PostconditionField{FieldDockerStatus, FieldDockerLastStarted},+ expectCompare: []PostconditionComparator{CompareEquals, CompareAfterOrEqualActionStart},+ expectWindow: 2 * time.Minute,+ mustReferenceCmd: "docker inspect",+ },+ {+ capability: "systemctl.restart",+ minChecks: 3,+ expectFields: []PostconditionField{FieldUnitActiveState, FieldUnitSubState, FieldUnitActiveEnterTimestamp},+ expectCompare: []PostconditionComparator{CompareEquals, CompareEquals, CompareAfterOrEqualActionStart},+ expectWindow: 2 * time.Minute,+ mustReferenceCmd: "systemctl show",+ },+ {+ capability: "kubectl.rollout",+ minChecks: 1,+ expectFields: []PostconditionField{FieldDeploymentReadyReplicas},+ expectCompare: []PostconditionComparator{CompareEqualsField},+ expectWindow: 2 * time.Minute,+ mustReferenceCmd: "kubectl get deployment",+ },+ }++ for _, tc := range cases {+ t.Run(tc.capability, func(t *testing.T) {+ entry, ok := LookupCapabilityPostcondition(tc.capability)+ if !ok {+ t.Fatalf("missing postcondition for %q", tc.capability)+ }+ if entry.Capability != tc.capability {+ t.Fatalf("entry.Capability = %q, want %q", entry.Capability, tc.capability)+ }+ if entry.Window != tc.expectWindow {+ t.Fatalf("entry.Window = %v, want %v", entry.Window, tc.expectWindow)+ }+ if !strings.Contains(entry.VerifyRead, tc.mustReferenceCmd) {+ t.Fatalf("VerifyRead = %q, must reference %q", entry.VerifyRead, tc.mustReferenceCmd)+ }+ if entry.Description == "" {+ t.Fatalf("entry.Description is empty")+ }+ if len(entry.Checks) < tc.minChecks {+ t.Fatalf("checks for %q = %d, want at least %d", tc.capability, len(entry.Checks), tc.minChecks)+ }+ for i, want := range tc.expectFields {+ if entry.Checks[i].Field != want {+ t.Fatalf("%s.Checks[%d].Field = %q, want %q", tc.capability, i, entry.Checks[i].Field, want)+ }+ }+ for i, want := range tc.expectCompare {+ if entry.Checks[i].Comparator != want {+ t.Fatalf("%s.Checks[%d].Comparator = %q, want %q", tc.capability, i, entry.Checks[i].Comparator, want)+ }+ }+ })+ }+}++// TestLookupCapabilityPostconditionUnknown verifies the false return path so+// callers can branch into VerificationUnknown rather than seeing a zero-value+// entry that looks valid.+func TestLookupCapabilityPostconditionUnknown(t *testing.T) {+ if _, ok := LookupCapabilityPostcondition("does.not.exist"); ok {+ t.Fatalf("expected unknown capability to return ok=false")+ }+ if _, ok := LookupCapabilityPostcondition(" "); ok {+ t.Fatalf("expected blank capability to return ok=false")+ }+}diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex be850ee934..72f5f837e8 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -12206,7 +12206,10 @@ func TestContract_ActionDecisionJSONSnapshot(t *testing.T) {"outcome":"approved","reason":"inside maintenance window"}- ]+ ],+ "verificationOutcome":{+ "status":"unknown"+ }}},"event":{@@ -12383,6 +12386,9 @@ func TestContract_ActionExecutionJSONSnapshot(t *testing.T) {"result":{"success":true,"output":"restart dispatched"+ },+ "verificationOutcome":{+ "status":"unknown"}}},@@ -12705,6 +12711,9 @@ func TestContract_UnifiedActionAuditsJSONSnapshot(t *testing.T) {Success: true,Output: "done",},+ VerificationOutcome: unifiedresources.VerificationOutcome{+ Status: unifiedresources.VerificationUnknown,+ },},},Count: 1,@@ -12765,6 +12774,9 @@ func TestContract_UnifiedActionAuditsJSONSnapshot(t *testing.T) {"result":{"success":true,"output":"done"+ },+ "verificationOutcome":{+ "status":"unknown"}}],diff --git a/internal/unifiedresources/actions.go b/internal/unifiedresources/actions.goindex 82b1b02a70..1e26534f00 100644--- a/internal/unifiedresources/actions.go+++ b/internal/unifiedresources/actions.go@@ -117,16 +117,71 @@ type ActionVerificationResult struct {Note string `json:"note,omitempty"`}+// VerificationStatus classifies the post-execution read-after-write outcome+// for an action.+//+// The progression is read as: did Pulse confirm the intended state after the+// write?+// - VerificationUnknown: no verification has been attempted yet, or the+// record predates the verifier substrate. Default for older audits on+// read so the contract surface stays additive.+// - VerificationVerified: a postcondition was evaluated and matched.+// - VerificationUnverified: a postcondition was attempted but could not+// conclude (e.g. agent unreachable inside the window). Distinct from+// failure so operators are not misled into thinking the action broke.+// - VerificationFailed: a postcondition was evaluated and did not+// match - the write claims to have succeeded but the world disagrees.+type VerificationStatus string++const (+ VerificationUnknown VerificationStatus = "unknown"+ VerificationVerified VerificationStatus = "verified"+ VerificationUnverified VerificationStatus = "unverified"+ VerificationFailed VerificationStatus = "failed"+)++// VerificationOutcome is the durable verification projection persisted on+// the action audit record. EvidenceSummary carries an optional one-line+// human-readable note about what evidence (or its absence) drove the+// status - e.g. "systemctl ActiveState=active observed within 12s".+type VerificationOutcome struct {+ Status VerificationStatus `json:"status"`+ EvidenceSummary string `json:"evidenceSummary,omitempty"`+}++// IsValidVerificationStatus reports whether the given status is one of the+// closed enum values.+func IsValidVerificationStatus(status VerificationStatus) bool {+ switch status {+ case VerificationUnknown, VerificationVerified, VerificationUnverified, VerificationFailed:+ return true+ default:+ return false+ }+}++// NormalizeVerificationOutcome coerces empty or unrecognized statuses to+// VerificationUnknown so older audit records read without breaking the+// closed enum contract, and trims EvidenceSummary.+func NormalizeVerificationOutcome(outcome VerificationOutcome) VerificationOutcome {+ outcome.EvidenceSummary = strings.TrimSpace(outcome.EvidenceSummary)+ if outcome.Status == "" || !IsValidVerificationStatus(outcome.Status) {+ outcome.Status = VerificationUnknown+ }+ return outcome+}+// ActionAuditRecord tracks the full end-to-end lifecycle of a tool invocation.type ActionAuditRecord struct {- ID string `json:"id"`- CreatedAt time.Time `json:"createdAt"`- UpdatedAt time.Time `json:"updatedAt"`- State ActionState `json:"state"`- Request ActionRequest `json:"request"`- Plan ActionPlan `json:"plan"`- Approvals []ActionApprovalRecord `json:"approvals,omitempty"`- Result *ExecutionResult `json:"result,omitempty"`+ ID string `json:"id"`+ CreatedAt time.Time `json:"createdAt"`+ UpdatedAt time.Time `json:"updatedAt"`+ State ActionState `json:"state"`+ Request ActionRequest `json:"request"`+ Plan ActionPlan `json:"plan"`+ Approvals []ActionApprovalRecord `json:"approvals,omitempty"`+ Result *ExecutionResult `json:"result,omitempty"`+ VerificationOutcome VerificationOutcome `json:"verificationOutcome"`}// ActionLifecycleEvent represents an append-only state transition in an action's life.@@ -434,6 +489,7 @@ func NormalizeActionAuditRecord(record ActionAuditRecord) (ActionAuditRecord, er}}record.Plan.Preflight = NormalizeActionPreflight(record.Plan.Preflight, record.Request, record.Plan)+ record.VerificationOutcome = NormalizeVerificationOutcome(record.VerificationOutcome)for i := range record.Approvals {record.Approvals[i].Actor = strings.TrimSpace(record.Approvals[i].Actor)diff --git a/internal/unifiedresources/audit_redaction.go b/internal/unifiedresources/audit_redaction.goindex c437d1d622..ebca1b5ec2 100644--- a/internal/unifiedresources/audit_redaction.go+++ b/internal/unifiedresources/audit_redaction.go@@ -89,5 +89,6 @@ func RedactAuditRecord(record ActionAuditRecord) ActionAuditRecord {redacted.ErrorMessage = RedactAuditText(redacted.ErrorMessage)record.Result = &redacted}+ record.VerificationOutcome.EvidenceSummary = RedactAuditText(record.VerificationOutcome.EvidenceSummary)return record}diff --git a/internal/unifiedresources/store.go b/internal/unifiedresources/store.goindex 9011036191..9a28b4aa4d 100644--- a/internal/unifiedresources/store.go+++ b/internal/unifiedresources/store.go@@ -346,7 +346,8 @@ func (s *SQLiteResourceStore) initSchema() error {request_json TEXT NOT NULL,plan_json TEXT NOT NULL,approvals_json TEXT,- result_json TEXT+ result_json TEXT,+ verification_outcome_json TEXT NOT NULL DEFAULT '');CREATE INDEX IF NOT EXISTS idx_action_audits_canonical_created ON action_audits(canonical_id, created_at DESC);CREATE INDEX IF NOT EXISTS idx_action_audits_action_id ON action_audits(action_id);@@ -429,6 +430,27 @@ func (s *SQLiteResourceStore) initSchema() error {if err := s.ensureResourceChangesIndexes(); err != nil {return err}+ if err := s.migrateActionAuditsSchema(); err != nil {+ return err+ }+ return nil+}++// migrateActionAuditsSchema adds the verification_outcome_json column to+// older action_audits tables so the VerificationOutcome field on+// ActionAuditRecord persists across restarts. Records written before the+// migration read back with the default unknown status via the normalizer.+func (s *SQLiteResourceStore) migrateActionAuditsSchema() error {+ columns, err := s.tableColumns("action_audits")+ if err != nil {+ return err+ }+ if _, ok := columns["verification_outcome_json"]; ok {+ return nil+ }+ if _, err := s.db.Exec("ALTER TABLE action_audits ADD COLUMN verification_outcome_json TEXT NOT NULL DEFAULT ''"); err != nil {+ return fmt.Errorf("add action_audits.verification_outcome_json column: %w", err)+ }return nil}@@ -990,10 +1012,14 @@ func recordActionAuditSQL(exec sqlExecutor, record ActionAuditRecord) error {if err != nil {return fmt.Errorf("marshal action result: %w", err)}+ verificationOutcomeJSON, err := json.Marshal(record.VerificationOutcome)+ if err != nil {+ return fmt.Errorf("marshal verification outcome: %w", err)+ }_, err = exec.Exec(`- INSERT INTO action_audits (id, action_id, canonical_id, request_id, created_at, updated_at, state, request_json, plan_json, approvals_json, result_json)- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)+ INSERT INTO action_audits (id, action_id, canonical_id, request_id, created_at, updated_at, state, request_json, plan_json, approvals_json, result_json, verification_outcome_json)+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)ON CONFLICT(id) DO UPDATE SETaction_id=excluded.action_id,canonical_id=excluded.canonical_id,@@ -1004,8 +1030,9 @@ func recordActionAuditSQL(exec sqlExecutor, record ActionAuditRecord) error {request_json=excluded.request_json,plan_json=excluded.plan_json,approvals_json=excluded.approvals_json,- result_json=excluded.result_json- `, record.ID, record.ID, CanonicalResourceID(record.Request.ResourceID), record.Request.RequestID, record.CreatedAt, record.UpdatedAt, string(record.State), string(requestJSON), string(planJSON), string(approvalsJSON), string(resultJSON))+ result_json=excluded.result_json,+ verification_outcome_json=excluded.verification_outcome_json+ `, record.ID, record.ID, CanonicalResourceID(record.Request.ResourceID), record.Request.RequestID, record.CreatedAt, record.UpdatedAt, string(record.State), string(requestJSON), string(planJSON), string(approvalsJSON), string(resultJSON), string(verificationOutcomeJSON))if err != nil {return fmt.Errorf("insert action audit: %w", err)}@@ -1037,8 +1064,8 @@ func scanActionAuditRecord(scanner actionAuditScanner) (ActionAuditRecord, errorvar record ActionAuditRecordvar stateStr stringvar actionID, requestID string- var requestJSON, planJSON, approvalsJSON, resultJSON sql.NullString- if err := scanner.Scan(&record.ID, &actionID, &requestID, &record.CreatedAt, &record.UpdatedAt, &stateStr, &requestJSON, &planJSON, &approvalsJSON, &resultJSON); err != nil {+ var requestJSON, planJSON, approvalsJSON, resultJSON, verificationOutcomeJSON sql.NullString+ if err := scanner.Scan(&record.ID, &actionID, &requestID, &record.CreatedAt, &record.UpdatedAt, &stateStr, &requestJSON, &planJSON, &approvalsJSON, &resultJSON, &verificationOutcomeJSON); err != nil {return ActionAuditRecord{}, err}@@ -1065,6 +1092,14 @@ func scanActionAuditRecord(scanner actionAuditScanner) (ActionAuditRecord, error}record.Result = &result}+ if verificationOutcomeJSON.Valid && verificationOutcomeJSON.String != "" && verificationOutcomeJSON.String != "null" {+ var outcome VerificationOutcome+ if err := json.Unmarshal([]byte(verificationOutcomeJSON.String), &outcome); err != nil {+ return ActionAuditRecord{}, fmt.Errorf("unmarshal verification outcome: %w", err)+ }+ record.VerificationOutcome = outcome+ }+ record.VerificationOutcome = NormalizeVerificationOutcome(record.VerificationOutcome)record.Request.RequestID = requestIDrecord.Request.ResourceID = CanonicalResourceID(record.Request.ResourceID)_ = actionID@@ -1077,7 +1112,7 @@ func (s *SQLiteResourceStore) GetActionAudit(actionID string) (ActionAuditRecordfunc (s *SQLiteResourceStore) GetActionAudits(canonicalID string, since time.Time, limit int) ([]ActionAuditRecord, error) {query := `- SELECT id, action_id, request_id, created_at, updated_at, state, request_json, plan_json, approvals_json, result_json+ SELECT id, action_id, request_id, created_at, updated_at, state, request_json, plan_json, approvals_json, result_json, verification_outcome_jsonFROM action_audits`args := []any{}@@ -1300,7 +1335,7 @@ func (s *SQLiteResourceStore) getActionAudit(actionID string) (ActionAuditRecordreturn ActionAuditRecord{}, false, nil}row := s.db.QueryRow(`- SELECT id, action_id, request_id, created_at, updated_at, state, request_json, plan_json, approvals_json, result_json+ SELECT id, action_id, request_id, created_at, updated_at, state, request_json, plan_json, approvals_json, result_json, verification_outcome_jsonFROM action_auditsWHERE id = ?`, actionID)diff --git a/internal/unifiedresources/verification_outcome_test.go b/internal/unifiedresources/verification_outcome_test.gonew file mode 100644index 0000000000..556688461d--- /dev/null+++ b/internal/unifiedresources/verification_outcome_test.go@@ -0,0 +1,128 @@+package unifiedresources++import (+ "encoding/json"+ "strings"+ "testing"+ "time"+)++func TestNormalizeVerificationOutcomeDefaultsToUnknown(t *testing.T) {+ out := NormalizeVerificationOutcome(VerificationOutcome{})+ if out.Status != VerificationUnknown {+ t.Fatalf("empty status normalized to %q, want %q", out.Status, VerificationUnknown)+ }+ out = NormalizeVerificationOutcome(VerificationOutcome{Status: VerificationStatus("garbage"), EvidenceSummary: " trimmed me "})+ if out.Status != VerificationUnknown {+ t.Fatalf("invalid status not coerced to unknown: %q", out.Status)+ }+ if out.EvidenceSummary != "trimmed me" {+ t.Fatalf("evidence summary not trimmed: %q", out.EvidenceSummary)+ }+}++func TestNormalizeVerificationOutcomeAcceptsClosedEnum(t *testing.T) {+ for _, status := range []VerificationStatus{VerificationUnknown, VerificationVerified, VerificationUnverified, VerificationFailed} {+ out := NormalizeVerificationOutcome(VerificationOutcome{Status: status, EvidenceSummary: "ok"})+ if out.Status != status {+ t.Fatalf("status %q normalized to %q", status, out.Status)+ }+ }+}++func TestNormalizeActionAuditRecordDefaultsVerificationOutcomeToUnknown(t *testing.T) {+ now := time.Date(2026, 5, 4, 12, 0, 0, 0, time.UTC)+ record, err := NormalizeActionAuditRecord(ActionAuditRecord{+ ID: "act_verify",+ CreatedAt: now,+ State: ActionStateExecuting,+ Request: ActionRequest{+ ResourceID: "vm:42",+ CapabilityName: "qm.start",+ RequestedBy: "agent:test",+ },+ })+ if err != nil {+ t.Fatalf("NormalizeActionAuditRecord: %v", err)+ }+ if record.VerificationOutcome.Status != VerificationUnknown {+ t.Fatalf("verification status = %q, want %q", record.VerificationOutcome.Status, VerificationUnknown)+ }+}++// TestActionAuditRecordJSONRoundtripWithMissingVerificationOutcome simulates an+// older record persisted before the verifier substrate was added: the JSON+// blob omits the verificationOutcome field. After unmarshal + normalize, the+// status must read as unknown so the closed enum holds for older audits.+func TestActionAuditRecordJSONRoundtripWithMissingVerificationOutcome(t *testing.T) {+ raw := []byte(`{+ "id": "act_legacy",+ "createdAt": "2026-04-01T00:00:00Z",+ "updatedAt": "2026-04-01T00:00:00Z",+ "state": "completed",+ "request": {+ "requestId": "req-legacy",+ "resourceId": "vm:42",+ "capabilityName": "restart",+ "requestedBy": "agent:legacy"+ },+ "plan": {+ "actionId": "act_legacy",+ "requestId": "req-legacy",+ "allowed": true,+ "plannedAt": "2026-04-01T00:00:00Z",+ "expiresAt": "2026-04-01T00:05:00Z"+ }+ }`)+ var record ActionAuditRecord+ if err := json.Unmarshal(raw, &record); err != nil {+ t.Fatalf("unmarshal legacy record: %v", err)+ }+ normalized, err := NormalizeActionAuditRecord(record)+ if err != nil {+ t.Fatalf("normalize legacy record: %v", err)+ }+ if normalized.VerificationOutcome.Status != VerificationUnknown {+ t.Fatalf("legacy record verification status = %q, want %q", normalized.VerificationOutcome.Status, VerificationUnknown)+ }++ encoded, err := json.Marshal(normalized)+ if err != nil {+ t.Fatalf("marshal normalized record: %v", err)+ }+ if !strings.Contains(string(encoded), `"verificationOutcome":{"status":"unknown"}`) {+ t.Fatalf("verificationOutcome should serialize with the default status; got %s", encoded)+ }+}++func TestActionAuditRecordRedactionPreservesVerificationOutcome(t *testing.T) {+ rec := ActionAuditRecord{+ ID: "act_redact",+ CreatedAt: time.Now().UTC(),+ State: ActionStateCompleted,+ Request: ActionRequest{+ RequestID: "req-redact",+ ResourceID: "vm:42",+ CapabilityName: "qm.start",+ RequestedBy: "agent:test",+ Reason: "restart for upgrade",+ },+ Plan: ActionPlan{+ ActionID: "act_redact",+ RequestID: "req-redact",+ Allowed: true,+ PlannedAt: time.Now().UTC(),+ },+ VerificationOutcome: VerificationOutcome{+ Status: VerificationVerified,+ EvidenceSummary: "vm:42 status=running observed in 8s",+ },+ }+ out := RedactAuditRecord(rec)+ if out.VerificationOutcome.Status != VerificationVerified {+ t.Fatalf("redaction dropped status: %#v", out.VerificationOutcome)+ }+ if out.VerificationOutcome.EvidenceSummary == "" {+ t.Fatalf("redaction nuked evidence summary even when no secret present")+ }+}