Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): name stopped /ready 503 and flatten logger errors
Alfredo Lopezb11b9663f398
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 470d48e14..228cc22ad 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.233",+ "version": "0.1.234","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.233",+ "version": "0.1.234","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 bebc9f50a..bc1e9d0e4 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.233",+ "version": "0.1.234","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 6d9375fee..47fa0acbc 100644--- a/host-context-controller/src/k8sClient.test.ts+++ b/host-context-controller/src/k8sClient.test.ts@@ -1459,6 +1459,11 @@ describe('McpServerWatcher startup', () => {expect(watcher.isReadinessInventoryAuthoritative()).toBe(authoritative)}+ expectAligned(true)+ ;(watcher as any).stopped = true+ expectAligned(false)+ expect(watcher.getReadinessInventoryDetail().stopped).toBe(true)+ ;(watcher as any).stopped = falseexpectAligned(true);(watcher as any).mcpServerCacheSynced = falseexpectAligned(false)diff --git a/host-context-controller/src/logger.test.ts b/host-context-controller/src/logger.test.tsnew file mode 100644index 000000000..e5fbf0529--- /dev/null+++ b/host-context-controller/src/logger.test.ts@@ -0,0 +1,23 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { HostContextLogger } from './logger'++describe('HostContextLogger', () => {+ afterEach(() => {+ vi.restoreAllMocks()+ })++ it('flattens Error fields so { err } is not empty', () => {+ const errorLog = vi.spyOn(console, 'error').mockImplementation(() => undefined)+ const log = new HostContextLogger({ module: 'readiness' })+ log.error('readiness detail check failed', { err: new Error('detail unavailable') })++ expect(errorLog).toHaveBeenCalled()+ const payload = JSON.parse(String(errorLog.mock.calls[0][0])) as {+ msg: string+ err: { name: string; message: string }+ }+ expect(payload.msg).toBe('readiness detail check failed')+ expect(payload.err).toEqual({ name: 'Error', message: 'detail unavailable' })+ expect(payload).not.toHaveProperty('stack')+ })+})diff --git a/host-context-controller/src/logger.ts b/host-context-controller/src/logger.tsindex 200c33251..5652d5c5c 100644--- a/host-context-controller/src/logger.ts+++ b/host-context-controller/src/logger.ts@@ -19,6 +19,8 @@ function minLevel(): LogLevel {function sanitize(value: unknown, seen = new WeakSet<object>()): unknown {if (Array.isArray(value)) return value.map(item => sanitize(item, seen))+ // Error.message / stack are non-enumerable; Object.entries would log `{ err: {} }`.+ if (value instanceof Error) return { name: value.name, message: value.message }if (!value || typeof value !== 'object') return valueif (seen.has(value)) return '[Circular]'seen.add(value)diff --git a/host-context-controller/src/readinessGate.test.ts b/host-context-controller/src/readinessGate.test.tsindex 8d7a634ee..321ffb91b 100644--- a/host-context-controller/src/readinessGate.test.ts+++ b/host-context-controller/src/readinessGate.test.ts@@ -91,6 +91,9 @@ describe('readinessReasonsFromDetail', () => {})it('maps each false clause to a closed reason key', () => {+ expect(readinessReasonsFromDetail(authoritativeDetail({ stopped: true }))).toEqual([+ 'controller_stopped',+ ])expect(readinessReasonsFromDetail(authoritativeDetail({ mcpServerCacheSynced: false }))).toEqual(['mcp_watch_unsynced'])diff --git a/host-context-controller/src/readinessGate.ts b/host-context-controller/src/readinessGate.tsindex 6d0e9d64d..105c148a1 100644--- a/host-context-controller/src/readinessGate.ts+++ b/host-context-controller/src/readinessGate.ts@@ -10,6 +10,7 @@ export type ReadinessInventoryDetail = {}export type ReadinessReason =+ | 'controller_stopped'| 'mcp_watch_unsynced'| 'context_watch_unsynced'| 'host_watch_unsynced'@@ -18,6 +19,7 @@ export type ReadinessReason =export function readinessReasonsFromDetail(detail: ReadinessInventoryDetail): ReadinessReason[] {const reasons: ReadinessReason[] = []+ if (detail.stopped) reasons.push('controller_stopped')if (!detail.mcpServerCacheSynced) reasons.push('mcp_watch_unsynced')if (!detail.contextCacheSynced) reasons.push('context_watch_unsynced')if (!detail.hostCacheSynced) reasons.push('host_watch_unsynced')diff --git a/host-context-controller/src/server.test.ts b/host-context-controller/src/server.test.tsindex 95a89ada8..f9934a6c7 100644--- a/host-context-controller/src/server.test.ts+++ b/host-context-controller/src/server.test.ts@@ -15,6 +15,7 @@ import {type ReadinessInventoryDetail,resolveHostAuthoritativeFn,resolveProviderAuthoritativeFn,+ resolveReadinessDetailFn,} from './readinessGate'import { ContextMapperServer, McpHostApiRateLimiter } from './server'import type { McpServerInfo } from './types'@@ -518,10 +519,25 @@ describe('McpHostApiRateLimiter', () => {expect(response.statusCode).toBe(503)expect(JSON.parse(response.body)).toEqual({ status: 'degraded', ready: false })- expect(errorLog).toHaveBeenCalledWith(- '[Server] Provider authority readiness check failed:',- authorityError- )+ const readinessErrors = errorLog.mock.calls+ .map(args => {+ try {+ return JSON.parse(String(args[0])) as {+ msg?: string+ err?: { name?: string; message?: string }+ }+ } catch {+ return null+ }+ })+ .filter((entry): entry is { msg: string; err?: { name?: string; message?: string } } =>+ Boolean(entry && entry.msg === 'provider authority readiness check failed')+ )+ expect(readinessErrors).toHaveLength(1)+ expect(readinessErrors[0].err).toEqual({+ name: authorityError.name,+ message: authorityError.message,+ })})it('withdraws readiness as soon as shutdown begins', async () => {@@ -668,6 +684,7 @@ describe('ContextMapperServer /ready reasons', () => {undefined,undefined,() =>+ !detail.stopped &&detail.mcpServerCacheSynced &&detail.contextCacheSynced &&detail.hostCacheSynced &&@@ -723,4 +740,75 @@ describe('ContextMapperServer /ready reasons', () => {expect(JSON.parse(response.body)).toEqual({ status: 'degraded', ready: false })expect(JSON.parse(response.body)).not.toHaveProperty('reasons')})++ it('names controller_stopped when stopped is the only closed clause', async () => {+ const detail = { ...authoritativeDetail(), stopped: true }+ server = new ContextMapperServer(+ new FakeProvider(),+ 0,+ undefined,+ undefined,+ () =>+ !detail.stopped &&+ detail.mcpServerCacheSynced &&+ detail.contextCacheSynced &&+ detail.hostCacheSynced &&+ detail.safetyInventoryCertified &&+ detail.contextRevisionAligned &&+ detail.serverRevisionAligned,+ () => false,+ undefined,+ undefined,+ () => detail+ )+ server.setReady(true)++ const response = await invoke(server, '/ready')+ expect(response.statusCode).toBe(503)+ expect(JSON.parse(response.body)).toEqual({+ status: 'degraded',+ ready: false,+ reasons: ['controller_stopped'],+ })+ })++ it('emits closed reasons through the same resolvers main.ts uses', async () => {+ let detail = authoritativeDetail()+ const watcher = {+ isReadinessInventoryAuthoritative: () =>+ !detail.stopped &&+ detail.mcpServerCacheSynced &&+ detail.contextCacheSynced &&+ detail.hostCacheSynced &&+ detail.safetyInventoryCertified &&+ detail.contextRevisionAligned &&+ detail.serverRevisionAligned,+ getReadinessInventoryDetail: () => detail,+ }+ server = new ContextMapperServer(+ new FakeProvider(),+ 0,+ undefined,+ undefined,+ resolveProviderAuthoritativeFn(watcher),+ resolveHostAuthoritativeFn(null),+ undefined,+ undefined,+ resolveReadinessDetailFn(watcher)+ )+ server.setReady(true)++ let response = await invoke(server, '/ready')+ expect(response.statusCode).toBe(200)+ expect(JSON.parse(response.body)).toEqual({ status: 'ready', ready: true })++ detail = { ...detail, safetyInventoryCertified: false }+ response = await invoke(server, '/ready')+ expect(response.statusCode).toBe(503)+ expect(JSON.parse(response.body)).toEqual({+ status: 'degraded',+ ready: false,+ reasons: ['safety_pass_uncertified'],+ })+ })})diff --git a/host-context-controller/src/server.ts b/host-context-controller/src/server.tsindex bcaa18d42..791c59427 100644--- a/host-context-controller/src/server.ts+++ b/host-context-controller/src/server.ts@@ -193,7 +193,7 @@ export class ContextMapperServer {return ready}} catch (err) {- console.error('[Server] Provider authority readiness check failed:', err)+ readinessLog.error('provider authority readiness check failed', { err })}const degraded: ReadinessState = {