Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): mirror the provider gate for the dev desktop authority (R2-M1)
Alfredo Lopeze70fae305c96
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 489633e33..527afff9d 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.215",+ "version": "0.1.216","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.215",+ "version": "0.1.216","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 cefe713c5..875271749 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.215",+ "version": "0.1.216","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.tsindex 86a7028ff..565c537d3 100644--- a/host-context-controller/src/main.ts+++ b/host-context-controller/src/main.ts@@ -18,7 +18,7 @@ import {createMcpServerProvider,getKubeConfig,} from './k8sClient'-import { resolveProviderAuthoritativeFn } from './readinessGate'+import { resolveHostAuthoritativeFn, resolveProviderAuthoritativeFn } from './readinessGate'import { ContextMapperServer } from './server'import { StatelessLifecycleTracker } from './statelessLifecycleTracker'import {@@ -119,8 +119,11 @@ async function main(): Promise<void> {// /ready at 503 forever (R3-B1). See resolveProviderAuthoritativeFn.const providerAuthoritativeFn = resolveProviderAuthoritativeFn(watcher)// Desktop status gates on Host inventory authority alone (not full readiness).- // Dev (no watcher) leaves it undefined → the server default fails closed.- const hostAuthoritativeFn = watcher ? () => watcher.isHostInventoryAuthoritative() : undefined+ // Dev (no watcher) mirrors the provider gate above: there is no Host inventory+ // to certify, so authority is unconditional (permissive) — otherwise the+ // server's fail-closed default would pin /api/v1/desktop/* at 503 forever in+ // dev (R2-M1). See resolveHostAuthoritativeFn.+ const hostAuthoritativeFn = resolveHostAuthoritativeFn(watcher)// Stateless heartbeat consumption — mcp-host pods authenticate their// heartbeats toward control-api's /mcp-host facade (control-api is thediff --git a/host-context-controller/src/readinessGate.test.ts b/host-context-controller/src/readinessGate.test.tsindex fac67715d..a9b522ab0 100644--- a/host-context-controller/src/readinessGate.test.ts+++ b/host-context-controller/src/readinessGate.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { resolveProviderAuthoritativeFn } from './readinessGate'+import { resolveHostAuthoritativeFn, resolveProviderAuthoritativeFn } from './readinessGate'describe('resolveProviderAuthoritativeFn (dev-mode readiness gate — B1)', () => {it('dev provider (no watcher) is unconditionally authoritative', () => {@@ -25,3 +25,29 @@ describe('resolveProviderAuthoritativeFn (dev-mode readiness gate — B1)', () =expect(resolveProviderAuthoritativeFn(watcher)()).toBe(true)})})++describe('resolveHostAuthoritativeFn (dev-mode desktop gate — R2-M1)', () => {+ it('dev provider (no watcher) is unconditionally authoritative', () => {+ // Regression for R2-M1: main.ts left this undefined for DevMcpServerProvider,+ // so the ContextMapperServer fail-closed default (() => false) pinned every+ // /api/v1/desktop/* response at 503 after setReady(true) — where the base+ // answered 200 {status:'inactive'}. There is no Host inventory to certify in+ // dev, so authority must mirror the provider gate and be granted.+ expect(resolveHostAuthoritativeFn(null)()).toBe(true)+ })++ it('production watcher delegates to the live Host inventory certification', () => {+ let asked = false+ const watcher = {+ isHostInventoryAuthoritative: () => {+ asked = true+ return false+ },+ }+ // Delegates (returns the watcher's verdict) rather than a constant.+ expect(resolveHostAuthoritativeFn(watcher)()).toBe(false)+ expect(asked).toBe(true)+ watcher.isHostInventoryAuthoritative = () => true+ expect(resolveHostAuthoritativeFn(watcher)()).toBe(true)+ })+})diff --git a/host-context-controller/src/readinessGate.ts b/host-context-controller/src/readinessGate.tsindex 951f85e01..88ff77ee6 100644--- a/host-context-controller/src/readinessGate.ts+++ b/host-context-controller/src/readinessGate.ts@@ -17,3 +17,25 @@ export function resolveProviderAuthoritativeFn(): () => boolean {return watcher ? () => watcher.isReadinessInventoryAuthoritative() : () => true}++/**+ * Resolve the Host-inventory-authority gate the desktop route uses.+ *+ * Production (McpServerWatcher present): desktop status follows the live Host+ * inventory certification — a degraded Host lane 503s desktop rather than+ * answering a stale 200 'inactive'.+ *+ * Dev (DevMcpServerProvider — no watcher): there is NO Host inventory to+ * certify, exactly as there is no NetworkPolicy inventory for the provider+ * gate. 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 every /api/v1/desktop/* response at 503 forever (R2-M1).+ * Dev must therefore mirror the provider gate and 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 resolveHostAuthoritativeFn(+ watcher: { isHostInventoryAuthoritative(): boolean } | null+): () => boolean {+ return watcher ? () => watcher.isHostInventoryAuthoritative() : () => true+}diff --git a/host-context-controller/src/server.test.ts b/host-context-controller/src/server.test.tsindex fcc19b28c..0ab7d03aa 100644--- a/host-context-controller/src/server.test.ts+++ b/host-context-controller/src/server.test.ts@@ -1,5 +1,6 @@import { afterEach, describe, expect, it, vi } from 'vitest'import { McpServerProvider } from './k8sClient'+import { resolveHostAuthoritativeFn, resolveProviderAuthoritativeFn } from './readinessGate'import { ContextMapperServer } from './server'class FakeProvider implements McpServerProvider {@@ -265,6 +266,30 @@ describe('ContextMapperServer desktop status authority', () => {})})+ it('serves desktop status 200 in the dev wiring (no watcher), never 503 (R2-M1)', async () => {+ // Wiring regression for R2-M1: main.ts resolves both authority gates from the+ // same watcher. In dev (DevMcpServerProvider, watcher=null) the OLD wiring left+ // the Host gate undefined, so the server's fail-closed default pinned every+ // /api/v1/desktop/* at 503 after setReady(true) — where the base answered 200+ // {status:'inactive'}. Exercise the REAL resolvers with a null watcher, exactly+ // as main.ts does, so a revert to the undefined wiring turns this 200 into 503.+ const providerAuthoritativeFn = resolveProviderAuthoritativeFn(null)+ const hostAuthoritativeFn = resolveHostAuthoritativeFn(null)+ server = new ContextMapperServer(+ new FakeProvider(),+ 0,+ runningReconciler,+ hasDesktopFn,+ providerAuthoritativeFn,+ hostAuthoritativeFn+ )+ server.setReady(true)++ const desktop = await invoke(server, '/api/v1/desktop/host-a')+ expect(desktop.statusCode).toBe(200)+ expect(JSON.parse(desktop.body)).toEqual({ status: 'running', hostRef: 'host-a' })+ })+it('fails desktop closed when no Host-authority gate is wired (default)', async () => {// Omitting the 6th arg must default to fail-closed, exactly like the// provider gate — no type error catches the omission.