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.

Close the 2b residuals on the typed Patrol proposal seam

rcourtman94ccc7a0c202
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index a09089dac1..b05119a725 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -351,7 +351,8 @@ implicit command execution or define a parallel execution handoff. The
Patrol proposal broker (`internal/api/patrol_action_broker.go`) rides that
same API-owned lifecycle; agent lifecycle surfaces must not consume
Patrol-origin action audits as an agent command grant or lifecycle
-execution shortcut. Assistant
+execution shortcut, and must not subscribe lifecycle side effects to the
+API-owned org-scoped action-transition hook. Assistant
handoffs that recover a live Patrol approval by finding ID are still AI/runtime
review context only; agent lifecycle surfaces must not treat that recovered
approval reference as an agent command grant or host-execution shortcut.
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 4c6b1b55bf..bc340ec62d 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -280,11 +280,12 @@ call when building tool-result turns.
35. `internal/api/ai_handler.go` shared with `api-contracts`: Pulse Assistant handlers are both an AI runtime control surface and a canonical API payload contract boundary.
36. `internal/api/ai_handlers.go` shared with `api-contracts`: AI settings and remediation handlers are both an AI runtime control surface and a canonical API payload contract boundary.
37. `internal/api/ai_intelligence_handlers.go` shared with `api-contracts`: AI intelligence handlers are both an AI runtime control surface and a canonical API payload contract boundary.
-38. `pkg/aicontracts/fix_execution.go` shared with `api-contracts`: the public approved-fix execution contract is both an AI runtime approved-action boundary and a canonical API dependency contract for Patrol and enterprise auto-fix binders.
-39. `pkg/aicontracts/investigation.go` shared with `api-contracts`: the public Patrol investigation record and finding contract is both an AI runtime handoff boundary and a canonical API payload contract for Patrol, Assistant, unified findings, persistence, and audit surfaces.
-40. `pkg/aicontracts/orchestrator_deps.go` shared with `api-contracts`: the public investigation orchestrator dependency contract is both an AI runtime handoff boundary and a canonical API payload contract for Assistant and Patrol tool-call history.
-41. `pkg/extensions/ai_autofix.go` shared with `api-contracts`: the enterprise auto-fix extension dependency seam is both an AI runtime approved-action boundary and a canonical API extension contract over Assistant and Patrol execution dependencies.
-42. `scripts/generate-pulse-intelligence-docs.go` shared with `api-contracts`: the Pulse Intelligence manifest docs generator is both an AI runtime docs/onboarding projection and a canonical API contract projection over the agent capabilities manifest and Pulse MCP surface tool contract.
+38. `pkg/aicontracts/action_broker.go` shared with `api-contracts`: the public typed action-proposal broker contract is both an AI runtime proposal boundary (the only sanctioned Patrol route to an infrastructure mutation) and a canonical API dependency contract over the shared action lifecycle service.
+39. `pkg/aicontracts/fix_execution.go` shared with `api-contracts`: the public approved-fix execution contract is both an AI runtime approved-action boundary and a canonical API dependency contract for Patrol and enterprise auto-fix binders.
+40. `pkg/aicontracts/investigation.go` shared with `api-contracts`: the public Patrol investigation record and finding contract is both an AI runtime handoff boundary and a canonical API payload contract for Patrol, Assistant, unified findings, persistence, and audit surfaces.
+41. `pkg/aicontracts/orchestrator_deps.go` shared with `api-contracts`: the public investigation orchestrator dependency contract is both an AI runtime handoff boundary and a canonical API payload contract for Assistant and Patrol tool-call history.
+42. `pkg/extensions/ai_autofix.go` shared with `api-contracts`: the enterprise auto-fix extension dependency seam is both an AI runtime approved-action boundary and a canonical API extension contract over Assistant and Patrol execution dependencies.
+43. `scripts/generate-pulse-intelligence-docs.go` shared with `api-contracts`: the Pulse Intelligence manifest docs generator is both an AI runtime docs/onboarding projection and a canonical API contract projection over the agent capabilities manifest and Pulse MCP surface tool contract.
The shared agent-capabilities manifest also owns the runtime surface contract:
the manifest wire type and generated frontend projection must name Pulse
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 6632368162..e1f9118fa8 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -1587,6 +1587,7 @@ payload shape change when the portal presents compact client rows.
target, so installer preflight failures point operators at the artifact
they actually need.
84. `internal/api/updates.go` shared with `deployment-installability`: update handlers are both a deployment-installability control surface and a canonical API payload contract boundary.
+85. `pkg/aicontracts/action_broker.go` shared with `ai-runtime`: the public typed action-proposal broker contract is both an AI runtime proposal boundary (the only sanctioned Patrol route to an infrastructure mutation) and a canonical API dependency contract over the shared action lifecycle service.
The updater registry behind `GET /api/updates/plan` is a plan-provider
seam only (`SupportsApply`, `PrepareUpdate`, `GetDeploymentType`); apply
and rollback semantics ride the manager pipeline behind
@@ -1603,11 +1604,11 @@ payload shape change when the portal presents compact client rows.
and answers with the same started-acknowledgement shape as apply;
conflict responses cover pruned or missing backups and Docker
deployments, and not-found covers unknown history entries.
-85. `pkg/aicontracts/fix_execution.go` shared with `ai-runtime`: the public approved-fix execution contract is both an AI runtime approved-action boundary and a canonical API dependency contract for Patrol and enterprise auto-fix binders.
-86. `pkg/aicontracts/investigation.go` shared with `ai-runtime`: the public Patrol investigation record and finding contract is both an AI runtime handoff boundary and a canonical API payload contract for Patrol, Assistant, unified findings, persistence, and audit surfaces.
-87. `pkg/aicontracts/orchestrator_deps.go` shared with `ai-runtime`: the public investigation orchestrator dependency contract is both an AI runtime handoff boundary and a canonical API payload contract for Assistant and Patrol tool-call history.
-88. `pkg/extensions/ai_autofix.go` shared with `ai-runtime`: the enterprise auto-fix extension dependency seam is both an AI runtime approved-action boundary and a canonical API extension contract over Assistant and Patrol execution dependencies.
-89. `scripts/generate-pulse-intelligence-docs.go` shared with `ai-runtime`: the Pulse Intelligence manifest docs generator is both an AI runtime docs/onboarding projection and a canonical API contract projection over the agent capabilities manifest and Pulse MCP surface tool contract.
+86. `pkg/aicontracts/fix_execution.go` shared with `ai-runtime`: the public approved-fix execution contract is both an AI runtime approved-action boundary and a canonical API dependency contract for Patrol and enterprise auto-fix binders.
+87. `pkg/aicontracts/investigation.go` shared with `ai-runtime`: the public Patrol investigation record and finding contract is both an AI runtime handoff boundary and a canonical API payload contract for Patrol, Assistant, unified findings, persistence, and audit surfaces.
+88. `pkg/aicontracts/orchestrator_deps.go` shared with `ai-runtime`: the public investigation orchestrator dependency contract is both an AI runtime handoff boundary and a canonical API payload contract for Assistant and Patrol tool-call history.
+89. `pkg/extensions/ai_autofix.go` shared with `ai-runtime`: the enterprise auto-fix extension dependency seam is both an AI runtime approved-action boundary and a canonical API extension contract over Assistant and Patrol execution dependencies.
+90. `scripts/generate-pulse-intelligence-docs.go` shared with `ai-runtime`: the Pulse Intelligence manifest docs generator is both an AI runtime docs/onboarding projection and a canonical API contract projection over the agent capabilities manifest and Pulse MCP surface tool contract.
Update-plan responses own the structured readiness verdict for server
updater capability, rollback support, agent continuity, v5 agent migration
transport security, and agent reporting token scope. That verdict is part
@@ -1844,10 +1845,16 @@ a new API state machine, queue contract, or verification-accounting field.
so secret material never enters model output, investigation stores, or
action audit records. Capability inspection for proposals goes through
`Service.Capabilities`, which shares planning's registry resolution and
- typed errors. The service also exposes an additive `OnActionTransition`
- persisted-state callback (plan, decision, and terminal execution
+ typed errors. The service also exposes an additive, org-scoped
+ `OnActionTransition` persisted-state callback
+ (`func(orgID, record)`; plan, decision, and terminal execution
transitions, published only after the corresponding store write
- succeeds) so proposing surfaces can reconcile decisions and outcomes.
+ succeeds), wired through
+ `ResourceHandlers.SetActionTransitionPublisher`, so proposing surfaces
+ can reconcile decisions and outcomes onto the correct tenant. A
+ Patrol proposal must carry both its finding and investigation IDs
+ before anything persists; identity-less proposals are refused so a
+ governed action can never lose deterministic correlation.
Plan-only proof: `TestContract_PatrolActionBrokerIsPlanOnly` in
`internal/api/contract_test.go`.
Executor-owned live readiness is part of planning, not a UI precheck:
diff --git a/docs/release-control/v6/internal/subsystems/registry.json b/docs/release-control/v6/internal/subsystems/registry.json
index 4c0630c36a..fbe6380b5c 100644
--- a/docs/release-control/v6/internal/subsystems/registry.json
+++ b/docs/release-control/v6/internal/subsystems/registry.json
@@ -956,6 +956,14 @@
"storage-recovery"
]
},
+ {
+ "path": "pkg/aicontracts/action_broker.go",
+ "rationale": "the public typed action-proposal broker contract is both an AI runtime proposal boundary (the only sanctioned Patrol route to an infrastructure mutation) and a canonical API dependency contract over the shared action lifecycle service",
+ "subsystems": [
+ "ai-runtime",
+ "api-contracts"
+ ]
+ },
{
"path": "pkg/aicontracts/fix_execution.go",
"rationale": "the public approved-fix execution contract is both an AI runtime approved-action boundary and a canonical API dependency contract for Patrol and enterprise auto-fix binders",
@@ -1481,6 +1489,7 @@
"internal/api/ai_handlers.go",
"internal/api/ai_intelligence_handlers.go",
"internal/config/ai.go",
+ "pkg/aicontracts/action_broker.go",
"pkg/aicontracts/fix_execution.go",
"pkg/aicontracts/investigation.go",
"pkg/aicontracts/orchestrator_deps.go",
@@ -1724,6 +1733,19 @@
"exact_files": [
"scripts/release_control/ai_runtime_docs_policy_test.py"
]
+ },
+ {
+ "id": "ai-action-proposal-broker-contract",
+ "label": "AI action proposal broker contract proof",
+ "match_prefixes": [],
+ "match_files": [
+ "pkg/aicontracts/action_broker.go"
+ ],
+ "allow_same_subsystem_tests": false,
+ "test_prefixes": [],
+ "exact_files": [
+ "pkg/aicontracts/contracts_test.go"
+ ]
}
],
"match_files": null
@@ -2057,6 +2079,7 @@
"frontend-modern/src/utils/infrastructureSettingsPresentation.ts",
"internal/api/setup_script_render.go",
"internal/websocket/hub.go",
+ "pkg/aicontracts/action_broker.go",
"pkg/aicontracts/fix_execution.go",
"pkg/aicontracts/investigation.go",
"pkg/aicontracts/orchestrator_deps.go",
@@ -2557,6 +2580,19 @@
"internal/api/actions_test.go",
"internal/api/contract_test.go"
]
+ },
+ {
+ "id": "ai-action-proposal-broker-contract",
+ "label": "AI action proposal broker API contract proof",
+ "match_prefixes": [],
+ "match_files": [
+ "pkg/aicontracts/action_broker.go"
+ ],
+ "allow_same_subsystem_tests": false,
+ "test_prefixes": [],
+ "exact_files": [
+ "pkg/aicontracts/contracts_test.go"
+ ]
}
],
"match_files": null
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 94051df422..52732f465c 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -316,7 +316,8 @@ stale-plan hash, blast-radius model, or execution protocol outside
(`internal/api/patrol_action_broker.go`) is part of that same API-owned
boundary: storage/recovery surfaces must not treat Patrol-proposed action
audits (origin surface `patrol`) as a storage-local execution channel or
-mint their own proposal origins.
+mint their own proposal origins, and they must not subscribe storage-local
+side effects to the API-owned org-scoped action-transition hook.
Storage/recovery surfaces may consume unified-resource `platformScopes` as
read-only platform membership context, but they must not reinterpret runtime
scope overlap as storage or recovery ownership. A Docker workload that also
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 7cd8debf54..4598038540 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -1332,6 +1332,12 @@ AI-only summary payloads, or page-local heuristics.
fields and collapses an all-empty origin to nil so absent metadata
never persists as an empty object. Origin fields are Pulse-produced
identifiers, not operator text, and stay outside the redaction set.
+ Downstream reconciliation of origin-tagged records rides the shared
+ lifecycle service's org-scoped `OnActionTransition` hook (wired via
+ `ResourceHandlers.SetActionTransitionPublisher`): transitions publish
+ only after the corresponding store write succeeds, so a subscriber
+ keyed by org ID never observes a state this store could still lose
+ or apply it to the wrong tenant.
Regression coverage: `TestSQLiteStoreActionAuditOriginRoundTrip` in
`internal/unifiedresources/store_test.go`.
diff --git a/internal/actionlifecycle/service.go b/internal/actionlifecycle/service.go
index d2e7c2a1fc..6d6166fb71 100644
--- a/internal/actionlifecycle/service.go
+++ b/internal/actionlifecycle/service.go
@@ -56,14 +56,16 @@ type Service struct {
// record, including refused-before-dispatch failures, so SSE bridges
// and reconcilers observe the full lifecycle regardless of transport.
OnActionCompleted func(unified.ActionAuditRecord)
- // OnActionTransition receives the audit record after every successfully
- // persisted state transition: plan creation, approval decisions, and
- // terminal execution outcomes (including refusals). Persistence always
- // happens before publication, so a subscriber that reconciles origin
- // surfaces (e.g. Patrol finding outcomes) never observes a state the
- // store could still lose. Terminal records additionally flow through
- // OnActionCompleted after this hook.
- OnActionTransition func(unified.ActionAuditRecord)
+ // OnActionTransition receives the org ID and audit record after every
+ // successfully persisted state transition: plan creation, approval
+ // decisions, and terminal execution outcomes (including refusals).
+ // Persistence always happens before publication, so a subscriber that
+ // reconciles origin surfaces (e.g. Patrol finding outcomes) never
+ // observes a state the store could still lose. The org ID keys the
+ // subscriber's per-tenant stores; without it a multi-tenant
+ // reconciler could apply a transition to the wrong tenant. Terminal
+ // records additionally flow through OnActionCompleted after this hook.
+ OnActionTransition func(orgID string, record unified.ActionAuditRecord)
Now func() time.Time
}
@@ -266,7 +268,7 @@ func (s *Service) PlanWithOptions(ctx context.Context, orgID string, req unified
if err != nil {
return unified.ActionPlan{}, &PersistError{Op: "action plan audit", Err: err}
}
- s.publishTransition(record)
+ s.publishTransition(orgID, record)
return plan, nil
}
@@ -395,7 +397,7 @@ func (s *Service) Decide(ctx context.Context, orgID, actionID string, approval u
}
return unified.ActionAuditRecord{}, &PersistError{Op: "action decision", Err: err}
}
- s.publishTransition(updated)
+ s.publishTransition(orgID, updated)
return updated, nil
}
@@ -429,7 +431,7 @@ func (s *Service) Execute(ctx context.Context, orgID, actionID, actor, reason st
if persistErr != nil {
return unified.ActionAuditRecord{}, &PersistError{Op: "refused action execution", Err: persistErr}
}
- s.publishTransition(failed)
+ s.publishTransition(orgID, failed)
s.publishCompleted(failed)
return failed, err
}
@@ -444,7 +446,7 @@ func (s *Service) Execute(ctx context.Context, orgID, actionID, actor, reason st
if persistErr != nil {
return unified.ActionAuditRecord{}, &PersistError{Op: "refused action execution", Err: persistErr}
}
- s.publishTransition(failed)
+ s.publishTransition(orgID, failed)
s.publishCompleted(failed)
return failed, err
}
@@ -456,7 +458,7 @@ func (s *Service) Execute(ctx context.Context, orgID, actionID, actor, reason st
if persistErr != nil {
return unified.ActionAuditRecord{}, &PersistError{Op: "refused action execution", Err: persistErr}
}
- s.publishTransition(failed)
+ s.publishTransition(orgID, failed)
s.publishCompleted(failed)
return failed, err
}
@@ -485,7 +487,7 @@ func (s *Service) Execute(ctx context.Context, orgID, actionID, actor, reason st
if err := store.RecordActionExecutionResult(completed, doneEvent); err != nil {
return unified.ActionAuditRecord{}, &PersistError{Op: "action execution result", Err: err}
}
- s.publishTransition(completed)
+ s.publishTransition(orgID, completed)
s.publishCompleted(completed)
return completed, nil
}
@@ -581,9 +583,9 @@ func (s *Service) publishCompleted(record unified.ActionAuditRecord) {
// publishTransition notifies the persisted-state subscriber. Callers invoke
// it only after the corresponding store write succeeded.
-func (s *Service) publishTransition(record unified.ActionAuditRecord) {
+func (s *Service) publishTransition(orgID string, record unified.ActionAuditRecord) {
if s == nil || s.OnActionTransition == nil {
return
}
- s.OnActionTransition(record)
+ s.OnActionTransition(orgID, record)
}
diff --git a/internal/actionlifecycle/service_test.go b/internal/actionlifecycle/service_test.go
index 5154c99452..b011d6baf8 100644
--- a/internal/actionlifecycle/service_test.go
+++ b/internal/actionlifecycle/service_test.go
@@ -455,8 +455,10 @@ func TestOnActionTransitionFiresAfterEachPersistedState(t *testing.T) {
now := time.Now().UTC()
env := newServiceEnv(t, testResource(now, unified.ApprovalAdmin))
var transitions []unified.ActionState
- env.service.OnActionTransition = func(record unified.ActionAuditRecord) {
+ var transitionOrgs []string
+ env.service.OnActionTransition = func(orgID string, record unified.ActionAuditRecord) {
transitions = append(transitions, record.State)
+ transitionOrgs = append(transitionOrgs, orgID)
}
plan, err := env.service.Plan(context.Background(), "default", restartRequest())
@@ -480,6 +482,9 @@ func TestOnActionTransitionFiresAfterEachPersistedState(t *testing.T) {
if transitions[i] != want[i] {
t.Fatalf("transitions = %v, want %v", transitions, want)
}
+ if transitionOrgs[i] != "default" {
+ t.Fatalf("transition org = %q, want default", transitionOrgs[i])
+ }
}
}
@@ -487,7 +492,7 @@ func TestOnActionTransitionFiresForPersistedRefusals(t *testing.T) {
now := time.Now().UTC()
env := newServiceEnv(t, testResource(now, unified.ApprovalNone))
var transitions []unified.ActionState
- env.service.OnActionTransition = func(record unified.ActionAuditRecord) {
+ env.service.OnActionTransition = func(orgID string, record unified.ActionAuditRecord) {
transitions = append(transitions, record.State)
}
diff --git a/internal/api/actions.go b/internal/api/actions.go
index 2176eeff25..49784fe38c 100644
--- a/internal/api/actions.go
+++ b/internal/api/actions.go
@@ -60,8 +60,9 @@ func (h *ResourceHandlers) ActionLifecycle() *actionlifecycle.Service {
Store: func(orgID string) (actionlifecycle.Store, error) {
return h.getStore(orgID)
},
- Executor: h.actionExecutor,
- OnActionCompleted: h.actionCompleted,
+ Executor: h.actionExecutor,
+ OnActionCompleted: h.actionCompleted,
+ OnActionTransition: h.actionTransition,
}
}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index ddc27d5b4c..cc4f45880a 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -1616,7 +1616,7 @@ func TestContract_AISettingsUpdateProviderResolutionJSONSnapshot(t *testing.T) {
"status":"warning",
"ready":true,
"cause":"model_tool_support_unverified",
- "summary":"Ollama connectivity alone does not prove tool support. Use an Ollama model that returns tool_calls for Patrol verification.",
+ "summary":"Ollama connectivity alone does not prove tool support. qwen3:8b passes Patrol's tool check; run ollama pull qwen3:8b and select it as the Patrol model.",
"provider":"ollama",
"model":"ollama:llama3:latest",
"checks":[{
@@ -1624,7 +1624,7 @@ func TestContract_AISettingsUpdateProviderResolutionJSONSnapshot(t *testing.T) {
"status":"warning",
"cause":"model_tool_support_unverified",
"label":"Patrol control",
- "message":"Ollama connectivity alone does not prove tool support. Use an Ollama model that returns tool_calls for Patrol verification."
+ "message":"Ollama connectivity alone does not prove tool support. qwen3:8b passes Patrol's tool check; run ollama pull qwen3:8b and select it as the Patrol model."
}]
}
}`, ollama.URL)
@@ -20436,6 +20436,10 @@ func TestContract_PatrolActionBrokerIsPlanOnly(t *testing.T) {
`patrolActionBrokerActor = "pulse_patrol"`,
`patrolActionOriginSurface = "patrol"`,
"rejectSensitiveParams",
+ // Correlation identity is mandatory before persistence so a
+ // planned action can always be reconciled onto its finding.
+ "action proposal requires a finding id",
+ "action proposal requires an investigation id",
} {
if !strings.Contains(src, snippet) {
t.Fatalf("patrol_action_broker.go must pin plan-only broker snippet %q", snippet)
diff --git a/internal/api/patrol_action_broker.go b/internal/api/patrol_action_broker.go
index abc7a16213..e61f009279 100644
--- a/internal/api/patrol_action_broker.go
+++ b/internal/api/patrol_action_broker.go
@@ -90,6 +90,16 @@ func (b *patrolActionBroker) Submit(ctx context.Context, proposal aicontracts.Ac
if proposal.Reason == "" {
return aicontracts.ActionDisposition{}, fmt.Errorf("action proposal requires a reason")
}
+ // Finding and investigation identity are required before persistence:
+ // without them the planned action cannot be deterministically
+ // reconciled back onto its Patrol finding at decision or terminal
+ // time, which would orphan a valid governed action.
+ if proposal.FindingID == "" {
+ return aicontracts.ActionDisposition{}, fmt.Errorf("action proposal requires a finding id")
+ }
+ if proposal.InvestigationID == "" {
+ return aicontracts.ActionDisposition{}, fmt.Errorf("action proposal requires an investigation id")
+ }
if err := b.rejectSensitiveParams(ctx, proposal); err != nil {
return aicontracts.ActionDisposition{}, err
diff --git a/internal/api/patrol_action_broker_test.go b/internal/api/patrol_action_broker_test.go
index 9d8802490b..0099d17cb4 100644
--- a/internal/api/patrol_action_broker_test.go
+++ b/internal/api/patrol_action_broker_test.go
@@ -185,3 +185,58 @@ func TestPatrolActionBrokerCapabilitiesCatalog(t *testing.T) {
t.Fatal("unknown resource must error")
}
}
+
+func TestPatrolActionBrokerRequiresCorrelationIdentity(t *testing.T) {
+ h, _ := newPatrolBrokerTestHandlers(t, unified.ApprovalAdmin)
+ broker := NewPatrolActionBroker("default", h)
+
+ missingFinding := patrolTestProposal()
+ missingFinding.FindingID = " "
+ if _, err := broker.Submit(context.Background(), missingFinding); err == nil {
+ t.Fatal("proposal without finding id must be refused")
+ }
+
+ missingInvestigation := patrolTestProposal()
+ missingInvestigation.InvestigationID = ""
+ if _, err := broker.Submit(context.Background(), missingInvestigation); err == nil {
+ t.Fatal("proposal without investigation id must be refused")
+ }
+
+ store, err := h.getStore("default")
+ if err != nil {
+ t.Fatalf("getStore: %v", err)
+ }
+ audits, err := store.GetActionAudits("vm:42", time.Time{}, 10)
+ if err != nil {
+ t.Fatalf("GetActionAudits: %v", err)
+ }
+ if len(audits) != 0 {
+ t.Fatalf("identity-less proposals must not persist audits, got %d", len(audits))
+ }
+}
+
+func TestPatrolActionBrokerSubmitPublishesOrgScopedTransition(t *testing.T) {
+ h, _ := newPatrolBrokerTestHandlers(t, unified.ApprovalAdmin)
+ var gotOrg string
+ var gotState unified.ActionState
+ var gotOrigin *unified.ActionOrigin
+ h.SetActionTransitionPublisher(func(orgID string, record unified.ActionAuditRecord) {
+ gotOrg = orgID
+ gotState = record.State
+ gotOrigin = record.Origin
+ })
+ broker := NewPatrolActionBroker("default", h)
+
+ if _, err := broker.Submit(context.Background(), patrolTestProposal()); err != nil {
+ t.Fatalf("Submit: %v", err)
+ }
+ if gotOrg != "default" {
+ t.Fatalf("transition org = %q, want default", gotOrg)
+ }
+ if gotState != unified.ActionStatePending {
+ t.Fatalf("transition state = %q, want pending_approval", gotState)
+ }
+ if gotOrigin == nil || gotOrigin.FindingID != "finding-1" {
+ t.Fatalf("transition origin = %#v", gotOrigin)
+ }
+}
diff --git a/internal/api/resources.go b/internal/api/resources.go
index 83080e3a77..2981175614 100644
--- a/internal/api/resources.go
+++ b/internal/api/resources.go
@@ -33,6 +33,7 @@ type ResourceHandlers struct {
tenantStateProvider TenantStateProvider
actionExecutor ActionExecutor
actionCompleted func(unified.ActionAuditRecord)
+ actionTransition func(orgID string, record unified.ActionAuditRecord)
discoveryReadiness ResourceDiscoveryReadinessProvider
}
@@ -110,6 +111,15 @@ func (h *ResourceHandlers) SetActionCompletedPublisher(publisher func(unified.Ac
h.actionCompleted = publisher
}
+// SetActionTransitionPublisher configures the persisted-state transition
+// hook on the shared action lifecycle: plan creation, approval decisions,
+// and terminal execution outcomes, published only after the corresponding
+// store write succeeds. The org ID keys per-tenant reconciliation (e.g.
+// mapping a Patrol-origin action's decision back onto its finding).
+func (h *ResourceHandlers) SetActionTransitionPublisher(publisher func(orgID string, record unified.ActionAuditRecord)) {
+ h.actionTransition = publisher
+}
+
// SetDiscoveryReadinessProvider wires the canonical discovery-readiness
// projection onto resource responses and Assistant context packs.
func (h *ResourceHandlers) SetDiscoveryReadinessProvider(provider ResourceDiscoveryReadinessProvider) {
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index 6995248e68..c18021be59 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -650,6 +650,12 @@ func TestActionExecutionContractStaysAPIOwned(t *testing.T) {
"func (s *Service) ValidatePlanFresh(orgID string, record unified.ActionAuditRecord) error",
"func RecordRefusedExecution(store Store, record unified.ActionAuditRecord",
"func (s *Service) publishCompleted(record unified.ActionAuditRecord)",
+ // The persisted-state transition hook is org-scoped so
+ // multi-tenant reconcilers (e.g. Patrol finding outcomes)
+ // can never apply a transition to the wrong tenant, and it
+ // publishes only after the corresponding store write.
+ "OnActionTransition func(orgID string, record unified.ActionAuditRecord)",
+ "func (s *Service) publishTransition(orgID string, record unified.ActionAuditRecord)",
"store.RecordActionExecutionStart(started, startEvent)",
"store.RecordActionExecutionResult(completed, doneEvent)",
},
@@ -668,8 +674,10 @@ func TestActionExecutionContractStaysAPIOwned(t *testing.T) {
filepath.Join("..", "api", "resources.go"): {
"actionExecutor ActionExecutor",
"actionCompleted func(unified.ActionAuditRecord)",
+ "actionTransition func(orgID string, record unified.ActionAuditRecord)",
"func (h *ResourceHandlers) SetActionExecutor(executor ActionExecutor)",
"func (h *ResourceHandlers) SetActionCompletedPublisher(",
+ "func (h *ResourceHandlers) SetActionTransitionPublisher(",
"func (h *ResourceHandlers) applyActionAvailability(ctx context.Context, resources []unified.Resource)",
"resources[i].ActionReadiness = readinesses",
},