Skip to content

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

TypeScript

fix(codex): finish ChatGPT assignment from the subscription hub

Alfredo Lopezd0c0a52d1e00
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 54a6a0334..c21e5539f 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.501",
+ "version": "0.1.502",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.501",
+ "version": "0.1.502",
"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 e1c71717b..4a24ed023 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.501",
+ "version": "0.1.502",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/codexSubscription.ts b/control-api/src/routes/admin/codexSubscription.ts
index d6bc5c9b2..b73a5c2a3 100644
--- a/control-api/src/routes/admin/codexSubscription.ts
+++ b/control-api/src/routes/admin/codexSubscription.ts
@@ -10,6 +10,8 @@ import {
type CodexCatalogTransport,
createCodexCatalogTransportFromEnv,
listCodexCatalogModels,
+ listOfferedCodexModelsForAssignment,
+ pickCodexGrantModel,
syncCodexSubscriptionCatalog,
} from '../../services/codexSubscriptionCatalog.js'
import {
@@ -127,13 +129,29 @@ type HostRecord = {
spec?: unknown
}
-function hostModel(spec: unknown): { provider?: string; connectionRef?: string } | null {
+type CodexAssignableHostRow = {
+ name: string
+ connectionRef: string
+ displayName: string
+ provider?: string
+ model?: string
+}
+
+function hostModel(
+ spec: unknown
+): { provider?: string; connectionRef?: string; name?: string } | null {
if (!spec || typeof spec !== 'object') return null
- const model = (spec as { model?: { provider?: string; connectionRef?: string } }).model
+ const model = (spec as { model?: { provider?: string; connectionRef?: string; name?: string } })
+ .model
if (!model || typeof model !== 'object') return null
return model
}
+function hostModelName(spec: unknown): string {
+ const name = hostModel(spec)?.name
+ return typeof name === 'string' ? name.trim() : ''
+}
+
function hostConnectionRef(spec: unknown): string | null {
const model = hostModel(spec)
if (!model || model.provider !== 'codex-subscription') return null
@@ -141,13 +159,23 @@ function hostConnectionRef(spec: unknown): string | null {
return raw || CODEX_UNASSIGNED_CONNECTION_KEY
}
-function assignableHostFromRecord(
- host: HostRecord
-): { name: string; connectionRef: string; displayName: string } | null {
+function assignableHostFromRecord(host: HostRecord): CodexAssignableHostRow | null {
const name = String(host.metadata?.name ?? '').trim()
- const connectionRef = hostConnectionRef(host.spec)
- if (!name || !connectionRef) return null
- return { name, connectionRef, displayName: name }
+ if (!name) return null
+ const model = hostModel(host.spec)
+ const provider = typeof model?.provider === 'string' ? model.provider.trim() : ''
+ const modelName = hostModelName(host.spec)
+ const connectionRef =
+ provider === 'codex-subscription'
+ ? hostConnectionRef(host.spec) || CODEX_UNASSIGNED_CONNECTION_KEY
+ : CODEX_UNASSIGNED_CONNECTION_KEY
+ return {
+ name,
+ connectionRef,
+ displayName: name,
+ ...(provider ? { provider } : {}),
+ ...(modelName ? { model: modelName } : {}),
+ }
}
function storedCodexConnectionRef(spec: unknown): string | null {
@@ -179,14 +207,10 @@ export function createAdminCodexSubscriptionRouter(
.filter(host => host.name)
}
- function collectAssignableHosts(
- hosts: HostRecord[]
- ): Array<{ name: string; connectionRef: string; displayName: string }> {
+ function collectAssignableHosts(hosts: HostRecord[]): CodexAssignableHostRow[] {
return hosts
.map(assignableHostFromRecord)
- .filter((row): row is { name: string; connectionRef: string; displayName: string } =>
- Boolean(row)
- )
+ .filter((row): row is CodexAssignableHostRow => Boolean(row))
}
async function loadHost(
@@ -219,7 +243,7 @@ export function createAdminCodexSubscriptionRouter(
host: HostRecord,
nextConnectionRef: string
): Promise<
- | { ok: true; warnings: StaleModelWarning[] }
+ | { ok: true; warnings: StaleModelWarning[]; model: string }
| { ok: false; status: number; error: string; message?: string; reason?: string }
> {
if (!gateway) return { ok: false, status: 503, error: 'hosts_unavailable' }
@@ -233,6 +257,21 @@ export function createAdminCodexSubscriptionRouter(
: {}
model.provider = 'codex-subscription'
model.connectionRef = nextConnectionRef
+ let resolvedModel = typeof model.name === 'string' ? model.name.trim() : ''
+ if (nextConnectionRef !== CODEX_UNASSIGNED_CONNECTION_KEY) {
+ const offered = await listOfferedCodexModelsForAssignment(dbClient(), nextConnectionRef)
+ if (offered.length === 0) {
+ return {
+ ok: false,
+ status: 422,
+ error: 'catalog_not_ready',
+ message:
+ 'This subscription has no offered models yet. Sign in and sync the catalog before assigning agents.',
+ }
+ }
+ resolvedModel = pickCodexGrantModel(resolvedModel, offered)
+ model.name = resolvedModel
+ }
spec.model = model
const stored =
host.spec && typeof host.spec === 'object'
@@ -267,7 +306,7 @@ export function createAdminCodexSubscriptionRouter(
config.hostsNamespace
)
for (const event of hostTolerations) emitHostSpecIncoherenceTolerated(event)
- return { ok: true, warnings: hostWarnings }
+ return { ok: true, warnings: hostWarnings, model: resolvedModel }
} catch (err) {
if (err instanceof K8sConflictError) {
return { ok: false, status: 409, error: 'conflict', reason: 'resource_changed' }
@@ -600,18 +639,22 @@ export function createAdminCodexSubscriptionRouter(
return
}
const storedRef = storedCodexConnectionRef(loaded.host.spec)
- if (storedRef === null) {
+ if (storedRef === null && action === 'unbind') {
res.status(409).json({ error: 'not_codex_host' })
return
}
// Empty/missing connectionRef is unassigned, never the reserved default grant.
+ // Non-Codex hosts bind as a conversion: the hub is the ops center that
+ // sets provider, grant, and a seeded default model in one write.
const currentRef = storedRef || CODEX_UNASSIGNED_CONNECTION_KEY
+ const currentModel = hostModelName(loaded.host.spec)
if (action === 'unbind') {
if (currentRef === CODEX_UNASSIGNED_CONNECTION_KEY) {
res.status(200).json({
host: hostRef,
connectionRef: CODEX_UNASSIGNED_CONNECTION_KEY,
+ ...(currentModel ? { model: currentModel } : {}),
})
return
}
@@ -635,13 +678,18 @@ export function createAdminCodexSubscriptionRouter(
res.status(200).json({
host: hostRef,
connectionRef: CODEX_UNASSIGNED_CONNECTION_KEY,
+ ...(written.model ? { model: written.model } : {}),
...(written.warnings.length > 0 ? { warnings: written.warnings } : {}),
})
return
}
- if (currentRef === connectionKey) {
- res.status(200).json({ host: hostRef, connectionRef: connectionKey })
+ if (currentRef === connectionKey && currentModel) {
+ res.status(200).json({
+ host: hostRef,
+ connectionRef: connectionKey,
+ model: currentModel,
+ })
return
}
const written = await writeHostConnectionRef(hostRef, loaded.host, connectionKey)
@@ -656,6 +704,7 @@ export function createAdminCodexSubscriptionRouter(
res.status(200).json({
host: hostRef,
connectionRef: connectionKey,
+ ...(written.model ? { model: written.model } : {}),
...(written.warnings.length > 0 ? { warnings: written.warnings } : {}),
})
})
diff --git a/control-api/src/services/codexSubscriptionCatalog.ts b/control-api/src/services/codexSubscriptionCatalog.ts
index eb7e25832..17e5e6b9d 100644
--- a/control-api/src/services/codexSubscriptionCatalog.ts
+++ b/control-api/src/services/codexSubscriptionCatalog.ts
@@ -176,6 +176,38 @@ export async function isCodexAssignmentAllowed(
return Boolean(state?.enabled && !state.stale)
}
+/**
+ * ChatGPT bind still needs a concrete spec.model.name. Keep the current name
+ * only when that grant already offers it. Otherwise seed the first offered
+ * model — never invent deployment-default or a global allowlist default.
+ */
+export function pickCodexGrantModel(current: string, offered: string[]): string {
+ const trimmed = current.trim()
+ if (trimmed && offered.includes(trimmed)) return trimmed
+ return offered[0] ?? trimmed
+}
+
+/** Enabled, non-stale models on a connected grant whose catalog is ready. */
+export async function listOfferedCodexModelsForAssignment(
+ db: DbClient,
+ connectionKey: string
+): Promise<string[]> {
+ const result = await db.query(
+ `SELECT m.model
+ FROM codex_catalog_models m
+ JOIN codex_subscription_connections c ON c.id = m.connection_id
+ WHERE c.connection_key = $1
+ AND c.revoked_at IS NULL
+ AND c.status = 'connected'
+ AND c.catalog_status = 'ready'
+ AND m.enabled
+ AND m.stale = false
+ ORDER BY m.model ASC`,
+ [connectionKey]
+ )
+ return (result.rows as Array<{ model: string }>).map(row => String(row.model))
+}
+
export async function listEnabledCodexModelsGroupedByConnection(
db: DbClient
): Promise<Record<string, string[]>> {
diff --git a/control-api/test/routes.admin.codexSubscription.hostWrite.test.ts b/control-api/test/routes.admin.codexSubscription.hostWrite.test.ts
index 695b45ad2..5a78d7d0a 100644
--- a/control-api/test/routes.admin.codexSubscription.hostWrite.test.ts
+++ b/control-api/test/routes.admin.codexSubscription.hostWrite.test.ts
@@ -5,6 +5,7 @@ import { createCodexCatalogTransportFromEnv } from '../src/services/codexSubscri
const assignment = vi.hoisted(() => ({
isCodexAssignmentAllowed: vi.fn(),
+ listOfferedCodexModelsForAssignment: vi.fn(),
}))
vi.mock('../src/services/codexSubscriptionCatalog.js', async () => {
@@ -12,6 +13,7 @@ vi.mock('../src/services/codexSubscriptionCatalog.js', async () => {
return {
...actual,
isCodexAssignmentAllowed: assignment.isCodexAssignmentAllowed,
+ listOfferedCodexModelsForAssignment: assignment.listOfferedCodexModelsForAssignment,
}
})
@@ -53,6 +55,8 @@ describe('admin Codex bind/unbind host write contract', () => {
process.env.CONTROL_API_CODEX_SUBSCRIPTION_ENABLED = 'true'
assignment.isCodexAssignmentAllowed.mockReset()
assignment.isCodexAssignmentAllowed.mockResolvedValue(true)
+ assignment.listOfferedCodexModelsForAssignment.mockReset()
+ assignment.listOfferedCodexModelsForAssignment.mockResolvedValue(['gpt-5.6-luna'])
})
afterEach(() => {
@@ -73,8 +77,13 @@ describe('admin Codex bind/unbind host write contract', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/unbind'
)
expect(res.status).toBe(200)
- expect(res.body).toEqual({ host: 'chatllm', connectionRef: 'unassigned' })
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'unassigned',
+ model: 'gpt-5.6-luna',
+ })
expect(assignment.isCodexAssignmentAllowed).not.toHaveBeenCalled()
+ expect(assignment.listOfferedCodexModelsForAssignment).not.toHaveBeenCalled()
expect(gateway.updateResource).toHaveBeenCalled()
})
@@ -95,7 +104,11 @@ describe('admin Codex bind/unbind host write contract', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
)
expect(res.status).toBe(200)
- expect(res.body).toEqual({ host: 'chatllm', connectionRef: 'codex-aaa' })
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.6-luna',
+ })
expect(assignment.isCodexAssignmentAllowed).toHaveBeenCalledWith(
expect.anything(),
'codex-aaa',
@@ -103,8 +116,78 @@ describe('admin Codex bind/unbind host write contract', () => {
)
})
- it('returns 422 when the destination grant does not offer the model', async () => {
- assignment.isCodexAssignmentAllowed.mockResolvedValue(false)
+ it('seeds the first offered model when the Host has no name', async () => {
+ assignment.listOfferedCodexModelsForAssignment.mockResolvedValue(['gpt-5.1', 'gpt-5.6-luna'])
+ const gateway = makeGateway()
+ gateway.getResource.mockResolvedValue({
+ metadata: { name: 'chatllm', resourceVersion: '12' },
+ spec: {
+ model: { provider: 'codex-subscription', connectionRef: 'unassigned' },
+ },
+ })
+ gateway.updateResource.mockResolvedValue({})
+ const res = await request(makeAuthedApp(gateway)).post(
+ '/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
+ )
+ expect(res.status).toBe(200)
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
+ expect(gateway.updateResource).toHaveBeenCalledWith(
+ 'hosts',
+ 'chatllm',
+ expect.objectContaining({
+ spec: expect.objectContaining({
+ model: expect.objectContaining({
+ provider: 'codex-subscription',
+ connectionRef: 'codex-aaa',
+ name: 'gpt-5.1',
+ }),
+ }),
+ }),
+ expect.any(String)
+ )
+ expect(assignment.isCodexAssignmentAllowed).toHaveBeenCalledWith(
+ expect.anything(),
+ 'codex-aaa',
+ 'gpt-5.1'
+ )
+ })
+
+ it('rematches to an offered model instead of 422 when the current name is not on the grant', async () => {
+ assignment.listOfferedCodexModelsForAssignment.mockResolvedValue(['gpt-5.1'])
+ const gateway = makeGateway()
+ gateway.getResource.mockResolvedValue({
+ metadata: { name: 'chatllm' },
+ spec: {
+ model: {
+ provider: 'codex-subscription',
+ name: 'gpt-5.6-luna',
+ connectionRef: 'unassigned',
+ },
+ },
+ })
+ gateway.updateResource.mockResolvedValue({})
+ const res = await request(makeAuthedApp(gateway)).post(
+ '/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
+ )
+ expect(res.status).toBe(200)
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
+ expect(assignment.isCodexAssignmentAllowed).toHaveBeenCalledWith(
+ expect.anything(),
+ 'codex-aaa',
+ 'gpt-5.1'
+ )
+ })
+
+ it('returns 422 when the destination grant has no offered models', async () => {
+ assignment.listOfferedCodexModelsForAssignment.mockResolvedValue([])
const gateway = makeGateway()
gateway.getResource.mockResolvedValue({
metadata: { name: 'chatllm' },
@@ -120,7 +203,66 @@ describe('admin Codex bind/unbind host write contract', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
)
expect(res.status).toBe(422)
- expect(res.body.error).toBe('invalid_host_spec')
+ expect(res.body.error).toBe('catalog_not_ready')
expect(gateway.updateResource).not.toHaveBeenCalled()
+ expect(assignment.isCodexAssignmentAllowed).not.toHaveBeenCalled()
+ })
+
+ it('converts a non-Codex host and seeds the grant default model', async () => {
+ assignment.listOfferedCodexModelsForAssignment.mockResolvedValue(['gpt-5.1'])
+ const gateway = makeGateway()
+ gateway.getResource.mockResolvedValue({
+ metadata: { name: 'api-agent', resourceVersion: '4' },
+ spec: { model: { provider: 'openai', name: 'gpt-5.4' }, secretRef: 'openai-secret' },
+ })
+ gateway.updateResource.mockResolvedValue({})
+ const res = await request(makeAuthedApp(gateway)).post(
+ '/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/api-agent/bind'
+ )
+ expect(res.status).toBe(200)
+ expect(res.body).toEqual({
+ host: 'api-agent',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
+ expect(gateway.updateResource).toHaveBeenCalledWith(
+ 'hosts',
+ 'api-agent',
+ expect.objectContaining({
+ spec: expect.objectContaining({
+ model: expect.objectContaining({
+ provider: 'codex-subscription',
+ connectionRef: 'codex-aaa',
+ name: 'gpt-5.1',
+ }),
+ }),
+ }),
+ expect.any(String)
+ )
+ })
+
+ it('completes an already-bound Host that is missing spec.model.name', async () => {
+ assignment.listOfferedCodexModelsForAssignment.mockResolvedValue(['gpt-5.1'])
+ const gateway = makeGateway()
+ gateway.getResource.mockResolvedValue({
+ metadata: { name: 'chatllm' },
+ spec: {
+ model: {
+ provider: 'codex-subscription',
+ connectionRef: 'codex-aaa',
+ },
+ },
+ })
+ gateway.updateResource.mockResolvedValue({})
+ const res = await request(makeAuthedApp(gateway)).post(
+ '/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
+ )
+ expect(res.status).toBe(200)
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
+ expect(gateway.updateResource).toHaveBeenCalled()
})
})
diff --git a/control-api/test/routes.admin.codexSubscription.test.ts b/control-api/test/routes.admin.codexSubscription.test.ts
index 13c6d2238..652efd169 100644
--- a/control-api/test/routes.admin.codexSubscription.test.ts
+++ b/control-api/test/routes.admin.codexSubscription.test.ts
@@ -16,6 +16,7 @@ const oauth = vi.hoisted(() => ({
const catalog = vi.hoisted(() => ({
loadSecrets: vi.fn(),
sync: vi.fn(),
+ listOffered: vi.fn(),
}))
vi.mock('../src/services/codexSubscriptionOAuth.js', async () => {
@@ -44,6 +45,7 @@ vi.mock('../src/services/codexSubscriptionCatalog.js', async () => {
return {
...actual,
syncCodexSubscriptionCatalog: catalog.sync,
+ listOfferedCodexModelsForAssignment: catalog.listOffered,
}
})
@@ -138,6 +140,8 @@ describe('admin Codex subscription routes', () => {
for (const fn of Object.values(oauth)) fn.mockReset()
catalog.loadSecrets.mockReset()
catalog.sync.mockReset()
+ catalog.listOffered.mockReset()
+ catalog.listOffered.mockResolvedValue(['gpt-5.1'])
vi.mocked(pool.query).mockReset()
})
@@ -473,8 +477,25 @@ describe('admin Codex subscription routes', () => {
)
expect(res.status).toBe(200)
expect(res.body.assignableHosts).toEqual([
- { name: 'chatllm', connectionRef: 'codex-aaa', displayName: 'chatllm' },
- { name: 'legacy', connectionRef: 'unassigned', displayName: 'legacy' },
+ {
+ name: 'chatllm',
+ connectionRef: 'codex-aaa',
+ displayName: 'chatllm',
+ provider: 'codex-subscription',
+ },
+ {
+ name: 'other',
+ connectionRef: 'unassigned',
+ displayName: 'other',
+ provider: 'openai',
+ model: 'gpt-5.4',
+ },
+ {
+ name: 'legacy',
+ connectionRef: 'unassigned',
+ displayName: 'legacy',
+ provider: 'codex-subscription',
+ },
])
})
@@ -491,7 +512,11 @@ describe('admin Codex subscription routes', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/unbind'
)
expect(res.status).toBe(200)
- expect(res.body).toEqual({ host: 'chatllm', connectionRef: 'unassigned' })
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'unassigned',
+ model: 'gpt-5.6-luna',
+ })
expect(oauth.revoke).not.toHaveBeenCalled()
expect(gateway.updateResource).toHaveBeenCalledWith(
'hosts',
@@ -545,7 +570,11 @@ describe('admin Codex subscription routes', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
)
expect(first.status).toBe(200)
- expect(first.body).toEqual({ host: 'chatllm', connectionRef: 'codex-aaa' })
+ expect(first.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
gateway.getResource.mockResolvedValueOnce({
metadata: { name: 'chatllm' },
@@ -557,7 +586,11 @@ describe('admin Codex subscription routes', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
)
expect(switched.status).toBe(200)
- expect(switched.body).toEqual({ host: 'chatllm', connectionRef: 'codex-aaa' })
+ expect(switched.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
expect(oauth.revoke).not.toHaveBeenCalled()
})
@@ -572,7 +605,11 @@ describe('admin Codex subscription routes', () => {
'/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/chatllm/bind'
)
expect(res.status).toBe(200)
- expect(res.body).toEqual({ host: 'chatllm', connectionRef: 'codex-aaa' })
+ expect(res.body).toEqual({
+ host: 'chatllm',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
expect(oauth.revoke).not.toHaveBeenCalled()
})
@@ -591,14 +628,14 @@ describe('admin Codex subscription routes', () => {
expect(gateway.updateResource).not.toHaveBeenCalled()
})
- it('rejects bind on a non-Codex host', async () => {
+ it('rejects unbind on a non-Codex host', async () => {
const gateway = makeGateway()
gateway.getResource.mockResolvedValue({
metadata: { name: 'api-agent' },
spec: { model: { provider: 'openai', name: 'gpt-5.4' } },
})
const res = await request(makeAuthedApp(gateway)).post(
- '/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/api-agent/bind'
+ '/admin/llm/providers/codex-subscription/connections/codex-aaa/hosts/api-agent/unbind'
)
expect(res.status).toBe(409)
expect(res.body).toEqual({ error: 'not_codex_host' })
diff --git a/control-api/test/services.codexSubscriptionCatalog.test.ts b/control-api/test/services.codexSubscriptionCatalog.test.ts
index c1224f018..b52c24dd4 100644
--- a/control-api/test/services.codexSubscriptionCatalog.test.ts
+++ b/control-api/test/services.codexSubscriptionCatalog.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest'
import {
createCodexCatalogTransportFromEnv,
createCodexProxyCatalogTransport,
+ pickCodexGrantModel,
planCodexCatalogReconcile,
syncCodexSubscriptionCatalog,
} from '../src/services/codexSubscriptionCatalog.js'
@@ -9,6 +10,22 @@ import { listEnabledGroupedByProvider } from '../src/services/llmAllowedModels.j
import { buildConfigMapData } from '../src/services/llmAllowedModelsConfigMap.js'
import { makeFakeDb } from './helpers/llmCatalogSyncFakeDb.js'
+describe('pickCodexGrantModel', () => {
+ it('keeps the current name when the grant already offers it', () => {
+ expect(pickCodexGrantModel('gpt-5.1', ['gpt-5.1', 'gpt-5.2'])).toBe('gpt-5.1')
+ })
+
+ it('seeds the first offered model when the current name is empty or not offered', () => {
+ expect(pickCodexGrantModel('', ['gpt-5.1', 'gpt-5.2'])).toBe('gpt-5.1')
+ expect(pickCodexGrantModel('gpt-5.4-mini', ['gpt-5.6-luna'])).toBe('gpt-5.6-luna')
+ })
+
+ it('does not invent a model when the grant list is empty', () => {
+ expect(pickCodexGrantModel('gpt-5.4-mini', [])).toBe('gpt-5.4-mini')
+ expect(pickCodexGrantModel('', [])).toBe('')
+ })
+})
+
describe('planCodexCatalogReconcile', () => {
it('ready upserts discovered rows, inserts disabled, and stales missing discovery models', () => {
const plan = planCodexCatalogReconcile(
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index cf01288fd..256ede412 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -12509,6 +12509,12 @@ button.cu-gfs-tree__button:focus-visible,
text-decoration: underline;
}
+.cu-codex-hub__agent-model {
+ color: var(--cu-text-muted);
+ font-weight: 400;
+ font-size: 0.85em;
+}
+
.cu-codex-hub__chip-remove {
display: inline-grid;
place-items: center;
diff --git a/control-ui/app/hosts/[name]/page.tsx b/control-ui/app/hosts/[name]/page.tsx
index b4acf4315..9e6f75852 100644
--- a/control-ui/app/hosts/[name]/page.tsx
+++ b/control-ui/app/hosts/[name]/page.tsx
@@ -16,7 +16,11 @@ import { LlmProviderConfig } from '../../../components/LlmProviderConfig'
import { IconRobot } from '../../../components/Sidebar/icons'
import { IconCheck, IconPencil, IconX } from '../../../components/icons'
import { apiSend, getHost, getHostDetailBundle } from '../../../lib/api'
-import { CODEX_UNASSIGNED_CONNECTION_KEY } from '../../../lib/codexSubscription'
+import {
+ CODEX_UNASSIGNED_CONNECTION_KEY,
+ type CodexSubscriptionConnectionView,
+ listCodexSubscriptionConnections,
+} from '../../../lib/codexSubscription'
import { useLlmAllowedModels } from '../../../lib/hooks/useLlmAllowedModels'
import { FIRST_PARTY_CHANNEL_WORKFLOW_CONTROL_SCOPES } from '../../../lib/hostWorkflowControl'
import {
@@ -139,6 +143,7 @@ export default function HostDetailsPage() {
const [modelNameDraft, setModelNameDraft] = useState('')
const [connectionRefDraft, setConnectionRefDraft] = useState(CODEX_UNASSIGNED_CONNECTION_KEY)
const [codexModels, setCodexModels] = useState<string[]>([])
+ const [codexConnections, setCodexConnections] = useState<CodexSubscriptionConnectionView[]>([])
const catalogForEditor = useMemo(() => {
if (providerDraft !== 'codex-subscription' || codexModels.length === 0) return allowedCatalog
const others = allowedCatalog.filter(row => row.provider !== 'codex-subscription')
@@ -241,6 +246,24 @@ export default function HostDetailsPage() {
}
}, [allowedModelsDraft, catalogForEditor, modelNameDraft, providerDraft, providerModelOptions])
+ useEffect(() => {
+ if (providerDraft !== 'codex-subscription') {
+ setCodexConnections([])
+ return
+ }
+ let cancelled = false
+ void listCodexSubscriptionConnections()
+ .then(rows => {
+ if (!cancelled) setCodexConnections(rows)
+ })
+ .catch(() => {
+ if (!cancelled) setCodexConnections([])
+ })
+ return () => {
+ cancelled = true
+ }
+ }, [providerDraft])
+
useEffect(() => {
setActiveTab(parseHostTab(params.tab))
}, [params.tab])
@@ -1032,13 +1055,20 @@ export default function HostDetailsPage() {
{providerDraft === 'codex-subscription' ? (
<div className="cu-field">
<label htmlFor="model-subscription">Subscription</label>
- <div className="cu-field__readonly">
+ <div className="cu-field__readonly" id="model-subscription">
{connectionRefDraft === CODEX_UNASSIGNED_CONNECTION_KEY
? 'No subscription assigned'
- : connectionRefDraft}
+ : codexConnections.find(row => row.connectionKey === connectionRefDraft)
+ ?.displayName || connectionRefDraft}
</div>
</div>
) : null}
+ <div className="cu-field">
+ <label htmlFor="model-name">Default model</label>
+ <div className="cu-field__readonly" id="model-name">
+ {modelNameDraft || 'Not set'}
+ </div>
+ </div>
<div className="cu-field">
<label htmlFor="model-allowed">Allowed models</label>
{allowedModelsSummary.length > 0 ? (
@@ -1126,6 +1156,7 @@ export default function HostDetailsPage() {
<LlmProviderConfig
provider={providerDraft}
model={modelNameDraft}
+ modelLabel="Default model"
subscriptionCredentialEnabled
afterPrimaryProvider={
providerDraft === 'codex-subscription' ? (
diff --git a/control-ui/components/CodexSubscriptionHub/index.tsx b/control-ui/components/CodexSubscriptionHub/index.tsx
index ccb9db1de..dc9134f48 100644
--- a/control-ui/components/CodexSubscriptionHub/index.tsx
+++ b/control-ui/components/CodexSubscriptionHub/index.tsx
@@ -19,6 +19,7 @@ import {
isCodexSubscriptionUiEnabled,
loadCodexSubscriptionCapability,
} from '@lib/codexSubscriptionFeature'
+import { getProviderLabel } from '@lib/llm'
import {
mapConnectionStatus,
statusLabel,
@@ -46,12 +47,25 @@ function otherGrantLabel(
return connections.find(row => row.connectionKey === connectionRef)?.displayName || connectionRef
}
+function isNonCodexHost(host: CodexAssignableHost): boolean {
+ return Boolean(host.provider && host.provider !== 'codex-subscription')
+}
+
function assignmentCaption(
host: CodexAssignableHost,
connections: CodexSubscriptionConnectionView[]
): string {
+ if (isNonCodexHost(host)) {
+ return [getProviderLabel(host.provider), host.model].filter(Boolean).join(' · ')
+ }
if (host.connectionRef === 'unassigned') return 'No subscription'
- return otherGrantLabel(connections, host.connectionRef)
+ const grant = otherGrantLabel(connections, host.connectionRef)
+ return host.model ? `${grant} · ${host.model}` : grant
+}
+
+function assignmentBadge(host: CodexAssignableHost): string {
+ if (isNonCodexHost(host)) return 'other provider'
+ return host.connectionRef === 'unassigned' ? 'unassigned' : 'other grant'
}
export function CodexSubscriptionHub() {
@@ -216,18 +230,35 @@ export function CodexSubscriptionHub() {
hosts: CodexAssignableHost[]
) {
if (hosts.length === 0) return
+ const converting = hosts.filter(isNonCodexHost)
const switching = hosts.filter(
- host => host.connectionRef !== 'unassigned' && host.connectionRef !== row.connectionKey
+ host =>
+ !isNonCodexHost(host) &&
+ host.connectionRef !== 'unassigned' &&
+ host.connectionRef !== row.connectionKey
)
- if (switching.length > 0) {
+ if (converting.length > 0 || switching.length > 0) {
+ const convertingNames = converting.map(host => hostLabel(host)).join(', ')
+ const switchingNames = switching.map(host => hostLabel(host)).join(', ')
const confirmed = await confirm({
title:
- hosts.length === 1
- ? `Switch ${hosts[0].name} to this subscription?`
- : `Add ${hosts.length} agents to this subscription?`,
- message: `${switching.map(host => hostLabel(host)).join(', ')} currently use another grant. Assign ${
- hosts.length === 1 ? 'it' : 'them'
- } to "${grantLabel(row)}"?`,
+ hosts.length === 1 && converting.length === 1
+ ? `Switch ${hosts[0].name} to ChatGPT?`
+ : hosts.length === 1
+ ? `Switch ${hosts[0].name} to this subscription?`
+ : `Add ${hosts.length} agents to this subscription?`,
+ message: [
+ converting.length > 0
+ ? `${convertingNames} will switch to ChatGPT on "${grantLabel(row)}". This sets the provider, subscription, and a default model from this grant.`
+ : '',
+ switching.length > 0
+ ? `${switchingNames} currently use another grant. Assign ${
+ switching.length === 1 ? 'it' : 'them'
+ } to "${grantLabel(row)}"?`
+ : '',
+ ]
+ .filter(Boolean)
+ .join(' '),
confirmLabel: hosts.length === 1 ? 'Assign agent' : `Add ${hosts.length} agents`,
})
if (!confirmed) return
@@ -235,11 +266,13 @@ export function CodexSubscriptionHub() {
setBusyKey(row.connectionKey)
const assigned: string[] = []
const failed: string[] = []
+ let lastModel = ''
try {
for (const host of hosts) {
try {
- await bindCodexHost(row.connectionKey, host.name)
+ const written = await bindCodexHost(row.connectionKey, host.name)
assigned.push(hostLabel(host))
+ if (written.model) lastModel = written.model
} catch (err) {
failed.push(hostLabel(host))
showToast(err instanceof Error ? err.message : `Could not assign ${hostLabel(host)}`, {
@@ -249,10 +282,11 @@ export function CodexSubscriptionHub() {
}
setPickedByGrant(prev => ({ ...prev, [row.connectionKey]: [] }))
await load()
+ const modelSuffix = lastModel && assigned.length === 1 ? ` · ${lastModel}` : ''
if (assigned.length > 0 && failed.length === 0) {
showToast(
assigned.length === 1
- ? `Assigned ${assigned[0]} to ${grantLabel(row)}`
+ ? `Assigned ${assigned[0]} to ${grantLabel(row)}${modelSuffix}`
: `Assigned ${assigned.length} agents to ${grantLabel(row)}`,
{ tone: 'success' }
)
@@ -271,7 +305,7 @@ export function CodexSubscriptionHub() {
{confirmDialog}
<TablePanelHeader
title="Subscriptions"
- subtitle="ChatGPT grants in the same table as other Secrets. Assign any number of agents per row."
+ subtitle="Assign agents here to connect a grant and set a default ChatGPT model. Models & creds edits one agent at a time."
actions={
<button
type="button"
@@ -410,9 +444,12 @@ export function CodexSubscriptionHub() {
>
{assigned.map(host => (
<span key={host.name} className="cu-chip cu-codex-hub__agent-chip">
- <a href={CONTROL_ROUTES.agents.detail(host.name)}>
+ <a href={CONTROL_ROUTES.agents.tab(host.name, 'model')}>
{hostLabel(host)}
</a>
+ {host.model ? (
+ <span className="cu-codex-hub__agent-model">{host.model}</span>
+ ) : null}
<button
type="button"
className="cu-codex-hub__chip-remove"
@@ -448,15 +485,12 @@ export function CodexSubscriptionHub() {
value: host.name,
label: hostLabel(host),
description: assignmentCaption(host, connections),
- badge:
- host.connectionRef === 'unassigned'
- ? 'unassigned'
- : 'other grant',
+ badge: assignmentBadge(host),
}))}
placeholder="Add agents…"
searchPlaceholder="Search agents…"
selectionLabel="agents"
- emptyLabel="No ChatGPT-capable agents available."
+ emptyLabel="No agents available."
disabled={busy || hostsUnavailable || row.status === 'revoked'}
onChange={next =>
setPickedByGrant(prev => ({
diff --git a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
index b675892f9..3d566e61e 100644
--- a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
+++ b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
@@ -67,7 +67,13 @@ describe('CodexSubscriptionHub', () => {
vi.mocked(listCodexSubscriptionFleet).mockResolvedValue({
connections: [connection({ connectionKey: 'codex-aaa', displayName: 'Team A' })],
assignableHosts: [
- { name: 'chatllm', connectionRef: 'codex-aaa', displayName: 'chatllm' },
+ {
+ name: 'chatllm',
+ connectionRef: 'codex-aaa',
+ displayName: 'chatllm',
+ provider: 'codex-subscription',
+ model: 'gpt-5.1',
+ },
{ name: 'writer', connectionRef: 'unassigned', displayName: 'writer' },
{ name: 'researcher', connectionRef: 'unassigned', displayName: 'researcher' },
],
@@ -113,6 +119,7 @@ describe('CodexSubscriptionHub', () => {
expect(screen.getByRole('columnheader', { name: 'Status' })).toBeInTheDocument()
expect(screen.getByRole('columnheader', { name: 'Agents' })).toBeInTheDocument()
expect(screen.getByRole('link', { name: 'chatllm' })).toBeInTheDocument()
+ expect(screen.getByText('gpt-5.1')).toBeInTheDocument()
expect(screen.queryByRole('heading', { name: 'Available' })).not.toBeInTheDocument()
expect(screen.queryByRole('heading', { name: 'Assigned' })).not.toBeInTheDocument()
expect(document.querySelectorAll('.cu-llm-config__block').length).toBe(0)
@@ -120,7 +127,11 @@ describe('CodexSubscriptionHub', () => {
})
it('assigns one available agent without revoking', async () => {
- vi.mocked(bindCodexHost).mockResolvedValue({ host: 'writer', connectionRef: 'codex-aaa' })
+ vi.mocked(bindCodexHost).mockResolvedValue({
+ host: 'writer',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
render(
<ToastProvider>
<CodexSubscriptionHub />
@@ -220,6 +231,47 @@ describe('CodexSubscriptionHub', () => {
expect(revokeCodexSubscription).not.toHaveBeenCalled()
})
+ it('confirms before switching a non-Codex agent to ChatGPT', async () => {
+ confirmMock.mockResolvedValue(true)
+ vi.mocked(listCodexSubscriptionFleet).mockResolvedValue({
+ connections: [connection({ connectionKey: 'codex-aaa', displayName: 'Team A' })],
+ assignableHosts: [
+ {
+ name: 'writer',
+ connectionRef: 'unassigned',
+ displayName: 'writer',
+ provider: 'zai',
+ model: 'glm-4.7',
+ },
+ ],
+ assignableHostsUnavailable: false,
+ })
+ vi.mocked(bindCodexHost).mockResolvedValue({
+ host: 'writer',
+ connectionRef: 'codex-aaa',
+ model: 'gpt-5.1',
+ })
+ render(
+ <ToastProvider>
+ <CodexSubscriptionHub />
+ </ToastProvider>
+ )
+ await waitFor(() => {
+ expect(screen.getByLabelText('Add agents to this subscription')).toBeInTheDocument()
+ })
+ fireEvent.click(screen.getByLabelText('Add agents to this subscription'))
+ fireEvent.click(screen.getByRole('option', { name: 'writer' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Add agents' }))
+ await waitFor(() => {
+ expect(confirmMock).toHaveBeenCalledWith(
+ expect.objectContaining({
+ title: 'Switch writer to ChatGPT?',
+ })
+ )
+ })
+ expect(bindCodexHost).toHaveBeenCalledWith('codex-aaa', 'writer')
+ })
+
it('unbinds an assigned agent without revoking', async () => {
confirmMock.mockResolvedValue(true)
vi.mocked(unbindCodexHost).mockResolvedValue({
diff --git a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
index 68fe598c9..d480c7a73 100644
--- a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
+++ b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
@@ -4,6 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render as rtlRender, screen, waitFor } from '@testing-library/react'
import HostDetailsPage from '../../app/hosts/[name]/page'
import * as api from '../../lib/api'
+import { listCodexSubscriptionConnections } from '../../lib/codexSubscription'
import { ToastProvider } from '../Toast'
const replaceMock = vi.fn()
@@ -41,6 +42,14 @@ vi.mock('../HostAccessTab', () => ({
),
}))
+vi.mock('../../lib/codexSubscription', async importOriginal => {
+ const actual = await importOriginal<typeof import('../../lib/codexSubscription')>()
+ return {
+ ...actual,
+ listCodexSubscriptionConnections: vi.fn().mockResolvedValue([]),
+ }
+})
+
vi.mock('../../lib/api', () => ({
apiGet: vi.fn(),
apiSend: vi.fn(),
@@ -133,6 +142,8 @@ describe('HostDetailsPage identity integration', () => {
const { container } = render(<HostDetailsPage />)
expect(await screen.findByText('Allowed models')).toBeInTheDocument()
+ expect(screen.getByText('Default model')).toBeInTheDocument()
+ expect(screen.getByText('gpt-5.4')).toBeInTheDocument()
expect(screen.queryByText('Model name')).not.toBeInTheDocument()
expect(screen.getByText('Secret reference')).toBeInTheDocument()
expect(container.querySelector('.cu-agent-detail-card')).toBeNull()
@@ -152,6 +163,54 @@ describe('HostDetailsPage identity integration', () => {
expect(container.querySelector('.cu-agent-detail-card .cu-agent-detail-scroll')).not.toBeNull()
})
+ it('shows a complete ChatGPT assignment without requiring Edit', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ vi.mocked(listCodexSubscriptionConnections).mockResolvedValue([
+ {
+ connectionKey: 'codex-aaa',
+ displayName: 'Team A',
+ status: 'connected',
+ credentialRevision: 1,
+ catalogRevision: 1,
+ accountFingerprint: 'fp',
+ catalogStatus: 'ready',
+ catalogSyncedAt: '2026-08-20T00:00:00.000Z',
+ lastRefreshAt: '2026-08-20T00:00:00.000Z',
+ lastAuthAt: '2026-08-20T00:00:00.000Z',
+ refreshLockHeld: false,
+ },
+ ])
+ const codexHost = {
+ ...host,
+ spec: {
+ ...host.spec,
+ secretRef: undefined,
+ model: {
+ provider: 'codex-subscription',
+ name: 'gpt-5.1',
+ connectionRef: 'codex-aaa',
+ },
+ },
+ }
+ ;(api.getHostDetailBundle as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ host: codexHost,
+ contexts: [{ metadata: { name: 'ctx' }, spec: { contextId: 'ctx' } }],
+ secrets: [],
+ users: [],
+ teams: [],
+ agentUsers: [],
+ agentTeams: [],
+ })
+ render(<HostDetailsPage />)
+
+ expect(await screen.findByText('Default model')).toBeInTheDocument()
+ expect(screen.getByText('gpt-5.1')).toBeInTheDocument()
+ expect(screen.getByText('Team A')).toBeInTheDocument()
+ expect(screen.queryByText('codex-aaa')).not.toBeInTheDocument()
+ expect(screen.getByText('Broker-backed — no LLM secret required')).toBeInTheDocument()
+ expect(screen.queryByRole('button', { name: 'Save' })).not.toBeInTheDocument()
+ })
+
it('opens Advanced on the Hooks sub-tab', async () => {
mockParams = { name: 'foo', tab: 'advanced' }
render(<HostDetailsPage />)
diff --git a/control-ui/lib/codexSubscription.ts b/control-ui/lib/codexSubscription.ts
index 186dedb5e..f0d9d826c 100644
--- a/control-ui/lib/codexSubscription.ts
+++ b/control-ui/lib/codexSubscription.ts
@@ -19,6 +19,8 @@ export type CodexAssignableHost = {
name: string
connectionRef: string
displayName?: string
+ provider?: string
+ model?: string
}
export const CODEX_UNASSIGNED_CONNECTION_KEY = 'unassigned'
@@ -228,7 +230,15 @@ function sanitizeAssignableHost(raw: unknown): CodexAssignableHost | null {
const name = pickString(raw.name)
const connectionRef = pickString(raw.connectionRef)
if (!name || !connectionRef) return null
- return { name, connectionRef, displayName: pickString(raw.displayName) ?? name }
+ const provider = pickString(raw.provider)
+ const model = pickString(raw.model)
+ return {
+ name,
+ connectionRef,
+ displayName: pickString(raw.displayName) ?? name,
+ ...(provider ? { provider } : {}),
+ ...(model ? { model } : {}),
+ }
}
export async function listCodexSubscriptionConnections(): Promise<
@@ -267,25 +277,28 @@ export async function listCodexSubscriptionFleet(): Promise<{
export async function unbindCodexHost(
connectionKey: string,
hostRef: string
-): Promise<{ host: string; connectionRef: string }> {
+): Promise<{ host: string; connectionRef: string; model?: string }> {
const raw = (await apiSend(
'POST',
`${CODEX_SUBSCRIPTION_API_BASE}/connections/${encodeURIComponent(connectionKey)}/hosts/${encodeURIComponent(hostRef)}/unbind`
- )) as { host?: unknown; connectionRef?: unknown }
+ )) as { host?: unknown; connectionRef?: unknown; model?: unknown }
+ const model = pickString(raw.model)
return {
host: pickString(raw.host) ?? hostRef,
connectionRef: pickString(raw.connectionRef) ?? CODEX_UNASSIGNED_CONNECTION_KEY,
+ ...(model ? { model } : {}),
}
}
export async function bindCodexHost(
connectionKey: string,
hostRef: string
-): Promise<{ host: string; connectionRef: string }> {
+): Promise<{ host: string; connectionRef: string; model?: string }> {
const raw = (await apiSend(
'POST',
`${CODEX_SUBSCRIPTION_API_BASE}/connections/${encodeURIComponent(connectionKey)}/hosts/${encodeURIComponent(hostRef)}/bind`
- )) as { host?: unknown; connectionRef?: unknown }
+ )) as { host?: unknown; connectionRef?: unknown; model?: unknown }
+ const model = pickString(raw.model)
return {
host: pickString(raw.host) ?? hostRef,
connectionRef: (() => {
@@ -295,6 +308,7 @@ export async function bindCodexHost(
}
return next
})(),
+ ...(model ? { model } : {}),
}
}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index c7cda9813..886a7d583 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.459",
+ "version": "0.1.460",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.459",
+ "version": "0.1.460",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 29e399255..94a5d9dd2 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.459",
+ "version": "0.1.460",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",