Skip to content

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

TypeScript

fix(control-ui): treat every oauth broker alike in Host create and edit

Jose Gabriel Ramirez Encinasdc60c8e7a55c
diff --git a/control-ui/app/hosts/[name]/page.tsx b/control-ui/app/hosts/[name]/page.tsx
index 9ff21add7..6a8b9f270 100644
--- a/control-ui/app/hosts/[name]/page.tsx
+++ b/control-ui/app/hosts/[name]/page.tsx
@@ -58,8 +58,8 @@ import {
getProviderLabel,
getProvidersWithCompleteCredentials,
hostModelNameError,
+ isLinkedSecretUsableForChain,
isOauthBrokerProvider,
- isProviderUsable,
llmChainRequiresSecret,
normalizeAllowedModels,
normalizeLlmPolicy,
@@ -832,11 +832,9 @@ export default function HostDetailsPage() {
chainRequiresSecret &&
secretRefDraft.trim().length > 0 &&
currentSecretKeys.length > 0 &&
- (showFallbackSecretField
- ? !(llmPolicyDraft?.fallbacks ?? []).some(entry =>
- isProviderUsable(entry.provider as LlmProvider, key => currentSecretKeys.includes(key))
- )
- : !isProviderUsable(providerDraft, key => currentSecretKeys.includes(key)))
+ !isLinkedSecretUsableForChain(providerDraft, llmPolicyDraft?.fallbacks, key =>
+ currentSecretKeys.includes(key)
+ )
const secretMismatchLabel = showFallbackSecretField
? fallbackSecretLabels[0] || 'fallback'
: getProviderLabel(providerDraft)
@@ -948,7 +946,7 @@ export default function HostDetailsPage() {
setError(modelNameProblem)
return false
}
- if (providerDraft === 'codex-subscription' || providerDraft === GROK_SUBSCRIPTION_PROVIDER) {
+ if (isOauthBrokerProvider(providerDraft)) {
if (!connectionRefDraft.trim() || connectionRefDraft === CODEX_UNASSIGNED_CONNECTION_KEY) {
setError(
providerDraft === GROK_SUBSCRIPTION_PROVIDER
@@ -994,12 +992,11 @@ export default function HostDetailsPage() {
setError('Select an LLM secret for the static-credentials provider in this chain.')
return false
}
- const secretUsableFor =
- providerDraft === 'codex-subscription'
- ? (llmPolicyDraft?.fallbacks ?? []).find(entry =>
- isProviderUsable(entry.provider as LlmProvider, key => currentSecretKeys.includes(key))
- )
- : isProviderUsable(providerDraft, key => currentSecretKeys.includes(key))
+ const secretUsableFor = isLinkedSecretUsableForChain(
+ providerDraft,
+ llmPolicyDraft?.fallbacks,
+ key => currentSecretKeys.includes(key)
+ )
if (
chainRequiresSecret &&
secretRefDraft.trim() &&
@@ -1386,7 +1383,11 @@ export default function HostDetailsPage() {
onPrimaryChange={next => {
setProviderDraft(next.provider)
setModelNameDraft(next.model)
- if (!isOauthBrokerProvider(next.provider)) {
+ // A grant belongs to exactly one broker: any provider
+ // change (Codex → Grok, broker → static) drops the grant
+ // and its catalog so the next provider never reads
+ // another broker's connection key.
+ if (next.provider !== providerDraft) {
setConnectionRefDraft(CODEX_UNASSIGNED_CONNECTION_KEY)
setCodexModels([])
setGrokModels([])
@@ -1421,10 +1422,14 @@ export default function HostDetailsPage() {
disabled={
busy ||
Boolean(hostModelNameError(modelNameDraft)) ||
- (providerDraft === 'codex-subscription' &&
+ (isOauthBrokerProvider(providerDraft) &&
(connectionRefDraft === CODEX_UNASSIGNED_CONNECTION_KEY ||
Boolean(grantCatalogError) ||
- !codexModels.includes(modelNameDraft.trim())))
+ !(
+ providerDraft === GROK_SUBSCRIPTION_PROVIDER
+ ? grokModels
+ : codexModels
+ ).includes(modelNameDraft.trim())))
}
>
{busy ? 'Saving…' : 'Save'}
diff --git a/control-ui/components/HostWizard/index.tsx b/control-ui/components/HostWizard/index.tsx
index 25e9715db..6aa970ab3 100644
--- a/control-ui/components/HostWizard/index.tsx
+++ b/control-ui/components/HostWizard/index.tsx
@@ -198,7 +198,7 @@ function isStepValid(stepIndex: number, state: HostWizardValidationState): boole
if (stepIndex === 1) {
if (!state.modelName.trim()) return false
if (
- (state.provider === 'codex-subscription' || state.provider === GROK_SUBSCRIPTION_PROVIDER) &&
+ isOauthBrokerProvider(state.provider) &&
(!state.connectionRef.trim() ||
state.connectionRef.trim() === CODEX_UNASSIGNED_CONNECTION_KEY ||
(state.provider === GROK_SUBSCRIPTION_PROVIDER
@@ -211,8 +211,7 @@ function isStepValid(stepIndex: number, state: HostWizardValidationState): boole
// static primary/fallback still requires the exact credential slots.
if (!llmChainRequiresSecret(state.provider, state.llmPolicy?.fallbacks)) {
return (
- (state.provider === 'codex-subscription' ||
- state.provider === GROK_SUBSCRIPTION_PROVIDER) &&
+ isOauthBrokerProvider(state.provider) &&
parseCredentialSelect(state.existingSecret).kind === 'subscription'
)
}
@@ -229,7 +228,7 @@ function isStepValid(stepIndex: number, state: HostWizardValidationState): boole
)
const hasValidSecret =
state.secretMode === 'existing'
- ? state.provider === 'codex-subscription'
+ ? isOauthBrokerProvider(state.provider)
? state.existingLlmSecret.trim().length > 0
: parseCredentialSelect(state.existingSecret).kind === 'secret'
: toKebabCase(state.newSecretName).length > 0 &&
@@ -525,7 +524,7 @@ export function HostWizard({
// switch left the model out of range.
useEffect(() => {
if (modelsLoading) return
- if (provider === 'codex-subscription' || provider === GROK_SUBSCRIPTION_PROVIDER) {
+ if (isOauthBrokerProvider(provider)) {
const offered = constrainModelOptions(catalogForEditor, allowedModels, provider)
if (offered.length === 0) return
const grant = (
@@ -665,7 +664,7 @@ export function HostWizard({
if (
step === 1 &&
secretMode === 'existing' &&
- provider === 'codex-subscription' &&
+ isOauthBrokerProvider(provider) &&
chainRequiresSecret &&
!existingLlmSecret.trim()
) {
@@ -814,7 +813,7 @@ export function HostWizard({
? ''
: secretMode === 'new'
? normalizedSecretName
- : provider === 'codex-subscription'
+ : isOauthBrokerProvider(provider)
? existingLlmSecret.trim()
: parseCredentialSelect(existingSecret).kind === 'secret'
? existingSecret
@@ -1052,9 +1051,10 @@ export function HostWizard({
checked={secretMode === 'new'}
onChange={() => {
setSecretMode('new')
- if (provider === 'codex-subscription' && !llmPolicy?.fallbacks.length) {
+ if (isOauthBrokerProvider(provider) && !llmPolicy?.fallbacks.length) {
setConnectionRef(CODEX_UNASSIGNED_CONNECTION_KEY)
setCodexModels([])
+ setGrokModels([])
setExistingSecret('')
setExistingLlmSecret('')
setProvider('openai')
@@ -1082,7 +1082,7 @@ export function HostWizard({
options={secretOptions}
onChange={handleExistingSecretChange}
/>
- {provider === 'codex-subscription' && chainRequiresSecret ? (
+ {isOauthBrokerProvider(provider) && chainRequiresSecret ? (
<>
<strong>LLM secret</strong>
<LlmSecretSelect
@@ -1131,10 +1131,11 @@ export function HostWizard({
onPrimaryChange={next => {
setProvider(next.provider)
setModelName(next.model)
- if (
- next.provider !== 'codex-subscription' &&
- next.provider !== GROK_SUBSCRIPTION_PROVIDER
- ) {
+ // A grant belongs to exactly one broker: any provider change
+ // (Codex → Grok, broker → static) drops the selected grant, its
+ // model catalog and the subscription pick so the next provider
+ // never reads another broker's connection key.
+ if (next.provider !== provider) {
setConnectionRef(CODEX_UNASSIGNED_CONNECTION_KEY)
setCodexModels([])
setGrokModels([])
diff --git a/control-ui/components/LlmModelForm/index.tsx b/control-ui/components/LlmModelForm/index.tsx
index 91d6aef0d..b5d742780 100644
--- a/control-ui/components/LlmModelForm/index.tsx
+++ b/control-ui/components/LlmModelForm/index.tsx
@@ -3,7 +3,12 @@
import React, { useState } from 'react'
import { Button, CheckboxField, Field, FormSection, SelectInput, TextInput } from '@components/ui'
import type { CreateLlmModelInput } from '@lib/api'
-import { LLM_PROVIDER_OPTIONS, isKnownProvider } from '@lib/llm'
+import {
+ GROK_SUBSCRIPTION_PROVIDER,
+ LLM_PROVIDER_OPTIONS,
+ isKnownProvider,
+ isOauthBrokerProvider,
+} from '@lib/llm'
import type { LlmModelFormProps } from './types'
// Returns a positive integer, or null when empty. Returns undefined when the
@@ -41,6 +46,9 @@ export function LlmModelForm({
const [showErrors, setShowErrors] = useState(false)
const providerIsKnown = isKnownProvider(provider)
+ // Subscription (oauth-broker) models are enabled by their grant catalog sync,
+ // never from this table — lock the toggle for every broker, not only Codex.
+ const brokerManaged = isOauthBrokerProvider(provider)
const modelInvalid = model.trim().length === 0
const contextWindowInvalid = parseContextWindow(contextWindow) === undefined
const hasErrors = modelInvalid || contextWindowInvalid
@@ -159,13 +167,15 @@ export function LlmModelForm({
<CheckboxField
label="Enabled"
description={
- provider === 'codex-subscription'
- ? 'ChatGPT subscription models are enabled by the assigned grant catalog after sync, not from this table.'
- : 'Only enabled models can be selected for agents and served at runtime. Disable to retire a model without deleting it.'
+ provider === GROK_SUBSCRIPTION_PROVIDER
+ ? 'Grok subscription models are enabled by the assigned grant catalog after sync, not from this table.'
+ : brokerManaged
+ ? 'ChatGPT subscription models are enabled by the assigned grant catalog after sync, not from this table.'
+ : 'Only enabled models can be selected for agents and served at runtime. Disable to retire a model without deleting it.'
}
checked={enabled}
onChange={event => setEnabled(event.target.checked)}
- disabled={saving || provider === 'codex-subscription'}
+ disabled={saving || brokerManaged}
/>
</FormSection>
diff --git a/control-ui/components/LlmPolicyEditor/index.tsx b/control-ui/components/LlmPolicyEditor/index.tsx
index 53884b073..529720e04 100644
--- a/control-ui/components/LlmPolicyEditor/index.tsx
+++ b/control-ui/components/LlmPolicyEditor/index.tsx
@@ -4,7 +4,6 @@ import React, { useEffect, useMemo } from 'react'
import { IconTrash } from '@/components/icons'
import { Button, CheckboxField, Field, SelectInput, TextInput } from '@/components/ui'
import {
- GROK_SUBSCRIPTION_PROVIDER,
LLM_DEFAULT_COOLDOWN_SECONDS,
LLM_TRIGGER_CLASSES,
LLM_TRIGGER_LABELS,
@@ -325,9 +324,11 @@ function FallbackRow({
{entry.provider === OPENAI_SUBSCRIPTION_PROVIDER ? (
<option value={OPENAI_SUBSCRIPTION_PROVIDER}>OpenAI (ChatGPT subscription)</option>
) : null}
- {entry.provider === GROK_SUBSCRIPTION_PROVIDER &&
- !pickerOptions.some(option => option.value === GROK_SUBSCRIPTION_PROVIDER) ? (
- <option value={GROK_SUBSCRIPTION_PROVIDER}>xAI Grok Subscription</option>
+ {entry.provider !== OPENAI_SUBSCRIPTION_PROVIDER &&
+ !pickerOptions.some(option => option.value === entry.provider) ? (
+ <option value={entry.provider}>
+ {getProviderDisplayLabel(entry.provider)} (disabled)
+ </option>
) : null}
</SelectInput>
</Field>
diff --git a/control-ui/components/LlmProviderConfig/index.tsx b/control-ui/components/LlmProviderConfig/index.tsx
index d25236964..e3fd2d7ce 100644
--- a/control-ui/components/LlmProviderConfig/index.tsx
+++ b/control-ui/components/LlmProviderConfig/index.tsx
@@ -127,16 +127,25 @@ export function LlmProviderConfig({
[catalog, allowedModels, provider]
)
const primaryModelOutOfAllowlist = Boolean(model) && !primaryModelOptions.includes(model)
- const pickerOptions = operatorProviderOptions({ grokEnabled })
- const primaryProviderOptions = useMemo(
- () =>
- pickerOptions.map(option => ({
- ...option,
- icon: <LlmProviderIcon provider={option.value} label={option.label} />,
- })),
- [pickerOptions]
- )
const providerPickerValue = isOpenAiFamily(provider) ? 'openai' : provider
+ const primaryProviderOptions = useMemo(() => {
+ const options = operatorProviderOptions({ grokEnabled }).map(option => ({
+ ...option,
+ icon: <LlmProviderIcon provider={option.value} label={option.label} />,
+ }))
+ // A saved provider the picker no longer offers (e.g. a Grok primary while
+ // the Grok capability is off) stays visible and selected, marked disabled,
+ // instead of rendering as an empty selection.
+ if (!options.some(option => option.value === providerPickerValue)) {
+ const label = `${getProviderLabel(providerPickerValue)} (disabled)`
+ options.push({
+ value: providerPickerValue as LlmProvider,
+ label,
+ icon: <LlmProviderIcon provider={providerPickerValue} label={label} />,
+ })
+ }
+ return options
+ }, [grokEnabled, providerPickerValue])
const primaryModelSelectOptions = useMemo(() => {
const options: SelectionDropdownOption[] = primaryModelOptions.map(option => ({
value: option,
diff --git a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
index 42eb2c50c..83591af6b 100644
--- a/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
+++ b/control-ui/components/__tests__/HostDetailsPage.identity.test.tsx
@@ -121,6 +121,94 @@ function render(children: ReactNode) {
return rtlRender(<ToastProvider>{children}</ToastProvider>)
}
+function mockGrokGrant() {
+ vi.mocked(listGrokSubscriptionConnections).mockResolvedValue([
+ {
+ connectionKey: 'team-grok',
+ displayName: 'Team Grok',
+ status: 'connected',
+ credentialRevision: 2,
+ catalogRevision: 5,
+ 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,
+ defaultModel: 'grok-4.6',
+ },
+ ])
+ vi.mocked(listGrokConnectionModels).mockResolvedValue([
+ { model: 'grok-4.6', enabled: true, stale: false },
+ ])
+}
+
+function mockCodexGrant() {
+ 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,
+ defaultModel: 'gpt-5.1',
+ },
+ ])
+ vi.mocked(listCodexConnectionModels).mockResolvedValue([
+ { model: 'gpt-5.1', enabled: true, stale: false },
+ ])
+}
+
+// Grok primary with a same-broker Grok fallback AND a static OpenAI fallback:
+// only the static fallback needs the linked Secret.
+function grokFallbackHost(opts: { secretRef: string }) {
+ return {
+ ...host,
+ spec: {
+ ...host.spec,
+ secretRef: opts.secretRef,
+ model: { provider: 'grok-subscription', name: 'grok-4.6', connectionRef: 'team-grok' },
+ llmPolicy: {
+ fallbacks: [
+ { provider: 'grok-subscription', model: 'grok-4.6' },
+ { provider: 'openai', model: 'gpt-4o' },
+ ],
+ },
+ },
+ }
+}
+
+function mockHostBundle(hostResource: unknown, secrets: Array<{ name: string; keys?: string[] }>) {
+ ;(api.getHostDetailBundle as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ host: hostResource,
+ contexts: [{ metadata: { name: 'ctx' }, spec: { contextId: 'ctx' } }],
+ secrets,
+ users: [],
+ teams: [],
+ agentUsers: [],
+ agentTeams: [],
+ })
+ ;(api.getHost as unknown as ReturnType<typeof vi.fn>).mockResolvedValue(hostResource)
+ // Earlier tests override the allowlist; these cases exercise the Secret gate only.
+ ;(api.getLlmModels as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({ rows: [] })
+}
+
+async function findGrokProviderOption(): Promise<HTMLElement> {
+ let option: HTMLElement | null = null
+ await waitFor(() => {
+ const trigger = screen.getByLabelText('Provider', { selector: '#llm-primary-provider' })
+ if (trigger.getAttribute('aria-expanded') !== 'true') fireEvent.click(trigger)
+ option = screen.getByRole('option', { name: 'xAI Grok Subscription' })
+ })
+ return option as unknown as HTMLElement
+}
+
afterEach(() => {
cleanup()
})
@@ -547,6 +635,155 @@ describe('HostDetailsPage identity integration', () => {
})
})
+ it('blocks saving a Grok Host whose static fallback Secret lacks the fallback credential', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ mockGrokGrant()
+ const grokHost = grokFallbackHost({ secretRef: 'claude-secret' })
+ mockHostBundle(grokHost, [{ name: 'claude-secret', keys: ['claude-api-key'] }])
+ render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }))
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled()
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+ expect(
+ await screen.findAllByText(/does not contain a usable OpenAI credential/i)
+ ).not.toHaveLength(0)
+ expect(api.apiSend).not.toHaveBeenCalledWith(
+ 'PUT',
+ '/api/v1/admin/hosts/foo',
+ expect.anything()
+ )
+ })
+
+ it('saves a Grok Host with a same-broker fallback and a static fallback whose Secret is usable', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ mockGrokGrant()
+ const grokHost = grokFallbackHost({ secretRef: 'openai-secret' })
+ mockHostBundle(grokHost, [{ name: 'openai-secret', keys: ['openai-api-key'] }])
+ render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }))
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled()
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+ await waitFor(() => {
+ expect(api.apiSend).toHaveBeenCalledWith(
+ 'PUT',
+ '/api/v1/admin/hosts/foo',
+ expect.objectContaining({
+ spec: expect.objectContaining({
+ secretRef: 'openai-secret',
+ model: {
+ provider: 'grok-subscription',
+ name: 'grok-4.6',
+ connectionRef: 'team-grok',
+ },
+ }),
+ })
+ )
+ })
+ })
+
+ it('blocks saving a Codex Host whose static fallback Secret lacks the fallback credential', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ mockCodexGrant()
+ const codexHost = {
+ ...host,
+ spec: {
+ ...host.spec,
+ secretRef: 'claude-secret',
+ model: { provider: 'codex-subscription', name: 'gpt-5.1', connectionRef: 'codex-aaa' },
+ llmPolicy: { fallbacks: [{ provider: 'openai', model: 'gpt-4o' }] },
+ },
+ }
+ mockHostBundle(codexHost, [{ name: 'claude-secret', keys: ['claude-api-key'] }])
+ render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }))
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: 'Save' })).toBeEnabled()
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+ expect(
+ await screen.findAllByText(/does not contain a usable OpenAI credential/i)
+ ).not.toHaveLength(0)
+ expect(api.apiSend).not.toHaveBeenCalledWith(
+ 'PUT',
+ '/api/v1/admin/hosts/foo',
+ expect.anything()
+ )
+ })
+
+ it('drops the Codex grant when the primary switches to Grok and blocks Save until a Grok grant is chosen', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ mockCodexGrant()
+ mockGrokGrant()
+ const codexHost = {
+ ...host,
+ spec: {
+ ...host.spec,
+ secretRef: undefined,
+ model: { provider: 'codex-subscription', name: 'gpt-5.1', connectionRef: 'codex-aaa' },
+ },
+ }
+ mockHostBundle(codexHost, [])
+ render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }))
+ await waitFor(() => {
+ expect(listCodexConnectionModels).toHaveBeenCalledWith('codex-aaa')
+ })
+ fireEvent.click(await findGrokProviderOption())
+ await waitFor(() => {
+ expect(
+ screen.getByLabelText('Provider', { selector: '#llm-primary-provider' })
+ ).toHaveTextContent('xAI Grok Subscription')
+ })
+ expect(listGrokConnectionModels).not.toHaveBeenCalledWith('codex-aaa')
+ expect(screen.queryByText(/codex-aaa \(unavailable\)/)).not.toBeInTheDocument()
+ expect(screen.queryByText(/Could not load Grok grant models/)).not.toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled()
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))
+ expect(api.apiSend).not.toHaveBeenCalledWith(
+ 'PUT',
+ '/api/v1/admin/hosts/foo',
+ expect.anything()
+ )
+ })
+
+ it('keeps Save disabled while the assigned Grok grant catalog has not offered the model', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ mockGrokGrant()
+ vi.mocked(listGrokConnectionModels).mockReturnValue(new Promise(() => undefined))
+ const grokHost = {
+ ...host,
+ spec: {
+ ...host.spec,
+ secretRef: undefined,
+ model: { provider: 'grok-subscription', name: 'grok-4.6', connectionRef: 'team-grok' },
+ },
+ }
+ mockHostBundle(grokHost, [])
+ render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }))
+ await waitFor(() => {
+ expect(listGrokConnectionModels).toHaveBeenCalledWith('team-grok')
+ })
+ expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled()
+ })
+
+ it('hides the Grok provider option when the Grok capability probe reports disabled', async () => {
+ mockParams = { name: 'foo', tab: 'model' }
+ vi.mocked(listGrokSubscriptionConnections).mockRejectedValue({ status: 404 })
+ render(<HostDetailsPage />)
+ fireEvent.click(await screen.findByRole('button', { name: 'Edit' }))
+ await waitFor(() => {
+ expect(listGrokSubscriptionConnections).toHaveBeenCalled()
+ })
+ fireEvent.click(screen.getByLabelText('Provider', { selector: '#llm-primary-provider' }))
+ expect(screen.getByRole('option', { name: /^OpenAI$/ })).toBeInTheDocument()
+ expect(screen.queryByRole('option', { name: /xAI Grok Subscription/ })).not.toBeInTheDocument()
+ })
+
it('does not surface a page error when ChatGPT subscriptions are disabled', async () => {
mockParams = { name: 'foo', tab: 'model' }
const err = Object.assign(new Error('disabled'), { status: 404, code: 'disabled' })
diff --git a/control-ui/components/__tests__/HostWizard.test.tsx b/control-ui/components/__tests__/HostWizard.test.tsx
index 396b1eb6c..f18eed5f1 100644
--- a/control-ui/components/__tests__/HostWizard.test.tsx
+++ b/control-ui/components/__tests__/HostWizard.test.tsx
@@ -1058,6 +1058,49 @@ async function selectCodexSubscription(model = 'gpt-5.1') {
expect(screen.queryByRole('radio', { name: /^ChatGPT subscription$/i })).not.toBeInTheDocument()
}
+function mockGrokGrant() {
+ vi.mocked(listGrokSubscriptionConnections).mockResolvedValue([
+ {
+ connectionKey: 'team-grok',
+ displayName: 'Team Grok',
+ status: 'connected',
+ defaultModel: 'grok-4.6',
+ credentialRevision: 2,
+ catalogRevision: 5,
+ 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,
+ },
+ ])
+ vi.mocked(listGrokConnectionModels).mockResolvedValue([
+ { model: 'grok-4.6', enabled: true, stale: false },
+ ])
+}
+
+async function selectGrokSubscription(model = 'grok-4.6') {
+ fireEvent.click(screen.getByRole('button', { name: /Select LLM Secret/i }))
+ fireEvent.click(await screen.findByRole('option', { name: /Team Grok/i }))
+ await waitFor(() => {
+ expect(
+ screen.getByLabelText('Default model', { selector: '#llm-primary-model' })
+ ).toHaveTextContent(model)
+ })
+}
+
+async function addOpenAiFallback() {
+ fireEvent.click(screen.getByRole('button', { name: /Fallback providers/i }))
+ fireEvent.click(screen.getByRole('button', { name: /Add fallback provider/i }))
+ fireEvent.change(screen.getByLabelText('Provider', { selector: '#llm-fallback-0-provider' }), {
+ target: { value: 'openai' },
+ })
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: /Select secret/i })).toBeInTheDocument()
+ })
+}
+
describe('HostWizard — broker-backed Codex authoring', () => {
it('creates a Codex-only Host without secretRef or a Secret POST', async () => {
await renderWizard()
@@ -1182,6 +1225,126 @@ describe('HostWizard — broker-backed Codex authoring', () => {
expect(screen.getByText(/Use an existing LLM Secret/i)).toBeInTheDocument()
}, 15_000)
+ it('creates a Grok primary + OpenAI fallback Host with an existing Secret and the Grok grant', async () => {
+ mockGrokGrant()
+ await renderWizard()
+ await walkToModelStep({ agentName: 'grok-mixed' })
+ await selectGrokSubscription()
+ await addOpenAiFallback()
+ expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled()
+ expect(screen.getByText('Select an existing LLM Secret.')).toBeInTheDocument()
+ fireEvent.click(screen.getByRole('button', { name: /Select secret/i }))
+ fireEvent.click(screen.getByRole('option', { name: /secret-a/i }))
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: 'Next' })).toBeEnabled()
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))
+ continueToConnectorsStep()
+ submitFromConnectorsStep()
+ await waitFor(() => {
+ expect(api.apiSend).toHaveBeenCalledWith(
+ 'POST',
+ '/api/v1/admin/hosts',
+ expect.objectContaining({
+ metadata: { name: 'grok-mixed' },
+ spec: expect.objectContaining({
+ secretRef: 'secret-a',
+ model: {
+ provider: 'grok-subscription',
+ name: 'grok-4.6',
+ connectionRef: 'team-grok',
+ },
+ llmPolicy: expect.objectContaining({
+ fallbacks: [expect.objectContaining({ provider: 'openai' })],
+ }),
+ }),
+ })
+ )
+ })
+ expect(
+ vi
+ .mocked(api.apiSend)
+ .mock.calls.some(call => call[0] === 'POST' && call[1] === '/api/v1/admin/secrets')
+ ).toBe(false)
+ }, 15_000)
+
+ it('creates a Codex primary + OpenAI fallback Host with an existing Secret and the Codex grant', async () => {
+ await renderWizard()
+ await walkToModelStep({ agentName: 'codex-mixed-submit' })
+ await selectCodexSubscription()
+ await addOpenAiFallback()
+ fireEvent.click(screen.getByRole('button', { name: /Select secret/i }))
+ fireEvent.click(screen.getByRole('option', { name: /secret-a/i }))
+ await waitFor(() => {
+ expect(screen.getByRole('button', { name: 'Next' })).toBeEnabled()
+ })
+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))
+ continueToConnectorsStep()
+ submitFromConnectorsStep()
+ await waitFor(() => {
+ expect(api.apiSend).toHaveBeenCalledWith(
+ 'POST',
+ '/api/v1/admin/hosts',
+ expect.objectContaining({
+ metadata: { name: 'codex-mixed-submit' },
+ spec: expect.objectContaining({
+ secretRef: 'secret-a',
+ model: {
+ provider: 'codex-subscription',
+ name: 'gpt-5.1',
+ connectionRef: 'codex-aaa',
+ },
+ }),
+ })
+ )
+ })
+ }, 15_000)
+
+ it('resets the Codex grant when the primary switches to Grok (never loads Grok models with a Codex key)', async () => {
+ mockGrokGrant()
+ await renderWizard()
+ await walkToModelStep({ agentName: 'codex-to-grok' })
+ await selectCodexSubscription()
+ vi.mocked(listGrokConnectionModels).mockClear()
+ fireEvent.click(screen.getByLabelText('Provider', { selector: '#llm-primary-provider' }))
+ fireEvent.click(screen.getByRole('option', { name: 'xAI Grok Subscription' }))
+ await waitFor(() => {
+ expect(
+ screen.getByLabelText('Provider', { selector: '#llm-primary-provider' })
+ ).toHaveTextContent('xAI Grok Subscription')
+ })
+ await act(async () => {
+ await Promise.resolve()
+ })
+ expect(listGrokConnectionModels).not.toHaveBeenCalledWith('codex-aaa')
+ expect(screen.queryByText('Could not load Grok grant models')).not.toBeInTheDocument()
+ expect(screen.getByRole('button', { name: /Select LLM Secret/i })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled()
+ }, 15_000)
+
+ it('hides the Grok provider when the Grok capability probe reports disabled', async () => {
+ vi.mocked(listGrokSubscriptionConnections).mockRejectedValue({ status: 404 })
+ await renderWizard()
+ await walkToModelStep({ agentName: 'grok-flag-off' })
+ await waitFor(() => {
+ expect(listGrokSubscriptionConnections).toHaveBeenCalled()
+ })
+ fireEvent.click(screen.getByLabelText('Provider', { selector: '#llm-primary-provider' }))
+ expect(screen.getByRole('option', { name: /^OpenAI$/ })).toBeInTheDocument()
+ expect(screen.queryByRole('option', { name: 'xAI Grok Subscription' })).not.toBeInTheDocument()
+ }, 15_000)
+
+ it('offers the Grok provider once the Grok capability probe succeeds', async () => {
+ mockGrokGrant()
+ await renderWizard()
+ await walkToModelStep({ agentName: 'grok-flag-on' })
+ await waitFor(() => {
+ fireEvent.click(screen.getByLabelText('Provider', { selector: '#llm-primary-provider' }))
+ expect(screen.getByRole('option', { name: 'xAI Grok Subscription' })).toBeInTheDocument()
+ })
+ expect(screen.getByRole('option', { name: /^OpenAI$/ })).toBeInTheDocument()
+ }, 15_000)
+
it('requires exact credential slots when a static fallback joins a Codex primary', async () => {
await renderWizard()
await walkToModelStep({ agentName: 'codex-mixed' })
diff --git a/control-ui/components/__tests__/LlmModelForm.test.tsx b/control-ui/components/__tests__/LlmModelForm.test.tsx
index 3f355aed7..b4ac71e86 100644
--- a/control-ui/components/__tests__/LlmModelForm.test.tsx
+++ b/control-ui/components/__tests__/LlmModelForm.test.tsx
@@ -39,6 +39,23 @@ describe('LlmModelForm', () => {
).toBeInTheDocument()
})
+ it('disables the Enabled toggle for Grok subscription models with Grok copy', () => {
+ render(
+ <LlmModelForm
+ mode="edit"
+ initial={{ ...model, provider: 'grok-subscription', model: 'grok-4.6', vendor: 'xAI' }}
+ saving={false}
+ onSubmit={() => undefined}
+ onCancel={() => undefined}
+ />
+ )
+ expect(screen.getByRole('checkbox')).toBeDisabled()
+ expect(
+ screen.getByText(/Grok subscription models are enabled by the assigned grant catalog/i)
+ ).toBeInTheDocument()
+ expect(screen.queryByText(/ChatGPT/)).not.toBeInTheDocument()
+ })
+
it('keeps the Enabled toggle editable for API-key providers', () => {
render(
<LlmModelForm
diff --git a/control-ui/components/__tests__/LlmPolicyEditor.test.tsx b/control-ui/components/__tests__/LlmPolicyEditor.test.tsx
index cd56a28ac..0bbaba8de 100644
--- a/control-ui/components/__tests__/LlmPolicyEditor.test.tsx
+++ b/control-ui/components/__tests__/LlmPolicyEditor.test.tsx
@@ -22,10 +22,12 @@ function Harness({
initial,
secretKeys,
onLatest,
+ grokEnabled,
}: {
initial?: LlmPolicy
secretKeys?: string[]
onLatest?: (p: LlmPolicy | undefined) => void
+ grokEnabled?: boolean
}) {
const [policy, setPolicy] = useState<LlmPolicy | undefined>(initial)
return (
@@ -38,6 +40,7 @@ function Harness({
catalog={CATALOG}
secretKeys={secretKeys}
defaultProvider="claude"
+ grokEnabled={grokEnabled}
/>
)
}
@@ -256,3 +259,38 @@ describe('LlmPolicyEditor (spec §3-R5 / R4.5.6)', () => {
expect(latest?.fallbacks[0].credentialSlot).toBeUndefined()
})
})
+
+describe('LlmPolicyEditor — Grok capability gate', () => {
+ function providerOptionLabels(): string[] {
+ const select = screen.getByLabelText('Provider', { selector: '#llm-fallback-0-provider' })
+ return Array.from((select as HTMLSelectElement).options).map(option => option.textContent ?? '')
+ }
+
+ it('omits Grok from the fallback provider options when the capability is off', () => {
+ render(<Harness initial={{ fallbacks: [{ provider: 'claude', model: 'claude-opus-4-8' }] }} />)
+ const labels = providerOptionLabels()
+ expect(labels).toContain('OpenAI')
+ expect(labels.some(label => /Grok Subscription/.test(label))).toBe(false)
+ })
+
+ it('offers Grok as a fallback provider when the capability is on', () => {
+ render(
+ <Harness
+ initial={{ fallbacks: [{ provider: 'claude', model: 'claude-opus-4-8' }] }}
+ grokEnabled
+ />
+ )
+ expect(providerOptionLabels()).toContain('xAI Grok Subscription')
+ })
+
+ it('keeps a saved Grok fallback as a (disabled) option when the capability is off', () => {
+ render(
+ <Harness initial={{ fallbacks: [{ provider: 'grok-subscription', model: 'grok-4.6' }] }} />
+ )
+ const select = screen.getByLabelText('Provider', {
+ selector: '#llm-fallback-0-provider',
+ }) as HTMLSelectElement
+ expect(select.value).toBe('grok-subscription')
+ expect(select.selectedOptions[0]?.textContent).toBe('xAI Grok Subscription (disabled)')
+ })
+})
diff --git a/control-ui/components/__tests__/LlmProviderConfig.test.tsx b/control-ui/components/__tests__/LlmProviderConfig.test.tsx
index d8338d219..5f65db232 100644
--- a/control-ui/components/__tests__/LlmProviderConfig.test.tsx
+++ b/control-ui/components/__tests__/LlmProviderConfig.test.tsx
@@ -22,6 +22,7 @@ function Harness({
existingKeys,
replacePrimaryModelWithAllowedModels = false,
catalog = CATALOG,
+ grokEnabled,
}: {
initialProvider?: LlmProvider
initialModel?: string
@@ -31,6 +32,7 @@ function Harness({
existingKeys?: string[]
replacePrimaryModelWithAllowedModels?: boolean
catalog?: LlmModelCatalogEntry[]
+ grokEnabled?: boolean
}) {
const [provider, setProvider] = useState<LlmProvider>(initialProvider)
const [model, setModel] = useState(initialModel)
@@ -61,6 +63,7 @@ function Harness({
}
replacePrimaryModelWithAllowedModels={replacePrimaryModelWithAllowedModels}
secretKeys={existingKeys}
+ grokEnabled={grokEnabled}
/>
)
}
@@ -202,6 +205,45 @@ describe('LlmProviderConfig (spec Topic 1b — domain projection + usable gate)'
})
})
+describe('LlmProviderConfig — Grok capability gate', () => {
+ it('hides Grok from the provider picker when the capability is off', () => {
+ render(<Harness />)
+ fireEvent.click(screen.getByLabelText('Provider', { selector: '#llm-primary-provider' }))
+ expect(screen.getByRole('option', { name: /^OpenAI$/ })).toBeInTheDocument()
+ expect(screen.queryByRole('option', { name: /xAI Grok Subscription/ })).not.toBeInTheDocument()
+ })
+
+ it('keeps a saved Grok primary visible as a (disabled) option when the capability is off', () => {
+ render(
+ <Harness
+ initialProvider="grok-subscription"
+ initialModel="grok-4.6"
+ withCredentials={false}
+ />
+ )
+ const trigger = screen.getByLabelText('Provider', { selector: '#llm-primary-provider' })
+ expect(trigger).toHaveTextContent('xAI Grok Subscription (disabled)')
+ fireEvent.click(trigger)
+ expect(
+ screen.getByRole('option', { name: 'xAI Grok Subscription (disabled)' })
+ ).toBeInTheDocument()
+ })
+
+ it('offers Grok without a (disabled) marker when the capability is on', () => {
+ render(
+ <Harness
+ initialProvider="grok-subscription"
+ initialModel="grok-4.6"
+ withCredentials={false}
+ grokEnabled
+ />
+ )
+ const trigger = screen.getByLabelText('Provider', { selector: '#llm-primary-provider' })
+ expect(trigger).toHaveTextContent('xAI Grok Subscription')
+ expect(trigger).not.toHaveTextContent('(disabled)')
+ })
+})
+
describe('LlmProviderConfig (spec Topic 3a — per-host allowed-models subset)', () => {
it('defaults the primary provider to the "All models" (unrestricted) state', () => {
render(<Harness />)
diff --git a/control-ui/lib/llm.ts b/control-ui/lib/llm.ts
index 0fda436d8..76dc723c4 100644
--- a/control-ui/lib/llm.ts
+++ b/control-ui/lib/llm.ts
@@ -58,7 +58,11 @@ export function isOpenAiFamily(provider: string | undefined | null): boolean {
}
export function isOauthBrokerProvider(provider: string | undefined | null): boolean {
- return provider === OPENAI_SUBSCRIPTION_PROVIDER || provider === GROK_SUBSCRIPTION_PROVIDER
+ return (
+ typeof provider === 'string' &&
+ isLlmProviderId(provider) &&
+ PROVIDER_AUTH_MODE[provider] === 'oauth-broker'
+ )
}
/** Provider dropdown: one OpenAI entry. Runtime still persists `codex-subscription`. */
@@ -409,6 +413,25 @@ export function isProviderUsable(
return getLlmGroupCompleteness(getLlmCredentialGroup(provider), isPresent).usable
}
+// Whether a linked LLM Secret (its data keys via `isPresent`) can serve the
+// chain it is linked for. A static primary must itself be usable (asymmetric
+// gate). An oauth-broker primary authenticates through its grant, so the Secret
+// exists only for the static-credential fallbacks: at least one of THOSE must
+// be usable. Broker fallbacks never count — a zero-slot broker is trivially
+// "usable" and would otherwise make any Secret look valid.
+export function isLinkedSecretUsableForChain(
+ primary: LlmProvider,
+ fallbacks: Array<{ provider: string }> | undefined,
+ isPresent: (dataKey: string) => boolean
+): boolean {
+ if (!isOauthBrokerProvider(primary)) return isProviderUsable(primary, isPresent)
+ return (fallbacks ?? []).some(
+ entry =>
+ providerRequiresLlmSecret(entry.provider) &&
+ isProviderUsable(entry.provider as LlmProvider, isPresent)
+ )
+}
+
// The credential dataKeys currently in the provider domain — the primary's
// canonical slots ∪ each fallback's EFFECTIVE slot(s) (its chosen extra slot, or
// its provider's canonical slots). This is the exact projection the Host's
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 120b830d6..d2ca01301 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.589",
+ "version": "0.1.590",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.589",
+ "version": "0.1.590",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index c36f97bca..2cd46ba7e 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.589",
+ "version": "0.1.590",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",