Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(hcc): collapse duplicated revoke branches and name the outcome recorder
Alfredo Lopez33b689f1808b
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 470a40b17..f691dec4c 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.186",+ "version": "0.1.187","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.186",+ "version": "0.1.187","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.jsonindex 9895007c7..b707789fb 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.186",+ "version": "0.1.187","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.ts b/host-context-controller/src/networkPolicyReconciler.tsindex 788183942..1dfe2b5aa 100644--- a/host-context-controller/src/networkPolicyReconciler.ts+++ b/host-context-controller/src/networkPolicyReconciler.ts@@ -754,8 +754,7 @@ export class NetworkPolicyReconciler {/*** Reconcile NetworkPolicies for a Context CRD.* Creates one policy per allowed MCP server.- */- /**+ ** Returns whether this Context's stale-allow revocation ran to completion.* Callers that certify readiness from a scoped delta MUST honour it: the pass* aborts as soon as its authority fence breaks, and an aborted pass leaves@@ -850,6 +849,28 @@ export class NetworkPolicyReconciler {// nothing. The scoped lane has no second source of truth to reclassify// from, so it finishes its remaining work and then declines to certify.let lostDeleteFence = false+ /**+ * Revoke one orphaned policy in any lane. Returns false only when the+ * caller must abort the pass outright, which is what the authoritative+ * safety-snapshot lane does with a lost delete fence; the scoped lane+ * records it and keeps going so the rest of its work still lands.+ */+ const revokeOrphanedPolicy = async (+ namespace: string,+ existing: k8s.V1NetworkPolicy+ ): Promise<boolean> => {+ const deleted = await this.deleteSafetyPolicySnapshot(+ namespace,+ existing,+ isCurrent,+ undefined,+ 'report'+ )+ if (deleted) return true+ if (safetySnapshotProvided) return false+ lostDeleteFence = true+ return true+ }const contextId = context.spec.contextIdconst allowedServers = context.spec.mcpServers || []const desiredIngress = new Map<string, k8s.V1NetworkPolicy>()@@ -873,29 +894,7 @@ export class NetworkPolicyReconciler {const desired = desiredIngress.get(existingName)if (!desired) {console.log(`[NetPol] Deleting orphaned policy "${existingName}"`)- if (safetySnapshotProvided) {- if (- !(await this.deleteSafetyPolicySnapshot(- config.namespace,- existing,- isCurrent,- undefined,- 'report'- ))- ) {- return false- }- } else if (- !(await this.deleteSafetyPolicySnapshot(- config.namespace,- existing,- isCurrent,- undefined,- 'report'- ))- ) {- lostDeleteFence = true- }+ if (!(await revokeOrphanedPolicy(config.namespace, existing))) return falseonRevoked?.()} else if (!sameNetworkPolicySpec(existing, desired) ||@@ -936,29 +935,7 @@ export class NetworkPolicyReconciler {const desired = desiredHostEgress.get(existingName)if (!desired) {console.log(`[NetPol] Deleting orphaned L2 egress policy "${existingName}"`)- if (safetySnapshotProvided) {- if (- !(await this.deleteSafetyPolicySnapshot(- config.hostNamespace,- existing,- isCurrent,- undefined,- 'report'- ))- ) {- return false- }- } else if (- !(await this.deleteSafetyPolicySnapshot(- config.hostNamespace,- existing,- isCurrent,- undefined,- 'report'- ))- ) {- lostDeleteFence = true- }+ if (!(await revokeOrphanedPolicy(config.hostNamespace, existing))) return falseonRevoked?.()} else if (!sameNetworkPolicySpec(existing, desired) ||@@ -999,29 +976,7 @@ export class NetworkPolicyReconciler {const desired = desiredRpcProxyEgress.get(existingName)if (!desired) {console.log(`[NetPol] Deleting orphaned rpc-proxy egress policy "${existingName}"`)- if (safetySnapshotProvided) {- if (- !(await this.deleteSafetyPolicySnapshot(- config.rpcProxyNamespace,- existing,- isCurrent,- undefined,- 'report'- ))- ) {- return false- }- } else if (- !(await this.deleteSafetyPolicySnapshot(- config.rpcProxyNamespace,- existing,- isCurrent,- undefined,- 'report'- ))- ) {- lostDeleteFence = true- }+ if (!(await revokeOrphanedPolicy(config.rpcProxyNamespace, existing))) return falseonRevoked?.()} else if (!sameNetworkPolicySpec(existing, desired) ||@@ -1097,13 +1052,16 @@ export class NetworkPolicyReconciler {}const safetyPassStartedAt = performance.now()- let safetyPassDurationRecorded = false- const recordSafetyPassDuration = (outcome: 'completed' | 'failed'): void => {- if (safetyPassDurationRecorded) return- safetyPassDurationRecorded = true- // First outcome wins for both the sample and the delta fence: a pass that- // certified and only then failed an additive effect still revoked every- // stale allow its inventory implied.+ let safetyPassOutcomeRecorded = false+ /**+ * Settles both observable results of this pass: the duration sample and the+ * cross-lane fence the scoped delta reads. First outcome wins for both — a+ * pass that certified and only then failed an additive effect still revoked+ * every stale allow its inventory implied.+ */+ const recordSafetyPassOutcome = (outcome: 'completed' | 'failed'): void => {+ if (safetyPassOutcomeRecorded) return+ safetyPassOutcomeRecorded = truethis.safetyPassLeftUncertified = outcome === 'failed'networkPolicySafetyPassDurationSeconds.observe({ outcome },@@ -1116,15 +1074,15 @@ export class NetworkPolicyReconciler {...options,onAuthoritativeRevocationComplete: () => {onAuthoritativeRevocationComplete()- recordSafetyPassDuration('completed')+ recordSafetyPassOutcome('completed')},})// 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.- recordSafetyPassDuration('failed')+ recordSafetyPassOutcome('failed')} catch (error) {- recordSafetyPassDuration('failed')+ recordSafetyPassOutcome('failed')throw error}}diff --git a/scripts/tests/test-hcc-watch-recovery-gate.sh b/scripts/tests/test-hcc-watch-recovery-gate.shindex 1d277a4c5..33aa920f4 100755--- a/scripts/tests/test-hcc-watch-recovery-gate.sh+++ b/scripts/tests/test-hcc-watch-recovery-gate.sh@@ -523,6 +523,12 @@ for ((marker_index = 0; marker_index < ${#marker_bindings[@]}; marker_index += 4producer_file="${marker_bindings[marker_index + 2]}"producer_marker="${marker_bindings[marker_index + 3]}"marker_binding_count=$((marker_binding_count + 1))+ # `grep -Fq -- ""` matches every file, so an empty marker would disarm this+ # pair while still reporting a pass. Refuse it instead of searching for it.+ if [ -z "$consumer_marker" ] || [ -z "$producer_marker" ]; then+ marker_drift+=" marker pair at index ${marker_index} has an empty marker"$'\n'+ continue+ fiif ! grep -Fq -- "$consumer_marker" "$consumer_file"; thenmarker_drift+=" consumer $(basename "$consumer_file") no longer reads: ${consumer_marker}"$'\n'fi@@ -530,7 +536,13 @@ for ((marker_index = 0; marker_index < ${#marker_bindings[@]}; marker_index += 4marker_drift+=" producer $(basename "$producer_file") no longer emits: ${producer_marker}"$'\n'fidone-if [ "$marker_binding_count" -eq 29 ] && [ -z "$marker_drift" ]; then+# The stride loop consumes 4 elements per pair, so an array whose length is not+# a multiple of 4 silently shifts every entry after the edit and leaves the tail+# unset. Assert the arity explicitly rather than relying on the pair count to+# happen to notice.+if [ $((${#marker_bindings[@]} % 4)) -eq 0 ] &&+ [ "$marker_binding_count" -eq 29 ] &&+ [ -z "$marker_drift" ]; thenpass "all ${marker_binding_count} consumed HCC log markers stay bound to their runtime producers"elseprintf '%s' "$marker_drift" >&2