Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): keep the cold-start fleet gate off the unbounded watch start
Alfredo Lopez94e3721bcb1c
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 5f0eec783..2ac99500f 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.189",+ "version": "0.1.190","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.189",+ "version": "0.1.190","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 59a0864f5..a285b54a7 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.189",+ "version": "0.1.190","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 f47ec22c5..55288603e 100644--- a/host-context-controller/src/k8sClient.test.ts+++ b/host-context-controller/src/k8sClient.test.ts@@ -8,6 +8,7 @@ import {listAllCommunicationChannels,listAllGlobalFileSystems,listAllHosts,+ listAllSharedFileSystems,} from './k8sClient'import { registry } from './metrics'import { ContextMapperServer } from './server'@@ -131,6 +132,7 @@ const mocks = vi.hoisted(() => {const sfsFullReconcile = vi.fn().mockResolvedValue(undefined)const watch = vi.fn().mockResolvedValue({ abort: vi.fn() })const hostListCallOptions = vi.fn()+ const sharedFileSystemListCallOptions = vi.fn()const createAdministrativeOutcomeReporter = vi.fn().mockReturnValue(undefined)return {hasCertifiedSafetyInventory,@@ -144,6 +146,7 @@ const mocks = vi.hoisted(() => {sfsFullReconcile,watch,hostListCallOptions,+ sharedFileSystemListCallOptions,createAdministrativeOutcomeReporter,}})@@ -188,6 +191,8 @@ vi.mock('@kubernetes/client-node', () => {return {listNamespacedCustomObject: async (request: { plural?: string }, options?: unknown) => {if (request.plural === 'hosts') mocks.hostListCallOptions(options)+ if (request.plural === 'sharedfilesystems')+ mocks.sharedFileSystemListCallOptions(options)const response = await mocks.listNamespacedCustomObject(request)if (request.plural &&@@ -435,6 +440,51 @@ describe('McpServerWatcher startup', () => {}})+ it('lists the SharedFileSystem inventory through the deadline-bearing client', async () => {+ // The cold-start Host fleet pass waits on this inventory. Bounding the wait+ // is not enough: an unbounded request stays hung, so the socket leaks and+ // `startSharedFileSystemWatch()` — which runs after this await — never+ // starts. Only the deadline-bearing client aborts the request itself, and+ // it is observable because it appends its deadline middleware to the call.+ mocks.listNamespacedCustomObject.mockResolvedValue({ items: [] })++ await listAllSharedFileSystems()++ expect(mocks.sharedFileSystemListCallOptions).toHaveBeenCalledWith(+ expect.objectContaining({+ middleware: [expect.objectContaining({ pre: expect.any(Function) })],+ middlewareMergeStrategy: 'append',+ })+ )+ })++ it('schedules the first Host fleet pass when the SharedFileSystem watch never starts', async () => {+ // `k8s.Watch` carries no transport deadline — client-node overwrites its own+ // AbortSignal.timeout with a bare controller signal — so awaiting the watch+ // start inside the inventory promise re-strands the cold-start fleet pass+ // that bounding the LIST was meant to protect.+ mocks.listNamespacedCustomObject.mockImplementation(async ({ plural }: { plural: string }) => {+ if (plural === 'communicationchannels') {+ return { metadata: { resourceVersion: 'sfs-watch-stall-cc-rv' }, items: [] }+ }+ return { items: [] }+ })+ mocks.watch.mockImplementation(async (path: string) => {+ if (path.endsWith('/sharedfilesystems')) return new Promise(() => undefined)+ return { abort: vi.fn() }+ })+ const watcher = new McpServerWatcher()+ const start = watcher.start()++ try {+ await start+ await vi.waitFor(() => expect(mocks.hostFullReconcile).toHaveBeenCalledOnce())+ } finally {+ await watcher.stop()+ await start.catch(() => undefined)+ }+ })+it('schedules the first Host fleet pass when the SharedFileSystem inventory fails', async () => {// The inventory LIST runs on the deadline-bearing client, so an apiserver// that never answers is aborted and surfaces here as a rejection. The Hostdiff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.tsindex 448e894b0..b8301c201 100644--- a/host-context-controller/src/k8sClient.ts+++ b/host-context-controller/src/k8sClient.ts@@ -2492,12 +2492,16 @@ export class McpServerWatcher implements McpServerProvider {error)}- try {- await this.startSharedFileSystemWatch()- } catch (error) {+ // The cold-start Host fleet pass gates on this promise, so it must settle on+ // the inventory alone. `k8s.Watch` carries no transport deadline — the+ // client builds `AbortSignal.any([controller, timeout])` and then overwrites+ // it with the bare controller — so awaiting the watch start here would+ // re-strand the fleet behind an already-certified readiness, which is the+ // exact failure bounding the LIST was meant to close.+ void this.startSharedFileSystemWatch().catch(error => {console.error('[K8s] SharedFileSystem background watch failed to start:', error)this.scheduleSharedFileSystemWatchRestart(5000)- }+ })if (inventoryComplete && !this.stopped) {return true}