Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(wrc): keep runtime egress resolved-at while the resolved set is unchanged
Alfredo Lopezc56671b41795
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 3da8ec4dd..f2f146703 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.375",+ "version": "0.1.376","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.375",+ "version": "0.1.376","license": "SEE LICENSE IN LICENSE","dependencies": {"@aws-sdk/client-s3": "^3.1009.0",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex 76e8ba257..8ebe94a41 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.375",+ "version": "0.1.376","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.ts b/workflow-recipes/src/workflow/workflowReconciler.tsindex d4874af83..d217edca1 100644--- a/workflow-recipes/src/workflow/workflowReconciler.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.ts@@ -408,6 +408,27 @@ function latestDate(a: Date | undefined, b: Date | undefined): Date | undefinedreturn a.getTime() >= b.getTime() ? a : b}+/**+ * The latest live resolved-at when every policy exists and already carries the+ * computed CIDR state. Undefined when a policy is missing, the resolved set+ * changed, or no live value parses, so the caller stamps the current time.+ */+function unchangedRuntimeHttpEgressResolvedAt(+ liveAnnotationSets: Array<Record<string, string> | undefined>,+ computed: Record<string, string>+): Date | undefined {+ let latest: Date | undefined+ for (const live of liveAnnotationSets) {+ if (!live) return undefined+ for (const key of RUNTIME_HTTP_EGRESS_OWNED_ANNOTATIONS) {+ if (key === RUNTIME_HTTP_EGRESS_RESOLVED_AT_ANNOTATION) continue+ if (live[key] !== computed[key]) return undefined+ }+ latest = latestDate(latest, parseDate(live[RUNTIME_HTTP_EGRESS_RESOLVED_AT_ANNOTATION]))+ }+ return latest+}+function addRuntimeHttpEgressPreviousExpiry(expiries: Map<string, Date>,cidr: string,@@ -3222,6 +3243,7 @@ export class WorkflowReconciler {)const currentSerialized = serializeCidrs(currentCidrs)const previousExpiries = new Map<string, Date>()+ const liveAnnotationSets: Array<Record<string, string> | undefined> = []// Coordinator and snippet policies share one WorkflowRecipe runtimeEgress contract.// Merge valid annotations from all matching policies so a partial refresh or restart@@ -3229,6 +3251,7 @@ export class WorkflowReconciler {// Taking the latest expiration avoids one policy shortening another policy's DNS rollover.for (const policyName of policyNames) {const annotations = await this.readNetworkPolicyAnnotations(namespace, policyName)+ liveAnnotationSets.push(annotations)if (!annotations) continueconst existingCurrent = parseCidrsAnnotation(@@ -3278,8 +3301,6 @@ export class WorkflowReconciler {const annotations: Record<string, string> = {[RUNTIME_HTTP_EGRESS_CURRENT_CIDRS_ANNOTATION]: currentSerialized,- // Observability only; policy decisions use current/previous CIDR annotations above.- [RUNTIME_HTTP_EGRESS_RESOLVED_AT_ANNOTATION]: now.toISOString(),}if (activePreviousCidrs.length > 0) {const activePreviousExpiries = new Map(activePreviousEntries)@@ -3294,6 +3315,12 @@ export class WorkflowReconciler {annotations[RUNTIME_HTTP_EGRESS_PREVIOUS_CIDR_EXPIRIES_ANNOTATION] =serializeRuntimeHttpEgressCidrExpiries(activePreviousExpiries)}+ // Observability only; policy decisions use current/previous CIDR annotations above.+ // The key records the last change of the resolved set, not the last resolution:+ // stamping every pass made each refresh a replace of an otherwise converged policy.+ annotations[RUNTIME_HTTP_EGRESS_RESOLVED_AT_ANNOTATION] = (+ unchangedRuntimeHttpEgressResolvedAt(liveAnnotationSets, annotations) ?? now+ ).toISOString()return { currentCidrs, effectiveCidrs, annotations }}diff --git a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.tsindex 47ce85064..67e55daa3 100644--- a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts+++ b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts@@ -3004,6 +3004,93 @@ describe('WorkflowReconciler — reconcile loop', () => {}})+ describe('runtime HTTP egress resolved-at', () => {+ // runtimeEgressSpec has no coordinator, so the snippet runner is the+ // only runtime HTTP egress policy.+ const RUNTIME_EGRESS_POLICIES = ['test-wf-snippet-runner-egress']+ const RESOLVED_AT = 'clerum.io/runtime-http-egress-resolved-at'+ const FIRST_PASS_AT = new Date('2026-09-23T10:00:00.000Z')+ const SECOND_PASS_AT = new Date('2026-09-23T10:05:00.000Z')++ afterEach(() => {+ vi.useRealTimers()+ })++ async function refreshTwice(+ resolveRuntimeHttpEgressCidrs: ReturnType<typeof vi.fn>+ ): Promise<ReturnType<typeof makeApiserverNetworkingApi>> {+ const apiserver = makeApiserverNetworkingApi()+ const reconciler = new WorkflowReconciler(+ makeDeps({+ networkingApi: apiserver.api as never,+ resolveRuntimeHttpEgressCidrs,+ config: { ...makeConfig(), enableSnippetRuntime: true } as never,+ })+ )+ const spec = runtimeEgressSpec()+ vi.useFakeTimers({ toFake: ['Date'] })+ vi.setSystemTime(FIRST_PASS_AT)+ await reconciler.refreshRuntimeHttpEgressNetworkPolicies(+ 'sandbox-recipes',+ 'test-wf',+ 'uid-123',+ spec+ )+ for (const name of RUNTIME_EGRESS_POLICIES) {+ expect(+ apiserver.live.get(apiserver.key('sandbox-recipes', name))?.metadata?.annotations?.[+ RESOLVED_AT+ ]+ ).toBe(FIRST_PASS_AT.toISOString())+ }++ apiserver.api.createNamespacedNetworkPolicy.mockClear()+ apiserver.api.readNamespacedNetworkPolicy.mockClear()+ apiserver.api.replaceNamespacedNetworkPolicy.mockClear()+ vi.setSystemTime(SECOND_PASS_AT)+ await reconciler.refreshRuntimeHttpEgressNetworkPolicies(+ 'sandbox-recipes',+ 'test-wf',+ 'uid-123',+ spec+ )+ return apiserver+ }++ it('keeps the live resolved-at and writes nothing when the resolved set is unchanged', async () => {+ const resolve = vi.fn().mockResolvedValue(['93.184.216.34/32'])+ const { api, live, key } = await refreshTwice(resolve)++ expect(resolve).toHaveBeenCalledTimes(2)+ expect(readPolicyNames(api)).toEqual(expect.arrayContaining(RUNTIME_EGRESS_POLICIES))+ expect(api.createNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)+ expect(api.replaceNamespacedNetworkPolicy).toHaveBeenCalledTimes(0)+ for (const name of RUNTIME_EGRESS_POLICIES) {+ expect(live.get(key('sandbox-recipes', name))?.metadata?.annotations?.[RESOLVED_AT]).toBe(+ FIRST_PASS_AT.toISOString()+ )+ }+ })++ it('stamps the current time when the resolved set changes', async () => {+ const resolve = vi+ .fn()+ .mockResolvedValueOnce(['93.184.216.34/32'])+ .mockResolvedValueOnce(['93.184.216.35/32'])+ const { api } = await refreshTwice(resolve)++ const replaced = api.replaceNamespacedNetworkPolicy.mock.calls.map(([arg]) => arg)+ expect(replaced.map(arg => arg.name).sort()).toEqual(RUNTIME_EGRESS_POLICIES)+ for (const arg of replaced) {+ expect(arg.body.metadata?.annotations).toMatchObject({+ [RESOLVED_AT]: SECOND_PASS_AT.toISOString(),+ 'clerum.io/runtime-http-egress-current-cidrs': '93.184.216.35/32',+ 'clerum.io/runtime-http-egress-previous-cidrs': '93.184.216.34/32',+ })+ }+ })+ })+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 }))