Skip to content

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

TypeScript

fix(workflow-recipes): reapply pending run-lane NetworkPolicies from the short-circuits

Alfredo Lopeza72f7d849cec
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index 11360c072..2b9c3013c 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.404",
+ "version": "0.1.405",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.404",
+ "version": "0.1.405",
"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 924727e21..c43d9d0b3 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.404",
+ "version": "0.1.405",
"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 5e2732da9..3a5a2d96c 100644
--- a/workflow-recipes/src/k8sClient.test.ts
+++ b/workflow-recipes/src/k8sClient.test.ts
@@ -246,6 +246,29 @@ describe('shouldPatchRecipeStatus', () => {
).toBe(false)
expect(shouldPatchRecipeStatus(steadyRecipe([conflict]), steadyResult())).toBe(false)
})
+
+ const retryMarker = {
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False' as const,
+ reason: 'RetryPending',
+ message:
+ 'One or more run-lane NetworkPolicies are pending a retry (terminating or contended)',
+ lastTransitionTime: '2026-09-23T10:00:00.000Z',
+ }
+
+ it('patches when the retry marker appears or disappears, the ownership condition unchanged', () => {
+ expect(shouldPatchRecipeStatus(steadyRecipe(), steadyResult([retryMarker]))).toBe(true)
+ expect(
+ shouldPatchRecipeStatus(steadyRecipe([conflict, retryMarker]), steadyResult([conflict]))
+ ).toBe(true)
+ // Witness: the same pair with the marker on both sides opens no patch.
+ expect(
+ shouldPatchRecipeStatus(
+ steadyRecipe([conflict, retryMarker]),
+ steadyResult([conflict, { ...retryMarker, lastTransitionTime: '2026-09-24T00:00:00Z' }])
+ )
+ ).toBe(false)
+ })
})
it('patches when a terminal workflow keeps the same phase but updates the message', () => {
diff --git a/workflow-recipes/src/k8sClient.ts b/workflow-recipes/src/k8sClient.ts
index b40962e28..3239a9ff6 100644
--- a/workflow-recipes/src/k8sClient.ts
+++ b/workflow-recipes/src/k8sClient.ts
@@ -61,7 +61,7 @@ import {
CODEX_CONNECTION_REF_ANNOTATION,
SUBSCRIPTION_CONNECTION_REF_ANNOTATION,
} from './workflow/llmAllowedModelsSnapshot'
-import { NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE } from './workflow/workflowReconciler'
+import { networkPolicyConditionsChanged } from './workflow/workflowReconciler'
function grantIdentityFingerprint(
recipe: { metadata?: { annotations?: Record<string, string> } } | undefined
@@ -170,15 +170,16 @@ export function shouldPatchRecipeStatus(
)
return true
- // A NetworkPolicy ownership conflict changes neither phase nor message, so
- // without this clause the condition would not be published or cleared on a
- // pass where nothing else changed. An undefined field means the pass never
- // reached the apply, so it does not force a patch.
+ // A NetworkPolicy ownership conflict or a pending retry changes neither
+ // phase nor message, so without this clause those conditions would not be
+ // published or cleared on a pass where nothing else changed. An undefined
+ // field means the pass never reached the apply, so it does not force a patch.
if (
result.networkPolicyOwnershipConditions !== undefined &&
- ownedConditionsChanged(recipe.status?.conditions, result.networkPolicyOwnershipConditions, [
- NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE,
- ])
+ networkPolicyConditionsChanged(
+ recipe.status?.conditions,
+ result.networkPolicyOwnershipConditions
+ )
)
return true
diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.ts
index 8e133cea1..f5853340b 100644
--- a/workflow-recipes/src/reconciler/reconciler.test.ts
+++ b/workflow-recipes/src/reconciler/reconciler.test.ts
@@ -7,7 +7,13 @@ import { resolve } from 'node:path'
import { EVENFIRE_REGISTRY_PULL_SECRET_NAME } from '@clerum/workflow-runtime-core'
import { loadConfig } from '../config'
import { WorkflowRecipeWatcher, shouldPatchRecipeStatus } from '../k8sClient'
-import { CronJobDef, WorkflowRecipeCRD, WorkflowRecipeGfsIntentSpec, WorkloadDef } from '../types'
+import {
+ CronJobDef,
+ StatusCondition,
+ WorkflowRecipeCRD,
+ WorkflowRecipeGfsIntentSpec,
+ WorkloadDef,
+} from '../types'
import { INHERITED_PARENT_RESOURCES_ANNOTATION } from '../workflow/childRecipeFactory'
import { buildCoordinatorGfsNetworkPolicy } from '../workflow/networkPolicyFactory'
import { captureLogger } from './__tests__/captureLogger'
@@ -1615,7 +1621,15 @@ describe('WorkflowRecipeReconciler', () => {
expect(retrying.phase).toBe('active')
expect(retrying.requeueAfterMs).toBe(TRANSIENT_REQUEUE_BASE_MS)
expect(retrying.requeueFixedInterval).toBe(false)
- expect(retrying.networkPolicyOwnershipConditions).toEqual([])
+ // Being deleted is not a conflict; the only owned condition is the
+ // RetryPending marker the short-circuits key their reapply on.
+ expect(retrying.networkPolicyOwnershipConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False',
+ reason: 'RetryPending',
+ }),
+ ])
const settled = stubSdkOnly({
phase: 'active',
@@ -1629,6 +1643,7 @@ describe('WorkflowRecipeReconciler', () => {
expect(settled).toHaveBeenCalledTimes(1)
expect(steady.phase).toBe('active')
expect(steady.requeueAfterMs).toBeUndefined()
+ expect(steady.networkPolicyOwnershipConditions).toEqual([])
})
// The mcp-host pod failed after an apply that left a policy being deleted.
@@ -1650,7 +1665,13 @@ describe('WorkflowRecipeReconciler', () => {
expect(retrying.message).toBe('Plugin Workload SDK mcp-host could not start')
expect(retrying.requeueAfterMs).toBe(TRANSIENT_REQUEUE_BASE_MS)
expect(retrying.requeueFixedInterval).toBe(false)
- expect(retrying.networkPolicyOwnershipConditions).toEqual([])
+ expect(retrying.networkPolicyOwnershipConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False',
+ reason: 'RetryPending',
+ }),
+ ])
const settled = stubSdkOnly({
phase: 'failed',
@@ -9590,11 +9611,12 @@ describe('WorkflowRecipeReconciler', () => {
expect(result.requeueFixedInterval).toBeFalsy()
})
- // A running workflow has no periodic pass of its own, and its status-only
- // MODIFIED events are absorbed, so a policy being deleted needs a timer to be
- // written once the deletion completes. It rides the progress interval, but
- // with backoff: nothing bounds how long the deletion takes.
- it('requeues an active workflow on the backoff path while a run-lane policy is being deleted', async () => {
+ // A pass that reaches WorkflowReconciler.reconcile() (here the first deploy)
+ // and leaves a run-lane policy pending a retry requeues on the progress
+ // interval, with backoff: nothing bounds how long a deletion or a contention
+ // lasts. The passes of a running workflow stop at the short-circuits; those
+ // reapply the policies from the published marker (tests below).
+ it('requeues on the backoff path when a pass through reconcile() leaves a run-lane policy pending a retry', async () => {
const workflowReconcile = vi.fn().mockResolvedValue({
phase: 'active',
message: 'Workflow running',
@@ -9667,6 +9689,262 @@ describe('WorkflowRecipeReconciler', () => {
expect(result.requeueAfterMs).toBeUndefined()
})
+ // The in-progress and active short-circuits return before reconcile(), so
+ // they reapply the run-lane policies themselves while the retry marker is
+ // published, and publish only status.conditions: a full status patch would
+ // recompute the SDK projection without a bootstrap proof.
+ describe('run-lane NetworkPolicy retry from the short-circuits', () => {
+ const retryMarker = {
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False' as const,
+ reason: 'RetryPending',
+ message:
+ 'One or more run-lane NetworkPolicies are pending a retry (terminating or contended)',
+ lastTransitionTime: '2026-09-24T08:00:00.000Z',
+ }
+ const unrelatedCondition = {
+ type: 'WorkflowOutputPrepareGate',
+ status: 'True' as const,
+ reason: 'Ready',
+ message: 'ready',
+ lastTransitionTime: '2026-09-24T07:00:00.000Z',
+ }
+
+ function installRunLane(retryRunLaneNetworkPolicies: ReturnType<typeof vi.fn>) {
+ const stub = {
+ ensureMcpHostRuntimeCredentials: vi.fn().mockResolvedValue(undefined),
+ refreshRuntimeHttpEgressNetworkPolicies: vi
+ .fn()
+ .mockResolvedValue({ conflicts: [], retryPending: false }),
+ retryRunLaneNetworkPolicies,
+ validateWorkflowSpec: () => undefined,
+ }
+ ;(reconciler as unknown as { workflowReconciler: typeof stub }).workflowReconciler = stub
+ return stub
+ }
+
+ function runningRecipe(overrides: {
+ phase?: 'active' | 'deploying'
+ execPhase?: 'running' | 'completed'
+ conditions?: StatusCondition[]
+ runId?: string | null
+ dryRun?: boolean
+ deletionTimestamp?: string
+ }): WorkflowRecipeCRD {
+ const runId = overrides.runId === undefined ? 'run-42' : overrides.runId
+ return makeRecipe({
+ metadata: {
+ name: 'test-recipe',
+ namespace: 'sandbox-recipes',
+ uid: 'uid-123',
+ ...(runId ? { labels: { 'clerum.io/workflow-run-id': runId } } : {}),
+ ...(overrides.deletionTimestamp
+ ? { deletionTimestamp: overrides.deletionTimestamp }
+ : {}),
+ },
+ spec: {
+ agent: { provider: 'zai', model: 'glm-4.7' },
+ steps: [{ id: 'research', instruction: 'run' }],
+ ...(overrides.dryRun ? { dryRun: true } : {}),
+ },
+ status: {
+ phase: overrides.phase ?? 'active',
+ message: 'Workflow running',
+ workflowExecution: { phase: overrides.execPhase ?? 'running' },
+ conditions: overrides.conditions ?? [unrelatedCondition, retryMarker],
+ } as WorkflowRecipeCRD['status'],
+ })
+ }
+
+ function conditionPatches() {
+ return mockCustomApi.patchNamespacedCustomObjectStatus.mock.calls.map(
+ call => call[0] as { name: string; body: { status: Record<string, unknown> } }
+ )
+ }
+
+ it('reapplies from the active short-circuit and removes the marker with a conditions-only patch once converged', async () => {
+ const retry = vi.fn().mockResolvedValue({ conflicts: [], retryPending: false })
+ installRunLane(retry)
+ const recipe = runningRecipe({})
+
+ const result = await reconciler.reconcile(recipe)
+
+ expect(retry).toHaveBeenCalledTimes(1)
+ expect(retry.mock.calls[0][0]).toBe('test-recipe')
+ expect(retry.mock.calls[0][1]).toBe('uid-123')
+ expect(retry.mock.calls[0][4]).toBe('run-42')
+ const patches = conditionPatches()
+ expect(patches).toHaveLength(1)
+ expect(patches[0].name).toBe('test-recipe')
+ expect(Object.keys(patches[0].body.status)).toEqual(['conditions'])
+ expect(patches[0].body.status.conditions).toEqual([unrelatedCondition])
+ expect(recipe.status?.conditions).toEqual([unrelatedCondition])
+ expect(result).toMatchObject({ phase: 'active', skipStatusPatch: true })
+ expect(result.requeueAfterMs).toBeUndefined()
+ })
+
+ it('reapplies from the in-progress short-circuit and requeues on backoff while still pending', async () => {
+ const retry = vi.fn().mockResolvedValue({ conflicts: [], retryPending: true })
+ installRunLane(retry)
+ const recipe = runningRecipe({ phase: 'deploying' })
+
+ const result = await reconciler.reconcile(recipe)
+
+ expect(retry).toHaveBeenCalledTimes(1)
+ // The marker is unchanged, so no patch opens.
+ expect(conditionPatches()).toHaveLength(0)
+ expect(result.phase).toBe('active')
+ expect(result.requeueAfterMs).toBe(WORKFLOW_PROGRESS_REQUEUE_BASE_MS)
+ expect(result.requeueFixedInterval).toBe(false)
+ })
+
+ it('publishes a changed condition once across two pending passes', async () => {
+ const summary = {
+ conflicts: [{ policy: 'test-recipe-coord-to-wrc', reason: 'owner-reference-mismatch' }],
+ retryPending: true,
+ }
+ const retry = vi.fn().mockResolvedValue(summary)
+ installRunLane(retry)
+ const recipe = runningRecipe({})
+
+ await reconciler.reconcile(recipe)
+ const second = await reconciler.reconcile(recipe)
+
+ expect(retry).toHaveBeenCalledTimes(2)
+ const patches = conditionPatches()
+ expect(patches).toHaveLength(1)
+ expect(Object.keys(patches[0].body.status)).toEqual(['conditions'])
+ const published = patches[0].body.status.conditions as Array<{
+ type: string
+ reason?: string
+ lastTransitionTime?: string
+ }>
+ expect(published.map(c => c.type).sort()).toEqual([
+ 'WorkflowNetworkPoliciesConverged',
+ 'WorkflowNetworkPolicyOwnership',
+ 'WorkflowOutputPrepareGate',
+ ])
+ // The marker keeps the time the retry began.
+ expect(
+ published.find(c => c.type === 'WorkflowNetworkPoliciesConverged')?.lastTransitionTime
+ ).toBe(retryMarker.lastTransitionTime)
+ expect(second.requeueAfterMs).toBe(WORKFLOW_PROGRESS_REQUEUE_BASE_MS)
+ })
+
+ it('does not reapply without the marker', async () => {
+ const retry = vi.fn()
+ const stub = installRunLane(retry)
+ const recipe = runningRecipe({ conditions: [unrelatedCondition] })
+
+ const result = await reconciler.reconcile(recipe)
+
+ // Witness: the active short-circuit ran.
+ expect(stub.ensureMcpHostRuntimeCredentials).toHaveBeenCalledTimes(1)
+ expect(retry).not.toHaveBeenCalled()
+ expect(conditionPatches()).toHaveLength(0)
+ expect(result.requeueAfterMs).toBeUndefined()
+ })
+
+ it('keeps the marker and requeues on backoff when the reapply throws', async () => {
+ const errorLog = captureLogger('error')
+ try {
+ const retry = vi.fn().mockRejectedValue(new Error('connect ECONNRESET'))
+ installRunLane(retry)
+ const recipe = runningRecipe({})
+
+ const result = await reconciler.reconcile(recipe)
+
+ expect(retry).toHaveBeenCalledTimes(1)
+ expect(errorLog).toHaveBeenCalledWith(
+ 'Failed to reapply run-lane NetworkPolicies pending a retry; keeping the marker',
+ expect.objectContaining({ name: 'test-recipe' })
+ )
+ expect(conditionPatches()).toHaveLength(0)
+ expect(recipe.status?.conditions).toEqual([unrelatedCondition, retryMarker])
+ expect(result.phase).toBe('active')
+ expect(result.requeueAfterMs).toBe(TRANSIENT_REQUEUE_BASE_MS)
+ expect(result.requeueFixedInterval).toBe(false)
+ } finally {
+ errorLog.mockRestore()
+ }
+ })
+
+ it.each([
+ ['the coordinator GFS policy cannot open', { dryRun: true }],
+ ['the run awaits a trigger', { phase: 'deploying' as const, runId: null }],
+ ])('does not reapply when %s', async (_label, overrides) => {
+ const retry = vi.fn()
+ const stub = installRunLane(retry)
+ const recipe = runningRecipe(overrides)
+
+ await reconciler.reconcile(recipe)
+
+ // Witness: a short-circuit ran.
+ expect(stub.ensureMcpHostRuntimeCredentials).toHaveBeenCalledTimes(1)
+ expect(retry).not.toHaveBeenCalled()
+ expect(conditionPatches()).toHaveLength(0)
+ })
+
+ // A deleting recipe stops at the initial check, before any short-circuit.
+ it('does not reapply for a recipe being deleted', async () => {
+ const retry = vi.fn()
+ installRunLane(retry)
+ const recipe = runningRecipe({ deletionTimestamp: '2026-09-24T09:00:00Z' })
+
+ const result = await reconciler.reconcile(recipe)
+
+ // Witness: the pass stopped at the initial check.
+ expect(result.message).toBe('Recipe deleted during reconcile; skipped initial check')
+ expect(retry).not.toHaveBeenCalled()
+ expect(conditionPatches()).toHaveLength(0)
+ })
+
+ // A finished run no longer needs its policies, so the terminal branch drops
+ // the marker without reapplying, and keeps an ownership conflict.
+ it('removes the marker from the terminal branch without reapplying', async () => {
+ const ownershipConflict = {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False' as const,
+ reason: 'OwnershipConflict',
+ message:
+ 'NetworkPolicy ownership conflict: test-recipe-coord-to-wrc (owner-reference-mismatch)',
+ lastTransitionTime: '2026-09-24T08:00:00.000Z',
+ }
+ const retry = vi.fn()
+ const stub = installRunLane(retry)
+ const recipe = runningRecipe({
+ execPhase: 'completed',
+ conditions: [unrelatedCondition, ownershipConflict, retryMarker],
+ })
+
+ const result = await reconciler.reconcile(recipe)
+
+ // Witness: the terminal branch ran.
+ expect(stub.ensureMcpHostRuntimeCredentials).toHaveBeenCalledTimes(1)
+ expect(retry).not.toHaveBeenCalled()
+ const patches = conditionPatches()
+ expect(patches).toHaveLength(1)
+ expect(Object.keys(patches[0].body.status)).toEqual(['conditions'])
+ expect(patches[0].body.status.conditions).toEqual([unrelatedCondition, ownershipConflict])
+ expect(recipe.status?.conditions).toEqual([unrelatedCondition, ownershipConflict])
+ expect(result.phase).toBe('active')
+ expect(result.requeueAfterMs).toBeUndefined()
+ })
+
+ it('opens no patch from the terminal branch without the marker', async () => {
+ const retry = vi.fn()
+ const stub = installRunLane(retry)
+ const recipe = runningRecipe({ execPhase: 'completed', conditions: [unrelatedCondition] })
+
+ await reconciler.reconcile(recipe)
+
+ // Witness: the terminal branch ran.
+ expect(stub.ensureMcpHostRuntimeCredentials).toHaveBeenCalledTimes(1)
+ expect(retry).not.toHaveBeenCalled()
+ expect(conditionPatches()).toHaveLength(0)
+ })
+ })
+
// §5 priority: a transient ERROR (skipStatusPatch) wins over PROGRESS even when
// the phase is `deploying`. The error path keeps the TRANSIENT base + backoff
// (requeueFixedInterval false), so genuine flakiness still backs off; it must
diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
index ded01544c..c73653edf 100644
--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
@@ -63,10 +63,13 @@ import { HttpPluginWorkloadSdkRevocationClient } from '../workflow/pluginWorkloa
import { deriveWorkflowRuntimePlan } from '../workflow/runtimePlan'
import { validateWorkflowRecipeLimits } from '../workflow/workflowLimits'
import {
+ NETWORK_POLICIES_CONVERGED_CONDITION_TYPE,
NETWORK_POLICY_OWNERSHIP_CONDITION_TYPES,
WORKFLOW_OUTPUT_CONDITION_TYPES,
WorkflowReconciler,
WorkflowReconcilerDeps,
+ hasNetworkPolicyRetryPendingMarker,
+ networkPolicyConditionsChanged,
translateNetworkPolicyApplySummary,
} from '../workflow/workflowReconciler'
import { evaluateComputedValues } from './computedValuesEvaluator'
@@ -1455,6 +1458,103 @@ export class WorkflowRecipeReconciler {
}
}
+ /**
+ * Applies the run-lane NetworkPolicies again from a short-circuit when the
+ * published status carries the retry marker. Those short-circuits never
+ * reach `WorkflowReconciler.reconcile()`, so without this a policy left
+ * pending a retry would stay unapplied until the run ends. Nothing is
+ * pruned: the prune decisions depend on the eligibility verdicts that only
+ * the full pass computes.
+ *
+ * Returns the requeue delay the short-circuit must add: the progress base
+ * while a policy is still pending, the transient base when the apply threw
+ * (the marker is kept), and `undefined` once the policies converged or when
+ * there was nothing to retry.
+ */
+ private async retryPendingRunLaneNetworkPolicies(
+ recipe: WorkflowRecipeCRD,
+ workflowRuntimeSpec: WorkflowRecipeCRD['spec'],
+ runtimeScopeRecipeName: string,
+ coordinatorGfsPolicyCanOpen: boolean,
+ awaitsTriggeredRun: boolean
+ ): Promise<number | undefined> {
+ if (
+ !this.workflowReconciler ||
+ !coordinatorGfsPolicyCanOpen ||
+ awaitsTriggeredRun ||
+ !hasNetworkPolicyRetryPendingMarker(recipe.status?.conditions)
+ ) {
+ return undefined
+ }
+ let summary: WorkflowNetworkPolicyApplySummary
+ try {
+ summary = await this.workflowReconciler.retryRunLaneNetworkPolicies(
+ recipe.metadata.name,
+ recipe.metadata.uid ?? '',
+ workflowRuntimeSpec,
+ runtimeScopeRecipeName,
+ recipe.metadata.labels?.[WORKFLOW_RUN_ID_LABEL]
+ )
+ } catch (error) {
+ createLogger('wrc', recipe.metadata.name).error(
+ 'Failed to reapply run-lane NetworkPolicies pending a retry; keeping the marker',
+ { name: recipe.metadata.name, err: error }
+ )
+ return TRANSIENT_REQUEUE_BASE_MS
+ }
+ const existing = recipe.status?.conditions
+ const translated = translateNetworkPolicyApplySummary(
+ summary,
+ existing,
+ new Date().toISOString()
+ )
+ const fresh = translated.networkPolicyOwnershipConditions ?? []
+ if (networkPolicyConditionsChanged(existing, fresh)) {
+ await this.publishNetworkPolicyConditions(
+ recipe,
+ mergeOwnedConditions(existing, fresh, NETWORK_POLICY_OWNERSHIP_CONDITION_TYPES) ?? []
+ )
+ }
+ return translated.networkPolicyRetryPending ? WORKFLOW_PROGRESS_REQUEUE_BASE_MS : undefined
+ }
+
+ /**
+ * Drops the retry marker once the run is terminal: the run no longer needs
+ * its policies, so there is nothing left to retry. The ownership condition,
+ * if any, stays published.
+ */
+ private async clearNetworkPolicyRetryMarker(recipe: WorkflowRecipeCRD): Promise<void> {
+ const existing = recipe.status?.conditions
+ if (!hasNetworkPolicyRetryPendingMarker(existing)) return
+ await this.publishNetworkPolicyConditions(
+ recipe,
+ (existing ?? []).filter(c => c.type !== NETWORK_POLICIES_CONVERGED_CONDITION_TYPE)
+ )
+ }
+
+ /**
+ * A conditions-only merge patch. A full `patchStatus` here would recompute
+ * the SDK capability projection without a bootstrap proof, which is why the
+ * short-circuits skip it.
+ */
+ private async publishNetworkPolicyConditions(
+ recipe: WorkflowRecipeCRD,
+ conditions: StatusCondition[]
+ ): Promise<void> {
+ await this.customApi.patchNamespacedCustomObjectStatus(
+ {
+ group: CRD_GROUP,
+ version: CRD_VERSION,
+ namespace: recipe.metadata.namespace,
+ plural: WORKFLOWRECIPE_PLURAL,
+ name: recipe.metadata.name,
+ body: { status: { conditions } },
+ },
+ { middleware: [k8s.setHeaderMiddleware('Content-Type', 'application/merge-patch+json')] }
+ )
+ if (recipe.status) recipe.status.conditions = conditions
+ }
+
async refreshInProgressWorkflowRuntimeCredentials(recipe: WorkflowRecipeCRD): Promise<void> {
const isWorkflow = (recipe.spec.steps ?? []).length > 0
const workflowPhase = recipe.status?.workflowExecution?.phase
@@ -1918,6 +2018,7 @@ export class WorkflowRecipeReconciler {
// torn down above; this teardown is idempotent/404-tolerant).
const terminalOwnership = await this.revokeOrRequeueSteadyWorkflow(recipe, derivedPhase)
if (terminalOwnership) return terminalOwnership
+ await this.clearNetworkPolicyRetryMarker(recipe)
// The recipe phase may remain active across running -> completed. Still
// patch once if the top-level message is stale so UIs do not show a
// completed execution as still running.
@@ -1977,12 +2078,22 @@ export class WorkflowRecipeReconciler {
(wfExecPhase === 'running' ? 'active' : currentPhase) as RecipePhase
)
if (inProgressOwnership) return inProgressOwnership
+ const inProgressRequeueMs = await this.retryPendingRunLaneNetworkPolicies(
+ recipe,
+ policyPreflight.workflowRuntimeSpec,
+ approvalScopeRecipeName,
+ coordinatorGfsPolicyCanOpen,
+ awaitsTriggeredRun
+ )
const derivedPhase: RecipePhase = wfExecPhase === 'running' ? 'active' : currentPhase
return {
phase: derivedPhase,
message: `Workflow ${wfExecPhase}`,
workloadStatuses: [],
skipStatusPatch: currentPhase === derivedPhase,
+ ...(inProgressRequeueMs !== undefined
+ ? { requeueAfterMs: inProgressRequeueMs, requeueFixedInterval: false }
+ : {}),
}
}
}
@@ -2017,11 +2128,21 @@ export class WorkflowRecipeReconciler {
// level-triggered (requeue + watchdog) so it lands on the next
// non-running pass.
if (!recipe.spec.pluginWorkloadSdk || wfInProgress) {
+ const activeRequeueMs = await this.retryPendingRunLaneNetworkPolicies(
+ recipe,
+ policyPreflight.workflowRuntimeSpec,
+ approvalScopeRecipeName,
+ coordinatorGfsPolicyCanOpen,
+ awaitsTriggeredRun
+ )
return {
phase: 'active' as RecipePhase,
message: wfExecPhase ? `Workflow ${wfExecPhase}` : 'Workflow completed',
workloadStatuses: [],
skipStatusPatch: true,
+ ...(activeRequeueMs !== undefined
+ ? { requeueAfterMs: activeRequeueMs, requeueFixedInterval: false }
+ : {}),
}
}
}
@@ -2290,25 +2411,22 @@ export class WorkflowRecipeReconciler {
// 30s credential-refresh floor. Polling cannot advance it, and it has no
// deadline that bounds a fixed-interval loop.
//
- // A NetworkPolicy left pending a retry (terminating, deleted before the
- // replace, or conflicted twice) requeues on the backoff path unless the
- // phase is `deploying`: nothing bounds how long the deletion or the
+ // A NetworkPolicy left pending a retry (terminating, or still contended
+ // after the bounded apply rounds) requeues on the backoff path unless
+ // the phase is `deploying`: nothing bounds how long the deletion or the
// contention lasts. An ownership conflict does not requeue; it waits for
// an operator and is published as a condition. The SDK-only lane joins
// its own TRANSIENT_REQUEUE_BASE_MS term instead; the two bases differ
// by lane only because each flag joins that lane's existing requeue
// term, and both are 5s.
//
- // Known limit: the requeued pass reaches the run-lane apply only while
- // the run is still initializing or recovering. Otherwise the
- // awaiting-trigger, terminal, in-progress and active short-circuits above
- // return before WorkflowReconciler.reconcile() (the awaiting-trigger and
- // active ones let a Plugin Workload SDK recipe fall through unless its
- // run is in progress), so the policy is rewritten by the next pass that
- // reaches it (the next run or a crash recovery). The 30s
- // runtime HTTP egress refresh reapplies only coord-to-wrc and
- // snippet-runner-egress, and only when the spec gives them public HTTP
- // egress.
+ // The pending retry is also published as the
+ // WorkflowNetworkPoliciesConverged=False/RetryPending marker. The
+ // requeued pass can stop at a short-circuit above, before
+ // WorkflowReconciler.reconcile(): the in-progress and active
+ // short-circuits reapply the run-lane policies while the marker is
+ // present, and the terminal branch removes it. The awaiting-trigger
+ // short-circuit does not reapply; the triggered run applies them.
requeueAfterMs: result.skipStatusPatch
? TRANSIENT_REQUEUE_BASE_MS
: result.phase === 'deploying' ||
@@ -3007,8 +3125,8 @@ export class WorkflowRecipeReconciler {
pluginWorkloadSdkBootstrapProof: sdkOnlyRuntime?.pluginWorkloadSdkBootstrapProof,
// Issue #637 — requeue if a denied workload's teardown failed (deniedTeardownFailed),
// so the revocation is retried rather than left to the next event.
- // A NetworkPolicy left unwritten (being deleted, vanished before the
- // replace, or conflicted twice) is retried the same way; an ownership
+ // A NetworkPolicy left unwritten (terminating, or still contended after
+ // the bounded apply rounds) is retried the same way; an ownership
// conflict is not.
requeueAfterMs:
legacyRawCleanupPending ||
diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
index ceb9a013d..e574c969c 100644
--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.ts
@@ -53,8 +53,7 @@ export type EagerSdkMcpHostStatus =
* 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 left unwritten for a later pass: it was
- * being deleted, it vanished before the replace, or the replace conflicted
- * twice.
+ * terminating, or still contended after the bounded apply rounds.
*/
export type WorkflowNetworkPolicyApplySummary = {
conflicts: { policy: string; reason: NetworkPolicyConflictReason }[]
diff --git a/workflow-recipes/src/workflow/workflowReconciler.test.ts b/workflow-recipes/src/workflow/workflowReconciler.test.ts
index d83040e7b..c64c120dd 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.test.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.test.ts
@@ -1922,7 +1922,13 @@ describe('WorkflowReconciler — Plugin Workload SDK eager mcp-host', () => {
expect(ensure).toHaveBeenCalledTimes(1)
expect(result.phase).toBe('failed')
- expect(result.networkPolicyOwnershipConditions).toEqual([])
+ expect(result.networkPolicyOwnershipConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False',
+ reason: 'RetryPending',
+ }),
+ ])
expect(result.networkPolicyRetryPending).toBe(true)
})
@@ -1969,6 +1975,11 @@ describe('WorkflowReconciler — Plugin Workload SDK eager mcp-host', () => {
reason: 'OwnershipConflict',
message: expect.stringContaining(`${foreignName} (owner-reference-mismatch)`),
}),
+ expect.objectContaining({
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False',
+ reason: 'RetryPending',
+ }),
])
expect(result.networkPolicyRetryPending).toBe(true)
})
diff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.ts
index 2fd7bd604..0ca2a594c 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.ts
@@ -247,15 +247,71 @@ export interface PluginWorkloadSdkCleanupOptions {
export const NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE = 'WorkflowNetworkPolicyOwnership'
+/**
+ * Published only as `False/RetryPending` while a run-lane NetworkPolicy is
+ * left pending a retry (terminating or contended), and removed once the
+ * policies converge. The WRC short-circuits of a running workflow never reach
+ * `reconcile()`, so this marker is what tells them to apply the policies again.
+ */
+export const NETWORK_POLICIES_CONVERGED_CONDITION_TYPE = 'WorkflowNetworkPoliciesConverged'
+
+const NETWORK_POLICY_RETRY_PENDING_MESSAGE =
+ 'One or more run-lane NetworkPolicies are pending a retry (terminating or contended)'
+
/**
* Merged by its own group in `patchStatus`, apart from the workflow-output
* group: a pass that never reached the policy apply leaves the field
- * undefined, and the published condition must survive that pass's patch.
+ * undefined, and the published conditions must survive that pass's patch.
*/
export const NETWORK_POLICY_OWNERSHIP_CONDITION_TYPES = new Set([
NETWORK_POLICY_OWNERSHIP_CONDITION_TYPE,
+ NETWORK_POLICIES_CONVERGED_CONDITION_TYPE,
])
+/**
+ * Whether `fresh` differs from the conditions of the NetworkPolicy group
+ * already in `existing`, by status, reason and message. `lastTransitionTime`
+ * and every type outside the group are ignored, so a pass that republishes the
+ * same conditions opens no status patch.
+ */
+export function networkPolicyConditionsChanged(
+ existing: StatusCondition[] | undefined,
+ fresh: StatusCondition[]
+): boolean {
+ const signal = (conditions: StatusCondition[]) =>
+ conditions
+ .filter(c => NETWORK_POLICY_OWNERSHIP_CONDITION_TYPES.has(c.type))
+ .map(c => `${c.type}\u0000${c.status}\u0000${c.reason ?? ''}\u0000${c.message ?? ''}`)
+ .sort()
+ .join('\u0001')
+ return signal(existing ?? []) !== signal(fresh)
+}
+
+/** True when the published status still carries the retry marker. */
+export function hasNetworkPolicyRetryPendingMarker(
+ conditions: StatusCondition[] | undefined
+): boolean {
+ return (conditions ?? []).some(
+ c => c.type === NETWORK_POLICIES_CONVERGED_CONDITION_TYPE && c.status === 'False'
+ )
+}
+
+function buildNetworkPolicyRetryPendingCondition(
+ now: string,
+ existingConditions?: StatusCondition[]
+): StatusCondition {
+ const existing = existingConditions?.find(
+ c => c.type === NETWORK_POLICIES_CONVERGED_CONDITION_TYPE && c.status === 'False'
+ )
+ return {
+ type: NETWORK_POLICIES_CONVERGED_CONDITION_TYPE,
+ status: 'False',
+ reason: 'RetryPending',
+ message: NETWORK_POLICY_RETRY_PENDING_MESSAGE,
+ lastTransitionTime: existing?.lastTransitionTime ?? now,
+ }
+}
+
export const WORKFLOW_OUTPUT_CONDITION_TYPES = new Set([
'WorkflowOutputRwoCompatibility',
'WorkflowOutputWrcManagedLifecycle',
@@ -301,8 +357,9 @@ export function buildNetworkPolicyOwnershipConditions(
* The status fields one policy apply pass contributes, shared by the run lane
* and the SDK-only lane so both translate a summary the same way. No summary
* (the pass returned before the apply) yields neither field, which keeps the
- * published condition. A summary always yields the ownership conditions, `[]`
- * included, and the retry flag only when a policy was left pending a retry.
+ * published conditions. A summary always yields the group's conditions, `[]`
+ * included: the ownership condition when a policy conflicts, and the retry
+ * marker plus the retry flag when a policy was left pending a retry.
*/
export function translateNetworkPolicyApplySummary(
summary: WorkflowNetworkPolicyApplySummary | undefined,
@@ -311,11 +368,12 @@ export function translateNetworkPolicyApplySummary(
): Pick<WorkflowReconcileResult, 'networkPolicyOwnershipConditions' | 'networkPolicyRetryPending'> {
if (summary === undefined) return {}
return {
- networkPolicyOwnershipConditions: buildNetworkPolicyOwnershipConditions(
- summary,
- now,
- existingConditions
- ),
+ networkPolicyOwnershipConditions: [
+ ...buildNetworkPolicyOwnershipConditions(summary, now, existingConditions),
+ ...(summary.retryPending
+ ? [buildNetworkPolicyRetryPendingCondition(now, existingConditions)]
+ : []),
+ ],
...(summary.retryPending ? { networkPolicyRetryPending: true } : {}),
}
}
@@ -855,10 +913,11 @@ export interface WorkflowReconcileResult {
/** Eager host identity is ready, but prompt policy awaits operator action. */
pluginWorkloadSdkPolicyPending?: boolean
/**
- * A NetworkPolicy this pass left unwritten and wants retried: it is being
- * deleted, it vanished before the replace, or the replace conflicted twice.
- * The caller requeues. The requeued pass reaches this apply only if the
- * recipe reconciler does not short-circuit it (see its requeue comment).
+ * A NetworkPolicy this pass left unwritten and wants retried: it is
+ * terminating, or it was still contended after the bounded apply rounds.
+ * The caller requeues and publishes the RetryPending marker, which lets the
+ * recipe reconciler's short-circuits reapply the policies (see its requeue
+ * comment).
*/
networkPolicyRetryPending?: boolean
}
@@ -2885,6 +2944,50 @@ export class WorkflowReconciler {
)
}
+ /**
+ * Reapply the run-lane NetworkPolicies outside reconcile(). The running and
+ * active short-circuits return before reconcile(), so a policy a previous
+ * pass left pending (terminating or contended) would otherwise stay as it is
+ * until the run ends. Builds the same set reconcile() applies and only
+ * applies it: no codex, grok or legacy prune, because those follow an
+ * eligibility verdict that can change while a run is in progress.
+ */
+ async retryRunLaneNetworkPolicies(
+ recipeName: string,
+ recipeUid: string,
+ spec: WorkflowRecipeSpec,
+ runtimeScopeRecipeName = recipeName,
+ workflowRunId?: string
+ ): Promise<WorkflowNetworkPolicyApplySummary> {
+ const runId = workflowRunId?.trim()
+ const runtime = deriveWorkflowRuntimePlan(spec, {
+ recipeName,
+ runtimeScopeRecipeName,
+ workflowRunId: runId,
+ pluginWorkloadSdkEnabled: this.deps.config.pluginWorkloadSdkEnabled,
+ })
+ const awaitsTriggeredRun = runtime.mcpHost.required && !runId
+ const codexView = await this.refreshCodexSnapshot()
+ const codexVerdict = this.codexVerdictFor(
+ spec,
+ recipeUid,
+ recipeName,
+ runtimeScopeRecipeName,
+ codexView
+ )
+ const policies = await this.buildWorkflowNetworkPoliciesForSpec(
+ recipeName,
+ recipeUid,
+ spec,
+ runtime,
+ awaitsTriggeredRun,
+ codexVerdict.projection,
+ false,
+ codexVerdict.grokProjection
+ )
+ return this.applyNetworkPolicyList(policies)
+ }
+
async ensureCoordinatorRuntimeCredentials(
recipeNamespace: string,
recipeName: string,
diff --git a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
index e0d4c23fc..fcc659b32 100644
--- a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
+++ b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
@@ -35,6 +35,7 @@ import {
WorkflowReconciler,
type WorkflowReconcilerDeps,
buildNetworkPolicyOwnershipConditions,
+ networkPolicyConditionsChanged,
translateNetworkPolicyApplySummary,
} from '../../../src/workflow/workflowReconciler'
import { asApiserverNetworkPolicy } from './asApiserverNetworkPolicy'
@@ -3812,8 +3813,14 @@ describe('WorkflowReconciler — reconcile loop', () => {
expect(second.phase).not.toBe('failed')
expect(second.workflowPhase).not.toBe('failed')
// A policy being deleted is not a conflict: the pass reached the apply
- // and found none, so the owned set is empty rather than absent.
- expect(second.networkPolicyOwnershipConditions).toEqual([])
+ // and found none, so the owned set holds only the RetryPending marker.
+ expect(second.networkPolicyOwnershipConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False',
+ reason: 'RetryPending',
+ }),
+ ])
expect(
api.replaceNamespacedNetworkPolicy.mock.calls.filter(
([arg]) => arg.name === 'test-wf-coord-to-wrc'
@@ -4163,8 +4170,15 @@ describe('WorkflowReconciler — reconcile loop', () => {
expect(second.phase).not.toBe('failed')
expect(second.workflowPhase).not.toBe('failed')
expect(second.networkPolicyRetryPending).toBe(true)
- // Being deleted is not a conflict: the owned set is empty, not absent.
- expect(second.networkPolicyOwnershipConditions).toEqual([])
+ // Being deleted is not a conflict: the owned set holds only the
+ // RetryPending marker.
+ expect(second.networkPolicyOwnershipConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False',
+ reason: 'RetryPending',
+ }),
+ ])
expect(
logs.entries.filter(
entry => entry.level === 'warn' && String(entry.msg).includes('test-wf-coord-to-wrc')
@@ -4373,6 +4387,92 @@ describe('WorkflowReconciler — reconcile loop', () => {
)
})
})
+
+ // The recipe reconciler calls this from the running and active
+ // short-circuits, which never reach reconcile(), to retry a policy a
+ // previous pass left pending.
+ describe('retryRunLaneNetworkPolicies', () => {
+ const spec = () =>
+ makeSpec({ agent: undefined, steps: [{ id: 'prepare', run: snippetRun() }] })
+
+ async function convergedRunLane() {
+ const apiserver = makeApiserverNetworkingApi()
+ const reconciler = new WorkflowReconciler(
+ makeDeps({ networkingApi: apiserver.api as never })
+ )
+ const first = await reconciler.reconcile('test-wf', 'uid-123', 'sandbox-recipes', spec())
+ expect(first.workflowPhase).not.toBe('failed')
+ expect([...apiserver.live.keys()].sort()).toEqual(RUN_LANE_POLICY_NAMES)
+ // reconcile() also prunes the codex, grok and legacy policies, so a
+ // zero delete count below means the retry skipped them, not that no
+ // prune exists for this spec.
+ expect(apiserver.api.deleteNamespacedNetworkPolicy).toHaveBeenCalled()
+ apiserver.api.createNamespacedNetworkPolicy.mockClear()
+ apiserver.api.readNamespacedNetworkPolicy.mockClear()
+ apiserver.api.replaceNamespacedNetworkPolicy.mockClear()
+ apiserver.api.deleteNamespacedNetworkPolicy.mockClear()
+ return { apiserver, reconciler }
+ }
+
+ it('recreates an absent run-lane policy and deletes nothing', async () => {
+ const { apiserver, reconciler } = await convergedRunLane()
+ const absentKey = apiserver.key('sandbox-recipes', 'test-wf-coord-to-wrc')
+ const convergedSpec = structuredClone(apiserver.live.get(absentKey)!.spec)
+ expect(apiserver.live.delete(absentKey)).toBe(true)
+
+ const summary = await reconciler.retryRunLaneNetworkPolicies('test-wf', 'uid-123', spec())
+
+ expect(summary).toEqual({ conflicts: [], retryPending: false })
+ expect(readPolicyNames(apiserver.api)).toEqual(
+ RUN_LANE_POLICY_NAMES.map(entry => entry.split('/')[1]!).sort()
+ )
+ expect(
+ apiserver.api.createNamespacedNetworkPolicy.mock.calls.map(
+ ([arg]) => arg.body.metadata?.name
+ )
+ ).toEqual(['test-wf-coord-to-wrc'])
+ expect(apiserver.live.get(absentKey)!.spec).toEqual(convergedSpec)
+ expect(apiserver.api.replaceNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ expect(apiserver.api.deleteNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ })
+
+ it('writes nothing when every run-lane policy is live and equal', async () => {
+ const { apiserver, reconciler } = await convergedRunLane()
+
+ const summary = await reconciler.retryRunLaneNetworkPolicies('test-wf', 'uid-123', spec())
+
+ expect(summary).toEqual({ conflicts: [], retryPending: false })
+ expect(readPolicyNames(apiserver.api)).toEqual(
+ RUN_LANE_POLICY_NAMES.map(entry => entry.split('/')[1]!).sort()
+ )
+ expect(apiserver.api.createNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ expect(apiserver.api.replaceNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ expect(apiserver.api.deleteNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ })
+
+ it('still reports the retry, and writes nothing, while a policy is being deleted', async () => {
+ const { apiserver, reconciler } = await convergedRunLane()
+ const terminating = apiserver.live.get(
+ apiserver.key('sandbox-recipes', 'test-wf-coord-to-wrc')
+ )!
+ terminating.spec = {
+ ...terminating.spec!,
+ podSelector: { matchLabels: { drifted: 'yes' } },
+ }
+ terminating.metadata = {
+ ...terminating.metadata,
+ deletionTimestamp: new Date('2026-09-24T10:00:00Z'),
+ }
+
+ const summary = await reconciler.retryRunLaneNetworkPolicies('test-wf', 'uid-123', spec())
+
+ expect(summary).toEqual({ conflicts: [], retryPending: true })
+ expect(readPolicyNames(apiserver.api)).toContain('test-wf-coord-to-wrc')
+ expect(apiserver.api.createNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ expect(apiserver.api.replaceNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ expect(apiserver.api.deleteNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)
+ })
+ })
})
it('resolves snippet MCP transport workloads into the mounted runner config', async () => {
@@ -7732,6 +7832,13 @@ describe('translateNetworkPolicyApplySummary', () => {
message: 'NetworkPolicy ownership conflict: test-wf-coord-to-wrc (owner-reference-mismatch)',
lastTransitionTime: earlier,
}
+ const publishedRetryMarker = {
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False' as const,
+ reason: 'RetryPending',
+ message: 'One or more run-lane NetworkPolicies are pending a retry (terminating or contended)',
+ lastTransitionTime: earlier,
+ }
it('emits neither field when the pass produced no summary, so the published condition is kept', () => {
const result = translateNetworkPolicyApplySummary(undefined, [publishedConflict], now)
@@ -7757,7 +7864,7 @@ describe('translateNetworkPolicyApplySummary', () => {
expect(result).toStrictEqual({ networkPolicyOwnershipConditions: [] })
})
- it('clears the condition with [] and sets the retry flag when a retry is pending without a conflict', () => {
+ it('replaces the conflict with the retry marker and sets the retry flag when a retry is pending without a conflict', () => {
const result = translateNetworkPolicyApplySummary(
{ conflicts: [], retryPending: true },
[publishedConflict],
@@ -7765,11 +7872,34 @@ describe('translateNetworkPolicyApplySummary', () => {
)
expect(result).toStrictEqual({
- networkPolicyOwnershipConditions: [],
+ networkPolicyOwnershipConditions: [{ ...publishedRetryMarker, lastTransitionTime: now }],
networkPolicyRetryPending: true,
})
})
+ it('keeps the lastTransitionTime of a published retry marker while the retry stays pending', () => {
+ const result = translateNetworkPolicyApplySummary(
+ { conflicts: [], retryPending: true },
+ [publishedRetryMarker],
+ now
+ )
+
+ expect(result).toStrictEqual({
+ networkPolicyOwnershipConditions: [publishedRetryMarker],
+ networkPolicyRetryPending: true,
+ })
+ })
+
+ it('clears a published retry marker with [] once no retry is pending', () => {
+ const result = translateNetworkPolicyApplySummary(
+ { conflicts: [], retryPending: false },
+ [publishedRetryMarker],
+ now
+ )
+
+ expect(result).toStrictEqual({ networkPolicyOwnershipConditions: [] })
+ })
+
it('replaces the condition with one False condition naming every conflicting policy', () => {
const result = translateNetworkPolicyApplySummary(
{
@@ -7811,8 +7941,61 @@ describe('translateNetworkPolicyApplySummary', () => {
)
expect(result).toStrictEqual({
- networkPolicyOwnershipConditions: [{ ...publishedConflict, lastTransitionTime: now }],
+ networkPolicyOwnershipConditions: [
+ { ...publishedConflict, lastTransitionTime: now },
+ { ...publishedRetryMarker, lastTransitionTime: now },
+ ],
networkPolicyRetryPending: true,
})
})
})
+
+describe('networkPolicyConditionsChanged', () => {
+ const conflict = {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False' as const,
+ reason: 'OwnershipConflict',
+ message: 'NetworkPolicy ownership conflict: test-wf-coord-to-wrc (owner-reference-mismatch)',
+ lastTransitionTime: '2026-09-20T08:00:00.000Z',
+ }
+ const marker = {
+ type: 'WorkflowNetworkPoliciesConverged',
+ status: 'False' as const,
+ reason: 'RetryPending',
+ message: 'One or more run-lane NetworkPolicies are pending a retry (terminating or contended)',
+ lastTransitionTime: '2026-09-20T08:00:00.000Z',
+ }
+ const unrelated = {
+ type: 'Ready',
+ status: 'True' as const,
+ reason: 'Ready',
+ message: 'ready',
+ lastTransitionTime: '2026-09-20T08:00:00.000Z',
+ }
+
+ it('reports no change when the group matches, whatever lastTransitionTime or other types say', () => {
+ expect(
+ networkPolicyConditionsChanged(
+ [conflict, marker, unrelated],
+ [
+ { ...conflict, lastTransitionTime: '2026-09-24T00:00:00.000Z' },
+ { ...marker, lastTransitionTime: '2026-09-24T00:00:00.000Z' },
+ ]
+ )
+ ).toBe(false)
+ })
+
+ it('reports a change when the retry marker appears', () => {
+ expect(networkPolicyConditionsChanged([conflict], [conflict, marker])).toBe(true)
+ })
+
+ it('reports a change when the retry marker goes away', () => {
+ expect(networkPolicyConditionsChanged([marker, unrelated], [])).toBe(true)
+ })
+
+ it('reports a change when the ownership condition message changes', () => {
+ expect(networkPolicyConditionsChanged([conflict], [{ ...conflict, message: 'other' }])).toBe(
+ true
+ )
+ })
+})