Skip to content

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

TypeScript

fix(wrc): publish run-lane NetworkPolicy ownership conflicts as a condition

Alfredo Lopez8710bf0c5111
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index fa59ea564..09b8aeca9 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.373",
+ "version": "0.1.374",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.373",
+ "version": "0.1.374",
"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 e989368d5..5d5a68519 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.373",
+ "version": "0.1.374",
"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.ts
index 7649ba932..fa4666618 100644
--- a/workflow-recipes/src/k8sClient.test.ts
+++ b/workflow-recipes/src/k8sClient.test.ts
@@ -199,6 +199,53 @@ describe('rotateBrokerTokensOnce', () => {
})
describe('shouldPatchRecipeStatus', () => {
+ describe('WorkflowNetworkPolicyOwnership condition', () => {
+ const conflict = {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False' as const,
+ reason: 'OwnershipConflict',
+ message: 'NetworkPolicy ownership conflict: idle-wf-coord-to-wrc (owner-reference-mismatch)',
+ lastTransitionTime: '2026-09-23T10:00:00.000Z',
+ }
+ const steadyRecipe = (conditions?: (typeof conflict)[]): WorkflowRecipeCRD => ({
+ apiVersion: 'clerum.io/v1alpha1',
+ kind: 'WorkflowRecipe',
+ metadata: { name: 'idle-wf', namespace: 'sandbox-recipes' },
+ spec: { steps: [{ id: 'run', instruction: 'run' }] },
+ status: {
+ phase: 'active',
+ message: 'Workflow idle',
+ ...(conditions ? { conditions } : {}),
+ },
+ })
+ const steadyResult = (workflowConditions?: (typeof conflict)[]) => ({
+ phase: 'active' as const,
+ message: 'Workflow idle',
+ workloadStatuses: [],
+ ...(workflowConditions !== undefined ? { workflowConditions } : {}),
+ })
+
+ it('patches when the condition appears', () => {
+ expect(shouldPatchRecipeStatus(steadyRecipe(), steadyResult([conflict]))).toBe(true)
+ })
+
+ it('patches when the condition disappears', () => {
+ expect(shouldPatchRecipeStatus(steadyRecipe([conflict]), steadyResult([]))).toBe(true)
+ })
+
+ it('does not patch when only lastTransitionTime differs or the result carries no conditions', () => {
+ // Witness: the same steady pair does patch once the condition set changes.
+ expect(shouldPatchRecipeStatus(steadyRecipe(), steadyResult([conflict]))).toBe(true)
+ expect(
+ shouldPatchRecipeStatus(
+ steadyRecipe([conflict]),
+ steadyResult([{ ...conflict, lastTransitionTime: '2026-09-23T11:00:00.000Z' }])
+ )
+ ).toBe(false)
+ expect(shouldPatchRecipeStatus(steadyRecipe([conflict]), steadyResult())).toBe(false)
+ })
+ })
+
it('patches when a terminal workflow keeps the same phase but updates the message', () => {
expect(
shouldPatchRecipeStatus(
diff --git a/workflow-recipes/src/k8sClient.ts b/workflow-recipes/src/k8sClient.ts
index bb96fccc9..736c524f0 100644
--- a/workflow-recipes/src/k8sClient.ts
+++ b/workflow-recipes/src/k8sClient.ts
@@ -61,6 +61,7 @@ import {
CODEX_CONNECTION_REF_ANNOTATION,
SUBSCRIPTION_CONNECTION_REF_ANNOTATION,
} from './workflow/llmAllowedModelsSnapshot'
+import { NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE } from './workflow/workflowReconciler'
function grantIdentityFingerprint(
recipe: { metadata?: { annotations?: Record<string, string> } } | undefined
@@ -169,6 +170,16 @@ export function shouldPatchRecipeStatus(
)
return true
+ // A NetworkPolicy ownership conflict changes neither phase nor message, so
+ // without this clause the condition would never be published or cleared.
+ if (
+ result.workflowConditions !== undefined &&
+ ownedConditionsChanged(recipe.status?.conditions, result.workflowConditions, [
+ NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE,
+ ])
+ )
+ return true
+
return false
}
diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.ts
index 6e2a71115..a2c99d6fe 100644
--- a/workflow-recipes/src/reconciler/reconciler.test.ts
+++ b/workflow-recipes/src/reconciler/reconciler.test.ts
@@ -1312,6 +1312,7 @@ describe('WorkflowRecipeReconciler', () => {
policyReady: true,
verifiedAt: '2026-08-04T00:00:00.000Z',
},
+ networkPolicies: { conflicts: [], retryPending: false },
})
const workflowReconcile = vi.fn()
const setCodexReconcileContext = vi.fn()
@@ -1370,6 +1371,7 @@ describe('WorkflowRecipeReconciler', () => {
const reconcilePluginWorkloadSdkOnly = vi.fn().mockResolvedValue({
phase: 'active',
message: 'Plugin Workload SDK mcp-host registered',
+ networkPolicies: { conflicts: [], retryPending: false },
})
;(
reconciler as unknown as {
@@ -1409,6 +1411,7 @@ describe('WorkflowRecipeReconciler', () => {
const reconcilePluginWorkloadSdkOnly = vi.fn().mockResolvedValue({
phase: 'deploying',
message: 'Plugin Workload SDK mcp-host starting',
+ networkPolicies: { conflicts: [], retryPending: false },
})
;(
reconciler as unknown as {
@@ -1444,6 +1447,110 @@ describe('WorkflowRecipeReconciler', () => {
})
})
+ describe('SDK-only NetworkPolicy ownership condition', () => {
+ const ownershipCondition = {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False' as const,
+ reason: 'OwnershipConflict',
+ message:
+ 'NetworkPolicy ownership conflict: test-recipe-mcp-host-to-gfs (owner-reference-mismatch)',
+ lastTransitionTime: '2026-09-23T10:00:00.000Z',
+ }
+ const bootstrapProof = {
+ ready: true,
+ contractVersion: 2,
+ podUid: 'sdk-pod-uid',
+ provider: 'zai',
+ model: 'glm-4.7',
+ policyReady: true,
+ verifiedAt: '2026-08-04T00:00:00.000Z',
+ }
+ const sdkOnlyRecipe = (conditions?: unknown[]) =>
+ makeRecipe({
+ spec: {
+ agent: { provider: 'zai', model: 'glm-4.7' },
+ workloads: [{ id: 'app', type: 'deployment', image: 'nginx:1.30.1-alpine', port: 8080 }],
+ pluginWorkloadSdk: { promptBridge: {}, allowedCallers: ['app'] },
+ },
+ status: { phase: 'active', ...(conditions ? { conditions } : {}) },
+ } as Partial<WorkflowRecipeCRD>)
+ const stubSdkOnly = (resolved: Record<string, unknown>) => {
+ const reconcilePluginWorkloadSdkOnly = vi.fn().mockResolvedValue(resolved)
+ ;(
+ reconciler as unknown as { config: { pluginWorkloadSdkEnabled: boolean } }
+ ).config.pluginWorkloadSdkEnabled = true
+ ;(
+ reconciler as unknown as {
+ workflowReconciler: {
+ reconcilePluginWorkloadSdkOnly: typeof reconcilePluginWorkloadSdkOnly
+ }
+ }
+ ).workflowReconciler = { reconcilePluginWorkloadSdkOnly }
+ return reconcilePluginWorkloadSdkOnly
+ }
+
+ it('publishes a False condition naming each conflicting policy', async () => {
+ const sdkOnly = stubSdkOnly({
+ phase: 'active',
+ message: 'Plugin Workload SDK mcp-host registered',
+ pluginWorkloadSdkBootstrapProof: bootstrapProof,
+ networkPolicies: {
+ conflicts: [
+ {
+ policy: 'test-recipe-workload-to-mcp-host-sdk-ingress',
+ reason: 'owner-reference-mismatch',
+ },
+ ],
+ retryPending: false,
+ },
+ })
+
+ const result = await reconciler.reconcile(sdkOnlyRecipe())
+
+ expect(sdkOnly).toHaveBeenCalledTimes(1)
+ expect(result.phase).toBe('active')
+ expect(result.workflowConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message: expect.stringContaining(
+ 'test-recipe-workload-to-mcp-host-sdk-ingress (owner-reference-mismatch)'
+ ),
+ }),
+ ])
+ })
+
+ it('clears the condition with an explicit empty set once no policy conflicts', async () => {
+ const sdkOnly = stubSdkOnly({
+ phase: 'active',
+ message: 'Plugin Workload SDK mcp-host registered',
+ pluginWorkloadSdkBootstrapProof: bootstrapProof,
+ networkPolicies: { conflicts: [], retryPending: false },
+ })
+
+ const result = await reconciler.reconcile(sdkOnlyRecipe([ownershipCondition]))
+
+ expect(sdkOnly).toHaveBeenCalledTimes(1)
+ expect(result.phase).toBe('active')
+ expect(result.workflowConditions).toEqual([])
+ })
+
+ it('carries the existing condition forward when the eager host fails before applying', async () => {
+ const sdkOnly = stubSdkOnly({
+ phase: 'failed',
+ message: 'Plugin Workload SDK promptBridge has no resolvable agent',
+ networkPolicies: { conflicts: [], retryPending: false },
+ })
+
+ const result = await reconciler.reconcile(sdkOnlyRecipe([ownershipCondition]))
+
+ expect(sdkOnly).toHaveBeenCalledTimes(1)
+ expect(result.phase).toBe('failed')
+ expect(result.workflowConditions).toEqual([ownershipCondition])
+ })
+ })
+
// awaiting_policy waits for an operator grant. The grant arrives by event
// (handleGrantUpdateNotification) or by the 30s credential-refresh floor, so a
// fixed 5s poll cannot make the state advance. It must keep requeueing, but on
@@ -1453,6 +1560,7 @@ describe('WorkflowRecipeReconciler', () => {
const reconcilePluginWorkloadSdkOnly = vi.fn().mockResolvedValue({
phase: 'awaiting_policy',
message: 'operator policy pending (policy_not_ready)',
+ networkPolicies: { conflicts: [], retryPending: false },
})
;(
reconciler as unknown as {
@@ -4095,6 +4203,38 @@ describe('WorkflowRecipeReconciler', () => {
])
})
+ it('patchStatus removes the NetworkPolicy ownership condition when the owned set is empty', async () => {
+ const r = makeRecipe({
+ status: {
+ phase: 'active',
+ conditions: [
+ { type: 'ExternalEgressReady', status: 'True', lastTransitionTime: 'old' },
+ {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message:
+ 'NetworkPolicy ownership conflict: test-recipe-coord-to-wrc (owner-reference-mismatch)',
+ lastTransitionTime: 'old',
+ },
+ ],
+ },
+ })
+
+ await reconciler.patchStatus(r, {
+ phase: 'active',
+ message: 'All workloads deployed',
+ workloadStatuses: [],
+ workflowConditions: [],
+ })
+
+ expect(mockCustomApi.patchNamespacedCustomObjectStatus).toHaveBeenCalledTimes(1)
+ const patch = mockCustomApi.patchNamespacedCustomObjectStatus.mock.calls[0][0].body
+ expect(patch.status.conditions).toEqual([
+ { type: 'ExternalEgressReady', status: 'True', lastTransitionTime: 'old' },
+ ])
+ })
+
it('replaces and clears the SDK provider-unavailable condition on recovery', async () => {
;(
reconciler as unknown as { config: { pluginWorkloadSdkEnabled: boolean } }
@@ -15347,6 +15487,7 @@ describe('WorkflowRecipeReconciler', () => {
policyReady: true,
verifiedAt: '2026-08-04T00:00:00.000Z',
},
+ networkPolicies: { conflicts: [], retryPending: false },
})
;(
reconciler as unknown as { config: { pluginWorkloadSdkEnabled: boolean } }
@@ -15391,6 +15532,7 @@ describe('WorkflowRecipeReconciler', () => {
policyReady: true,
verifiedAt: new Date().toISOString(),
},
+ networkPolicies: { conflicts: [], retryPending: false },
})
;(
reconciler as unknown as { config: { pluginWorkloadSdkEnabled: boolean } }
diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
index 45c2d013f..193160302 100644
--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
@@ -55,7 +55,10 @@ import {
} from '../workflow/llmAllowedModelsSnapshot'
import { ModelConfigHandler } from '../workflow/modelConfigHandler'
import { buildCoordinatorGfsNetworkPolicy } from '../workflow/networkPolicyFactory'
-import type { EagerSdkBootstrapProof } from '../workflow/pluginWorkloadSdkProvisioner'
+import type {
+ EagerSdkBootstrapProof,
+ WorkflowNetworkPolicyApplySummary,
+} from '../workflow/pluginWorkloadSdkProvisioner'
import { HttpPluginWorkloadSdkRevocationClient } from '../workflow/pluginWorkloadSdkRevocationClient'
import { deriveWorkflowRuntimePlan } from '../workflow/runtimePlan'
import { validateWorkflowRecipeLimits } from '../workflow/workflowLimits'
@@ -63,6 +66,8 @@ import {
WORKFLOW_OUTPUT_CONDITION_TYPES,
WorkflowReconciler,
WorkflowReconcilerDeps,
+ buildNetworkPolicyOwnershipConditions,
+ carriedNetworkPolicyOwnershipConditions,
} from '../workflow/workflowReconciler'
import { evaluateComputedValues } from './computedValuesEvaluator'
import { CRD_GROUP, CRD_VERSION, WORKFLOWRECIPE_PLURAL } from './crdConstants'
@@ -2878,6 +2883,8 @@ export class WorkflowRecipeReconciler {
secretOwnershipConditions: secretOwnership.conditions,
workloadConditions,
transportNetworkConditions: [],
+ // `failed` can return before the policy apply; keep what was published.
+ workflowConditions: carriedNetworkPolicyOwnershipConditions(recipe.status?.conditions),
}
}
@@ -2931,6 +2938,13 @@ export class WorkflowRecipeReconciler {
secretOwnershipConditions: secretOwnership.conditions,
workloadConditions,
transportNetworkConditions: [],
+ workflowConditions: sdkOnlyRuntime
+ ? buildNetworkPolicyOwnershipConditions(
+ sdkOnlyRuntime.networkPolicies,
+ new Date().toISOString(),
+ recipe.status?.conditions
+ )
+ : undefined,
pluginWorkloadSdkProviderUnavailable: sdkOnlyProviderUnavailable,
pluginWorkloadSdkPolicyPending: sdkOnlyPolicyPending,
pluginWorkloadSdkBootstrapProof: sdkOnlyRuntime?.pluginWorkloadSdkBootstrapProof,
@@ -3034,11 +3048,13 @@ export class WorkflowRecipeReconciler {
phase: 'active' | 'awaiting_policy' | 'deploying' | 'failed' | 'provider_unavailable'
message: string
pluginWorkloadSdkBootstrapProof?: EagerSdkBootstrapProof
+ networkPolicies: WorkflowNetworkPolicyApplySummary
}> {
if (!this.workflowReconciler) {
return {
phase: 'failed',
message: 'Plugin Workload SDK subsystem not initialized — missing clerum-wrc-signing-key',
+ networkPolicies: { conflicts: [], retryPending: false },
}
}
const runtimeScopeRecipeName = await this.workflowRuntimeScopeRecipeName(recipe)
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
index 0a3d8a25c..3112ea7c1 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts
@@ -124,7 +124,7 @@ function makeHarness(configureResult: unknown) {
modelConfigHandler: { configurePluginWorkloadSdkBootstrap: configure },
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
createIfNotExists: vi.fn().mockResolvedValue(true),
safeDelete: vi.fn().mockResolvedValue(undefined),
@@ -135,18 +135,20 @@ function makeHarness(configureResult: unknown) {
codexBinding?: PluginWorkloadSdkCodexBindingProof | null
codexBindingUndecidable?: boolean
}) =>
- provisioner.ensureEagerSdkMcpHost(
- RECIPE,
- 'recipe-uid',
- EAGER_SDK_SANDBOX_NS,
- RECIPE,
- CODEX_SPEC,
- EAGER_SDK_RUNTIME,
- {
- mcpHostPhase: 'Running',
- codexVerdict: verdictFor(opts),
- }
- )
+ provisioner
+ .ensureEagerSdkMcpHost(
+ RECIPE,
+ 'recipe-uid',
+ EAGER_SDK_SANDBOX_NS,
+ RECIPE,
+ CODEX_SPEC,
+ EAGER_SDK_RUNTIME,
+ {
+ mcpHostPhase: 'Running',
+ codexVerdict: verdictFor(opts),
+ }
+ )
+ .then(result => result.status)
return {
provisioner,
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts
index df9f74f4d..546f560d7 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts
@@ -119,7 +119,7 @@ function makeHarness(configureResult: unknown) {
modelConfigHandler: { configurePluginWorkloadSdkBootstrap: configure },
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
createIfNotExists: vi.fn().mockResolvedValue(true),
safeDelete: vi.fn().mockResolvedValue(undefined),
@@ -130,18 +130,20 @@ function makeHarness(configureResult: unknown) {
grokBinding?: PluginWorkloadSdkCodexBindingProof | null
grokBindingUndecidable?: boolean
}) =>
- provisioner.ensureEagerSdkMcpHost(
- RECIPE,
- 'recipe-uid',
- EAGER_SDK_SANDBOX_NS,
- RECIPE,
- GROK_SPEC,
- EAGER_SDK_RUNTIME,
- {
- mcpHostPhase: 'Running',
- codexVerdict: verdictFor(opts),
- }
- )
+ provisioner
+ .ensureEagerSdkMcpHost(
+ RECIPE,
+ 'recipe-uid',
+ EAGER_SDK_SANDBOX_NS,
+ RECIPE,
+ GROK_SPEC,
+ EAGER_SDK_RUNTIME,
+ {
+ mcpHostPhase: 'Running',
+ codexVerdict: verdictFor(opts),
+ }
+ )
+ .then(result => result.status)
return {
provisioner,
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts
index 2848c280d..9014aca3d 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.imageDrift.test.ts
@@ -70,6 +70,9 @@ function makeProvisioner(
deleteNamespacedPod,
createNamespacedPod,
}
+ const applyWorkflowNetworkPolicies = vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false })
const deps = {
coreApi,
@@ -77,7 +80,7 @@ function makeProvisioner(
tokenFactory: {},
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(opts.tokenRefresh),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies,
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
modelConfigHandler: {
configurePluginWorkloadSdkBootstrap: vi.fn().mockResolvedValue({ status: 503 }),
@@ -87,7 +90,13 @@ function makeProvisioner(
} as unknown as PluginWorkloadSdkProvisionerDeps
const provisioner = new PluginWorkloadSdkProvisioner(deps)
- return { provisioner, readNamespacedPod, deleteNamespacedPod, createNamespacedPod }
+ return {
+ provisioner,
+ readNamespacedPod,
+ deleteNamespacedPod,
+ createNamespacedPod,
+ applyWorkflowNetworkPolicies,
+ }
}
// spec.agent resolves to a complete agent so ensureEagerSdkMcpHost does not
@@ -187,7 +196,7 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
it('rolls a healthy eager mcp-host pod when its image drifts from the platform image', async () => {
const { provisioner, deleteNamespacedPod, createNamespacedPod } = makeProvisioner(STALE_IMAGE)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -233,7 +242,7 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
it('rolls a same-image pod when the runtime contract hash is missing', async () => {
const { provisioner, deleteNamespacedPod } = makeProvisioner(DESIRED_IMAGE)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -256,7 +265,7 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
'Pending'
)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -281,7 +290,7 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
{ deleting: true }
)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -315,7 +324,9 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
},
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
// Invoke the create thunk so the recreated pod body is observable on
// createNamespacedPod, proving it is built from the platform image.
@@ -327,7 +338,7 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
} as unknown as PluginWorkloadSdkProvisionerDeps
const provisioner = new PluginWorkloadSdkProvisioner(deps)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -382,7 +393,9 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
},
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
createIfNotExists: vi.fn(async (fn: () => Promise<unknown>) => {
await fn()
@@ -392,7 +405,7 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
} as unknown as PluginWorkloadSdkProvisionerDeps
const provisioner = new PluginWorkloadSdkProvisioner(deps)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -450,14 +463,16 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
modelConfigHandler: { handle },
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
createIfNotExists: vi.fn().mockResolvedValue(true),
safeDelete: vi.fn().mockResolvedValue(undefined),
} as unknown as PluginWorkloadSdkProvisionerDeps
const provisioner = new PluginWorkloadSdkProvisioner(deps)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -530,25 +545,29 @@ describe('ensureEagerSdkMcpHost image-drift roll', () => {
modelConfigHandler: { handle },
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
createIfNotExists: vi.fn().mockResolvedValue(true),
safeDelete: vi.fn().mockResolvedValue(undefined),
} as unknown as PluginWorkloadSdkProvisionerDeps
const provisioner = new PluginWorkloadSdkProvisioner(deps)
const reconcile = () =>
- provisioner.ensureEagerSdkMcpHost(
- RECIPE,
- 'recipe-uid',
- SANDBOX_NS,
- RECIPE,
- promptBridgeSpec,
- RUNTIME,
- {
- mcpHostPhase: 'Running',
- codexVerdict: decidedVerdict,
- }
- )
+ provisioner
+ .ensureEagerSdkMcpHost(
+ RECIPE,
+ 'recipe-uid',
+ SANDBOX_NS,
+ RECIPE,
+ promptBridgeSpec,
+ RUNTIME,
+ {
+ mcpHostPhase: 'Running',
+ codexVerdict: decidedVerdict,
+ }
+ )
+ .then(result => result.status)
// Two configure failures on a healthy, image-matching pod (budget -> 2 of 3).
expect(await reconcile()).toBe('deploying')
@@ -576,7 +595,7 @@ describe('ensureEagerSdkMcpHost runtime token roll', () => {
}
)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -624,7 +643,7 @@ describe('ensureEagerSdkMcpHost runtime token roll', () => {
}
)
- const status = await provisioner.ensureEagerSdkMcpHost(
+ const { status } = await provisioner.ensureEagerSdkMcpHost(
RECIPE,
'recipe-uid',
SANDBOX_NS,
@@ -715,7 +734,9 @@ describe('ensureEagerSdkMcpHost ConfigMap snapshot skip', () => {
tokenFactory: { signWrcConfigureToken },
log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),
- applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),
+ applyWorkflowNetworkPolicies: vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false }),
ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),
modelConfigHandler: { configurePluginWorkloadSdkBootstrap: configure },
createIfNotExists: vi.fn().mockResolvedValue(true),
@@ -770,8 +791,90 @@ describe('ensureEagerSdkMcpHost ConfigMap snapshot skip', () => {
} satisfies CodexRecipeVerdict,
}
)
- ).resolves.toBe('awaiting_policy')
+ ).resolves.toMatchObject({ status: 'awaiting_policy' })
expect(configure).not.toHaveBeenCalled()
expect(deps.tokenFactory.signWrcConfigureToken).not.toHaveBeenCalled()
})
})
+
+describe('ensureEagerSdkMcpHost NetworkPolicy summary', () => {
+ function captureProvisionerLogs(): {
+ entries: Array<Record<string, unknown>>
+ restore: () => void
+ } {
+ const previousLevel = process.env.LOG_LEVEL
+ process.env.LOG_LEVEL = 'info'
+ const entries: Array<Record<string, unknown>> = []
+ const spy = vi.spyOn(process.stdout, 'write').mockImplementation(((chunk: unknown) => {
+ const text = typeof chunk === 'string' ? chunk : Buffer.from(chunk as Uint8Array).toString()
+ for (const line of text.split('\n')) {
+ if (line.startsWith('{')) entries.push(JSON.parse(line) as Record<string, unknown>)
+ }
+ return true
+ }) as unknown as typeof process.stdout.write)
+ return {
+ entries,
+ restore: () => {
+ spy.mockRestore()
+ if (previousLevel === undefined) delete process.env.LOG_LEVEL
+ else process.env.LOG_LEVEL = previousLevel
+ },
+ }
+ }
+
+ it('returns an empty summary without applying policies when promptBridge has no agent', async () => {
+ const logs = captureProvisionerLogs()
+ try {
+ const { provisioner, applyWorkflowNetworkPolicies } = makeProvisioner(DESIRED_IMAGE)
+ const agentless = { pluginWorkloadSdk: { promptBridge: {} } } as unknown as WorkflowRecipeSpec
+
+ const result = await provisioner.ensureEagerSdkMcpHost(
+ RECIPE,
+ 'recipe-uid',
+ SANDBOX_NS,
+ RECIPE,
+ agentless,
+ RUNTIME,
+ { mcpHostPhase: 'Running', codexVerdict: decidedVerdict }
+ )
+
+ // Witness: the early-return branch ran, not some later failure.
+ expect(
+ logs.entries.some(
+ entry =>
+ entry.level === 'warn' &&
+ String(entry.msg).includes('promptBridge declared but no agent is resolvable')
+ )
+ ).toBe(true)
+ expect(result).toEqual({
+ status: 'failed',
+ networkPolicies: { conflicts: [], retryPending: false },
+ })
+ expect(applyWorkflowNetworkPolicies).toHaveBeenCalledTimes(0)
+ } finally {
+ logs.restore()
+ }
+ })
+
+ it('returns the apply summary alongside the status', async () => {
+ const { provisioner, applyWorkflowNetworkPolicies } = makeProvisioner(STALE_IMAGE)
+ const summary = {
+ conflicts: [{ policy: `${RECIPE}-mcp-host-to-gfs`, reason: 'owner-reference-mismatch' }],
+ retryPending: true,
+ }
+ applyWorkflowNetworkPolicies.mockResolvedValueOnce(summary)
+
+ const result = await provisioner.ensureEagerSdkMcpHost(
+ RECIPE,
+ 'recipe-uid',
+ SANDBOX_NS,
+ RECIPE,
+ SPEC,
+ RUNTIME,
+ { mcpHostPhase: 'Running', codexVerdict: decidedVerdict }
+ )
+
+ expect(applyWorkflowNetworkPolicies).toHaveBeenCalledTimes(1)
+ expect(result).toEqual({ status: 'deploying', networkPolicies: summary })
+ })
+})
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
index e7f5ef922..e4956d81a 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
@@ -48,6 +48,22 @@ export type EagerSdkMcpHostStatus =
| 'failed'
| 'provider_unavailable'
+/**
+ * What one `applyWorkflowNetworkPolicies` pass could not converge. A conflict
+ * names a live policy another controller owns; WRC leaves it untouched. A
+ * pending retry means a policy was mid-deletion and needs a later pass.
+ */
+export type WorkflowNetworkPolicyApplySummary = {
+ conflicts: { policy: string; reason: string }[]
+ retryPending: boolean
+}
+
+export type EagerSdkMcpHostResult = {
+ status: EagerSdkMcpHostStatus
+ /** Empty when the pass returned before applying the policies. */
+ networkPolicies: WorkflowNetworkPolicyApplySummary
+}
+
/** Why the mcp-host runtime JWT Secret was reminted. */
export type McpHostRuntimeTokenRefreshReason = 'scope' | 'binding' | 'ttl'
@@ -139,7 +155,7 @@ export type PluginWorkloadSdkProvisionerDeps = {
codexProjection: CodexRecipeVerdict['projection'],
eagerSdkMcpHost: boolean,
grokProjection?: CodexRecipeVerdict['grokProjection']
- ) => Promise<void>
+ ) => Promise<WorkflowNetworkPolicyApplySummary>
ensureMcpHostHeadlessService: (recipeName: string) => Promise<void>
createIfNotExists: (createFn: () => Promise<unknown>, label: string) => Promise<boolean>
safeDelete: (deleteFn: () => Promise<unknown>) => Promise<void>
@@ -227,7 +243,7 @@ export class PluginWorkloadSdkProvisioner {
*/
codexVerdict: CodexRecipeVerdict
}
- ): Promise<EagerSdkMcpHostStatus> {
+ ): Promise<EagerSdkMcpHostResult> {
const log = createLogger('wrc', recipeName)
const capabilities = declaredPluginWorkloadSdkCapabilities(spec.pluginWorkloadSdk)
const requiresPromptBridge = capabilities.includes('promptBridge')
@@ -238,7 +254,7 @@ export class PluginWorkloadSdkProvisioner {
'Plugin Workload SDK promptBridge declared but no agent is resolvable; ' +
'declare spec.agent with provider+model to bind the eager mcp-host'
)
- return 'failed'
+ return { status: 'failed', networkPolicies: { conflicts: [], retryPending: false } }
}
const tokenRefresh = await this.deps.ensureMcpHostSecrets(
@@ -250,7 +266,7 @@ export class PluginWorkloadSdkProvisioner {
opts.codexVerdict
)
- await this.deps.applyWorkflowNetworkPolicies(
+ const networkPolicies = await this.deps.applyWorkflowNetworkPolicies(
recipeName,
recipeUid,
spec,
@@ -261,6 +277,34 @@ export class PluginWorkloadSdkProvisioner {
opts.codexVerdict.grokProjection
)
+ const status = await this.provisionEagerSdkMcpHostPod(
+ recipeName,
+ namespace,
+ runtimeScopeRecipeName,
+ spec,
+ opts,
+ { log, capabilities, requiresPromptBridge, mcpHostAgent, tokenRefresh }
+ )
+ return { status, networkPolicies }
+ }
+
+ /** Pod lifecycle and bootstrap half of `ensureEagerSdkMcpHost`, after the policy apply. */
+ private async provisionEagerSdkMcpHostPod(
+ recipeName: string,
+ namespace: string,
+ runtimeScopeRecipeName: string,
+ spec: WorkflowRecipeSpec,
+ opts: { mcpHostPhase: string | undefined; codexVerdict: CodexRecipeVerdict },
+ pass: {
+ log: Logger
+ capabilities: ReturnType<typeof declaredPluginWorkloadSdkCapabilities>
+ requiresPromptBridge: boolean
+ mcpHostAgent: ReturnType<typeof resolveEagerSdkMcpHostAgent>
+ tokenRefresh: McpHostRuntimeTokenRefreshResult | void
+ }
+ ): Promise<EagerSdkMcpHostStatus> {
+ const { log, capabilities, requiresPromptBridge, mcpHostAgent, tokenRefresh } = pass
+
await this.deps.ensureMcpHostHeadlessService(recipeName)
// Build the desired Pod once per reconcile so drift checks compare the
diff --git a/workflow-recipes/src/workflow/workflowReconciler.grokWrcFlag.test.ts b/workflow-recipes/src/workflow/workflowReconciler.grokWrcFlag.test.ts
index 2998acf69..8e02c5524 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.grokWrcFlag.test.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.grokWrcFlag.test.ts
@@ -252,7 +252,10 @@ describe('WorkflowReconciler Grok WRC switch', () => {
pluginWorkloadSdkProvisioner: { ensureEagerSdkMcpHost: (...args: unknown[]) => unknown }
}
).pluginWorkloadSdkProvisioner
- const ensure = vi.spyOn(provisioner, 'ensureEagerSdkMcpHost').mockResolvedValue('deploying')
+ const ensure = vi.spyOn(provisioner, 'ensureEagerSdkMcpHost').mockResolvedValue({
+ status: 'deploying',
+ networkPolicies: { conflicts: [], retryPending: false },
+ })
await reconciler.reconcilePluginWorkloadSdkOnly(RECIPE, `uid-${RECIPE}`, sandboxNamespace, {
agent: { provider: 'grok-subscription', model: GROK_MODEL },
diff --git a/workflow-recipes/src/workflow/workflowReconciler.test.ts b/workflow-recipes/src/workflow/workflowReconciler.test.ts
index 59e3a5f3e..a7065dceb 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.test.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.test.ts
@@ -1624,6 +1624,158 @@ describe('WorkflowReconciler — Plugin Workload SDK eager mcp-host', () => {
expect(createdServiceNames).not.toContain(serviceName)
})
+ describe('NetworkPolicy ownership conflicts', () => {
+ const foreignOwnedPolicy = (name: string) => ({
+ metadata: {
+ name,
+ namespace: sandboxNamespace,
+ resourceVersion: '7',
+ ownerReferences: [
+ {
+ apiVersion: 'apps/v1',
+ kind: 'Deployment',
+ name: 'another-controller',
+ uid: 'foreign-owner-uid',
+ controller: true,
+ },
+ ],
+ },
+ spec: { podSelector: {} },
+ })
+ const foreignOnly = (foreignName: string) =>
+ mockNetworkingApi.readNamespacedNetworkPolicy.mockImplementation(
+ async ({ name }: { name: string }) => {
+ if (name === foreignName) return foreignOwnedPolicy(foreignName)
+ throw { code: 404 }
+ }
+ )
+ const writesTo = (name: string) => [
+ ...mockNetworkingApi.createNamespacedNetworkPolicy.mock.calls.filter(
+ call => call[0].body.metadata.name === name
+ ),
+ ...mockNetworkingApi.replaceNamespacedNetworkPolicy.mock.calls.filter(
+ call => call[0].name === name
+ ),
+ ]
+ const createdNames = () =>
+ mockNetworkingApi.createNamespacedNetworkPolicy.mock.calls.map(
+ call => call[0].body.metadata.name
+ )
+ const ownershipCondition = (conditions: unknown) =>
+ (conditions as Array<{ type: string }> | undefined)?.find(
+ condition => condition.type === 'WorkflowNetworkPolicyOwnership'
+ )
+
+ it('SDK-only lane returns the conflict and leaves the foreign policy untouched', async () => {
+ const foreignName = 'sdk-only-workload-to-mcp-host-sdk-ingress'
+ foreignOnly(foreignName)
+ const reconciler = new WorkflowReconciler(makeDeps())
+
+ const result = await reconciler.reconcilePluginWorkloadSdkOnly(
+ 'sdk-only',
+ 'uid-sdk-only',
+ sandboxNamespace,
+ sdkSpec({ steps: undefined })
+ )
+
+ expect(mockNetworkingApi.readNamespacedNetworkPolicy).toHaveBeenCalledWith(
+ expect.objectContaining({ name: foreignName })
+ )
+ // The conflict did not stop the rest of the pass.
+ expect(createdNames()).toContain('sdk-only-workload-to-mcp-host-sdk-egress')
+ expect(result.phase).toBe('active')
+ expect(result.networkPolicies).toEqual({
+ conflicts: [{ policy: foreignName, reason: 'owner-reference-mismatch' }],
+ retryPending: false,
+ })
+ expect(writesTo(foreignName)).toHaveLength(0)
+ })
+
+ it('workflow lane surfaces the conflict as a False condition and clears it on recovery', async () => {
+ const foreignName = 'sdk-recipe-workload-to-mcp-host-sdk-ingress'
+ foreignOnly(foreignName)
+ const reconciler = new WorkflowReconciler(makeDeps())
+
+ const first = await reconciler.reconcile(
+ 'sdk-recipe',
+ 'uid-sdk',
+ sandboxNamespace,
+ sdkSpec(),
+ { workflowExecution: { phase: 'initializing' } },
+ undefined,
+ 'sdk-recipe',
+ undefined
+ )
+
+ expect(mockNetworkingApi.readNamespacedNetworkPolicy).toHaveBeenCalledWith(
+ expect.objectContaining({ name: foreignName })
+ )
+ expect(createdNames()).toContain('sdk-recipe-workload-to-mcp-host-sdk-egress')
+ expect(first.phase).not.toBe('failed')
+ expect(first.workflowPhase).not.toBe('failed')
+ expect(ownershipCondition(first.workflowConditions)).toMatchObject({
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message: expect.stringContaining(foreignName),
+ })
+ expect(writesTo(foreignName)).toHaveLength(0)
+
+ // The foreign owner goes away: the policy is created and the condition
+ // is dropped from the owned set, so patchStatus removes it.
+ mockNetworkingApi.readNamespacedNetworkPolicy.mockRejectedValue({ code: 404 })
+ mockNetworkingApi.createNamespacedNetworkPolicy.mockClear()
+ const second = await reconciler.reconcile(
+ 'sdk-recipe',
+ 'uid-sdk',
+ sandboxNamespace,
+ sdkSpec(),
+ { workflowExecution: { phase: 'initializing' }, conditions: first.workflowConditions },
+ undefined,
+ 'sdk-recipe',
+ undefined
+ )
+
+ expect(createdNames()).toContain(foreignName)
+ expect(second.workflowConditions).toBeDefined()
+ expect(ownershipCondition(second.workflowConditions)).toBeUndefined()
+ })
+
+ it('workflow lane keeps the existing condition when the eager host fails before applying', async () => {
+ const reconciler = new WorkflowReconciler(makeDeps())
+ const provisioner = (
+ reconciler as unknown as {
+ pluginWorkloadSdkProvisioner: { ensureEagerSdkMcpHost: (...args: unknown[]) => unknown }
+ }
+ ).pluginWorkloadSdkProvisioner
+ const ensure = vi.spyOn(provisioner, 'ensureEagerSdkMcpHost').mockResolvedValue({
+ status: 'failed',
+ networkPolicies: { conflicts: [], retryPending: false },
+ })
+ const existing = {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False' as const,
+ reason: 'OwnershipConflict',
+ message: 'sdk-recipe-mcp-host-to-gfs (owner-reference-mismatch)',
+ lastTransitionTime: '2026-09-23T10:00:00.000Z',
+ }
+
+ const result = await reconciler.reconcile(
+ 'sdk-recipe',
+ 'uid-sdk',
+ sandboxNamespace,
+ sdkSpec(),
+ { workflowExecution: { phase: 'initializing' }, conditions: [existing] },
+ undefined,
+ 'sdk-recipe',
+ undefined
+ )
+
+ expect(ensure).toHaveBeenCalledTimes(1)
+ expect(result.phase).toBe('failed')
+ expect(ownershipCondition(result.workflowConditions)).toEqual(existing)
+ })
+ })
+
it('creates a provider-free eager mcp-host for clientNotifications-only without an agent', async () => {
const reconciler = new WorkflowReconciler(makeDeps())
mockModelConfigHandler.configurePluginWorkloadSdkBootstrap.mockResolvedValue({
diff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.ts
index 9501c81d4..1ce078758 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.ts
@@ -95,6 +95,7 @@ import {
type McpHostRuntimeTokenRefreshResult,
NO_MCP_HOST_RUNTIME_TOKEN_REFRESH,
PluginWorkloadSdkProvisioner,
+ type WorkflowNetworkPolicyApplySummary,
} from './pluginWorkloadSdkProvisioner'
import type {
PluginWorkloadSdkRevocationClient,
@@ -239,14 +240,58 @@ export interface PluginWorkloadSdkCleanupOptions {
preserveWorkflowRuntime?: boolean
}
+export const NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE = 'WorkflowNetworkPolicyOwnership'
+
export const WORKFLOW_OUTPUT_CONDITION_TYPES = new Set([
'WorkflowOutputRwoCompatibility',
'WorkflowOutputWrcManagedLifecycle',
'WorkflowOutputPrepareGate',
'WorkflowOutputExternalClaim',
'WorkflowOutputLegacyGlobalClaim',
+ NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE,
])
+/**
+ * The ownership condition for one policy apply pass: `False` naming every
+ * policy another controller owns, or none when every policy converged. The
+ * type is in `WORKFLOW_OUTPUT_CONDITION_TYPES`, so an empty result removes a
+ * previously published condition.
+ */
+export function buildNetworkPolicyOwnershipConditions(
+ summary: WorkflowNetworkPolicyApplySummary,
+ now: string,
+ existingConditions?: StatusCondition[]
+): StatusCondition[] {
+ if (summary.conflicts.length === 0) return []
+ const conflicts = summary.conflicts
+ .map(conflict => `${conflict.policy} (${conflict.reason})`)
+ .sort()
+ .join(', ')
+ const existing = existingConditions?.find(
+ c => c.type === NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE && c.status === 'False'
+ )
+ return [
+ {
+ type: NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE,
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message: `NetworkPolicy ownership conflict: ${conflicts}`,
+ lastTransitionTime: existing?.lastTransitionTime ?? now,
+ },
+ ]
+}
+
+/**
+ * The ownership condition as last published. A pass that returns before it
+ * applies the policies re-emits it, because a patch that carries owned
+ * conditions without it would remove it.
+ */
+export function carriedNetworkPolicyOwnershipConditions(
+ existingConditions?: StatusCondition[]
+): StatusCondition[] {
+ return (existingConditions ?? []).filter(c => c.type === NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE)
+}
+
interface CoordinatorTokenRefreshOptions {
includeMcpHostToken?: boolean
useCustomCoordinatorWrcToken?: boolean
@@ -1182,9 +1227,14 @@ export class WorkflowReconciler {
phase: 'active' | 'awaiting_policy' | 'deploying' | 'failed' | 'provider_unavailable'
message: string
pluginWorkloadSdkBootstrapProof?: EagerSdkBootstrapProof
+ networkPolicies: WorkflowNetworkPolicyApplySummary
}> {
if (!this.deps.config.pluginWorkloadSdkEnabled || !spec.pluginWorkloadSdk) {
- return { phase: 'active', message: 'Plugin Workload SDK runtime disabled' }
+ return {
+ phase: 'active',
+ message: 'Plugin Workload SDK runtime disabled',
+ networkPolicies: { conflicts: [], retryPending: false },
+ }
}
if ((spec.steps?.length ?? 0) > 0) {
throw new Error('SDK-only runtime requires spec.steps to be absent or empty')
@@ -1211,15 +1261,16 @@ export class WorkflowReconciler {
`${recipeName}-mcp-host`,
this.deps.config.sandboxNamespace
)
- const status = await this.pluginWorkloadSdkProvisioner.ensureEagerSdkMcpHost(
- recipeName,
- recipeUid,
- namespace,
- runtimeScopeRecipeName,
- spec,
- runtime,
- { mcpHostPhase, codexVerdict }
- )
+ const { status, networkPolicies } =
+ await this.pluginWorkloadSdkProvisioner.ensureEagerSdkMcpHost(
+ recipeName,
+ recipeUid,
+ namespace,
+ runtimeScopeRecipeName,
+ spec,
+ runtime,
+ { mcpHostPhase, codexVerdict }
+ )
const bootstrapProof = this.pluginWorkloadSdkProvisioner.getBootstrapProof(recipeName)
switch (status) {
case 'ready':
@@ -1227,22 +1278,33 @@ export class WorkflowReconciler {
phase: 'active',
message: 'Plugin Workload SDK mcp-host registered',
pluginWorkloadSdkBootstrapProof: bootstrapProof,
+ networkPolicies,
}
case 'awaiting_policy':
return {
phase: 'awaiting_policy',
message: `Plugin Workload SDK operator policy pending (${pluginWorkloadSdkPolicyReason(spec, bootstrapProof)})`,
pluginWorkloadSdkBootstrapProof: bootstrapProof,
+ networkPolicies,
}
case 'deploying':
- return { phase: 'deploying', message: 'Plugin Workload SDK mcp-host starting' }
+ return {
+ phase: 'deploying',
+ message: 'Plugin Workload SDK mcp-host starting',
+ networkPolicies,
+ }
case 'provider_unavailable':
return {
phase: 'provider_unavailable',
message: 'Plugin Workload SDK mcp-host provider unavailable',
+ networkPolicies,
}
case 'failed':
- return { phase: 'failed', message: 'Plugin Workload SDK mcp-host could not start' }
+ return {
+ phase: 'failed',
+ message: 'Plugin Workload SDK mcp-host could not start',
+ networkPolicies,
+ }
}
}
@@ -1556,9 +1618,14 @@ export class WorkflowReconciler {
new Date().toISOString(),
currentStatus?.conditions
)
+ // Carried until this pass applies the policies, then replaced by what the
+ // apply found. A return before the apply keeps the published condition.
+ let networkPolicyOwnershipConditions = carriedNetworkPolicyOwnershipConditions(
+ currentStatus?.conditions
+ )
const withWorkflowConditions = (result: WorkflowReconcileResult): WorkflowReconcileResult => ({
...result,
- workflowConditions,
+ workflowConditions: [...workflowConditions, ...networkPolicyOwnershipConditions],
})
const outputAnchorPodName = runtime.output.anchorRequired
? buildWorkflowOutputAnchorPodName(runtimeScopeRecipeName)
@@ -1687,17 +1754,27 @@ export class WorkflowReconciler {
// let a concurrently-reconciled recipe's failed refresh hand over a
// null binding that read as decidable — a binding-less v3 configure
// that wipes the live host binding.
- const eagerStatus = await this.pluginWorkloadSdkProvisioner.ensureEagerSdkMcpHost(
- recipeName,
- recipeUid,
- namespace,
- runtimeScopeRecipeName,
- spec,
- runtime,
- { mcpHostPhase, codexVerdict }
- )
+ const { status: eagerStatus, networkPolicies: eagerNetworkPolicies } =
+ await this.pluginWorkloadSdkProvisioner.ensureEagerSdkMcpHost(
+ recipeName,
+ recipeUid,
+ namespace,
+ runtimeScopeRecipeName,
+ spec,
+ runtime,
+ { mcpHostPhase, codexVerdict }
+ )
const eagerBootstrapProof =
this.pluginWorkloadSdkProvisioner.getBootstrapProof(recipeName)
+ // `failed` can return before the apply with an empty summary, which
+ // must not read as "every policy converged".
+ if (eagerStatus !== 'failed') {
+ networkPolicyOwnershipConditions = buildNetworkPolicyOwnershipConditions(
+ eagerNetworkPolicies,
+ new Date().toISOString(),
+ currentStatus?.conditions
+ )
+ }
if (eagerStatus === 'failed') {
return withWorkflowConditions({
phase: 'failed',
@@ -1719,6 +1796,7 @@ export class WorkflowReconciler {
clearWorkflowExecution: true,
workflowConditions: [
...workflowConditions,
+ ...networkPolicyOwnershipConditions,
buildStatusCondition(
'PluginWorkloadSdkProviderUnavailable',
'EagerConfigureFailed',
@@ -2146,7 +2224,7 @@ export class WorkflowReconciler {
// already active, and custom coordinators can call WRC immediately on
// startup. Applying allow policies first avoids a startup race where the
// first status/probe request is blocked before coord-to-wrc exists.
- await this.applyWorkflowNetworkPolicies(
+ const runLaneNetworkPolicies = await this.applyWorkflowNetworkPolicies(
recipeName,
recipeUid,
spec,
@@ -2156,6 +2234,11 @@ export class WorkflowReconciler {
false,
codexVerdict.grokProjection
)
+ networkPolicyOwnershipConditions = buildNetworkPolicyOwnershipConditions(
+ runLaneNetworkPolicies,
+ new Date().toISOString(),
+ currentStatus?.conditions
+ )
// 6. Create Pods — mcp-host FIRST, then coordinator. If the coordinator
// resolves DNS before mcp-host's EndpointSlice exists, undici caches the
@@ -3072,7 +3155,7 @@ export class WorkflowReconciler {
codexProjection: CodexExecutionProjection,
eagerSdkMcpHost = false,
grokProjection?: CodexExecutionProjection & { requiresGrokProxyEgress?: boolean }
- ): Promise<void> {
+ ): Promise<WorkflowNetworkPolicyApplySummary> {
const policies = await this.buildWorkflowNetworkPoliciesForSpec(
recipeName,
recipeUid,
@@ -3083,8 +3166,16 @@ export class WorkflowReconciler {
eagerSdkMcpHost,
grokProjection
)
+ // A conflict or a pending retry leaves that one policy as it is and the
+ // loop moves on; the caller surfaces both, so neither fails the pass.
+ const summary: WorkflowNetworkPolicyApplySummary = { conflicts: [], retryPending: false }
for (const policy of policies) {
- await this.applyNetworkPolicy(policy)
+ const applied = await this.applyNetworkPolicy(policy)
+ if (applied.action === 'conflict') {
+ summary.conflicts.push({ policy: applied.policy, reason: applied.reason })
+ } else if (applied.action === 'retry') {
+ summary.retryPending = true
+ }
}
const policyNames = new Set(policies.map(policy => policy.metadata?.name))
const codexProxyPolicyName = `${recipeName}-mcp-host-to-codex-proxy`
@@ -3107,6 +3198,7 @@ export class WorkflowReconciler {
)
}
await this.pruneLegacyMcpServersInternetEgressPolicy(recipeName)
+ return summary
}
private async resolveRuntimeHttpEgressPolicyState(
diff --git a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
index 89717173e..3fb69ed47 100644
--- a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
+++ b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
@@ -3003,6 +3003,54 @@ describe('WorkflowReconciler — reconcile loop', () => {
logs.restore()
}
})
+
+ it('reports a foreign-owned run-lane policy as a condition and keeps the run alive', async () => {
+ const { api, live, key } = makeApiserverNetworkingApi()
+ const reconciler = new WorkflowReconciler(makeDeps({ networkingApi: api as never }))
+ const spec = makeSpec({ agent: undefined, steps: [{ id: 'prepare', run: snippetRun() }] })
+
+ const first = await reconciler.reconcile('test-wf', 'uid-123', 'sandbox-recipes', spec)
+ expect(first.workflowPhase).not.toBe('failed')
+ const foreign = live.get(key('sandbox-recipes', 'test-wf-coord-to-wrc'))
+ expect(foreign).toBeDefined()
+ // Drift the spec too, so that without the ownership check the pass would PUT.
+ foreign!.spec = { ...foreign!.spec!, podSelector: { matchLabels: { drifted: 'yes' } } }
+ foreign!.metadata = {
+ ...foreign!.metadata,
+ ownerReferences: [
+ {
+ apiVersion: 'apps/v1',
+ kind: 'Deployment',
+ name: 'another-controller',
+ uid: 'foreign-owner-uid',
+ controller: true,
+ },
+ ],
+ }
+ api.readNamespacedNetworkPolicy.mockClear()
+ api.replaceNamespacedNetworkPolicy.mockClear()
+
+ const second = await reconciler.reconcile('test-wf', 'uid-123', 'sandbox-recipes', spec)
+
+ const expectedNames = RUN_LANE_POLICY_NAMES.map(entry => entry.split('/')[1]!).sort()
+ expect(readPolicyNames(api)).toEqual(expectedNames)
+ expect(second.phase).not.toBe('failed')
+ expect(second.workflowPhase).not.toBe('failed')
+ expect(
+ second.workflowConditions?.find(
+ condition => condition.type === 'WorkflowNetworkPolicyOwnership'
+ )
+ ).toMatchObject({
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message: expect.stringContaining('test-wf-coord-to-wrc'),
+ })
+ expect(
+ api.replaceNamespacedNetworkPolicy.mock.calls.filter(
+ ([arg]) => arg.name === 'test-wf-coord-to-wrc'
+ )
+ ).toHaveLength(0)
+ })
})
it('resolves snippet MCP transport workloads into the mounted runner config', async () => {