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.

refactor(ai): share policy posture summary

rcourtmanc13dc9ddbc81
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index f8ce1255e5..6806a0805a 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -194,6 +194,12 @@ That governed posture block and its export-routing inputs now also flow through
the dedicated `internal/ai/resource_context_policy_model.go` owner, so
`resource_context.go` stays on AI context composition instead of duplicating
policy redaction sections or recomputing export metadata inline.
+That same ownership now includes the canonical policy-posture summary object
+itself: `resource_context.go` must compute the shared
+`unifiedresources.SummarizePolicyPosture(...)` result exactly once per unified
+context build and pass that summary into
+`buildUnifiedResourcePolicyContext(...)`, instead of letting downstream AI
+context helpers silently rebuild posture counts from the raw resource slice.
The same shared policy presenter also owns the routing-scope labels used in
the AI-facing policy surfaces, so the policy wording stays canonical instead
of being rendered inline by the consumer.
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index d84ea7c669..d876a03587 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -101,7 +101,8 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
infrastructure := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetInfrastructure())
workloads := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetWorkloads())
allResources := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetAll())
- policyContext := buildUnifiedResourcePolicyContext(allResources)
+ policyPosture := unifiedresources.SummarizePolicyPosture(allResources)
+ policyContext := buildUnifiedResourcePolicyContext(policyPosture)
byResourceID := make(map[string]unifiedresources.Resource, len(allResources))
for _, resource := range allResources {
byResourceID[resource.ID] = resource
diff --git a/internal/ai/resource_context_policy_model.go b/internal/ai/resource_context_policy_model.go
index 585f36d3b2..f7317a60ae 100644
--- a/internal/ai/resource_context_policy_model.go
+++ b/internal/ai/resource_context_policy_model.go
@@ -17,8 +17,7 @@ type unifiedResourcePolicyContext struct {
redactionLabels []string
}
-func buildUnifiedResourcePolicyContext(resources []unifiedresources.Resource) unifiedResourcePolicyContext {
- posture := unifiedresources.SummarizePolicyPosture(resources)
+func buildUnifiedResourcePolicyContext(posture *unifiedresources.PolicyPostureSummary) unifiedResourcePolicyContext {
context := unifiedResourcePolicyContext{
posture: posture,
sensitivityCounts: map[unifiedresources.ResourceSensitivity]int{},
diff --git a/internal/ai/resource_context_policy_model_test.go b/internal/ai/resource_context_policy_model_test.go
index 8587fcbf81..e3d5c0d4ca 100644
--- a/internal/ai/resource_context_policy_model_test.go
+++ b/internal/ai/resource_context_policy_model_test.go
@@ -48,7 +48,7 @@ func TestBuildUnifiedResourcePolicyContext(t *testing.T) {
},
})
- context := buildUnifiedResourcePolicyContext(resources)
+ context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources))
if !context.hasGovernedResources() {
t.Fatal("expected governed posture")