Skip to content

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

TypeScript

fix(workflow-recipes): honor the WRC Grok switch in redeemability and strict binding slots

Jose Gabriel Ramirez Encinasda38426c6a41
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index fc8ea1aa1..355fe9057 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.361",
+ "version": "0.1.362",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.361",
+ "version": "0.1.362",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@aws-sdk/client-s3": "^3.1009.0",
diff --git a/workflow-recipes/package.json b/workflow-recipes/package.json
index e7784fcd2..1377fd623 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.361",
+ "version": "0.1.362",
"description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface",
"main": "dist/main.js",
"engines": {
diff --git a/workflow-recipes/src/mcp/server.pluginSdkBroker.test.ts b/workflow-recipes/src/mcp/server.pluginSdkBroker.test.ts
index 501931387..698af1d36 100644
--- a/workflow-recipes/src/mcp/server.pluginSdkBroker.test.ts
+++ b/workflow-recipes/src/mcp/server.pluginSdkBroker.test.ts
@@ -157,3 +157,33 @@ describe('WRC Plugin SDK credential ticket TOCTOU revalidation', () => {
).resolves.toBe(false)
})
})
+
+// C-WRC: `/configure-model` grantRedeemable for Grok must honor the same
+// WRC_GROK_SUBSCRIPTION_ENABLED the recipe verdict folds in. Mutation caught:
+// building the REST ModelConfigHandler without the loaded Grok flag.
+describe('WRC MCP server ModelConfigHandler Grok flag wiring', () => {
+ function handlerFlag(env: string | undefined): unknown {
+ vi.stubEnv('WRC_GROK_SUBSCRIPTION_ENABLED', env)
+ try {
+ const kc = { makeApiClient: () => ({}) }
+ const server = new ClerumMcpServer(
+ {} as never,
+ 8082,
+ {} as never,
+ 'sandbox-recipes',
+ kc as never
+ )
+ const handler = (server as unknown as { modelConfigHandler: Record<string, unknown> | null })
+ .modelConfigHandler
+ return handler?.grokSubscriptionEnabled
+ } finally {
+ vi.unstubAllEnvs()
+ }
+ }
+
+ it('reads WRC_GROK_SUBSCRIPTION_ENABLED into the configure-model broker', () => {
+ expect(handlerFlag('true')).toBe(true)
+ expect(handlerFlag('false')).toBe(false)
+ expect(handlerFlag(undefined)).toBe(false)
+ })
+})
diff --git a/workflow-recipes/src/mcp/server.ts b/workflow-recipes/src/mcp/server.ts
index c6e03e593..e84d36a3f 100644
--- a/workflow-recipes/src/mcp/server.ts
+++ b/workflow-recipes/src/mcp/server.ts
@@ -11,6 +11,7 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'
import http from 'node:http'
import { z } from 'zod/v3'
+import { loadConfig } from '../config'
import { WorkflowRecipeProvider } from '../k8sClient'
import { registry } from '../metrics'
import { HttpMcpHostClient } from '../workflow/httpMcpHostClient'
@@ -198,8 +199,13 @@ export class ClerumMcpServer {
const coreApi = kc ? kc.makeApiClient(k8s.CoreV1Api) : null
const k8sReader = coreApi ? new K8sSecretReaderImpl(coreApi) : null
const mcpHostClient = new HttpMcpHostClient()
- // Handler requires K8sSecretReader; if unavailable (dev mode), configureModel returns 501
- this.modelConfigHandler = k8sReader ? new ModelConfigHandler(k8sReader, mcpHostClient) : null
+ // Handler requires K8sSecretReader; if unavailable (dev mode), configureModel returns 501.
+ // The Grok flag keeps `grantRedeemable` in step with the recipe verdict.
+ this.modelConfigHandler = k8sReader
+ ? new ModelConfigHandler(k8sReader, mcpHostClient, undefined, {
+ grokSubscriptionEnabled: loadConfig().grokSubscriptionEnabled,
+ })
+ : null
}
private consumePluginSdkTicket(jti: string): boolean {
diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.grokFlagWiring.test.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.grokFlagWiring.test.ts
new file mode 100644
index 000000000..3e068efc3
--- /dev/null
+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.grokFlagWiring.test.ts
@@ -0,0 +1,39 @@
+import { describe, expect, it, vi } from 'vitest'
+import * as k8s from '@kubernetes/client-node'
+import { generateKeyPairSync } from 'node:crypto'
+import { loadConfig } from '../config'
+import { WorkflowRecipeReconciler } from './workflowRecipeReconciler'
+
+vi.mock('../db', async importOriginal => ({
+ ...(await importOriginal<typeof import('../db')>()),
+ getPool: () => ({}),
+}))
+
+// C-WRC: the eager SDK broker must see the same WRC_GROK_SUBSCRIPTION_ENABLED
+// the recipe verdict sees. Mutation caught: constructing the workflow-subsystem
+// ModelConfigHandler without `{ grokSubscriptionEnabled: config... }`.
+describe('WorkflowRecipeReconciler ModelConfigHandler Grok flag wiring', () => {
+ const { privateKey } = generateKeyPairSync('rsa', { modulusLength: 2048 })
+ const pem = privateKey.export({ type: 'pkcs8', format: 'pem' }).toString()
+
+ async function handlerFlag(grokSubscriptionEnabled: boolean): Promise<unknown> {
+ const kc = new k8s.KubeConfig()
+ vi.spyOn(kc, 'makeApiClient').mockImplementation((() => ({})) as typeof kc.makeApiClient)
+ const reconciler = new WorkflowRecipeReconciler(kc, {
+ ...loadConfig(),
+ grokSubscriptionEnabled,
+ })
+ await reconciler.initializeWorkflow(pem)
+ const inner = (
+ reconciler as unknown as {
+ workflowReconciler: { deps: { modelConfigHandler: Record<string, unknown> } }
+ }
+ ).workflowReconciler
+ return inner.deps.modelConfigHandler.grokSubscriptionEnabled
+ }
+
+ it('passes the operator Grok flag through to the broker', async () => {
+ await expect(handlerFlag(true)).resolves.toBe(true)
+ await expect(handlerFlag(false)).resolves.toBe(false)
+ })
+})
diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
index fd8b09e75..f4e9afc6a 100644
--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
@@ -1048,7 +1048,9 @@ export class WorkflowRecipeReconciler {
// configure path (Option A). Same wiring as mcp/server.ts.
modelConfigHandler: new ModelConfigHandler(
new K8sSecretReaderImpl(this.coreApi),
- new HttpMcpHostClient()
+ new HttpMcpHostClient(),
+ undefined,
+ { grokSubscriptionEnabled: this.config.grokSubscriptionEnabled }
),
pluginWorkloadSdkRevocationClient: new HttpPluginWorkloadSdkRevocationClient(),
}
diff --git a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts
index 5e74f2bcf..381749832 100644
--- a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts
+++ b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts
@@ -23,8 +23,9 @@ export {
export const ALLOWLIST_CONFIGMAP_NAMESPACE = process.env.CLERUM_MODEL_CONFIG_NAMESPACE ?? 'mcp-host'
/**
- * Recipe annotation reader. Empty/missing is `unassigned`, never the reserved
- * grant: only an explicit annotation may spend a ChatGPT subscription.
+ * Recipe annotation reader for the given oauth-broker provider's grant.
+ * Empty/missing is `unassigned`, never the reserved grant: only an explicit
+ * annotation may spend a subscription grant (Codex or Grok).
*/
export function readRecipeCodexConnectionRef(
annotations: Record<string, string> | undefined,
diff --git a/workflow-recipes/src/workflow/modelConfigHandler.ts b/workflow-recipes/src/workflow/modelConfigHandler.ts
index fe20c4b93..51dc74b4c 100644
--- a/workflow-recipes/src/workflow/modelConfigHandler.ts
+++ b/workflow-recipes/src/workflow/modelConfigHandler.ts
@@ -112,6 +112,7 @@ export interface McpHostClient {
provider?: string
model?: string
contractVersion?: 2 | 3
+ /** Codex bootstrap only. */
codexBinding?: {
connectionKey: string
catalogRevision: number
@@ -119,6 +120,14 @@ export interface McpHostClient {
model: string
bindingHash: string
} | null
+ /** Grok bootstrap only. */
+ subscriptionBinding?: {
+ connectionKey: string
+ catalogRevision: number
+ credentialRevision: number
+ model: string
+ bindingHash: string
+ } | null
}
): Promise<{ status: number; body: Record<string, unknown> }>
}
@@ -150,6 +159,18 @@ export interface HandleOptions {
/** Per-broker assigned grant keys. Each broker reads only its own key. */
type BrokerConnectionKeys = Pick<HandleOptions, 'codexConnectionKey' | 'grokConnectionKey'>
+/** WRC process switches the broker needs to agree with the recipe verdict. */
+export interface ModelConfigHandlerOptions {
+ /**
+ * WRC_GROK_SUBSCRIPTION_ENABLED. Off (the default) means no Grok grant is
+ * redeemable here, matching `projectCodexRecipeVerdict`, which already
+ * withholds the Grok scope, egress, binding and pod env.
+ */
+ grokSubscriptionEnabled?: boolean
+}
+
+type AllowlistGate = BrokerConnectionKeys & { grokSubscriptionEnabled: boolean }
+
// ─── Handler ────────────────────────────────────────────────────────────
const CONFIGMAP_NAME = 'clerum-model-secret-mapping'
@@ -216,14 +237,17 @@ function isModelAllowed(
provider: string,
model: string,
allowlistCm: { data: Record<string, string>; annotations?: Record<string, string> },
- keys: BrokerConnectionKeys = {}
+ gate: AllowlistGate
): boolean {
const cm = { metadata: { annotations: allowlistCm.annotations ?? {} }, data: allowlistCm.data }
if (provider === GROK_PROVIDER) {
+ // The local master switch comes first: with it off the recipe pod has no
+ // Grok provider, so no grant can be redeemed whatever the ConfigMap says.
+ if (!gate.grokSubscriptionEnabled) return false
// Grok redeemability is the Grok projection of the assigned Grok grant:
// `grok-enabled`, the grant's own `grok-connections` row (status + models).
// The Codex parser would see the flat union of every Grok grant.
- const grokKey = assignedCodexConnectionKey(keys.grokConnectionKey)
+ const grokKey = assignedCodexConnectionKey(gate.grokConnectionKey)
if (grokKey === CODEX_UNASSIGNED_CONNECTION_KEY) return false
return (
projectGrokExecution(
@@ -234,7 +258,7 @@ function isModelAllowed(
}
if (isLlmProviderId(provider) && PROVIDER_AUTH_MODE[provider] === 'oauth-broker') {
const snapshot = snapshotForAssignedCodexGrant(
- assignedCodexConnectionKey(keys.codexConnectionKey),
+ assignedCodexConnectionKey(gate.codexConnectionKey),
cm,
{ flagEnabled: false }
)
@@ -247,11 +271,24 @@ function isModelAllowed(
}
export class ModelConfigHandler {
+ private readonly grokSubscriptionEnabled: boolean
+
constructor(
private readonly k8s: K8sSecretReader,
private readonly mcpHost: McpHostClient,
- private readonly objectStorage?: ObjectStorageReader
- ) {}
+ private readonly objectStorage?: ObjectStorageReader,
+ options: ModelConfigHandlerOptions = {}
+ ) {
+ this.grokSubscriptionEnabled = options.grokSubscriptionEnabled === true
+ }
+
+ private allowlistGate(keys: BrokerConnectionKeys = {}): AllowlistGate {
+ return {
+ codexConnectionKey: keys.codexConnectionKey,
+ grokConnectionKey: keys.grokConnectionKey,
+ grokSubscriptionEnabled: this.grokSubscriptionEnabled,
+ }
+ }
/**
* Publish an SDK host's public bootstrap binding without resolving a Secret.
@@ -350,12 +387,17 @@ export class ModelConfigHandler {
// Without a model there is no pin to apply, and an unpinned
// binding could be for another model. Refuse it rather than accept it
// blind — the pin is the point of this call.
- const verifiedCodexBinding = model
- ? readVerifiedSdkOnlyCodexBinding(result.body.codexBinding, model)
- : null
- const verifiedGrokBinding = model
- ? readVerifiedSdkOnlyGrokBinding(result.body.subscriptionBinding, model)
- : null
+ // Strict slots, matching mcp-host: a Codex binding travels only as
+ // `codexBinding`, a Grok binding only as `subscriptionBinding`, and a
+ // provider never republishes the other broker's slot.
+ const verifiedCodexBinding =
+ model && provider === 'codex-subscription'
+ ? readVerifiedSdkOnlyCodexBinding(result.body.codexBinding, model)
+ : null
+ const verifiedGrokBinding =
+ model && provider === 'grok-subscription'
+ ? readVerifiedSdkOnlyGrokBinding(result.body.subscriptionBinding, model)
+ : null
return {
status: 202,
body: {
@@ -434,7 +476,7 @@ export class ModelConfigHandler {
if (!allowlistCm.exists) {
return { status: 503, body: { error: 'Provider configuration unavailable' } }
}
- if (!isModelAllowed(target.provider, target.model, allowlistCm)) {
+ if (!isModelAllowed(target.provider, target.model, allowlistCm, this.allowlistGate())) {
return { status: 403, body: { error: 'Provider target is not enabled' } }
}
@@ -515,7 +557,7 @@ export class ModelConfigHandler {
)
const brokerBacked = PROVIDER_AUTH_MODE[req.provider] === 'oauth-broker'
if (allowlistCm.exists) {
- const allowed = isModelAllowed(req.provider, req.model, allowlistCm, opts)
+ const allowed = isModelAllowed(req.provider, req.model, allowlistCm, this.allowlistGate(opts))
// oauth-broker configure is identity-only. Spend is gated by
// grantRedeemable on the coordinator and by authorize, not by 4xx here.
if (!allowed && !brokerBacked) {
@@ -584,7 +626,8 @@ export class ModelConfigHandler {
model: req.model,
identityBound: true,
grantRedeemable:
- allowlistCm.exists && isModelAllowed(req.provider, req.model, allowlistCm, opts),
+ allowlistCm.exists &&
+ isModelAllowed(req.provider, req.model, allowlistCm, this.allowlistGate(opts)),
},
}
}
@@ -763,7 +806,12 @@ export class ModelConfigHandler {
log.warn('Skipping fallback with invalid provider/model', { stepId: req.stepId })
continue
}
- const allowed = isModelAllowed(entry.provider, entry.model, allowlist, keys)
+ const allowed = isModelAllowed(
+ entry.provider,
+ entry.model,
+ allowlist,
+ this.allowlistGate(keys)
+ )
if (!allowed) {
log.warn('Skipping fallback model not in allowlist', {
stepId: req.stepId,
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
index e9f9f597f..0a3d8a25c 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
@@ -15,6 +15,7 @@ import {
} from './pluginWorkloadSdkProvisioner.testFixtures'
import type { PluginWorkloadSdkCodexBindingProof } from './sdkOnlyCodexBinding'
import { mintSdkOnlyCodexBindingProof } from './sdkOnlyCodexBinding'
+import { mintSdkOnlyGrokBindingProof } from './sdkOnlyGrokBinding'
const RECIPE = 'codex-sdk'
const MODEL = 'gpt-5.3-codex'
@@ -339,4 +340,55 @@ describe('eager Codex policy gate', () => {
expect(await harness.reconcile({ codexBinding: MINTED })).toBe('deploying')
expect(harness.provisioner.getBootstrapProof(RECIPE)).toBeUndefined()
})
+
+ // B-L14: strict binding slots. mcp-host publishes a Codex binding only as
+ // `codexBinding`; WRC must read nothing else for Codex.
+ it('rejects a Codex bootstrap that echoes its binding only as subscriptionBinding', async () => {
+ // Mutation caught: parsing Codex as `codexBinding ?? subscriptionBinding`.
+ const body = readyBootstrapBody(null)
+ const harness = makeHarness({ ...body, body: { ...body.body, subscriptionBinding: MINTED } })
+
+ expect(await harness.reconcile({ codexBinding: MINTED })).toBe('deploying')
+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toBeUndefined()
+ })
+
+ it('never records a subscriptionBinding on a Codex proof', async () => {
+ // Mutation caught: parsing `subscriptionBinding` for a Codex body at all
+ // (the proof carried a second, unverified-for-this-provider slot).
+ const body = readyBootstrapBody(MINTED)
+ const harness = makeHarness({ ...body, body: { ...body.body, subscriptionBinding: MINTED } })
+
+ expect(await harness.reconcile({ codexBinding: MINTED })).toBe('ready')
+ const proof = harness.provisioner.getBootstrapProof(RECIPE)
+ expect(proof).toMatchObject({ codexBinding: MINTED })
+ expect(proof).not.toHaveProperty('subscriptionBinding')
+ })
+
+ it('does not let a cached Grok-slot binding answer ready for a Codex host', async () => {
+ // Mutation caught: the uncertain-provenance early return accepting
+ // `codexBinding || subscriptionBinding` instead of the agent's own slot.
+ const grokBinding = mintSdkOnlyGrokBindingProof({
+ connectionKey: 'team-plus',
+ catalogRevision: 4,
+ credentialRevision: 2,
+ model: MODEL,
+ })
+ const harness = makeHarness({
+ status: 202,
+ body: {
+ ...readyBootstrapBody(null).body,
+ provider: 'grok-subscription',
+ defaultProvider: 'grok-subscription',
+ subscriptionBinding: grokBinding,
+ },
+ })
+ expect(await harness.reconcile({ codexBinding: null })).toBe('awaiting_policy')
+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toMatchObject({
+ subscriptionBinding: grokBinding,
+ })
+
+ harness.configure.mockClear()
+ expect(await harness.reconcile({ codexBindingUndecidable: true })).toBe('awaiting_policy')
+ expect(harness.configure).not.toHaveBeenCalled()
+ })
})
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts
index 5651bdd22..df9f74f4d 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts
@@ -16,6 +16,7 @@ import {
ineligibleCodexProjection,
} from './pluginWorkloadSdkProvisioner.testFixtures'
import type { PluginWorkloadSdkCodexBindingProof } from './sdkOnlyCodexBinding'
+import { mintSdkOnlyCodexBindingProof } from './sdkOnlyCodexBinding'
import { mintSdkOnlyGrokBindingProof } from './sdkOnlyGrokBinding'
const RECIPE = 'grok-sdk'
@@ -254,4 +255,64 @@ describe('eager Grok policy gate', () => {
policyReason: 'execution_binding_missing',
})
})
+
+ // B-L14: strict binding slots. mcp-host publishes a Grok binding only as
+ // `subscriptionBinding`; WRC must read nothing else for Grok.
+ it('rejects a Grok bootstrap that echoes its binding only as codexBinding', async () => {
+ // Mutation caught: parsing Grok as `subscriptionBinding ?? codexBinding`
+ // (the pre-fix fallback), which reported this echo as ready.
+ const body = readyBootstrapBody(null)
+ const harness = makeHarness({ ...body, body: { ...body.body, codexBinding: MINTED } })
+
+ expect(await harness.reconcile({ grokBinding: MINTED })).toBe('deploying')
+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toBeUndefined()
+ })
+
+ it('never records a codexBinding on a Grok proof', async () => {
+ // Mutation caught: parsing `codexBinding` for a Grok body. The Codex digest
+ // below verifies as a Codex binding, so the pre-fix proof carried it.
+ const codexSlot = mintSdkOnlyCodexBindingProof({
+ connectionKey: 'team-grok',
+ catalogRevision: 5,
+ credentialRevision: 2,
+ model: MODEL,
+ })
+ const body = readyBootstrapBody(MINTED)
+ const harness = makeHarness({ ...body, body: { ...body.body, codexBinding: codexSlot } })
+
+ expect(await harness.reconcile({ grokBinding: MINTED })).toBe('ready')
+ const proof = harness.provisioner.getBootstrapProof(RECIPE)
+ expect(proof).toMatchObject({ subscriptionBinding: MINTED })
+ expect(proof).not.toHaveProperty('codexBinding')
+ })
+
+ it('does not let a cached Codex-slot binding answer ready for a Grok host', async () => {
+ // Mutation caught: the uncertain-provenance early return accepting
+ // `codexBinding || subscriptionBinding` instead of the agent's own slot.
+ const codexSlot = mintSdkOnlyCodexBindingProof({
+ connectionKey: 'team-grok',
+ catalogRevision: 5,
+ credentialRevision: 2,
+ model: MODEL,
+ })
+ const harness = makeHarness({
+ status: 202,
+ body: {
+ ...readyBootstrapBody(null).body,
+ provider: 'codex-subscription',
+ defaultProvider: 'codex-subscription',
+ codexBinding: codexSlot,
+ },
+ })
+ expect(await harness.reconcile({ grokBinding: null })).toBe('awaiting_policy')
+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toMatchObject({
+ codexBinding: codexSlot,
+ })
+
+ harness.configure.mockClear()
+ expect(await harness.reconcile({ grokBinding: null, grokBindingUndecidable: true })).toBe(
+ 'awaiting_policy'
+ )
+ expect(harness.configure).not.toHaveBeenCalled()
+ })
})
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
index a6e41a93d..e7f5ef922 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
@@ -423,7 +423,11 @@ export class PluginWorkloadSdkProvisioner {
!existing ||
existing.policyReady === false ||
existing.contractVersion !== 3 ||
- !(existing.codexBinding || existing.subscriptionBinding) ||
+ // The agent's own slot only: a proof holding the other broker's
+ // binding says nothing about this host's grant.
+ !(mcpHostAgent?.provider === 'grok-subscription'
+ ? existing.subscriptionBinding
+ : existing.codexBinding) ||
existing.policyReason === 'codex_execution_binding_missing' ||
existing.policyReason === 'execution_binding_missing'
) {
@@ -783,11 +787,17 @@ function parseEagerSdkBootstrapProof(
) {
return null
}
- const grok = body.provider === 'grok-subscription'
- const codexBinding = parseCodexBindingProof(body.codexBinding, expectedModel)
- const subscriptionBinding = grok
- ? parseGrokBindingProof(body.subscriptionBinding ?? body.codexBinding, expectedModel)
- : parseCodexBindingProof(body.subscriptionBinding, expectedModel)
+ // Strict slots, matching mcp-host's bootstrap identity: Codex proof lives
+ // only in `codexBinding`, Grok proof only in `subscriptionBinding`. Neither
+ // provider's proof ever carries the other slot.
+ const codexBinding =
+ body.provider === 'codex-subscription'
+ ? parseCodexBindingProof(body.codexBinding, expectedModel)
+ : undefined
+ const subscriptionBinding =
+ body.provider === 'grok-subscription'
+ ? parseGrokBindingProof(body.subscriptionBinding, expectedModel)
+ : undefined
if (
body.provider === 'codex-subscription' &&
body.policyReason === 'codex_execution_binding_missing'
diff --git a/workflow-recipes/src/workflow/sdkOnlyGrokBinding.test.ts b/workflow-recipes/src/workflow/sdkOnlyGrokBinding.test.ts
index 1f5ebabc2..3ac5c59a8 100644
--- a/workflow-recipes/src/workflow/sdkOnlyGrokBinding.test.ts
+++ b/workflow-recipes/src/workflow/sdkOnlyGrokBinding.test.ts
@@ -69,4 +69,17 @@ describe('readVerifiedSdkOnlyGrokBinding', () => {
)
).toBeNull()
})
+
+ it('rejects a self-consistent proof minted for another model', () => {
+ // Mutation caught: dropping the model pin. The hash covers the five
+ // fields, so a proof for another model verifies on its own.
+ const other = mintSdkOnlyGrokBindingProof({
+ connectionKey: 'team-grok',
+ catalogRevision: 5,
+ credentialRevision: 2,
+ model: 'grok-build-0.1',
+ })
+ expect(readVerifiedSdkOnlyGrokBinding(other, MODEL)).toBeNull()
+ expect(readVerifiedSdkOnlyGrokBinding(other, 'grok-build-0.1')).toEqual(other)
+ })
})
diff --git a/workflow-recipes/src/workflow/sdkOnlyGrokBinding.ts b/workflow-recipes/src/workflow/sdkOnlyGrokBinding.ts
index 0099d2c90..b28f88014 100644
--- a/workflow-recipes/src/workflow/sdkOnlyGrokBinding.ts
+++ b/workflow-recipes/src/workflow/sdkOnlyGrokBinding.ts
@@ -1,6 +1,9 @@
import { computeGrokPolicyHash } from '@clerum/grok-provider-attempt-contract'
import type { PluginWorkloadSdkCodexBindingProof } from './sdkOnlyCodexBinding'
-import { isPluginWorkloadSdkCodexBindingProof } from './sdkOnlyCodexBinding'
+import {
+ isPluginWorkloadSdkCodexBindingProof,
+ sanitizePluginWorkloadSdkCodexBindingProof,
+} from './sdkOnlyCodexBinding'
export function mintSdkOnlyGrokBindingProof(binding: {
connectionKey: string
@@ -41,11 +44,6 @@ export function readVerifiedSdkOnlyGrokBinding(
if (!isPluginWorkloadSdkCodexBindingProof(value)) return null
if (value.model !== model) return null
if (!verifySdkOnlyGrokBindingHash(value)) return null
- return {
- connectionKey: value.connectionKey,
- catalogRevision: value.catalogRevision,
- credentialRevision: value.credentialRevision,
- model: value.model,
- bindingHash: value.bindingHash,
- }
+ // The five-field proof shape is provider-neutral; only the digest differs.
+ return sanitizePluginWorkloadSdkCodexBindingProof(value)
}
diff --git a/workflow-recipes/tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts b/workflow-recipes/tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts
index 7bdd678f6..9d2d027b0 100644
--- a/workflow-recipes/tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts
+++ b/workflow-recipes/tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts
@@ -480,4 +480,105 @@ describe('ModelConfigHandler Plugin SDK per-attempt credential broker', () => {
expect(result.status).toBe(502)
expect(result.body).not.toHaveProperty('policyReason')
})
+
+ // B-L14: strict binding slots. mcp-host answers a Grok bootstrap with
+ // `subscriptionBinding` only and a Codex bootstrap with `codexBinding` only;
+ // the broker republishes nothing from the other provider's slot.
+ describe('strict binding slots', () => {
+ const fields = { catalogRevision: 5, credentialRevision: 2 }
+ const grokSlot = (model: string) => ({
+ connectionKey: 'team-key',
+ model,
+ ...fields,
+ bindingHash: computeGrokPolicyHash({ connectionKey: 'team-key', model, ...fields }),
+ })
+ const codexSlot = (model: string) => ({
+ connectionKey: 'team-key',
+ model,
+ ...fields,
+ bindingHash: computeCodexPolicyHash({ connectionKey: 'team-key', model, ...fields }),
+ })
+
+ async function publish(provider: string, model: string, echo: Record<string, unknown>) {
+ const mcpHost: McpHostClient = {
+ configure: vi.fn(async () => ({ status: 500, body: {} })),
+ configurePluginWorkloadSdkBootstrap: vi.fn(async () => ({
+ status: 200,
+ body: {
+ configured: true,
+ ready: true,
+ provider,
+ model,
+ contractVersion: 3,
+ policyReady: true,
+ policyState: 'active',
+ ...echo,
+ },
+ })),
+ }
+ const result = await new ModelConfigHandler(
+ reader(),
+ mcpHost
+ ).configurePluginWorkloadSdkBootstrap(
+ provider,
+ model,
+ 'http://mcp-host:8090',
+ 'wrc-token',
+ 'promptBridge',
+ null
+ )
+ expect(result.status).toBe(202)
+ return result.body
+ }
+
+ it('never republishes a codexBinding for a Grok bootstrap', async () => {
+ // Mutation caught: verifying `codexBinding` regardless of provider — a
+ // Codex digest verifies as a Codex binding and leaked onto a Grok proof.
+ const body = await publish('grok-subscription', 'grok-4.6', {
+ subscriptionBinding: grokSlot('grok-4.6'),
+ codexBinding: codexSlot('grok-4.6'),
+ })
+ expect(body.subscriptionBinding).toEqual(grokSlot('grok-4.6'))
+ expect(body).not.toHaveProperty('codexBinding')
+ })
+
+ it('never reads a Grok binding out of the codexBinding slot', async () => {
+ // Mutation caught: reading Grok as `subscriptionBinding ?? codexBinding`.
+ const body = await publish('grok-subscription', 'grok-4.6', {
+ codexBinding: grokSlot('grok-4.6'),
+ })
+ expect(body).not.toHaveProperty('subscriptionBinding')
+ expect(body).not.toHaveProperty('codexBinding')
+ })
+
+ it('never republishes a subscriptionBinding for a Codex bootstrap', async () => {
+ // Mutation caught: verifying `subscriptionBinding` regardless of provider.
+ const body = await publish('codex-subscription', 'gpt-5.1', {
+ codexBinding: codexSlot('gpt-5.1'),
+ subscriptionBinding: grokSlot('gpt-5.1'),
+ })
+ expect(body.codexBinding).toEqual(codexSlot('gpt-5.1'))
+ expect(body).not.toHaveProperty('subscriptionBinding')
+ })
+
+ it('never reads a Codex binding out of the subscriptionBinding slot', async () => {
+ // Mutation caught: reading Codex as `codexBinding ?? subscriptionBinding`.
+ const body = await publish('codex-subscription', 'gpt-5.1', {
+ subscriptionBinding: codexSlot('gpt-5.1'),
+ })
+ expect(body).not.toHaveProperty('codexBinding')
+ expect(body).not.toHaveProperty('subscriptionBinding')
+ })
+
+ it('republishes no binding for a static-provider bootstrap', async () => {
+ // Mutation caught: slot reads not gated on the provider at all.
+ const body = await publish('openai', 'gpt-5.1', {
+ codexBinding: codexSlot('gpt-5.1'),
+ subscriptionBinding: grokSlot('gpt-5.1'),
+ contractVersion: 2,
+ })
+ expect(body).not.toHaveProperty('codexBinding')
+ expect(body).not.toHaveProperty('subscriptionBinding')
+ })
+ })
})
diff --git a/workflow-recipes/tests/unit/workflow/modelConfigHandler.test.ts b/workflow-recipes/tests/unit/workflow/modelConfigHandler.test.ts
index 64c73b964..3a3bfa302 100644
--- a/workflow-recipes/tests/unit/workflow/modelConfigHandler.test.ts
+++ b/workflow-recipes/tests/unit/workflow/modelConfigHandler.test.ts
@@ -793,11 +793,12 @@ describe('POST /configure-model — Grok grantRedeemable uses the Grok projectio
async function redeemable(
annotations: Record<string, string>,
opts: { grokConnectionKey?: string; codexConnectionKey?: string },
- model = 'grok-4.6'
+ model = 'grok-4.6',
+ grokSubscriptionEnabled = true
): Promise<unknown> {
const k8s = mockK8s({}, null, GROK_ALLOWLIST, annotations)
const mcpHost = mockMcpHost()
- const handler = new ModelConfigHandler(k8s, mcpHost)
+ const handler = new ModelConfigHandler(k8s, mcpHost, undefined, { grokSubscriptionEnabled })
// Mirror the pre-fix REST caller, which handed the Grok key over as
// `codexConnectionKey`: a handler that still consults the Codex parser
// with that key reports every negative case below as redeemable.
@@ -919,11 +920,13 @@ describe('POST /configure-model — Grok grantRedeemable uses the Grok projectio
const mapping = { openai: 'openai-secret/apiKey', 'grok-subscription': 'grok-secret/key' }
const secret = { apiKey: 'sk-test-123', key: 'unused' }
const allowlist = { ...GROK_ALLOWLIST, openai: JSON.stringify([{ model: 'gpt-4' }]) }
- const run = async (annotations: Record<string, string>) => {
+ const run = async (annotations: Record<string, string>, grokSubscriptionEnabled = true) => {
const mcpHost = mockMcpHost()
const handler = new ModelConfigHandler(
mockK8s(mapping, secret, allowlist, annotations),
- mcpHost
+ mcpHost,
+ undefined,
+ { grokSubscriptionEnabled }
)
const result = await handler.handle(
{
@@ -946,5 +949,65 @@ describe('POST /configure-model — Grok grantRedeemable uses the Grok projectio
await expect(
run(grokAnnotations({ 'team-grok': connected(['grok-4.6']) }))
).resolves.toMatchObject({ fallbacks: [{ provider: 'grok-subscription', model: 'grok-4.6' }] })
+ // WRC_GROK_SUBSCRIPTION_ENABLED off: the same healthy grant is not a
+ // usable fallback, because the recipe pod never gets the Grok provider.
+ await expect(
+ run(grokAnnotations({ 'team-grok': connected(['grok-4.6']) }), false)
+ ).resolves.toBeUndefined()
+ })
+
+ // C-WRC / A-RP-007: WRC_GROK_SUBSCRIPTION_ENABLED is folded into the recipe
+ // verdict (no scope, egress, binding or pod env when off). The coordinator's
+ // grantRedeemable gate must agree, or a step passes it and dies at provider
+ // construction inside a pod that has no Grok provider.
+ it('is not redeemable when WRC_GROK_SUBSCRIPTION_ENABLED is off, even for a healthy grant', async () => {
+ const healthy = grokAnnotations({ 'team-grok': connected(['grok-4.6']) })
+ await expect(
+ redeemable(healthy, { grokConnectionKey: 'team-grok' }, 'grok-4.6', false)
+ ).resolves.toBe(false)
+ // Liveness witness: the identical input is redeemable with the flag on.
+ await expect(
+ redeemable(healthy, { grokConnectionKey: 'team-grok' }, 'grok-4.6', true)
+ ).resolves.toBe(true)
+ })
+
+ it('defaults the WRC Grok flag to off when the handler is built without options', async () => {
+ const k8s = mockK8s(
+ {},
+ null,
+ GROK_ALLOWLIST,
+ grokAnnotations({ 'team-grok': connected(['grok-4.6']) })
+ )
+ const result = await new ModelConfigHandler(k8s, mockMcpHost()).handle(
+ { stepId: 's1', provider: 'grok-subscription', model: 'grok-4.6' },
+ 'http://mcp:8080',
+ 'tok',
+ { grokConnectionKey: 'team-grok' }
+ )
+ expect(result.status).toBe(202)
+ expect(result.body.grantRedeemable).toBe(false)
+ })
+
+ it('leaves Codex grantRedeemable unaffected by the WRC Grok flag', async () => {
+ const annotations = {
+ 'clerum.io/codex-enabled': 'true',
+ 'clerum.io/codex-connections': JSON.stringify({ 'team-plus': connected(['gpt-5.1']) }),
+ }
+ const allowlist = { 'codex-subscription': JSON.stringify([{ model: 'gpt-5.1' }]) }
+ for (const grokSubscriptionEnabled of [false, true]) {
+ const handler = new ModelConfigHandler(
+ mockK8s({}, null, allowlist, annotations),
+ mockMcpHost(),
+ undefined,
+ { grokSubscriptionEnabled }
+ )
+ const result = await handler.handle(
+ { stepId: 's1', provider: 'codex-subscription', model: 'gpt-5.1' },
+ 'http://mcp:8080',
+ 'tok',
+ { codexConnectionKey: 'team-plus' }
+ )
+ expect(result.body.grantRedeemable).toBe(true)
+ }
})
})