Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat: dual-read subscription grant annotations
Jose Gabriel Ramirez Encinas91a831bf292e
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 7accde0c0..fa7611520 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.551",+ "version": "0.1.552","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.551",+ "version": "0.1.552","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.jsonindex b3b94222e..8211afaca 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.551",+ "version": "0.1.552","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/recipes.ts b/control-api/src/routes/admin/recipes.tsindex 92fac5937..f91df1c1e 100644--- a/control-api/src/routes/admin/recipes.ts+++ b/control-api/src/routes/admin/recipes.ts@@ -17,9 +17,9 @@ import {} from '../../secretOwnership.js'import {CODEX_CONNECTION_REF_ANNOTATION,+ CODEX_UNASSIGNED_CONNECTION_KEY,assertCodexConnectionKey,isCodexUnassignedConnectionKey,- readHostCodexConnectionRef,} from '../../services/codexSubscriptionConnection.js'import {ensureRegistryPullSecrets,@@ -27,6 +27,10 @@ import {} from '../../services/registryPullSecretService.js'import { K8sNotFoundError } from '../../services/resourceService.js'import { invalidSecretDataKeyReason } from '../../services/secretKeys.js'+import {+ SUBSCRIPTION_CONNECTION_REF_ANNOTATION,+ readSubscriptionConnectionRef,+} from '../../services/subscriptionGrantIdentity.js'import {validateWorkflowRecipeEgressPreflight,validateWorkflowRecipeLimits,@@ -1257,8 +1261,12 @@ function recipeHasPluginWorkloadSdk(spec?: Record<string, unknown>): boolean {}function readRequestedCodexRecipeGrant(body: RecipeBody): string {- const raw = body.metadata?.annotations?.[CODEX_CONNECTION_REF_ANNOTATION]- return readHostCodexConnectionRef(typeof raw === 'string' ? raw : '')+ const result = readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations: body.metadata?.annotations,+ })+ if (!result.ok) return CODEX_UNASSIGNED_CONNECTION_KEY+ return result.connectionKey}function validateCodexRecipeGrant(@@ -1293,9 +1301,10 @@ function validateCodexRecipeGrant(function bodyHasCodexGrantAnnotation(body: RecipeBody): boolean {const annotations = body.metadata?.annotations- return Boolean(- annotations &&- Object.prototype.hasOwnProperty.call(annotations, CODEX_CONNECTION_REF_ANNOTATION)+ if (!annotations) return false+ return (+ Object.prototype.hasOwnProperty.call(annotations, CODEX_CONNECTION_REF_ANNOTATION) ||+ Object.prototype.hasOwnProperty.call(annotations, SUBSCRIPTION_CONNECTION_REF_ANNOTATION))}diff --git a/control-api/src/services/recipeCodexGrantIdentity.ts b/control-api/src/services/recipeCodexGrantIdentity.tsindex 461262785..0864637c1 100644--- a/control-api/src/services/recipeCodexGrantIdentity.ts+++ b/control-api/src/services/recipeCodexGrantIdentity.ts@@ -6,9 +6,9 @@ import {CODEX_UNASSIGNED_CONNECTION_KEY,getSafeCodexSubscriptionConnection,isCodexUnassignedConnectionKey,- readHostCodexConnectionRef,} from './codexSubscriptionConnection.js'import { K8sConflictError } from './resourceService.js'+import { readSubscriptionConnectionRef } from './subscriptionGrantIdentity.js'export class RecipeCodexGrantIdentityError extends Error {constructor(@@ -22,7 +22,18 @@ export class RecipeCodexGrantIdentityError extends Error {}export function readRecipeGrantIdentity(annotations?: Record<string, string> | null): string {- return readHostCodexConnectionRef(annotations?.[CODEX_CONNECTION_REF_ANNOTATION])+ const result = readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations,+ })+ if (!result.ok) {+ throw new RecipeCodexGrantIdentityError(+ 422,+ 'subscription_annotations_disagree',+ result.message+ )+ }+ return result.connectionKey}function asRecord(value: unknown): Record<string, unknown> | undefined {diff --git a/control-api/test/services.recipeCodexGrantIdentity.test.ts b/control-api/test/services.recipeCodexGrantIdentity.test.tsindex 63dfdc507..1bdcb21b9 100644--- a/control-api/test/services.recipeCodexGrantIdentity.test.ts+++ b/control-api/test/services.recipeCodexGrantIdentity.test.ts@@ -41,6 +41,18 @@ describe('recipe Codex grant identity', () => {expect(readRecipeGrantIdentity({ 'clerum.io/codex-connection-ref': 'team-plus' })).toBe('team-plus')+ expect(+ readRecipeGrantIdentity({ 'clerum.io/subscription-connection-ref': 'personal-pro' })+ ).toBe('personal-pro')+ })++ it('rejects disagreeing subscription annotations', () => {+ expect(() =>+ readRecipeGrantIdentity({+ 'clerum.io/codex-connection-ref': 'team-plus',+ 'clerum.io/subscription-connection-ref': 'other-key',+ })+ ).toThrow(/disagree/)})it('rejects a named publish when the grant is not live', async () => {diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 8afefb69d..3e51a6eb4 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.329",+ "version": "0.1.330","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.329",+ "version": "0.1.330","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex e8e13a6e2..856c5c2a1 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.329",+ "version": "0.1.330","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.ts b/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.tsindex ef79d1ca4..0e801fa8d 100644--- a/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.ts+++ b/mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.ts@@ -1,4 +1,4 @@-import { isRunnableLlmModelId } from '@clerum/llm-providers'+import { PROVIDER_AUTH_MODE, isLlmProviderId, isRunnableLlmModelId } from '@clerum/llm-providers'import type { PluginWorkloadSdkCapability } from '../config'import { isLlmProvider } from '../llm/registryCore'import type { LlmProvider } from '../llm/registryCore'@@ -23,6 +23,10 @@ export interface PluginWorkloadSdkBootstrapIdentityDeps {export type PluginWorkloadSdkBootstrapCapabilityFamily = 'promptBridge' | 'clientNotifications'+function isOauthBrokerProvider(provider: string): boolean {+ return isLlmProviderId(provider) && PROVIDER_AUTH_MODE[provider] === 'oauth-broker'+}+/*** Resolve the one bootstrap proof WRC is allowed to request from the* capability projection mounted into this mcp-host. A mixed recipe bootstraps@@ -90,7 +94,7 @@ export async function configurePluginWorkloadSdkBootstrapIdentity(// Always integrity-check a supplied binding before the provider protocol// branch. Request-controlled provider/version must not skip this check.const verifiedBinding = readVerifiedSdkOnlyCodexBinding(req.codexBinding, model)- if (req.provider === 'codex-subscription') {+ if (isOauthBrokerProvider(req.provider)) {if (!verifiedBinding) {replaceSdkOnlyCodexBinding(null)return {@@ -121,20 +125,20 @@ export async function configurePluginWorkloadSdkBootstrapIdentity(try {proof = deps.verify ? await deps.verify(req.provider, model) : null} catch (err) {- if (req.provider === 'codex-subscription') replaceSdkOnlyCodexBinding(null)+ if (isOauthBrokerProvider(req.provider)) replaceSdkOnlyCodexBinding(null)throw err}if (deps.verify && !proof) {- if (req.provider === 'codex-subscription') replaceSdkOnlyCodexBinding(null)+ if (isOauthBrokerProvider(req.provider)) replaceSdkOnlyCodexBinding(null)return {configured: false,ready: false,- contractVersion: req.provider === 'codex-subscription' ? 3 : 2,+ contractVersion: isOauthBrokerProvider(req.provider) ? 3 : 2,message: 'Plugin Workload SDK identity bootstrap contract is not ready',}}if (- req.provider === 'codex-subscription' &&+ isOauthBrokerProvider(req.provider) &&proof &&(proof.codexBindingReady === false || proof.policyReason === 'codex_execution_binding_missing')) {@@ -154,7 +158,7 @@ export async function configurePluginWorkloadSdkBootstrapIdentity(}}deps.onConfigured?.({ provider: req.provider, defaultModel: model })- const contractVersion = req.provider === 'codex-subscription' ? 3 : 2+ const contractVersion = isOauthBrokerProvider(req.provider) ? 3 : 2return {configured: true,ready: true,@@ -178,7 +182,7 @@ export async function configurePluginWorkloadSdkBootstrapIdentity(...(proof?.clientNotificationsPolicyReason !== undefined? { clientNotificationsPolicyReason: proof.clientNotificationsPolicyReason }: {}),- ...(req.provider === 'codex-subscription' && verifiedBinding+ ...(isOauthBrokerProvider(req.provider) && verifiedBinding? { codexBinding: verifiedBinding }: {}),}diff --git a/packages/codex-catalog-projection/index.cjs b/packages/codex-catalog-projection/index.cjsindex c911f2bf8..9f62eb343 100644--- a/packages/codex-catalog-projection/index.cjs+++ b/packages/codex-catalog-projection/index.cjs@@ -8,6 +8,7 @@ const CODEX_CONNECTION_STATUS_ANNOTATION = 'clerum.io/codex-connection-status'const CODEX_ENABLED_ANNOTATION = 'clerum.io/codex-enabled'const CODEX_CONNECTIONS_ANNOTATION = 'clerum.io/codex-connections'const CODEX_CONNECTION_REF_ANNOTATION = 'clerum.io/codex-connection-ref'+const SUBSCRIPTION_CONNECTION_REF_ANNOTATION = 'clerum.io/subscription-connection-ref'const CODEX_UNASSIGNED_CONNECTION_KEY = 'unassigned'const CODEX_PROVIDER = 'codex-subscription'const CODEX_EXECUTE_SCOPE = 'llm:codex:execute'@@ -22,6 +23,40 @@ function isCodexUnassignedConnectionKey(value) {return assignedCodexConnectionKey(value) === CODEX_UNASSIGNED_CONNECTION_KEY}+/**+ * Dual-key grant reader. Codex alias is honored only when provider is+ * `codex-subscription`. Disagree (both set, unequal) fails closed. A leftover+ * Codex alias on any other provider fails closed.+ */+function readSubscriptionConnectionRef(input) {+ const provider = input && typeof input.provider === 'string' ? input.provider : ''+ const annotations = (input && input.annotations) || {}+ const canonical =+ typeof annotations[SUBSCRIPTION_CONNECTION_REF_ANNOTATION] === 'string'+ ? annotations[SUBSCRIPTION_CONNECTION_REF_ANNOTATION].trim()+ : ''+ const alias =+ typeof annotations[CODEX_CONNECTION_REF_ANNOTATION] === 'string'+ ? annotations[CODEX_CONNECTION_REF_ANNOTATION].trim()+ : ''++ if (provider === CODEX_PROVIDER) {+ if (canonical && alias && canonical !== alias) {+ return { ok: false, code: 'host_binding_mismatch', message: 'subscription connection annotations disagree' }+ }+ return { ok: true, connectionKey: assignedCodexConnectionKey(canonical || alias) }+ }++ if (alias) {+ return {+ ok: false,+ code: 'host_binding_mismatch',+ message: 'Codex connection annotation is not valid for this oauth-broker provider',+ }+ }+ return { ok: true, connectionKey: assignedCodexConnectionKey(canonical) }+}+function snapshotFromConfigMapError(error) {return { flagEnabled: false, snapshotError: error }}@@ -359,11 +394,13 @@ module.exports = {CODEX_ENABLED_ANNOTATION,CODEX_CONNECTIONS_ANNOTATION,CODEX_CONNECTION_REF_ANNOTATION,+ SUBSCRIPTION_CONNECTION_REF_ANNOTATION,CODEX_UNASSIGNED_CONNECTION_KEY,CODEX_PROVIDER,CODEX_EXECUTE_SCOPE,assignedCodexConnectionKey,isCodexUnassignedConnectionKey,+ readSubscriptionConnectionRef,snapshotFromConfigMapError,parseAllowedModelsSnapshot,snapshotForAssignedCodexGrant,diff --git a/packages/codex-catalog-projection/index.d.ts b/packages/codex-catalog-projection/index.d.tsindex f7be31004..886193317 100644--- a/packages/codex-catalog-projection/index.d.ts+++ b/packages/codex-catalog-projection/index.d.ts@@ -15,6 +15,7 @@ export declare const CODEX_CONNECTION_STATUS_ANNOTATION: 'clerum.io/codex-connecexport declare const CODEX_ENABLED_ANNOTATION: 'clerum.io/codex-enabled'export declare const CODEX_CONNECTIONS_ANNOTATION: 'clerum.io/codex-connections'export declare const CODEX_CONNECTION_REF_ANNOTATION: 'clerum.io/codex-connection-ref'+export declare const SUBSCRIPTION_CONNECTION_REF_ANNOTATION: 'clerum.io/subscription-connection-ref'export declare const CODEX_UNASSIGNED_CONNECTION_KEY: 'unassigned'export declare const CODEX_PROVIDER: 'codex-subscription'export declare const CODEX_EXECUTE_SCOPE: 'llm:codex:execute'@@ -112,6 +113,15 @@ export declare function snapshotForAssignedCodexGrant(lastConfigMap: CodexConfigMapView | undefined | null,fallback: CodexCatalogSnapshot): CodexCatalogSnapshot+export type SubscriptionConnectionRefResult =+ | { ok: true; connectionKey: string }+ | { ok: false; code: 'host_binding_mismatch'; message: string }++export declare function readSubscriptionConnectionRef(input: {+ provider: string+ annotations?: Record<string, string> | null+}): SubscriptionConnectionRefResult+export declare function collectCodexTargets(spec: CodexHostSpec): CodexTarget[]export declare function projectCodexExecution(spec: CodexHostSpec,diff --git a/packages/codex-catalog-projection/index.test.cjs b/packages/codex-catalog-projection/index.test.cjsindex 63fd68102..f3aa8e529 100644--- a/packages/codex-catalog-projection/index.test.cjs+++ b/packages/codex-catalog-projection/index.test.cjs@@ -41,6 +41,49 @@ test('runtime exports stay aligned with the declaration file', () => {assert.deepEqual(Object.keys(projection).sort(), declared)})+test('readSubscriptionConnectionRef dual-reads Codex alias and canonical annotation', () => {+ const CANON = projection.SUBSCRIPTION_CONNECTION_REF_ANNOTATION+ const ALIAS = projection.CODEX_CONNECTION_REF_ANNOTATION+ assert.equal(+ projection.readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations: { [ALIAS]: ' team-plus ' },+ }).connectionKey,+ 'team-plus'+ )+ assert.equal(+ projection.readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations: { [CANON]: 'personal-pro' },+ }).connectionKey,+ 'personal-pro'+ )+ assert.equal(+ projection.readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations: { [ALIAS]: 'team-plus', [CANON]: 'team-plus' },+ }).connectionKey,+ 'team-plus'+ )+ const disagree = projection.readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations: { [ALIAS]: 'team-plus', [CANON]: 'other-key' },+ })+ assert.equal(disagree.ok, false)+ const leftover = projection.readSubscriptionConnectionRef({+ provider: 'openai',+ annotations: { [ALIAS]: 'team-plus' },+ })+ assert.equal(leftover.ok, false)+ assert.equal(+ projection.readSubscriptionConnectionRef({+ provider: 'codex-subscription',+ annotations: {},+ }).connectionKey,+ 'unassigned'+ )+})+test('assignedCodexConnectionKey treats empty as unassigned and never invents deployment-default', () => {assert.equal(projection.assignedCodexConnectionKey(undefined), 'unassigned')assert.equal(projection.assignedCodexConnectionKey(''), 'unassigned')diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex dfadc90db..658e6bf84 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.351",+ "version": "0.1.352","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.351",+ "version": "0.1.352","license": "SEE LICENSE IN LICENSE","dependencies": {"@aws-sdk/client-s3": "^3.1009.0",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex 833f27248..a1304124e 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.351",+ "version": "0.1.352","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/k8sClient.test.ts b/workflow-recipes/src/k8sClient.test.tsindex af2d4f568..7649ba932 100644--- a/workflow-recipes/src/k8sClient.test.ts+++ b/workflow-recipes/src/k8sClient.test.ts@@ -1584,6 +1584,58 @@ describe('workload status refresh loop helpers', () => {})+ it('reconciles when the canonical subscription annotation changes without a generation bump', async () => {+ const cached = makeWorkloadRecipe({+ metadata: { name: 'active-recipe', namespace: 'sandbox-recipes', generation: 7 },+ status: { phase: 'active', message: 'All workloads deployed' },+ })+ const granted = makeWorkloadRecipe({+ metadata: {+ name: 'active-recipe',+ namespace: 'sandbox-recipes',+ generation: 7,+ resourceVersion: 'next',+ annotations: { 'clerum.io/subscription-connection-ref': 'personal-pro' },+ },+ status: { phase: 'active', message: 'All workloads deployed' },+ })+ const reconcile = vi.fn().mockResolvedValue({+ phase: 'active',+ message: 'All workloads deployed',+ workloadStatuses: [],+ })++ type InternalWatcher = {+ recipes: Map<string, WorkflowRecipeCRD>+ transientRetries: Map<string, { timer: ReturnType<typeof setTimeout>; attempts: number }>+ stopped: boolean+ reconciler: {+ reconcile: typeof reconcile+ isRecipeStillActive: ReturnType<typeof vi.fn>+ ensureFinalizer: ReturnType<typeof vi.fn>+ patchStatus: ReturnType<typeof vi.fn>+ }+ handleRecipeEvent: (type: string, recipe: WorkflowRecipeCRD) => Promise<void>+ scheduleTransientRetry: ReturnType<typeof vi.fn>+ clearTransientRetry: ReturnType<typeof vi.fn>+ }+ const internal = Object.create(WorkflowRecipeWatcher.prototype) as InternalWatcher+ internal.recipes = new Map([[cached.metadata.name, cached]])+ internal.transientRetries = new Map()+ internal.stopped = false+ internal.reconciler = {+ reconcile,+ isRecipeStillActive: vi.fn().mockResolvedValue(true),+ ensureFinalizer: vi.fn().mockResolvedValue(undefined),+ patchStatus: vi.fn().mockResolvedValue(undefined),+ }+ internal.handleRecipeEvent = WorkflowRecipeWatcher.prototype.handleRecipeEvent+ internal.scheduleTransientRetry = vi.fn()+ internal.clearTransientRetry = vi.fn()+ await internal.handleRecipeEvent('MODIFIED', granted)+ expect(reconcile).toHaveBeenCalledTimes(1)+ })+it('reconciles when Codex connection-ref changes without a generation bump', async () => {const cached = makeWorkloadRecipe({metadata: { name: 'active-recipe', namespace: 'sandbox-recipes', generation: 7 },diff --git a/workflow-recipes/src/k8sClient.ts b/workflow-recipes/src/k8sClient.tsindex a58690e47..bb96fccc9 100644--- a/workflow-recipes/src/k8sClient.ts+++ b/workflow-recipes/src/k8sClient.ts@@ -57,7 +57,17 @@ import {} from './types'import { createDbRunChildRecipe } from './workflow/dbRunChildRecipeCreator'import type { JwtTokenFactory } from './workflow/jwtTokenFactory'-import { CODEX_CONNECTION_REF_ANNOTATION } from './workflow/llmAllowedModelsSnapshot'+import {+ CODEX_CONNECTION_REF_ANNOTATION,+ SUBSCRIPTION_CONNECTION_REF_ANNOTATION,+} from './workflow/llmAllowedModelsSnapshot'++function grantIdentityFingerprint(+ recipe: { metadata?: { annotations?: Record<string, string> } } | undefined+): string {+ const annotations = recipe?.metadata?.annotations ?? {}+ return `${annotations[SUBSCRIPTION_CONNECTION_REF_ANNOTATION] ?? ''}\0${annotations[CODEX_CONNECTION_REF_ANNOTATION] ?? ''}`+}const PLURAL = 'workflowrecipes'const MIN_RUNTIME_CREDENTIAL_REFRESH_INTERVAL_MS = 5_000@@ -1181,8 +1191,8 @@ export class WorkflowRecipeWatcher implements WorkflowRecipeProvider {}// Grant identity is a metadata annotation and does not bump generation.// Treat it as a real reconcile, not a status-only skip.- const cachedRef = cached?.metadata.annotations?.[CODEX_CONNECTION_REF_ANNOTATION]- const nextRef = recipe.metadata.annotations?.[CODEX_CONNECTION_REF_ANNOTATION]+ const cachedRef = grantIdentityFingerprint(cached)+ const nextRef = grantIdentityFingerprint(recipe)return cachedRef === nextRef}diff --git a/workflow-recipes/src/workflow/dbRunChildRecipeCreator.test.ts b/workflow-recipes/src/workflow/dbRunChildRecipeCreator.test.tsindex ec491d994..7e2d86c8f 100644--- a/workflow-recipes/src/workflow/dbRunChildRecipeCreator.test.ts+++ b/workflow-recipes/src/workflow/dbRunChildRecipeCreator.test.ts@@ -217,6 +217,26 @@ describe('createDbRunChildRecipe', () => {).toBe('team-plus')})+ it('copies the canonical subscription annotation onto the DB-run child recipe', async () => {+ const parent = makeParent()+ ;(parent.metadata as Record<string, unknown>).annotations = {+ 'clerum.io/subscription-connection-ref': 'personal-pro',+ }+ const customApi = {+ getNamespacedCustomObject: vi.fn().mockResolvedValue(parent),+ createNamespacedCustomObject: vi.fn().mockResolvedValue({+ metadata: { name: 'demo-parent-00000000' },+ }),+ } as unknown as k8s.CustomObjectsApi++ await createDbRunChildRecipe(customApi, makeRun())++ expect(+ (customApi.createNamespacedCustomObject as unknown as ReturnType<typeof vi.fn>).mock+ .calls[0]?.[0]?.body?.metadata?.annotations?.['clerum.io/subscription-connection-ref']+ ).toBe('personal-pro')+ })+it('does not invent a Codex grant annotation when the parent has none', async () => {const customApi = {getNamespacedCustomObject: vi.fn().mockResolvedValue(makeParent()),diff --git a/workflow-recipes/src/workflow/dbRunChildRecipeCreator.ts b/workflow-recipes/src/workflow/dbRunChildRecipeCreator.tsindex 6b3d1eabb..348bdfb94 100644--- a/workflow-recipes/src/workflow/dbRunChildRecipeCreator.ts+++ b/workflow-recipes/src/workflow/dbRunChildRecipeCreator.ts@@ -10,7 +10,10 @@ import {buildChildRecipe,buildDbRunChildName,} from './childRecipeFactory.js'-import { CODEX_CONNECTION_REF_ANNOTATION } from './llmAllowedModelsSnapshot.js'+import {+ CODEX_CONNECTION_REF_ANNOTATION,+ SUBSCRIPTION_CONNECTION_REF_ANNOTATION,+} from './llmAllowedModelsSnapshot.js'import { WORKFLOW_TEAM_ID_LABEL } from './schedulingHandler.js'export const RUN_ID_LABEL = 'clerum.io/workflow-run-id'@@ -20,6 +23,17 @@ export const RUN_ACTOR_TYPE_LABEL = 'clerum.io/workflow-actor-type'export const RUN_OUTPUT_OVERRIDES_ANNOTATION = 'clerum.io/run-output-overrides'export const RUN_INTERMEDIATE_PARAMS_ANNOTATION = 'clerum.io/run-intermediate-parameters'+function copiedGrantIdentityAnnotations(+ annotations: Record<string, string> | undefined+): Record<string, string> {+ const copied: Record<string, string> = {}+ const alias = annotations?.[CODEX_CONNECTION_REF_ANNOTATION]?.trim()+ const canonical = annotations?.[SUBSCRIPTION_CONNECTION_REF_ANNOTATION]?.trim()+ if (alias) copied[CODEX_CONNECTION_REF_ANNOTATION] = alias+ if (canonical) copied[SUBSCRIPTION_CONNECTION_REF_ANNOTATION] = canonical+ return copied+}+const WORKFLOW_RECIPE_API_VERSION = `${CRD_GROUP}/${CRD_VERSION}`const WORKFLOW_RECIPE_KIND = 'WorkflowRecipe'const PARENT_RECIPE_LABEL = 'clerum.io/parent-recipe'@@ -174,12 +188,7 @@ export async function createDbRunChildRecipe(// stamps the parent's chosen connection key on the child so control-api// can attest the grant by reading the child recipe named in hostRef.// A parent without the annotation stays fail-closed (`unassigned`).- ...(response.metadata?.annotations?.[CODEX_CONNECTION_REF_ANNOTATION]?.trim()- ? {- [CODEX_CONNECTION_REF_ANNOTATION]:- response.metadata.annotations[CODEX_CONNECTION_REF_ANNOTATION].trim(),- }- : {}),+ ...copiedGrantIdentityAnnotations(response.metadata?.annotations),},})// Match the JSON representation persisted by Kubernetes: buildChildRecipediff --git a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.test.ts b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.test.tsindex e2b469ad8..c565f1e34 100644--- a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.test.ts+++ b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.test.ts@@ -91,6 +91,21 @@ describe('readRecipeCodexConnectionRef', () => {it('never aliases the reserved deployment-default grant for a missing annotation', () => {expect(readRecipeCodexConnectionRef({})).not.toBe('deployment-default')})++ it('reads the canonical subscription annotation for a Codex recipe', () => {+ expect(+ readRecipeCodexConnectionRef({ 'clerum.io/subscription-connection-ref': 'personal-pro' })+ ).toBe('personal-pro')+ })++ it('fail-closes to unassigned when Codex annotations disagree', () => {+ expect(+ readRecipeCodexConnectionRef({+ 'clerum.io/codex-connection-ref': 'team-plus',+ 'clerum.io/subscription-connection-ref': 'other-key',+ })+ ).toBe('unassigned')+ })})describe('snapshotForAssignedCodexGrant', () => {diff --git a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.tsindex f5d3c8e10..d0dabd7f0 100644--- a/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts+++ b/workflow-recipes/src/workflow/llmAllowedModelsSnapshot.ts@@ -1,6 +1,7 @@import {- CODEX_CONNECTION_REF_ANNOTATION,- assignedCodexConnectionKey,+ CODEX_PROVIDER,+ CODEX_UNASSIGNED_CONNECTION_KEY,+ readSubscriptionConnectionRef,} from '@clerum/codex-catalog-projection'export {@@ -13,6 +14,7 @@ export {CODEX_UNASSIGNED_CONNECTION_KEY,CONNECTION_REVISION_ANNOTATION,CONTENT_HASH_ANNOTATION,+ SUBSCRIPTION_CONNECTION_REF_ANNOTATION,parseAllowedModelsSnapshot,snapshotForAssignedCodexGrant,snapshotFromConfigMapError,@@ -25,7 +27,10 @@ export const ALLOWLIST_CONFIGMAP_NAMESPACE = process.env.CLERUM_MODEL_CONFIG_NAM* grant: only an explicit annotation may spend a ChatGPT subscription.*/export function readRecipeCodexConnectionRef(- annotations: Record<string, string> | undefined+ annotations: Record<string, string> | undefined,+ provider: string = CODEX_PROVIDER): string {- return assignedCodexConnectionKey(annotations?.[CODEX_CONNECTION_REF_ANNOTATION])+ const result = readSubscriptionConnectionRef({ provider, annotations })+ if (!result.ok) return CODEX_UNASSIGNED_CONNECTION_KEY+ return result.connectionKey}diff --git a/workflow-recipes/src/workflow/restEndpoints.ts b/workflow-recipes/src/workflow/restEndpoints.tsindex fb892887d..79bb48496 100644--- a/workflow-recipes/src/workflow/restEndpoints.ts+++ b/workflow-recipes/src/workflow/restEndpoints.ts@@ -2,10 +2,6 @@* WRC REST endpoints for workflow status reporting and management.*/import * as k8s from '@kubernetes/client-node'-import {- CODEX_CONNECTION_REF_ANNOTATION,- assignedCodexConnectionKey,-} from '@clerum/codex-catalog-projection'import { PROVIDER_AUTH_MODE, isLlmProviderId } from '@clerum/llm-providers'import { loadConfig } from '../config'import type {@@ -16,6 +12,7 @@ import { createLogger } from '../observability/logger'import { CRD_GROUP, CRD_VERSION, WORKFLOWRECIPE_PLURAL } from '../reconciler/crdConstants'import { getErrorCode } from '../reconciler/k8sErrors'import { JwtTokenFactory } from './jwtTokenFactory'+import { readRecipeCodexConnectionRef } from './llmAllowedModelsSnapshot'import { ModelConfigHandler } from './modelConfigHandler'import {buildArtifactReaderUrl as buildWorkflowArtifactReaderUrl,@@ -692,8 +689,9 @@ export function createWorkflowEndpointHandlers(} | nullconst handleOpts = {...(validateDegraded ? { validateDegraded } : {}),- codexConnectionKey: assignedCodexConnectionKey(- recipe?.metadata?.annotations?.[CODEX_CONNECTION_REF_ANNOTATION]+ codexConnectionKey: readRecipeCodexConnectionRef(+ recipe?.metadata?.annotations,+ typeof body.provider === 'string' ? body.provider : 'codex-subscription'),}// R5 F6 stop-point: `fallbacks`/`cooldownSeconds`/`triggerOn` are NOT