Skip to content

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

TypeScript

fix(hcc): bound the cold-start SharedFileSystem inventory wait

Alfredo Lopezad7dd8924f0f
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 6119182d4..42bc4c09b 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.183",
+ "version": "0.1.184",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.183",
+ "version": "0.1.184",
"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 0f22c3707..2a031ef82 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.183",
+ "version": "0.1.184",
"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/config.ts b/host-context-controller/src/config.ts
index decfeaeb8..f7aa27439 100644
--- a/host-context-controller/src/config.ts
+++ b/host-context-controller/src/config.ts
@@ -200,6 +200,13 @@ export interface Config {
// safety convergence indefinitely.
externalEgressDnsResolveTimeoutMs: number
+ // Deadline for the cold-start SharedFileSystem inventory that the first Host
+ // fleet pass waits on. Waiting is deliberate — a pass without the inventory
+ // writes mount-less templates and rerolls the fleet — but an apiserver that
+ // never answers must not strand the fleet pass behind an already-certified
+ // readiness.
+ hostFleetSfsInventoryTimeoutMs: number
+
// Plugin image-host allowlist (Phase 2.3). Trusted raw-image prefixes for
// local-mode McpServer images. Audit mode (default) logs would-be denials
// without blocking; enforce mode blocks the workload build.
@@ -233,6 +240,17 @@ function getEnvInt(key: string, defaultValue: number): number {
return isNaN(parsed) ? defaultValue : parsed
}
+export function parseHostFleetSfsInventoryTimeoutMs(raw: string | undefined): number {
+ if (raw === undefined || raw.trim() === '') return 30_000
+ const parsed = Number(raw)
+ if (!Number.isSafeInteger(parsed) || parsed <= 0 || parsed > 2_147_483_647) {
+ throw new Error(
+ `HCC_HOST_FLEET_SFS_INVENTORY_TIMEOUT_MS must be a positive integer no greater than 2147483647, got '${raw}'`
+ )
+ }
+ return parsed
+}
+
export function parseExternalEgressDnsTimeoutMs(raw: string | undefined): number {
if (raw === undefined || raw.trim() === '') return 5_000
const parsed = Number(raw)
@@ -611,6 +629,9 @@ export const config: Config = {
// Periodic external-egress DNS resync (default 5 min). 0 disables.
externalEgressResyncIntervalSec: getEnvInt('HCC_EXTERNAL_EGRESS_RESYNC_SEC', 300),
+ hostFleetSfsInventoryTimeoutMs: parseHostFleetSfsInventoryTimeoutMs(
+ getEnv('HCC_HOST_FLEET_SFS_INVENTORY_TIMEOUT_MS')
+ ),
externalEgressDnsResolveTimeoutMs: parseExternalEgressDnsTimeoutMs(
getEnv('HCC_EXTERNAL_EGRESS_DNS_TIMEOUT_MS')
),
diff --git a/host-context-controller/src/k8sClient.test.ts b/host-context-controller/src/k8sClient.test.ts
index 36925ba8d..ff77474cc 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import * as http from 'http'
+import { config } from './config'
import { HostFleetReconcileError } from './hostReconciler'
import { HostK8sRequestTimeoutError } from './k8s/hostK8sApiClient'
import {
@@ -156,6 +157,7 @@ vi.mock('./config', () => ({
port: 8081,
runtimeNamespaces: ['mcp-server', 'mcp-host', 'sandbox-recipes', 'rpc-proxy'],
hostK8sRequestTimeoutMs: 30_000,
+ hostFleetSfsInventoryTimeoutMs: 30_000,
hostResyncIntervalSec: 0,
externalEgressResyncIntervalSec: 0,
controlApiBaseUrl: 'http://control-api.test:8090',
@@ -395,17 +397,33 @@ describe('McpServerWatcher startup', () => {
return { items: [] }
})
const watcher = new McpServerWatcher()
+ // Sampling "not yet called" after a fixed number of microtask turns cannot
+ // distinguish "correctly waiting" from "scheduled but not drained yet".
+ // Record what the first pass actually observed instead: the invariant is
+ // that it never runs against an unpopulated SharedFileSystem cache, because
+ // that is what writes mount-less templates and rerolls the fleet.
+ let sfsCacheSizeAtFirstPass: number | undefined
+ mocks.hostFullReconcile.mockImplementation(async () => {
+ if (sfsCacheSizeAtFirstPass === undefined) {
+ sfsCacheSizeAtFirstPass = (watcher as any).sharedFileSystems.size
+ }
+ })
const start = watcher.start()
try {
+ // Await the whole startup first. That is the positive signal that the
+ // cold-start Host recovery already reached the point where it decides
+ // whether to schedule the fleet pass, so the absence assertion below
+ // cannot pass merely because nothing has been drained yet.
+ await start
await flushMicrotasks()
expect(mocks.hostFullReconcile).not.toHaveBeenCalled()
sharedFileSystemsListed.resolve({
items: [{ metadata: { name: 'initial-sfs', namespace: 'mcp-host' }, spec: {} }],
})
- await start
await vi.waitFor(() => expect(mocks.hostFullReconcile).toHaveBeenCalledOnce())
+ expect(sfsCacheSizeAtFirstPass).toBe(1)
expect((watcher as any).sharedFileSystems.get('initial-sfs')).toEqual(
expect.objectContaining({ name: 'initial-sfs' })
)
@@ -416,6 +434,32 @@ describe('McpServerWatcher startup', () => {
}
})
+ it('schedules the first Host fleet pass when the SharedFileSystem inventory never settles', async () => {
+ vi.useFakeTimers()
+ // A SharedFileSystem LIST that never settles must not strand the initial
+ // Host fleet pass: readiness can already be certified, so a Host fleet that
+ // never reconciles is invisible to every probe.
+ const neverSettles = new Promise<{ items: unknown[] }>(() => undefined)
+ mocks.listNamespacedCustomObject.mockImplementation(async ({ plural }: { plural: string }) => {
+ if (plural === 'sharedfilesystems') return neverSettles
+ if (plural === 'communicationchannels') {
+ return { metadata: { resourceVersion: 'sfs-stall-cc-rv' }, items: [] }
+ }
+ return { items: [] }
+ })
+ const watcher = new McpServerWatcher()
+ const start = watcher.start()
+
+ try {
+ await vi.advanceTimersByTimeAsync(config.hostFleetSfsInventoryTimeoutMs + 1000)
+ await vi.waitFor(() => expect(mocks.hostFullReconcile).toHaveBeenCalledOnce())
+ } finally {
+ await watcher.stop()
+ await start.catch(() => undefined)
+ vi.useRealTimers()
+ }
+ })
+
it('retains Context uid and generation from the authoritative initial snapshot', async () => {
mocks.listNamespacedCustomObject.mockImplementation(async ({ plural }: { plural: string }) => {
if (plural === 'contexts') {
diff --git a/host-context-controller/src/k8sClient.ts b/host-context-controller/src/k8sClient.ts
index 8d67d22a9..59c82dd8e 100644
--- a/host-context-controller/src/k8sClient.ts
+++ b/host-context-controller/src/k8sClient.ts
@@ -1579,7 +1579,27 @@ export class McpServerWatcher implements McpServerProvider {
const initialSfsInventory =
request.cause === 'cold-start' ? this.initialHostFleetSfsInventory : null
if (initialSfsInventory) {
- void initialSfsInventory.then(() => requestFleetPass())
+ // Waiting for the inventory is deliberate: a Host fleet pass without it
+ // writes mount-less templates and immediately rerolls the whole fleet.
+ // An apiserver that never answers the LIST, though, would strand the
+ // fleet pass behind an already-certified readiness — no Host would ever
+ // reconcile while `/ready` reports 200 — so the wait is bounded.
+ let fleetPassRequested = false
+ const requestFleetPassOnce = () => {
+ if (fleetPassRequested) return
+ fleetPassRequested = true
+ requestFleetPass()
+ }
+ const inventoryDeadline = setTimeout(() => {
+ console.error(
+ `[K8s] SharedFileSystem inventory did not settle within ${config.hostFleetSfsInventoryTimeoutMs}ms — scheduling the initial Host fleet pass without it`
+ )
+ requestFleetPassOnce()
+ }, config.hostFleetSfsInventoryTimeoutMs)
+ void initialSfsInventory.then(() => {
+ clearTimeout(inventoryDeadline)
+ requestFleetPassOnce()
+ })
} else {
requestFleetPass()
}