Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(wrc): compare full recipe ownerRef flags before Context no-op
Alfredo Lopez12c4ed18a03f
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex fbee3b101..8549a3f01 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.340",+ "version": "0.1.341","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.340",+ "version": "0.1.341","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 7747bce78..0e09abecd 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.340",+ "version": "0.1.341","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/mcpDelegation.test.ts b/workflow-recipes/src/reconciler/mcpDelegation.test.tsindex 5f7443ff6..8903ef100 100644--- a/workflow-recipes/src/reconciler/mcpDelegation.test.ts+++ b/workflow-recipes/src/reconciler/mcpDelegation.test.ts@@ -1342,6 +1342,26 @@ describe('ensureRecipeContext', () => {expect(mockCustomApi.replaceNamespacedCustomObject).not.toHaveBeenCalled()})+ it('rewrites a same-namespace private ownerRef when controller flags drifted', async () => {+ const driftedOwnerRef = { ...ownerRef, controller: false, blockOwnerDeletion: false }+ const { mockCustomApi, deps, liveOf } = contextApiWithLiveState({+ metadata: {+ resourceVersion: '3',+ labels: { 'clerum.io/recipe': 'test-recipe', 'clerum.io/managed-by': 'wrc' },+ ownerReferences: [driftedOwnerRef],+ },+ spec: { contextId: 'wf-test-recipe', mcpServers: ['server-a', 'server-b'] },+ })++ await ensureRecipeContext(deps, 'test-recipe', ['server-a', 'server-b'], 'mcp-server', ownerRef)+ await ensureRecipeContext(deps, 'test-recipe', ['server-a', 'server-b'], 'mcp-server', ownerRef)++ expect(mockCustomApi.replaceNamespacedCustomObject).toHaveBeenCalledTimes(1)+ expect(+ (liveOf().metadata as { ownerReferences?: unknown } | undefined)?.ownerReferences+ ).toEqual([ownerRef])+ })+it('skips canonical private Context replace when servers and labels match without a recipe ownerRef', async () => {const mockCustomApi = {createNamespacedCustomObject: vi.fn().mockRejectedValueOnce({ code: 409 }),diff --git a/workflow-recipes/src/reconciler/mcpDelegation.ts b/workflow-recipes/src/reconciler/mcpDelegation.tsindex 08b0cc281..852ce28e4 100644--- a/workflow-recipes/src/reconciler/mcpDelegation.ts+++ b/workflow-recipes/src/reconciler/mcpDelegation.ts@@ -20,6 +20,7 @@ import {isPlatformRegistryImage,} from '@clerum/workflow-runtime-core'import { loadConfig } from '../config'+import { createLogger } from '../observability/logger'import { WorkflowRecipeCRD, WorkloadDef } from '../types'import { CRD_GROUP, CRD_VERSION } from './crdConstants'import { getErrorCode } from './k8sErrors'@@ -177,13 +178,24 @@ function desiredOwnerReferences(return kept}+function ownerReferenceKey(ref: ContextOwnerReference): string {+ return [+ ref.apiVersion,+ ref.kind,+ ref.name,+ ref.uid,+ ref.controller === true ? '1' : '0',+ ref.blockOwnerDeletion === true ? '1' : '0',+ ].join('\0')+}+function sameOwnerReferences(left: readonly ContextOwnerReference[],right: readonly ContextOwnerReference[]): boolean {if (left.length !== right.length) return false- const keys = new Set(right.map(ref => `${ref.kind}/${ref.name}/${ref.uid}`))- return left.every(ref => keys.has(`${ref.kind}/${ref.name}/${ref.uid}`))+ const keys = new Set(right.map(ownerReferenceKey))+ return left.every(ref => keys.has(ownerReferenceKey(ref)))}function authoredLabelsMatch(@@ -931,7 +943,7 @@ export async function ensureRecipeContext(`[MCP-Delegation] Updated per-recipe Context "${contextName}" with ${serverNames.length} server(s)`)} else {- console.log(`[MCP-Delegation] Context "${contextName}" unchanged; skipping update`)+ createLogger('wrc', recipeName).info('Context unchanged; skipping update', { contextName })}} else {throw error