Skip to content

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

TypeScript

fix(hcc): opt into the reported lost fence only when a certificate can absorb it

Alfredo Lopezd449a84bf4a3
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index c3a903d0c..1fb621a87 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.191",
+ "version": "0.1.192",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.191",
+ "version": "0.1.192",
"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 2d51c049d..10a0018d5 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.191",
+ "version": "0.1.192",
"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 ef3eca4e3..c0aecad29 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -1475,6 +1475,73 @@ describe('McpServerWatcher startup', () => {
}
})
+ it('recovers when a Context delta loses the delete fence with no certificate to withhold', async () => {
+ // A MODIFIED that does not move the desired revision — a status or label
+ // write by another controller — still runs a scoped revocation, but builds
+ // no delta certificate. Nothing reads the returned boolean there, so a lost
+ // delete fence must stay loud and reach the convergence retry instead of
+ // leaving a stale allow live with no NetworkPolicy resync to recover it.
+ let contextWatchCallback:
+ | ((
+ type: string,
+ apiObj: {
+ metadata: { name: string; namespace: string; uid: string; generation?: number }
+ spec: { contextId: string; mcpServers: string[] }
+ }
+ ) => Promise<void>)
+ | undefined
+ mocks.watch.mockImplementationOnce(async (path, _options, callback) => {
+ if (path.endsWith('/contexts')) contextWatchCallback = callback
+ return { abort: vi.fn() }
+ })
+
+ const watcher = new McpServerWatcher()
+ await (watcher as any).startContextWatch('lost-fence-no-certificate-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('steady-context', {
+ name: 'steady-context',
+ namespace: 'mcp-server',
+ uid: 'steady-context-uid',
+ generation: 4,
+ spec: { contextId: 'steady-context', mcpServers: [] },
+ })
+ markNetworkPolicyRevocationAuthoritative(watcher)
+ const passesBefore = mocks.netPolFullReconcile.mock.calls.length
+ // With honorsLostFence false the real reconciler throws the 409 rather than
+ // reporting it, which is the whole point: the throw is what reaches the
+ // convergence retry below.
+ ;(watcher as any).netPolReconciler.reconcileContext.mockRejectedValueOnce(
+ Object.assign(new Error('the UID in the precondition does not match'), { code: 409 })
+ )
+
+ try {
+ await contextWatchCallback!('MODIFIED', {
+ metadata: {
+ name: 'steady-context',
+ namespace: 'mcp-server',
+ uid: 'steady-context-uid',
+ generation: 4,
+ },
+ spec: { contextId: 'steady-context', mcpServers: [] },
+ })
+
+ // This lane cannot act on the boolean, so it must not have opted into the
+ // reported outcome.
+ expect((watcher as any).netPolReconciler.reconcileContext).toHaveBeenCalledWith(
+ expect.objectContaining({ name: 'steady-context' }),
+ expect.objectContaining({ honorsLostFence: false })
+ )
+ await vi.waitFor(() =>
+ expect(mocks.netPolFullReconcile.mock.calls.length).toBeGreaterThan(passesBefore)
+ )
+ } finally {
+ 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 4653a9a2e..1476806d5 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -3738,10 +3738,12 @@ 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,
+ // Only opt in when there is a certificate to withhold. Without
+ // one the result below is discarded, so a reported lost fence
+ // would vanish: no throw to reach the retry, and the recovery
+ // in the desired-state branch does not run for an event that
+ // did not move the revision.
+ honorsLostFence: deltaSafetyCertificate !== undefined,
}
)
if (deltaSafetyCertificate && scopedRevocationCompleted) {