Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): withdraw readiness while the safety inventory is uncertified
Alfredo Lopezb5bcf49195dd
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 57da9f0c1..4313781f8 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.196",+ "version": "0.1.197","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.196",+ "version": "0.1.197","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 92ba95aba..36fe3f04e 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.196",+ "version": "0.1.197","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.tsindex c0aecad29..4dc67f44e 100644--- a/host-context-controller/src/k8sClient.test.ts+++ b/host-context-controller/src/k8sClient.test.ts@@ -1056,6 +1056,54 @@ describe('McpServerWatcher startup', () => {expect(watcher.isReadinessInventoryAuthoritative()).toBe(false)})+ it('withdraws readiness when the safety pass leaves its inventory uncertified', async () => {+ // Losing a delete fence is the one doom cause that bumps no watch+ // generation and moves no desired revision, so every equality below stays+ // satisfied while an allow this pass classified as stale is still live.+ // The reconciler already degrades its fence at the point of loss; readiness+ // has to read it, or /ready keeps answering 200 over that allow until a+ // retry lands (>=5s, and indefinitely against a persistent second writer —+ // e.g. the two-replica overlap every rolling update opens, since the+ // Deployment carries no leader election).+ const watcher = newContextAuthoritativeWatcher()+ ;(watcher as any).mcpServerCacheSynced = true+ ;(watcher as any).hostCacheSynced = true+ markNetworkPolicyRevocationAuthoritative(watcher)+ expect(watcher.isReadinessInventoryAuthoritative()).toBe(true)++ try {+ mocks.hasCertifiedSafetyInventory.mockReturnValue(false)++ expect(watcher.isReadinessInventoryAuthoritative()).toBe(false)+ } finally {+ // vi.clearAllMocks() clears calls, not implementations, so an escaped+ // mockReturnValue would silently re-gate every later test in this file.+ mocks.hasCertifiedSafetyInventory.mockReturnValue(true)+ }+ })++ it('restores readiness once a later safety pass certifies its inventory again', async () => {+ // The withdrawal above must not be a one-way latch: a fence raised by a+ // transient loss has to clear on the next completed pass, or the retry+ // machinery would leave the controller permanently unready.+ const watcher = newContextAuthoritativeWatcher()+ ;(watcher as any).mcpServerCacheSynced = true+ ;(watcher as any).hostCacheSynced = true+ markNetworkPolicyRevocationAuthoritative(watcher)+ try {+ mocks.hasCertifiedSafetyInventory.mockReturnValue(false)+ expect(watcher.isReadinessInventoryAuthoritative()).toBe(false)++ mocks.hasCertifiedSafetyInventory.mockReturnValue(true)++ expect(watcher.isReadinessInventoryAuthoritative()).toBe(true)+ } finally {+ // An assertion failure above must not escape a false implementation into+ // the rest of the file — vi.clearAllMocks() would not undo it.+ mocks.hasCertifiedSafetyInventory.mockReturnValue(true)+ }+ })+it('ignores a late McpServer callback from a retired watch generation', async () => {const callbacks: Array<(type: string, apiObj: any) => Promise<void>> = []mocks.watch.mockImplementation(async (path, _options, callback) => {@@ -1440,15 +1488,18 @@ describe('McpServerWatcher startup', () => {;(watcher as any).netPolReconciler.reconcileContext.mockImplementationOnce(() => uncertifiedDelta.promise)- // The delta's own revocation completes, but the last authoritative pass left- // the namespace-wide inventory uncertified. A label-scoped delta cannot- // vouch for that namespace, so readiness must stay withheld.- mocks.hasCertifiedSafetyInventory.mockReturnValue(false)-try {await vi.waitFor(() => expect(mocks.netPolFullReconcile).toHaveBeenCalledOnce())+ // Baseline: the inventory is still certified here, so readiness is+ // genuinely green. Degrading the fence before this point would assert a+ // 200 that only the missing readiness gate could produce.expect((await requestReadyOverHttp(server)).statusCode).toBe(200)+ // The delta's own revocation completes, but the last authoritative pass left+ // the namespace-wide inventory uncertified. A label-scoped delta cannot+ // vouch for that namespace, so readiness must stay withheld.+ mocks.hasCertifiedSafetyInventory.mockReturnValue(false)+const delta = contextWatchCallback!('MODIFIED', {metadata: {name: 'delta-context',diff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.tsindex 1476806d5..82c6b169b 100644--- a/host-context-controller/src/k8sClient.ts+++ b/host-context-controller/src/k8sClient.ts@@ -901,6 +901,14 @@ export class McpServerWatcher implements McpServerProvider {this.mcpServerCacheSynced &&this.contextCacheSynced &&this.hostCacheSynced &&+ // The generation/revision equalities below prove no newer desired state+ // is outstanding; they cannot prove the last pass actually revoked what+ // it set out to revoke. Losing a delete fence bumps no generation and+ // moves no revision, so it is invisible to every other term here while+ // leaving live an allow the pass classified as stale. The reconciler+ // degrades this fence at the point of loss; readiness reads it so the+ // gate re-closes for the same reason it opened.+ this.netPolReconciler.hasCertifiedSafetyInventory() &&this.networkPolicyRevocationContextGeneration === this.contextWatchGeneration &&this.networkPolicyRevocationServerGeneration === this.mcpWatchGeneration &&this.networkPolicyRevocationContextRevision === this.contextDesiredRevision &&