Skip to content

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

TypeScript

fix(hcc): let the safety fence degrade after the pass has certified

Alfredo Lopezb125465d8ff2
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index ecae26212..735301e15 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.194",
+ "version": "0.1.195",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.194",
+ "version": "0.1.195",
"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 c8f04297b..929556796 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.194",
+ "version": "0.1.195",
"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 22a11173a..c39678756 100644
--- a/host-context-controller/src/networkPolicyReconciler.test.ts
+++ b/host-context-controller/src/networkPolicyReconciler.test.ts
@@ -4816,6 +4816,58 @@ describe('NetworkPolicyReconciler', () => {
)
})
+ it('withdraws certification when an additive revocation loses the fence after certifying', async () => {
+ // The additive phase re-runs reconcileContext, which carries a second
+ // revocation lane over a fresh LIST. Losing the fence there happens after
+ // the pass already certified, and the outcome recorder is first-wins — so
+ // the duration sample stays 'completed', which is right, but the safety
+ // fence must still degrade. It is an assertion about live allows, and it
+ // may only ever move toward unsafe.
+ const additiveContext: ContextCRD = {
+ name: 'additive',
+ namespace: 'mcp-server',
+ spec: { contextId: 'additive', mcpServers: [] },
+ }
+ const additiveStalePolicy: k8s.V1NetworkPolicy = {
+ metadata: {
+ name: 'ctx-additive-alpha',
+ namespace: 'mcp-server',
+ labels: {
+ 'clerum.io/managed-by': 'host-context-controller',
+ 'clerum.io/policy-type': 'context-allow',
+ 'clerum.io/context': 'additive',
+ 'clerum.io/mcpserver': 'alpha',
+ },
+ },
+ spec: { podSelector: {}, policyTypes: ['Ingress'] },
+ }
+ // Self-synchronising: the stale policy only becomes visible once the pass
+ // has already certified, so the safety phase is clean by construction and
+ // only the additive re-LIST finds work.
+ let certified = false
+ mockApi.listNamespacedNetworkPolicy.mockImplementation(
+ async ({ namespace }: { namespace?: string }) => ({
+ items: certified && namespace === 'mcp-server' ? [additiveStalePolicy] : [],
+ })
+ )
+ mockApi.deleteNamespacedNetworkPolicy.mockRejectedValue(lostFence)
+ const onAuthoritativeRevocationComplete = vi.fn(() => {
+ certified = true
+ })
+
+ await expect(
+ reconciler.fullReconcile([additiveContext], [], {
+ ensureDefaults: false,
+ contextInventoryAuthoritative: () => true,
+ serverInventoryAuthoritative: () => true,
+ onAuthoritativeRevocationComplete,
+ })
+ ).rejects.toThrow()
+
+ expect(onAuthoritativeRevocationComplete).toHaveBeenCalledOnce()
+ expect(reconciler.hasCertifiedSafetyInventory()).toBe(false)
+ })
+
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
diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index 0a67e0d3c..7add53bc2 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -1094,6 +1094,15 @@ export class NetworkPolicyReconciler {
* every stale allow its inventory implied.
*/
const recordSafetyPassOutcome = (outcome: 'completed' | 'failed'): void => {
+ // The fence is an assertion about live allows, so it only ever moves
+ // toward unsafe. The additive phase re-runs reconcileContext, which
+ // carries a second revocation lane over a fresh LIST; losing the fence
+ // there happens after this pass certified, and first-outcome-wins would
+ // otherwise leave the gate green over an allow that was not revoked.
+ if (outcome === 'failed') this.safetyPassLeftUncertified = true
+ // The duration sample describes the pass's primary outcome, so it stays
+ // first-wins: a certified pass that later fails an additive effect did
+ // complete its authoritative revocation.
if (safetyPassOutcomeRecorded) return
safetyPassOutcomeRecorded = true
this.safetyPassLeftUncertified = outcome === 'failed'
@@ -1113,8 +1122,10 @@ export class NetworkPolicyReconciler {
})
// The pass returned without certifying: no exception, no certificate.
// Operators alert on this exact condition, so it must produce a sample
- // rather than the absence of one.
- recordSafetyPassOutcome('failed')
+ // rather than the absence of one. Stated as a condition rather than
+ // leaning on first-outcome-wins to swallow it, because the fence below is
+ // deliberately not first-wins.
+ if (!safetyPassOutcomeRecorded) recordSafetyPassOutcome('failed')
} catch (error) {
recordSafetyPassOutcome('failed')
throw error