Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
chore(workflow-recipes): drop the unused K8s checkConcurrency helper
Jose Ramirez7f7823df4854
diff --git a/docs/crds/workflowrecipe.md b/docs/crds/workflowrecipe.mdindex 51899d793..def649df5 100644--- a/docs/crds/workflowrecipe.md+++ b/docs/crds/workflowrecipe.md@@ -1181,6 +1181,14 @@ spec:**Runtime behavior.** Scheduling is **Postgres-backed, not a Kubernetes CronJob**: WRC keeps a `workflow_schedules` row in sync and the advance loop lives in a control-api worker. `enabled = NOT suspend`, so suspending keeps the row rather than deleting it.+**`concurrencyPolicy`** (and `spec.scheduling.concurrencyPolicy` on the legacy path, §3.14) applies to scheduled ticks only; on-demand and autonomous triggers are never gated by it.++- `Forbid` (default): a tick is skipped while a run of the recipe is still live, whatever started it. Live means `Pending` for less than 15 minutes, or `Running` for less than `maxRunDurationSeconds` (capped at 24 hours, the controller maximum, and assumed when unset) plus a 5-minute grace. The schedule advances to its next future window; skipped windows are not replayed.+- `Allow`: every tick fires, and runs may overlap.+- `Replace`: accepted but **not implemented**. It currently behaves exactly like `Allow`.++A run that never reaches a terminal phase stops blocking once it passes that bound, so a stuck run cannot silence a schedule forever. After the bound, one new scheduled run may overlap the stuck one. Set `spec.runRetention.maxRunDurationSeconds` so a stuck run is failed (and the schedule resumes) sooner than the 24-hour default. Every skip is logged as `workflow_schedule_worker_concurrency_forbidden` with the blocking run id and age. Six consecutive skips of one schedule also log `workflow_schedule_worker_concurrency_forbidden_sustained` (warn) and increment `wrc_schedule_worker_concurrency_forbidden_sustained_total`.+### 3.14 Scheduling (`spec.scheduling`) — legacyThe predecessor of `spec.triggers.schedule` (§3.13), still accepted for backwards compatibility. The reconciler prefers `spec.triggers.schedule`. **Prefer `spec.triggers` in new recipes.**diff --git a/workflow-recipes/README.md b/workflow-recipes/README.mdindex 05652d52a..b37950d0f 100644--- a/workflow-recipes/README.md+++ b/workflow-recipes/README.md@@ -161,7 +161,6 @@ src/├── httpMcpHostClient.ts # mcp-host HTTP client├── schedulingHandler.ts # Cron/trigger scheduling├── signalStore.ts # Inter-step signal passing- ├── rateLimiter.ts # LLM call rate limiting├── historyManager.ts # Execution history├── restEndpoints.ts # REST API for coordinator├── objectStorageAdapter.ts # S3-compatible artifact storagediff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 03766c6f1..936aed870 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.471",+ "version": "0.1.472","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.471",+ "version": "0.1.472","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 7280a3569..808c03d9f 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.471",+ "version": "0.1.472","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/crdConstants.ts b/workflow-recipes/src/reconciler/crdConstants.tsindex b618a5575..834485264 100644--- a/workflow-recipes/src/reconciler/crdConstants.ts+++ b/workflow-recipes/src/reconciler/crdConstants.ts@@ -4,7 +4,7 @@ export const CRD_VERSION = 'v1alpha1'export const WORKFLOWRECIPE_PLURAL = 'workflowrecipes'/**- * Shared set of terminal workflow phases used by rateLimiter, historyManager,+ * Shared set of terminal workflow phases used by historyManager,* and any other module that needs to distinguish "still running" from "done".* Single source of truth — prevents drift between modules.*/diff --git a/workflow-recipes/src/workflow/rateLimiter.ts b/workflow-recipes/src/workflow/rateLimiter.tsdeleted file mode 100644index db8548e3a..000000000--- a/workflow-recipes/src/workflow/rateLimiter.ts+++ /dev/null@@ -1,81 +0,0 @@-/**- * Concurrency control for scheduled workflow triggers.- *- * Enforces Forbid, Replace, and Allow policies before creating- * a child WorkflowRecipe.- * */-import * as k8s from '@kubernetes/client-node'-import {- CRD_GROUP,- CRD_VERSION,- WORKFLOWRECIPE_PLURAL,- WORKFLOW_TERMINAL_PHASES,-} from '../reconciler/crdConstants'--const DEFAULT_MAX_CONCURRENT = 3--export type ConcurrencyPolicy = 'Forbid' | 'Replace' | 'Allow'-export type ConcurrencyDecision = 'proceed' | 'skip' | 'replace'--interface RunningChild {- metadata: { name: string; namespace: string }- status?: { workflowExecution?: { phase?: string } }-}--function isRunning(child: RunningChild): boolean {- const phase = child.status?.workflowExecution?.phase- return !WORKFLOW_TERMINAL_PHASES.has(phase ?? 'pending')-}--export async function listRunningChildren(- customApi: k8s.CustomObjectsApi,- parentName: string,- namespace: string-): Promise<RunningChild[]> {- const result = (await customApi.listNamespacedCustomObject({- group: CRD_GROUP,- version: CRD_VERSION,- namespace,- plural: WORKFLOWRECIPE_PLURAL,- labelSelector: `clerum.io/parent-recipe=${parentName},clerum.io/scheduled=true`,- })) as { items?: RunningChild[] }- return (result.items ?? []).filter(isRunning)-}--export interface ConcurrencyResult {- decision: ConcurrencyDecision- runningChildren?: RunningChild[]- reason?: string-}--export async function checkConcurrency(- customApi: k8s.CustomObjectsApi,- parentName: string,- namespace: string,- concurrencyPolicy: ConcurrencyPolicy,- maxConcurrent?: number-): Promise<ConcurrencyResult> {- const running = await listRunningChildren(customApi, parentName, namespace)-- if (running.length === 0) return { decision: 'proceed' }-- if (concurrencyPolicy === 'Forbid') {- return { decision: 'skip', reason: 'Forbid: child already running' }- }-- if (concurrencyPolicy === 'Replace') {- return {- decision: 'replace',- runningChildren: running,- reason: `Replace: cancelling ${running.length} running child(ren)`,- }- }-- // Allow — check global cap- const cap = maxConcurrent ?? DEFAULT_MAX_CONCURRENT- if (running.length >= cap) {- return { decision: 'skip', reason: `Allow: at capacity (${running.length}/${cap})` }- }-- return { decision: 'proceed' }-}diff --git a/workflow-recipes/tests/unit/workflow/rateLimiter.test.ts b/workflow-recipes/tests/unit/workflow/rateLimiter.test.tsdeleted file mode 100644index bb15a26f3..000000000--- a/workflow-recipes/tests/unit/workflow/rateLimiter.test.ts+++ /dev/null@@ -1,120 +0,0 @@-import { describe, expect, it, vi } from 'vitest'-import { checkConcurrency, listRunningChildren } from '../../../src/workflow/rateLimiter'--function makeRunningChild(name: string, phase = 'running') {- return {- metadata: { name, namespace: 'sandbox-recipes' },- status: { workflowExecution: { phase } },- }-}--function makeMockApi(items: unknown[]) {- return {- listNamespacedCustomObject: vi.fn().mockResolvedValue({ items }),- } as any-}--describe('listRunningChildren', () => {- it('returns only running children', async () => {- const items = [- makeRunningChild('r1', 'running'),- makeRunningChild('c1', 'completed'),- makeRunningChild('f1', 'failed'),- makeRunningChild('r2', 'pending'),- ]- const api = makeMockApi(items)- const result = await listRunningChildren(api, 'parent', 'ns')- // running and pending are non-terminal → running- expect(result).toHaveLength(2)- expect(result.map((r: any) => r.metadata.name)).toEqual(['r1', 'r2'])- })-- it('excludes cancelled children', async () => {- const items = [makeRunningChild('x1', 'cancelled')]- const api = makeMockApi(items)- const result = await listRunningChildren(api, 'parent', 'ns')- expect(result).toHaveLength(0)- })-- it('treats missing phase as running (pending)', async () => {- const items = [{ metadata: { name: 'no-status', namespace: 'ns' } }]- const api = makeMockApi(items)- const result = await listRunningChildren(api, 'parent', 'ns')- expect(result).toHaveLength(1)- })-- it('uses correct label selector', async () => {- const api = makeMockApi([])- await listRunningChildren(api, 'my-recipe', 'sandbox-recipes')- expect(api.listNamespacedCustomObject).toHaveBeenCalledWith(- expect.objectContaining({- labelSelector: 'clerum.io/parent-recipe=my-recipe,clerum.io/scheduled=true',- })- )- })-})--describe('checkConcurrency', () => {- it('proceeds when no running children', async () => {- const api = makeMockApi([])- const result = await checkConcurrency(api, 'parent', 'ns', 'Forbid')- expect(result.decision).toBe('proceed')- })-- describe('Forbid policy', () => {- it('skips when child is running', async () => {- const api = makeMockApi([makeRunningChild('r1')])- const result = await checkConcurrency(api, 'parent', 'ns', 'Forbid')- expect(result.decision).toBe('skip')- expect(result.reason).toContain('Forbid')- })- })-- describe('Replace policy', () => {- it('proceeds when no running children', async () => {- const api = makeMockApi([])- const result = await checkConcurrency(api, 'parent', 'ns', 'Replace')- expect(result.decision).toBe('proceed')- })-- it('returns replace with running child reference', async () => {- const api = makeMockApi([makeRunningChild('r1')])- const result = await checkConcurrency(api, 'parent', 'ns', 'Replace')- expect(result.decision).toBe('replace')- expect(result.runningChildren?.[0]?.metadata.name).toBe('r1')- expect(result.reason).toContain('Replace')- })- })-- describe('Allow policy', () => {- it('proceeds when below default capacity (3)', async () => {- const api = makeMockApi([makeRunningChild('r1'), makeRunningChild('r2')])- const result = await checkConcurrency(api, 'parent', 'ns', 'Allow')- expect(result.decision).toBe('proceed')- })-- it('skips when at default capacity (3)', async () => {- const api = makeMockApi([- makeRunningChild('r1'),- makeRunningChild('r2'),- makeRunningChild('r3'),- ])- const result = await checkConcurrency(api, 'parent', 'ns', 'Allow')- expect(result.decision).toBe('skip')- expect(result.reason).toContain('3/3')- })-- it('respects custom maxConcurrent', async () => {- const api = makeMockApi([makeRunningChild('r1')])- const result = await checkConcurrency(api, 'parent', 'ns', 'Allow', 1)- expect(result.decision).toBe('skip')- expect(result.reason).toContain('1/1')- })-- it('proceeds when below custom maxConcurrent', async () => {- const api = makeMockApi([makeRunningChild('r1')])- const result = await checkConcurrency(api, 'parent', 'ns', 'Allow', 5)- expect(result.decision).toBe('proceed')- })- })-})