Skip to content

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

TypeScript

fix(codex): materialize the allowlist ConfigMap from live grant rows only

Alfredo Lopez4bed4dba43cf
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index e32dc2841..0bd1c2229 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.514",
+ "version": "0.1.515",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.514",
+ "version": "0.1.515",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index 0454b18e2..6e966ea12 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.514",
+ "version": "0.1.515",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/services/codexSubscriptionConnection.ts b/control-api/src/services/codexSubscriptionConnection.ts
index 610cf9019..2eebc6a7e 100644
--- a/control-api/src/services/codexSubscriptionConnection.ts
+++ b/control-api/src/services/codexSubscriptionConnection.ts
@@ -313,6 +313,19 @@ export async function listSafeCodexSubscriptionConnections(
return (result.rows as SafeConnectionRow[]).map(toSafeConnection)
}
+/** Live grants only. ConfigMap / choose / spend. Hub audit still uses listSafe. */
+export async function listLiveCodexSubscriptionConnections(
+ db: DbClient
+): Promise<CodexSubscriptionSafeConnection[]> {
+ const result = await db.query(
+ `SELECT ${SAFE_CONNECTION_COLUMNS}
+ FROM codex_subscription_connections
+ WHERE revoked_at IS NULL
+ ORDER BY created_at ASC, connection_key ASC`
+ )
+ return (result.rows as SafeConnectionRow[]).map(toSafeConnection)
+}
+
export async function createNamedCodexSubscriptionConnection(
db: DbClient,
input: { connectionKey: string; displayName: string; createdBy?: string | null }
diff --git a/control-api/src/services/llmAllowedModelsConfigMap.ts b/control-api/src/services/llmAllowedModelsConfigMap.ts
index 18e2a35bc..77f27196a 100644
--- a/control-api/src/services/llmAllowedModelsConfigMap.ts
+++ b/control-api/src/services/llmAllowedModelsConfigMap.ts
@@ -25,7 +25,7 @@ import { pool } from '../db.js'
import { listEnabledCodexModelsGroupedByConnection } from './codexSubscriptionCatalog.js'
import {
type CodexSubscriptionSafeConnection,
- listSafeCodexSubscriptionConnections,
+ listLiveCodexSubscriptionConnections,
} from './codexSubscriptionConnection.js'
import { type AllowedModelEntry, listEnabledGroupedByProvider } from './llmAllowedModels.js'
@@ -168,7 +168,7 @@ export class LlmAllowedModelsConfigMapWriter implements AllowedModelsConfigMapMa
async materialize(db: DbClient = pool): Promise<void> {
const grouped = await listEnabledGroupedByProvider(db)
const { data, contentHash } = buildConfigMapData(grouped)
- const connections = await listSafeCodexSubscriptionConnections(db)
+ const connections = await listLiveCodexSubscriptionConnections(db)
const modelsByKey = await listEnabledCodexModelsGroupedByConnection(db)
const defaultConnection =
connections.find(row => row.connectionKey === 'deployment-default') ?? null
diff --git a/control-api/test/services.codexSubscriptionConnection.test.ts b/control-api/test/services.codexSubscriptionConnection.test.ts
index 1a8e292a4..4777da16d 100644
--- a/control-api/test/services.codexSubscriptionConnection.test.ts
+++ b/control-api/test/services.codexSubscriptionConnection.test.ts
@@ -8,6 +8,7 @@ import {
generateCodexConnectionKey,
getSafeCodexSubscriptionConnection,
insertInitialCodexSubscriptionConnection,
+ listLiveCodexSubscriptionConnections,
normalizeCodexConnectionKey,
readHostCodexConnectionRef,
rotateCodexSubscriptionCredentials,
@@ -85,6 +86,14 @@ describe('codex subscription connection repository', () => {
expect(String(query.mock.calls[0]?.[0])).toContain('connection_key = $1')
})
+ it('lists only live connection rows for the ConfigMap cache', async () => {
+ query.mockResolvedValueOnce({ rows: [], rowCount: 0 })
+ await listLiveCodexSubscriptionConnections({ query })
+ const sql = String(query.mock.calls[0]?.[0])
+ expect(sql).toContain('revoked_at IS NULL')
+ expect(sql).not.toContain('connection_key = $1')
+ })
+
it('inserts encrypted credentials and never binds plaintext tokens', async () => {
query.mockResolvedValueOnce({
rows: [
diff --git a/control-api/test/services.llmAllowedModelsConfigMap.test.ts b/control-api/test/services.llmAllowedModelsConfigMap.test.ts
index cc5d6e37a..849438119 100644
--- a/control-api/test/services.llmAllowedModelsConfigMap.test.ts
+++ b/control-api/test/services.llmAllowedModelsConfigMap.test.ts
@@ -4,6 +4,7 @@ import type { CodexSubscriptionSafeConnection } from '../src/services/codexSubsc
import {
ALLOWED_MODELS_CONFIGMAP_NAME,
CATALOG_REVISION_ANNOTATION,
+ CODEX_CONNECTIONS_ANNOTATION,
CODEX_CONNECTION_STATUS_ANNOTATION,
CODEX_ENABLED_ANNOTATION,
CONNECTION_REVISION_ANNOTATION,
@@ -22,7 +23,11 @@ function fakeDb(
return {
query: vi.fn().mockImplementation((sql: string) => {
if (String(sql).includes('codex_subscription_connections')) {
- return Promise.resolve({ rows: connectionRows, rowCount: connectionRows.length })
+ const liveOnly = String(sql).includes('revoked_at IS NULL')
+ const selected = liveOnly
+ ? connectionRows.filter(row => row.revoked_at == null)
+ : connectionRows
+ return Promise.resolve({ rows: selected, rowCount: selected.length })
}
return Promise.resolve({ rows, rowCount: rows.length })
}),
@@ -165,6 +170,45 @@ describe('LlmAllowedModelsConfigMapWriter', () => {
expect(JSON.stringify(arg.body.data)).not.toMatch(/catalogRevision|credentialRevision|status/)
})
+ it('indexes the live deployment-default row after 0105 reuse, not the tombstone', async () => {
+ const coreApi = {
+ createNamespacedConfigMap: vi.fn().mockResolvedValue({}),
+ readNamespacedConfigMap: vi.fn(),
+ replaceNamespacedConfigMap: vi.fn(),
+ }
+ const tombstone = {
+ ...connectedRow(),
+ id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
+ status: 'revoked',
+ credential_revision: 1,
+ catalog_revision: 1,
+ revoked_at: new Date('2026-08-21T00:00:00Z'),
+ }
+ const live = {
+ ...connectedRow(),
+ id: 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
+ credential_revision: 8,
+ catalog_revision: 9,
+ revoked_at: null,
+ }
+ const writer = new LlmAllowedModelsConfigMapWriter(coreApi, 'mcp-host')
+ const db = fakeDb(rows, [tombstone, live])
+ await writer.materialize(db)
+ const connectionSql = (db.query as ReturnType<typeof vi.fn>).mock.calls
+ .map(call => String(call[0]))
+ .find(sql => sql.includes('codex_subscription_connections'))
+ expect(connectionSql).toContain('revoked_at IS NULL')
+ const arg = coreApi.createNamespacedConfigMap.mock.calls.at(-1)?.[0]
+ expect(arg.body.metadata.annotations[CODEX_CONNECTION_STATUS_ANNOTATION]).toBe('connected')
+ expect(arg.body.metadata.annotations[CATALOG_REVISION_ANNOTATION]).toBe('9')
+ expect(arg.body.metadata.annotations[CONNECTION_REVISION_ANNOTATION]).toBe('8')
+ const map = JSON.parse(arg.body.metadata.annotations[CODEX_CONNECTIONS_ANNOTATION] as string)
+ expect(Object.keys(map)).toEqual(['deployment-default'])
+ expect(map['deployment-default'].catalogRevision).toBe(9)
+ expect(map['deployment-default'].connectionRevision).toBe(8)
+ expect(map['deployment-default'].status).toBe('connected')
+ })
+
it('falls back to read + replace on a 409 conflict', async () => {
const coreApi = {
createNamespacedConfigMap: vi
diff --git a/scripts/tests/test-codex-subscription-t0.sh b/scripts/tests/test-codex-subscription-t0.sh
index 7b35f8724..baece585f 100755
--- a/scripts/tests/test-codex-subscription-t0.sh
+++ b/scripts/tests/test-codex-subscription-t0.sh
@@ -161,6 +161,7 @@ run_group "control-api" "control-api" \
"test/hostSpecValidation.codexSubscription.test.ts" \
"test/llmProviders.test.ts" \
"test/services.codexSubscriptionConnection.test.ts" \
+ "test/services.llmAllowedModelsConfigMap.test.ts" \
"test/services.codexSubscriptionOAuth.test.ts" \
"test/services.codexSubscriptionCatalog.test.ts" \
"test/services.llmProviderAttemptAuthorizer.test.ts" \