Skip to content

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

TypeScript

fix(hcc): refuse a Context delta certificate when its revocation aborted

Alfredo Lopez027aa2569d47
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index b2ec82197..6119182d4 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.182",
+ "version": "0.1.183",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.182",
+ "version": "0.1.183",
"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 88fb028b3..0f22c3707 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.182",
+ "version": "0.1.183",
"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 6fb3ea2f1..36925ba8d 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -1147,7 +1147,7 @@ describe('McpServerWatcher startup', () => {
it('keeps readiness after a current Context safety delta while an older additive pass is pending', async () => {
const olderAdditivePass = deferred()
- const currentDeltaSafety = deferred()
+ const currentDeltaSafety = deferred<boolean>()
let contextWatchCallback:
| ((
type: string,
@@ -1208,7 +1208,9 @@ describe('McpServerWatcher startup', () => {
expect((watcher as any).netPolReconciler.reconcileContext).toHaveBeenCalledOnce()
)
expect((await requestReadyOverHttp(server)).statusCode).toBe(503)
- currentDeltaSafety.resolve(undefined)
+ // The scoped revocation completed, which is what authorises the delta
+ // certificate; see the aborted-pass twin above for the negative side.
+ currentDeltaSafety.resolve(true)
await currentDelta
expect((await requestReadyOverHttp(server)).statusCode).toBe(200)
expect(mocks.netPolFullReconcile).toHaveBeenCalledOnce()
@@ -1220,6 +1222,86 @@ describe('McpServerWatcher startup', () => {
}
})
+ it('does not certify a Context delta whose stale-allow revocation aborted mid-pass', async () => {
+ const olderAdditivePass = deferred()
+ const abortedDeltaSafety = deferred<boolean>()
+ let contextWatchCallback:
+ | ((
+ type: string,
+ apiObj: {
+ metadata: { name: string; namespace: string; uid: string }
+ spec: { contextId: string; mcpServers: string[] }
+ }
+ ) => Promise<void>)
+ | undefined
+ let networkPolicyPasses = 0
+ mocks.watch.mockImplementationOnce(async (path, _options, callback) => {
+ if (path.endsWith('/contexts')) contextWatchCallback = callback
+ return { abort: vi.fn() }
+ })
+ mocks.netPolFullReconcile.mockImplementation(async (...args: unknown[]) => {
+ networkPolicyPasses += 1
+ const options = args[2] as { onAuthoritativeRevocationComplete?: () => void } | undefined
+ options?.onAuthoritativeRevocationComplete?.()
+ if (networkPolicyPasses === 1) await olderAdditivePass.promise
+ })
+
+ const watcher = new McpServerWatcher()
+ await (watcher as any).startContextWatch('aborted-delta-rv')
+ ;(watcher as any).contextCacheSynced = true
+ ;(watcher as any).mcpServerCacheSynced = true
+ ;(watcher as any).hostCacheSynced = true
+ ;(watcher as any).mcpWatchGeneration = 1
+ ;(watcher as any).contexts.set('delta-context', {
+ name: 'delta-context',
+ namespace: 'mcp-server',
+ uid: 'delta-context-uid',
+ spec: { contextId: 'delta-context', mcpServers: [] },
+ })
+ const server = new ContextMapperServer(watcher, 0, undefined, undefined, () =>
+ watcher.isReadinessInventoryAuthoritative()
+ )
+ await server.start()
+ server.setReady(true)
+ const initialPass = (watcher as any).runInitialNetworkPolicyConvergence() as Promise<void>
+ // `reconcileContext` reports that its authority fence broke, so the scoped
+ // revocation never finished deleting this Context's stale allows.
+ ;(watcher as any).netPolReconciler.reconcileContext.mockImplementationOnce(
+ () => abortedDeltaSafety.promise
+ )
+
+ try {
+ await vi.waitFor(() => expect(mocks.netPolFullReconcile).toHaveBeenCalledOnce())
+ expect((await requestReadyOverHttp(server)).statusCode).toBe(200)
+
+ const abortedDelta = contextWatchCallback!('MODIFIED', {
+ metadata: {
+ name: 'delta-context',
+ namespace: 'mcp-server',
+ uid: 'delta-context-uid',
+ },
+ spec: { contextId: 'delta-context', mcpServers: ['delta-server'] },
+ })
+
+ await vi.waitFor(() =>
+ expect((watcher as any).netPolReconciler.reconcileContext).toHaveBeenCalledOnce()
+ )
+ expect((await requestReadyOverHttp(server)).statusCode).toBe(503)
+ abortedDeltaSafety.resolve(false)
+ await abortedDelta
+
+ // An incomplete revocation must leave readiness withheld until the
+ // authoritative full pass re-certifies. Certifying here would report
+ // Ready while a stale allow is still live.
+ expect((await requestReadyOverHttp(server)).statusCode).toBe(503)
+ } finally {
+ olderAdditivePass.resolve(undefined)
+ await initialPass
+ await server.stop()
+ await watcher.stop()
+ }
+ })
+
it('does not issue a Context delta certificate before any authoritative safety certificate', async () => {
const pendingFullSafetyPass = deferred()
let contextWatchCallback:
diff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.ts
index c77458159..8d67d22a9 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -3708,14 +3708,22 @@ export class McpServerWatcher implements McpServerProvider {
} else if (current?.spec.contextId !== context.spec.contextId) {
return
}
+ // A scoped delta may only certify readiness when its own stale-allow
+ // revocation ran to completion. `reconcileContext` aborts mid-pass
+ // whenever its authority fence breaks, so treating "it returned" as
+ // "it revoked" would certify a Context whose stale allows are live.
+ let scopedRevocationCompleted = false
if (type === 'ADDED' || type === 'MODIFIED') {
const selectedContext = current!
- await this.netPolReconciler.reconcileContext(selectedContext, {
- isCurrent: () =>
- contextInventoryAuthoritative() &&
- this.hasMcpServerInventoryAuthority(serverInventoryGeneration) &&
- this.contexts.get(selectedContext.name) === selectedContext,
- })
+ scopedRevocationCompleted = await this.netPolReconciler.reconcileContext(
+ selectedContext,
+ {
+ isCurrent: () =>
+ contextInventoryAuthoritative() &&
+ this.hasMcpServerInventoryAuthority(serverInventoryGeneration) &&
+ this.contexts.get(selectedContext.name) === selectedContext,
+ }
+ )
} else if (type === 'DELETED') {
const deleteAllowed = () =>
this.contextAbsentForDelete(context.name, context.namespace, watchGeneration)
@@ -3726,7 +3734,7 @@ export class McpServerWatcher implements McpServerProvider {
)
}
- if (deltaSafetyCertificate) {
+ if (deltaSafetyCertificate && scopedRevocationCompleted) {
this.recordNetworkPolicySafetyCertificate(deltaSafetyCertificate)
}
} catch (error) {
diff --git a/host-context-controller/src/networkPolicyReconciler.test.ts b/host-context-controller/src/networkPolicyReconciler.test.ts
index 9fa4037f9..717e9c73c 100644
--- a/host-context-controller/src/networkPolicyReconciler.test.ts
+++ b/host-context-controller/src/networkPolicyReconciler.test.ts
@@ -2651,7 +2651,7 @@ describe('NetworkPolicyReconciler', () => {
...queuedContext,
spec: { contextId: 'replacement-context', mcpServers: [] },
}
- const reconcileContext = vi.spyOn(reconciler, 'reconcileContext').mockResolvedValue(undefined)
+ const reconcileContext = vi.spyOn(reconciler, 'reconcileContext').mockResolvedValue(true)
const effectKeys: string[] = []
await reconciler.fullReconcile([queuedContext], [], {
@@ -2686,6 +2686,7 @@ describe('NetworkPolicyReconciler', () => {
selectedLease = options?.isCurrent
mutationStarted.resolve(undefined)
await releaseMutation.promise
+ return true
})
const fullPass = reconciler.fullReconcile([selected], [], {
@@ -2784,7 +2785,7 @@ describe('NetworkPolicyReconciler', () => {
spec: { contextId: 'desired-context', mcpServers: [] },
}
const effectKeys: string[] = []
- vi.spyOn(reconciler, 'reconcileContext').mockResolvedValue(undefined)
+ vi.spyOn(reconciler, 'reconcileContext').mockResolvedValue(true)
mockApi.listNamespacedNetworkPolicy.mockImplementation(
async ({ namespace, labelSelector }: { namespace?: string; labelSelector?: string }) => {
if (namespace === 'mcp-server' && labelSelector?.includes('context-allow')) {
@@ -2843,6 +2844,7 @@ describe('NetworkPolicyReconciler', () => {
vi.spyOn(reconciler, 'reconcileContext').mockImplementationOnce(async () => {
additiveStarted.resolve(undefined)
await releaseAdditive.promise
+ return true
})
mockApi.listNamespacedNetworkPolicy.mockImplementation(
async ({ namespace, labelSelector }: { namespace?: string; labelSelector?: string }) => {
@@ -2946,6 +2948,7 @@ describe('NetworkPolicyReconciler', () => {
vi.spyOn(reconciler, 'reconcileContext').mockImplementationOnce(async () => {
additiveStarted.resolve(undefined)
await releaseAdditive.promise
+ return true
})
mockApi.listNamespacedNetworkPolicy.mockImplementation(
async ({ namespace, labelSelector }: { namespace?: string; labelSelector?: string }) => {
@@ -3089,6 +3092,7 @@ describe('NetworkPolicyReconciler', () => {
vi.spyOn(reconciler, 'reconcileContext').mockImplementation(async context => {
ordering.push(`context:${context.spec.contextId}`)
if (context.spec.contextId === 'aaa-poisoned') throw additiveFailure
+ return true
})
const onAuthoritativeRevocationComplete = vi.fn(() => {
ordering.push('certify')
@@ -3160,7 +3164,7 @@ describe('NetworkPolicyReconciler', () => {
}
}
)
- vi.spyOn(rec, 'reconcileContext').mockResolvedValue(undefined)
+ vi.spyOn(rec, 'reconcileContext').mockResolvedValue(true)
vi.spyOn(rec, 'reconcileExternalEgress').mockResolvedValue(undefined)
const ordering: string[] = []
mockApi.replaceNamespacedNetworkPolicy.mockImplementation(
@@ -3368,7 +3372,7 @@ describe('NetworkPolicyReconciler', () => {
}
}
)
- vi.spyOn(rec, 'reconcileContext').mockResolvedValue(undefined)
+ vi.spyOn(rec, 'reconcileContext').mockResolvedValue(true)
vi.spyOn(rec, 'reconcileExternalEgress').mockResolvedValue(undefined)
await rec.fullReconcile([liveContext], [server], {
@@ -4189,6 +4193,7 @@ describe('NetworkPolicyReconciler', () => {
vi.spyOn(reconciler, 'reconcileContext').mockImplementationOnce(async () => {
additiveStarted.resolve(undefined)
await releaseAdditive.promise
+ return true
})
mockApi.listNamespacedNetworkPolicy.mockResolvedValue({ items: [] })
@@ -4401,7 +4406,7 @@ describe('NetworkPolicyReconciler', () => {
namespace: 'mcp-server',
spec: { contextId: 'current', mcpServers: [] },
}
- const reconcileContext = vi.spyOn(reconciler, 'reconcileContext').mockResolvedValue(undefined)
+ const reconcileContext = vi.spyOn(reconciler, 'reconcileContext').mockResolvedValue(true)
const contextInventoryAuthoritative = vi
.fn()
.mockReturnValueOnce(true)
diff --git a/host-context-controller/src/networkPolicyReconciler.ts b/host-context-controller/src/networkPolicyReconciler.ts
index 4ebbb265a..d2d02006d 100644
--- a/host-context-controller/src/networkPolicyReconciler.ts
+++ b/host-context-controller/src/networkPolicyReconciler.ts
@@ -745,12 +745,18 @@ 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
+ * stale allows live.
+ */
async reconcileContext(
context: ContextCRD,
options: NetworkPolicyMutationOptions = {}
- ): Promise<void> {
+ ): Promise<boolean> {
const callerIsCurrent = options.isCurrent ?? (() => true)
- if (!callerIsCurrent()) return
+ if (!callerIsCurrent()) return false
const contextId = context.spec.contextId
const allowedServers = context.spec.mcpServers || []
const selectedServers = new Map(
@@ -764,7 +770,7 @@ export class NetworkPolicyReconciler {
if (!selected || !current) return selected === current
return sameMcpServerDesiredRevision(selected, current)
})
- if (!isCurrent()) return
+ if (!isCurrent()) return false
console.log(
`[NetPol] Reconciling context "${contextId}" — allowed servers: [${allowedServers.join(', ')}]`
@@ -772,7 +778,7 @@ export class NetworkPolicyReconciler {
// Create or update policies for each allowed server.
for (const serverName of allowedServers) {
- if (!isCurrent()) return
+ if (!isCurrent()) return false
const server = this.serverCache.get(serverName)
if (!server) {
console.warn(
@@ -784,7 +790,7 @@ export class NetworkPolicyReconciler {
const desired = this.buildContextAllowPolicies(context, server)
const ingressName = desired.ingress.metadata!.name!
await this.applyContextIngressPolicy(ingressName, desired.ingress, isCurrent)
- if (!isCurrent()) return
+ if (!isCurrent()) return false
const hostEgressName = desired.hostEgress.metadata!.name!
await this.applyOwnedPolicy(
@@ -794,7 +800,7 @@ export class NetworkPolicyReconciler {
'context-host-egress',
isCurrent
)
- if (!isCurrent()) return
+ if (!isCurrent()) return false
const rpcProxyEgressName = desired.rpcProxyEgress.metadata!.name!
await this.applyOwnedPolicy(
@@ -808,7 +814,7 @@ 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.
- await this.revokeStaleContextAllows(context, isCurrent)
+ return await this.revokeStaleContextAllows(context, isCurrent)
}
private async revokeStaleContextAllows(