Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: make SDK teardown absence checks race-free
Alfredo Lopezc96e1e0c79dd
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex fa166d2f2..427d02206 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.279",+ "version": "0.1.280","lockfileVersion": 3,"requires": true,"packages": {@@ -34,7 +34,7 @@"engines": {"node": ">=24"},- "version": "0.1.279"+ "version": "0.1.280"},"../packages/image-policy": {"name": "@clerum/image-policy",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex 7bc08787f..06f686096 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.279",+ "version": "0.1.280","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/workflow/workflowReconciler.test.ts b/workflow-recipes/src/workflow/workflowReconciler.test.tsindex cf65b01ef..69c5a08a3 100644--- a/workflow-recipes/src/workflow/workflowReconciler.test.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.test.ts@@ -1649,6 +1649,28 @@ describe('WorkflowReconciler — Plugin Workload SDK eager mcp-host', () => {expect(mockCoreApi.createNamespacedPod).not.toHaveBeenCalled()})+ it('defers absence reads until pod deletion completes so 404s cannot become unhandled rejections', async () => {+ const events: string[] = []+ crashRecoveryMocks.waitForPodDeletion.mockImplementationOnce(async () => {+ events.push('wait-start')+ await Promise.resolve()+ events.push('wait-end')+ return true+ })+ mockNetworkingApi.readNamespacedNetworkPolicy.mockImplementation(async () => {+ events.push('network-policy-read')+ throw { code: 404 }+ })++ const reconciler = new WorkflowReconciler(makeDeps())++ await expect(reconciler.cleanupPluginWorkloadSdk('sdk-only')).resolves.toBeUndefined()++ expect(events.indexOf('wait-start')).toBeGreaterThanOrEqual(0)+ expect(events.indexOf('wait-end')).toBeGreaterThan(events.indexOf('wait-start'))+ expect(events.indexOf('network-policy-read')).toBeGreaterThan(events.indexOf('wait-end'))+ })+it('removes only SDK-owned authority from a hybrid workflow runtime', async () => {const reconciler = new WorkflowReconciler(makeDeps())diff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.tsindex 27ec4bef8..52a7506ae 100644--- a/workflow-recipes/src/workflow/workflowReconciler.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.ts@@ -1138,13 +1138,20 @@ export class WorkflowReconciler {networkPolicyNames: string[],options: PluginWorkloadSdkCleanupOptions = {}): Promise<void> {- const checks: Array<Promise<unknown>> = [- this.deps.coreApi.readNamespacedSecret({- name: buildPluginWorkloadSdkTokenSecretName(recipeName),- namespace,- }),- ...networkPolicyNames.map(name =>- this.deps.networkingApi.readNamespacedNetworkPolicy({ name, namespace })+ // Keep the API calls lazy until every precondition (notably pod deletion)+ // has completed. Starting a read and then awaiting the pod poll leaves a+ // rejection from an already-absent object temporarily unhandled; Node can+ // terminate the controller before the later Promise.allSettled observes it.+ // Lazy checks preserve the fail-closed rule while making teardown safe for+ // the normal idempotent 404 path.+ const checks: Array<() => Promise<unknown>> = [+ () =>+ this.deps.coreApi.readNamespacedSecret({+ name: buildPluginWorkloadSdkTokenSecretName(recipeName),+ namespace,+ }),+ ...networkPolicyNames.map(+ name => () => this.deps.networkingApi.readNamespacedNetworkPolicy({ name, namespace })),]if (!options.preserveWorkflowRuntime) {@@ -1160,29 +1167,34 @@ export class WorkflowReconciler {if (!podGone)throw new Error(`Plugin Workload SDK pod for ${recipeName} still exists after teardown`)checks.push(- this.deps.coreApi.readNamespacedSecret({- name: `wf-${recipeName}-mcp-host-runtime-tokens`,- namespace,- }),- this.deps.coreApi.readNamespacedService({- name: buildMcpHostServiceName(recipeName),- namespace,- }),- this.deps.coreApi.readNamespacedEndpoints({- name: buildMcpHostServiceName(recipeName),- namespace,- }),- this.deps.networkingApi.listNamespacedNetworkPolicy({- namespace,- labelSelector: `clerum.io/recipe=${recipeName},clerum.io/managed-by=wrc`,- }),- this.deps.networkingApi.listNamespacedNetworkPolicy({- namespace: this.deps.config.mcpServerNamespace,- labelSelector: `clerum.io/recipe=${recipeName},clerum.io/managed-by=wrc`,- })+ () =>+ this.deps.coreApi.readNamespacedSecret({+ name: `wf-${recipeName}-mcp-host-runtime-tokens`,+ namespace,+ }),+ () =>+ this.deps.coreApi.readNamespacedService({+ name: buildMcpHostServiceName(recipeName),+ namespace,+ }),+ () =>+ this.deps.coreApi.readNamespacedEndpoints({+ name: buildMcpHostServiceName(recipeName),+ namespace,+ }),+ () =>+ this.deps.networkingApi.listNamespacedNetworkPolicy({+ namespace,+ labelSelector: `clerum.io/recipe=${recipeName},clerum.io/managed-by=wrc`,+ }),+ () =>+ this.deps.networkingApi.listNamespacedNetworkPolicy({+ namespace: this.deps.config.mcpServerNamespace,+ labelSelector: `clerum.io/recipe=${recipeName},clerum.io/managed-by=wrc`,+ }))}- const results = await Promise.allSettled(checks)+ const results = await Promise.allSettled(checks.map(check => check()))const unexpected = results.find(result => {if (result.status !== 'fulfilled') return falseconst value = result.value as { items?: unknown[] } | undefined