Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(hcc): condemn the safety inventory when the fence is lost, not when the pass unwinds

Alfredo Lopezb7b01b9c71e0
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 1fb621a87..df53818d7 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.192",
+ "version": "0.1.193",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.192",
+ "version": "0.1.193",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 10a0018d5..b01ea96aa 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.192",
+ "version": "0.1.193",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/networkPolicyReconciler.test.ts b/host-context-controller/src/networkPolicyReconciler.test.ts
index 0c7747f2e..22a11173a 100644
--- a/host-context-controller/src/networkPolicyReconciler.test.ts
+++ b/host-context-controller/src/networkPolicyReconciler.test.ts
@@ -4816,6 +4816,63 @@ describe('NetworkPolicyReconciler', () => {
)
})
+ it('marks the inventory uncertified the moment the authoritative pass loses the fence', async () => {
+ // The doom must be visible mid-pass, not only after the unwind. A lost
+ // fence is the one doom cause that does not bump a watch generation, so
+ // it is the only one where the whole certification machinery stays green
+ // while the pass is already condemned. A scoped delta interleaving in
+ // that window would certify readiness over a stale allow.
+ //
+ // Two contexts, each with its own stale policy: the first loses the fence
+ // and the second's delete gives an observation point while the pass is
+ // condemned but still unwinding.
+ const secondContext: ContextCRD = {
+ name: 'second',
+ namespace: 'mcp-server',
+ spec: { contextId: 'second', mcpServers: [] },
+ }
+ const secondStalePolicy: k8s.V1NetworkPolicy = {
+ metadata: {
+ name: 'ctx-second-beta',
+ namespace: 'mcp-server',
+ labels: {
+ 'clerum.io/managed-by': 'host-context-controller',
+ 'clerum.io/policy-type': 'context-allow',
+ 'clerum.io/context': 'second',
+ 'clerum.io/mcpserver': 'beta',
+ },
+ },
+ spec: { podSelector: {}, policyTypes: ['Ingress'] },
+ }
+ mockApi.listNamespacedNetworkPolicy.mockImplementation(
+ async ({ namespace }: { namespace?: string }) => ({
+ items: namespace === 'mcp-server' ? [stalePolicy, secondStalePolicy] : [],
+ })
+ )
+ let certifiedDuringUnwind: boolean | undefined
+ mockApi.deleteNamespacedNetworkPolicy.mockImplementation(async () => {
+ if (
+ certifiedDuringUnwind === undefined &&
+ mockApi.deleteNamespacedNetworkPolicy.mock.calls.length > 1
+ ) {
+ certifiedDuringUnwind = reconciler.hasCertifiedSafetyInventory()
+ return {}
+ }
+ throw lostFence
+ })
+
+ await expect(
+ reconciler.fullReconcile([staleContext, secondContext], [], {
+ ensureDefaults: false,
+ contextInventoryAuthoritative: () => true,
+ serverInventoryAuthoritative: () => true,
+ onAuthoritativeRevocationComplete: vi.fn(),
+ })
+ ).rejects.toThrow()
+
+ expect(certifiedDuringUnwind).toBe(false)
+ })
+
it('fails the additive phase when it loses the delete fence', async () => {
listOnlyTheStalePolicy()
// Safety phase revokes cleanly and certifies; the additive phase then
diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index 197727949..0a67e0d3c 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -892,7 +892,16 @@ export class NetworkPolicyReconciler {
lostFenceOutcome
)
if (deleted) return true
- if (safetySnapshotProvided) return false
+ if (safetySnapshotProvided) {
+ // The authoritative pass is condemned from here: it will unwind and
+ // throw. Losing the fence is the only doom cause that does not bump a
+ // watch generation, so without this the certification machinery stays
+ // green for the whole unwind and a concurrent scoped delta can certify
+ // readiness over the allow this pass failed to revoke. Record it the
+ // moment it is known rather than when the pass finally reports.
+ this.safetyPassLeftUncertified = true
+ return false
+ }
lostDeleteFence = true
return true
}