Skip to content

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

TypeScript

fix(hcc): grant an explicit readiness gate in dev mode [R3-B1]

Alfredo Lopez3a60a9e31b87
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 09e1ec4cb..9d66b3370 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.202",
+ "version": "0.1.203",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.202",
+ "version": "0.1.203",
"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 da6bddb33..c12e20a34 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.202",
+ "version": "0.1.203",
"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/main.ts b/host-context-controller/src/main.ts
index 82d993bb4..2afac8eb2 100644
--- a/host-context-controller/src/main.ts
+++ b/host-context-controller/src/main.ts
@@ -18,6 +18,7 @@ import {
createMcpServerProvider,
getKubeConfig,
} from './k8sClient'
+import { resolveProviderAuthoritativeFn } from './readinessGate'
import { ContextMapperServer } from './server'
import { StatelessLifecycleTracker } from './statelessLifecycleTracker'
import {
@@ -113,9 +114,10 @@ async function main(): Promise<void> {
const hasDesktopFn = hostReconciler
? (hostRef: string) => hostReconciler.hasDesktop(hostRef)
: undefined
- const providerAuthoritativeFn = watcher
- ? () => watcher.isReadinessInventoryAuthoritative()
- : undefined
+ // Dev (no watcher) gets an explicit always-authoritative gate: no inventory
+ // to certify there, and the server's fail-closed default would otherwise pin
+ // /ready at 503 forever (R3-B1). See resolveProviderAuthoritativeFn.
+ const providerAuthoritativeFn = resolveProviderAuthoritativeFn(watcher)
// Stateless heartbeat consumption — mcp-host pods authenticate their
// heartbeats toward control-api's /mcp-host facade (control-api is the
diff --git a/host-context-controller/src/readinessGate.test.ts b/host-context-controller/src/readinessGate.test.ts
new file mode 100644
index 000000000..fac67715d
--- /dev/null
+++ b/host-context-controller/src/readinessGate.test.ts
@@ -0,0 +1,27 @@
+import { describe, expect, it } from 'vitest'
+import { resolveProviderAuthoritativeFn } from './readinessGate'
+
+describe('resolveProviderAuthoritativeFn (dev-mode readiness gate — B1)', () => {
+ it('dev provider (no watcher) is unconditionally authoritative', () => {
+ // Regression for R3-B1: main.ts left this undefined for DevMcpServerProvider,
+ // so the ContextMapperServer fail-closed default (() => false) pinned /ready
+ // and every /api/v1/* endpoint at 503 forever in dev mode. There is no
+ // NetworkPolicy inventory to certify in dev, so authority must be granted.
+ expect(resolveProviderAuthoritativeFn(null)()).toBe(true)
+ })
+
+ it('production watcher delegates to the live inventory certification', () => {
+ let asked = false
+ const watcher = {
+ isReadinessInventoryAuthoritative: () => {
+ asked = true
+ return false
+ },
+ }
+ // Delegates (returns the watcher's verdict) rather than a constant.
+ expect(resolveProviderAuthoritativeFn(watcher)()).toBe(false)
+ expect(asked).toBe(true)
+ watcher.isReadinessInventoryAuthoritative = () => true
+ expect(resolveProviderAuthoritativeFn(watcher)()).toBe(true)
+ })
+})
diff --git a/host-context-controller/src/readinessGate.ts b/host-context-controller/src/readinessGate.ts
new file mode 100644
index 000000000..951f85e01
--- /dev/null
+++ b/host-context-controller/src/readinessGate.ts
@@ -0,0 +1,19 @@
+/**
+ * Resolve the readiness-authority gate for the server from the provider.
+ *
+ * Production (McpServerWatcher present): readiness follows the live inventory
+ * certification — /ready is 200 only once stale allows are revoked.
+ *
+ * Dev (DevMcpServerProvider — no watcher): there is NO NetworkPolicy inventory
+ * to certify, so authority is unconditional. The ContextMapperServer default
+ * for a missing gate is fail-closed (`() => false`), which is correct for a
+ * caller that forgets to wire one — but in dev it would pin /ready (and every
+ * data endpoint) at 503 forever. Dev must therefore pass an explicit
+ * always-authoritative gate; this function is that single, named decision so
+ * the affirmative literal never gets copy-pasted into a production path.
+ */
+export function resolveProviderAuthoritativeFn(
+ watcher: { isReadinessInventoryAuthoritative(): boolean } | null
+): () => boolean {
+ return watcher ? () => watcher.isReadinessInventoryAuthoritative() : () => true
+}