Skip to content

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

TypeScript

fix(hcc): gate /api/v1/desktop/* on Host authority, not full readiness [R3-H1]

Alfredo Lopez7b4e119515b2
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 97d1c9fb5..5a60bed07 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.208",
+ "version": "0.1.209",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.208",
+ "version": "0.1.209",
"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 e6ccf6b4f..651fb0321 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.208",
+ "version": "0.1.209",
"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 2afac8eb2..86a7028ff 100644
--- a/host-context-controller/src/main.ts
+++ b/host-context-controller/src/main.ts
@@ -118,6 +118,9 @@ async function main(): Promise<void> {
// 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)
+ // 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
// Stateless heartbeat consumption — mcp-host pods authenticate their
// heartbeats toward control-api's /mcp-host facade (control-api is the
@@ -155,7 +158,8 @@ async function main(): Promise<void> {
config.port,
hostReconciler,
hasDesktopFn,
- providerAuthoritativeFn
+ providerAuthoritativeFn,
+ hostAuthoritativeFn
)
await server.start()
diff --git a/host-context-controller/src/server.test.ts b/host-context-controller/src/server.test.ts
index 115925999..fcc19b28c 100644
--- a/host-context-controller/src/server.test.ts
+++ b/host-context-controller/src/server.test.ts
@@ -206,3 +206,82 @@ describe('ContextMapperServer readiness', () => {
expect(JSON.parse(response.body)).toEqual({ status: 'starting', ready: false })
})
})
+
+describe('ContextMapperServer desktop status authority', () => {
+ let server: ContextMapperServer | null = null
+
+ // A Host reconciler that reports a running desktop, so the only thing that can
+ // withhold a 200 is the Host-authority gate under test.
+ const runningReconciler = {
+ getStatus: () => ({ deployed: true, ready: true, message: '' }),
+ hasDesktop: () => true,
+ } as unknown as ConstructorParameters<typeof ContextMapperServer>[2]
+ const hasDesktopFn = () => true
+
+ afterEach(async () => {
+ await server?.stop()
+ server = null
+ vi.restoreAllMocks()
+ })
+
+ it('serves desktop status on Host authority alone even when the provider inventory is not authoritative', async () => {
+ // The heart of H1: desktop needs only Host authority. A degraded
+ // McpServer/Context lane (providerAuthoritative=false) must NOT 503 desktop,
+ // while /api/v1/mcpservers still 503s on the same server.
+ server = new ContextMapperServer(
+ new FakeProvider(),
+ 0,
+ runningReconciler,
+ hasDesktopFn,
+ () => false, // provider inventory NOT authoritative
+ () => true // Host inventory authoritative
+ )
+ 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' })
+
+ const mcpservers = await invoke(server, '/api/v1/mcpservers')
+ expect(mcpservers.statusCode).toBe(503)
+ })
+
+ it('fails desktop closed (503, never 200 inactive) when Host inventory is not authoritative', async () => {
+ server = new ContextMapperServer(
+ new FakeProvider(),
+ 0,
+ runningReconciler,
+ hasDesktopFn,
+ () => true, // provider authoritative — must not rescue desktop
+ () => false // Host inventory NOT authoritative
+ )
+ server.setReady(true)
+
+ const desktop = await invoke(server, '/api/v1/desktop/host-a')
+ expect(desktop.statusCode).toBe(503)
+ expect(JSON.parse(desktop.body)).toEqual({
+ error: 'Service Unavailable',
+ message: 'Host inventory is not authoritative',
+ })
+ })
+
+ 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.
+ server = new ContextMapperServer(
+ new FakeProvider(),
+ 0,
+ runningReconciler,
+ hasDesktopFn,
+ () => true
+ )
+ server.setReady(true)
+
+ const desktop = await invoke(server, '/api/v1/desktop/host-a')
+ expect(desktop.statusCode).toBe(503)
+ expect(JSON.parse(desktop.body)).toEqual({
+ error: 'Service Unavailable',
+ message: 'Host inventory is not authoritative',
+ })
+ })
+})
diff --git a/host-context-controller/src/server.ts b/host-context-controller/src/server.ts
index 41ac5e76f..03f576dcf 100644
--- a/host-context-controller/src/server.ts
+++ b/host-context-controller/src/server.ts
@@ -19,6 +19,7 @@ export class ContextMapperServer {
private hostReconciler: HostReconciler | null
private hasDesktopFn: ((hostRef: string) => boolean) | null
private providerAuthoritativeFn: () => boolean
+ private hostAuthoritativeFn: () => boolean
private ready = false
constructor(
@@ -29,13 +30,31 @@ export class ContextMapperServer {
// Fails closed. /ready is the assertion that no stale allow is live, and a
// caller that omits this gate gets no type error, so the default must
// withhold readiness rather than grant it.
- providerAuthoritativeFn: () => boolean = () => false
+ providerAuthoritativeFn: () => boolean = () => false,
+ // Desktop status needs ONLY Host inventory authority, not the full
+ // readiness inventory. Fails closed like providerAuthoritativeFn: a caller
+ // that omits it gets a 503 on desktop rather than a wrong 200 'inactive'.
+ hostAuthoritativeFn: () => boolean = () => false
) {
this.provider = provider
this.port = port
this.hostReconciler = hostReconciler ?? null
this.hasDesktopFn = hasDesktopFn ?? null
this.providerAuthoritativeFn = providerAuthoritativeFn
+ this.hostAuthoritativeFn = hostAuthoritativeFn
+ }
+
+ /**
+ * Host inventory authority, fail-closed on error — the desktop route's only
+ * authority gate. Same shape as the provider check in getReadinessState().
+ */
+ private safeHostAuthoritative(): boolean {
+ try {
+ return this.hostAuthoritativeFn()
+ } catch (err) {
+ console.error('[Server] Host authority check failed:', err)
+ return false
+ }
}
/**
@@ -117,6 +136,25 @@ export class ContextMapperServer {
return
}
+ // Desktop status: Host inventory is the ONLY authority this route needs, so
+ // it is gated here — ABOVE the blanket readiness gate — on Host authority
+ // alone. A degraded McpServer/Context lane must NOT 503 desktop, and a
+ // degraded Host lane must 503 it (never answer 200 'inactive' from a stale
+ // cache). See the E3 design note's endpoint→authority matrix.
+ if (req.method === 'GET' && url.pathname.startsWith('/api/v1/desktop/')) {
+ if (!this.ready || !this.safeHostAuthoritative()) {
+ this.sendJson(res, 503, {
+ error: 'Service Unavailable',
+ message: 'Host inventory is not authoritative',
+ })
+ return
+ }
+ if (!this.checkDesktopAuth(req, res)) return
+ const hostRef = url.pathname.replace('/api/v1/desktop/', '')
+ await this.handleDesktopStatus(res, hostRef)
+ return
+ }
+
const readiness = this.getReadinessState()
if (!readiness.ready) {
this.sendJson(res, 503, {
@@ -150,14 +188,6 @@ export class ContextMapperServer {
return
}
- // Desktop status (requires service token)
- if (req.method === 'GET' && url.pathname.startsWith('/api/v1/desktop/')) {
- if (!this.checkDesktopAuth(req, res)) return
- const hostRef = url.pathname.replace('/api/v1/desktop/', '')
- await this.handleDesktopStatus(res, hostRef)
- return
- }
-
// 404
this.sendJson(res, 404, { error: 'Not Found', message: 'Endpoint not found' })
}