Skip to content

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

TypeScript

fix(control-api): make the registry boot guard observational, removing the boot-order deadlock

Jose Ramirez80c8b71f35aa
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 4ca2905b2..38e38fe3d 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.379",
+ "version": "0.1.380",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.379",
+ "version": "0.1.380",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index a393c8217..664ca403d 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.379",
+ "version": "0.1.380",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/main.ts b/control-api/src/main.ts
index 8332f9b0b..76c7b08ae 100644
--- a/control-api/src/main.ts
+++ b/control-api/src/main.ts
@@ -2,7 +2,7 @@ import { config } from './config.js'
import { assertDbReady, pool } from './db.js'
import { K8sGateway } from './k8s.js'
import { reconcileAllowedModelsConfigMapOnBoot } from './llmAllowedModelsBootReconcile.js'
-import { assertRegistryConnectionReady } from './registryBootGuard.js'
+import { logRegistryConnectionState } from './registryBootGuard.js'
import { ControlApiServer } from './server.js'
import {
startAdminRevokedTokenCleanup,
@@ -52,9 +52,10 @@ async function main(): Promise<void> {
await assertDbReady()
console.log('[ControlAPI] Database schema ready')
- // Self-hosted fail-fast (spec §8 / §14.3): refuse to boot a registry-enabled
- // self-hosted deployment that has no registry_connection identity row.
- await assertRegistryConnectionReady()
+ // Observability only (never fatal): report whether this self-hosted deployment
+ // holds a registry identity. Auth is derived from credential presence, so a
+ // missing row simply means auth is inactive until the connect flow runs.
+ await logRegistryConnectionState()
// Anti-drift (spec §3-R3.4 / V7): re-materialize the LLM allowlist ConfigMap
// from Postgres. Non-fatal — logs + metric on failure, never aborts boot.
diff --git a/control-api/src/registryBootGuard.ts b/control-api/src/registryBootGuard.ts
index 36ea610ca..44c696ada 100644
--- a/control-api/src/registryBootGuard.ts
+++ b/control-api/src/registryBootGuard.ts
@@ -1,22 +1,33 @@
import { config } from './config.js'
+import { rootLogger } from './observability/logger.js'
import { getRegistryConnection } from './services/registryConnectionDb.js'
/**
- * Self-hosted fail-fast (spec §8 / §14.3): a registry-enabled self-hosted
- * control-api must have a claimed registry_connection row (its identity), else
- * it would silently boot unable to emit vouchers. Cannot live in config.ts
- * (synchronous, no DB access). Fail-closed at M3 — no break-glass bypass.
+ * Boot-time observability for the self-hosted registry identity.
*
- * C-M5: this lives in a standalone module importing ONLY config +
- * registryConnectionDb so its test doesn't pull in main.ts's server/cron graph.
+ * This used to be a fail-fast guard that threw when registry auth was enabled
+ * without a connection row. With auth now DERIVED from credential presence,
+ * that state is unrepresentable — and throwing would have been a boot-order
+ * deadlock: control-api could not start without a connection, and a connection
+ * could not be made without a running control-api.
+ *
+ * It still logs, because "no row" has two very different causes: a fresh
+ * install that has not connected yet (normal), and a deployment whose row
+ * disappeared (bad restore, accidental delete). INFO rather than WARN so it
+ * does not cry wolf on every first boot.
+ *
+ * Standalone module importing only config + logger + registryConnectionDb, so
+ * its test does not pull in main.ts's server/cron graph.
*/
-export async function assertRegistryConnectionReady(): Promise<void> {
- if (!config.registryAuthEnabled) return
+export async function logRegistryConnectionState(): Promise<void> {
if (config.registryConnectionMode !== 'self-hosted') return
+ if (config.registryUrl === '') return
const row = await getRegistryConnection()
- if (!row) {
- throw new Error(
- '[ControlAPI] self-hosted registry mode requires a registry_connection row — run the connect flow before enabling registry auth'
- )
- }
+ const connected = row?.clientId != null
+ rootLogger.info(
+ { event: 'registry_connection_state', connected },
+ connected
+ ? 'self-hosted registry connection present'
+ : 'self-hosted registry not yet connected — auth inactive until the connect flow completes'
+ )
}
diff --git a/control-api/test/main.selfHostedBootGuard.test.ts b/control-api/test/main.selfHostedBootGuard.test.ts
index 438fc851c..9e018f800 100644
--- a/control-api/test/main.selfHostedBootGuard.test.ts
+++ b/control-api/test/main.selfHostedBootGuard.test.ts
@@ -1,13 +1,13 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { assertRegistryConnectionReady } from '../src/registryBootGuard.js'
+import { logRegistryConnectionState } from '../src/registryBootGuard.js'
-// C-M5: the guard lives in a standalone module (src/registryBootGuard.ts) that
-// imports ONLY config + registryConnectionDb, so this test never pulls in
-// main.ts's full server/cron graph.
+// The function lives in a standalone module importing ONLY config, the logger,
+// and registryConnectionDb, so this test never pulls in main.ts's full
+// server/cron graph.
const { cfg } = vi.hoisted(() => ({
cfg: {
registryConnectionMode: 'self-hosted',
- registryAuthEnabled: true,
+ registryUrl: 'https://registry.evenfire.ai',
} as Record<string, unknown>,
}))
vi.mock('../src/config.js', () => ({ config: cfg }))
@@ -15,32 +15,57 @@ vi.mock('../src/config.js', () => ({ config: cfg }))
const connDb = vi.hoisted(() => ({ getRegistryConnection: vi.fn() }))
vi.mock('../src/services/registryConnectionDb.js', () => connDb)
+const logger = vi.hoisted(() => ({ rootLogger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() } }))
+vi.mock('../src/observability/logger.js', () => logger)
+
afterEach(() => {
vi.clearAllMocks()
cfg.registryConnectionMode = 'self-hosted'
- cfg.registryAuthEnabled = true
+ cfg.registryUrl = 'https://registry.evenfire.ai'
})
-describe('assertRegistryConnectionReady (self-hosted boot guard)', () => {
- it('throws when self-hosted + enabled + no connection row', async () => {
+describe('logRegistryConnectionState', () => {
+ // The deadlock regression guard. `.resolves` (not `.rejects`) is the detector:
+ // if a future change reintroduces a throw here, control-api cannot boot
+ // before it has connected, and this test fails.
+ it('does NOT throw when self-hosted with no connection row', { retry: 0 }, async () => {
connDb.getRegistryConnection.mockResolvedValue(null)
- await expect(assertRegistryConnectionReady()).rejects.toThrow(/registry_connection/)
+ await expect(logRegistryConnectionState()).resolves.toBeUndefined()
+ expect(logger.rootLogger.info).toHaveBeenCalledWith(
+ expect.objectContaining({ connected: false }),
+ expect.any(String)
+ )
})
- it('passes when a connected row exists', async () => {
- connDb.getRegistryConnection.mockResolvedValue({ status: 'connected' })
- await expect(assertRegistryConnectionReady()).resolves.toBeUndefined()
+ it('reports connected for a row holding client credentials', async () => {
+ connDb.getRegistryConnection.mockResolvedValue({ status: 'connected', clientId: 'cid' })
+ await expect(logRegistryConnectionState()).resolves.toBeUndefined()
+ expect(logger.rootLogger.info).toHaveBeenCalledWith(
+ expect.objectContaining({ connected: true }),
+ expect.any(String)
+ )
})
- it('no-op when registry auth is disabled', async () => {
- cfg.registryAuthEnabled = false
- connDb.getRegistryConnection.mockResolvedValue(null)
- await expect(assertRegistryConnectionReady()).resolves.toBeUndefined()
+ // An auto-approved row whose claim has not landed has no clientId.
+ it('reports NOT connected for an approved row with no clientId', async () => {
+ connDb.getRegistryConnection.mockResolvedValue({ status: 'approved', clientId: null })
+ await logRegistryConnectionState()
+ expect(logger.rootLogger.info).toHaveBeenCalledWith(
+ expect.objectContaining({ connected: false }),
+ expect.any(String)
+ )
})
- it('no-op in managed mode', async () => {
+ it('no-op in managed mode — does not even read the row', async () => {
cfg.registryConnectionMode = 'managed'
- connDb.getRegistryConnection.mockResolvedValue(null)
- await expect(assertRegistryConnectionReady()).resolves.toBeUndefined()
+ await expect(logRegistryConnectionState()).resolves.toBeUndefined()
+ expect(connDb.getRegistryConnection).not.toHaveBeenCalled()
+ expect(logger.rootLogger.info).not.toHaveBeenCalled()
+ })
+
+ it('no-op when no registry URL is configured', async () => {
+ cfg.registryUrl = ''
+ await expect(logRegistryConnectionState()).resolves.toBeUndefined()
+ expect(connDb.getRegistryConnection).not.toHaveBeenCalled()
})
})