Skip to content

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

TypeScript

fix(hcc): keep the lost delete fence loud for callers that discard the result

Alfredo Lopez0bf127f09064
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 2ac99500f..c3a903d0c 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.190",
+ "version": "0.1.191",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.190",
+ "version": "0.1.191",
"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 a285b54a7..2d51c049d 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.190",
+ "version": "0.1.191",
"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/k8sClient.test.ts b/host-context-controller/src/k8sClient.test.ts
index 55288603e..ef3eca4e3 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -2433,7 +2433,7 @@ describe('McpServerWatcher startup', () => {
await flushMicrotasks()
expect(netPol.reconcileContext).toHaveBeenCalledWith(
expect.objectContaining({ name: 'current-context' }),
- { isCurrent: expect.any(Function) }
+ expect.objectContaining({ isCurrent: expect.any(Function) })
)
releaseFullReconcile.resolve(undefined)
@@ -2442,7 +2442,7 @@ describe('McpServerWatcher startup', () => {
expect(reconciliationOrder).toEqual(['watch', 'initial'])
expect(netPol.reconcileContext).toHaveBeenLastCalledWith(
expect.objectContaining({ name: 'current-context' }),
- { isCurrent: expect.any(Function) }
+ expect.objectContaining({ isCurrent: expect.any(Function) })
)
await watcher.stop()
})
@@ -2508,7 +2508,7 @@ describe('McpServerWatcher startup', () => {
name: contextName,
spec: expect.objectContaining({ contextId, description: 'recreated' }),
}),
- { isCurrent: expect.any(Function) }
+ expect.objectContaining({ isCurrent: expect.any(Function) })
)
await watcher.stop()
})
@@ -2676,7 +2676,7 @@ describe('McpServerWatcher startup', () => {
expect.objectContaining({
spec: expect.objectContaining({ description: 'new' }),
}),
- { isCurrent: expect.any(Function) }
+ expect.objectContaining({ isCurrent: expect.any(Function) })
)
await watcher.stop()
})
@@ -2779,7 +2779,7 @@ describe('McpServerWatcher startup', () => {
await flushMicrotasks()
expect(netPol.reconcileContext).toHaveBeenCalledWith(
expect.objectContaining({ name: 'live-context' }),
- { isCurrent: expect.any(Function) }
+ expect.objectContaining({ isCurrent: expect.any(Function) })
)
releaseResync.resolve(undefined)
@@ -4334,7 +4334,7 @@ describe('McpServerWatcher external egress retries', () => {
expect.objectContaining({
spec: expect.objectContaining({ contextId: 'context1' }),
}),
- { isCurrent: expect.any(Function) }
+ expect.objectContaining({ isCurrent: expect.any(Function) })
)
watcher.stop()
diff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.ts
index b8301c201..4653a9a2e 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -3738,6 +3738,10 @@ export class McpServerWatcher implements McpServerProvider {
contextInventoryAuthoritative() &&
this.hasMcpServerInventoryAuthority(serverInventoryGeneration) &&
this.contexts.get(selectedContext.name) === selectedContext,
+ // This lane reads the result and withholds the certificate on
+ // false, so a lost delete fence is a reported outcome here
+ // rather than a thrown one.
+ honorsLostFence: true,
}
)
if (deltaSafetyCertificate && scopedRevocationCompleted) {
diff --git a/host-context-controller/src/networkPolicyReconciler.test.ts b/host-context-controller/src/networkPolicyReconciler.test.ts
index dbf2533a0..0c7747f2e 100644
--- a/host-context-controller/src/networkPolicyReconciler.test.ts
+++ b/host-context-controller/src/networkPolicyReconciler.test.ts
@@ -4807,12 +4807,39 @@ describe('NetworkPolicyReconciler', () => {
// the one this pass classified. Nothing was revoked, so the delta must
// decline to certify — and it must not blow up the caller, which would
// only force a spurious full re-convergence.
- expect(await reconciler.reconcileContext(staleContext)).toBe(false)
+ // The scoped delta lane reads this boolean and withholds the certificate,
+ // so it is the one caller allowed to take the lost fence as an outcome
+ // rather than a throw.
+ expect(await reconciler.reconcileContext(staleContext, { honorsLostFence: true })).toBe(false)
expect(mockApi.deleteNamespacedNetworkPolicy).toHaveBeenCalledWith(
expect.objectContaining({ name: 'ctx-default-alpha', namespace: 'mcp-server' })
)
})
+ it('fails the additive phase when it loses the delete fence', async () => {
+ listOnlyTheStalePolicy()
+ // Safety phase revokes cleanly and certifies; the additive phase then
+ // races another writer and loses the fence. The additive caller discards
+ // reconcileContext's boolean, so swallowing the 409 there would record
+ // the pass as a success, disarm the convergence retry, and leave a stale
+ // allow live with no NetworkPolicy resync to recover it.
+ mockApi.deleteNamespacedNetworkPolicy
+ .mockResolvedValueOnce({})
+ .mockRejectedValueOnce(lostFence)
+ const onAuthoritativeRevocationComplete = vi.fn()
+
+ await expect(
+ reconciler.fullReconcile([staleContext], [], {
+ ensureDefaults: false,
+ contextInventoryAuthoritative: () => true,
+ serverInventoryAuthoritative: () => true,
+ onAuthoritativeRevocationComplete,
+ })
+ ).rejects.toThrow()
+
+ expect(onAuthoritativeRevocationComplete).toHaveBeenCalledOnce()
+ })
+
it('refuses to certify the safety pass instead of throwing the lost fence', async () => {
listOnlyTheStalePolicy()
mockApi.deleteNamespacedNetworkPolicy.mockRejectedValueOnce(lostFence)
diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index 211d511d8..197727949 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -53,6 +53,13 @@ type NetworkPolicyMutationOptions = {
isCurrent?: () => boolean
existingPolicies?: k8s.V1NetworkPolicy[]
onRevoked?: () => void
+ /**
+ * Set only by a caller that reads the returned boolean and withholds
+ * readiness on false. It downgrades a lost delete fence from a throw to a
+ * reported outcome; a caller that discards the boolean must not set it, or a
+ * stale allow survives while the pass is recorded as a success.
+ */
+ honorsLostFence?: boolean
}
export function sameContextDesiredRevision(expected: ContextCRD, current: ContextCRD): boolean {
@@ -823,7 +830,13 @@ export class NetworkPolicyReconciler {
// Re-LIST every lane after writes so a same-name policy that was just
// replaced is compared in its new form and cannot delete itself.
- return await this.revokeStaleContextAllows(context, isCurrent)
+ return await this.revokeStaleContextAllows(
+ context,
+ isCurrent,
+ undefined,
+ undefined,
+ options.honorsLostFence === true
+ )
}
/**
@@ -846,13 +859,20 @@ export class NetworkPolicyReconciler {
hostEgress?: k8s.V1NetworkPolicy[]
rpcProxyEgress?: k8s.V1NetworkPolicy[]
},
- onRevoked?: () => void
+ onRevoked?: () => void,
+ callerHonorsLostFence = false
): Promise<boolean> {
if (!isCurrent()) return false
const safetySnapshotProvided = listedPolicies !== undefined
// A delete whose uid/resourceVersion preconditions were rejected revoked
- // nothing. The scoped lane has no second source of truth to reclassify
- // from, so it finishes its remaining work and then declines to certify.
+ // nothing. Reporting it instead of throwing is only safe for a caller that
+ // reads the returned boolean: the authoritative snapshot lane aborts its
+ // pass on it, and the scoped delta lane declines to certify. Every other
+ // caller discards the boolean, so for them a swallowed 409 would leave a
+ // stale allow live while the pass is recorded as a success — they keep the
+ // loud default and let the failure reach the retry policy.
+ const lostFenceOutcome =
+ safetySnapshotProvided || callerHonorsLostFence ? ('report' as const) : ('throw' as const)
let lostDeleteFence = false
/**
* Revoke one orphaned policy in any lane. Returns false only when the
@@ -869,7 +889,7 @@ export class NetworkPolicyReconciler {
existing,
isCurrent,
undefined,
- 'report'
+ lostFenceOutcome
)
if (deleted) return true
if (safetySnapshotProvided) return false