Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(workflow-recipes): sync schedule concurrencyPolicy into workflow_schedules
Jose Ramirezcf004086de2b
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 7c554403c..03766c6f1 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.470",+ "version": "0.1.471","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.470",+ "version": "0.1.471","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 85b1a9380..7280a3569 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.470",+ "version": "0.1.471","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/types.ts b/workflow-recipes/src/types.tsindex ddd7865d0..b7a0ec092 100644--- a/workflow-recipes/src/types.ts+++ b/workflow-recipes/src/types.ts@@ -705,6 +705,7 @@ export interface WorkflowRecipeSpec {schedule?: {cron: stringtimezone?: string+ concurrencyPolicy?: 'Forbid' | 'Replace' | 'Allow'suspend?: boolean}}diff --git a/workflow-recipes/src/workflow/schedulingHandler.ts b/workflow-recipes/src/workflow/schedulingHandler.tsindex 46cb13b81..9874373c8 100644--- a/workflow-recipes/src/workflow/schedulingHandler.ts+++ b/workflow-recipes/src/workflow/schedulingHandler.ts@@ -19,6 +19,9 @@* whatever the worker has already advanced it to.* • `enabled = NOT suspend` so the worker's `enabled = TRUE` filter keeps* suspended schedules dormant without deleting the row.+ * • `concurrency_policy` mirrors `concurrencyPolicy` (default `Forbid`, the+ * CRD default; unknown values also map to `Forbid`). The control-api+ * worker enforces Forbid; Replace is not implemented and behaves as Allow.* • All UPDATEs explicitly set `updated_at = now()` — the codebase does not* use auto-update triggers (see control-api db.ts convention).*/@@ -29,6 +32,18 @@ import type { SchedulingSpec } from './types'export const WORKFLOW_TEAM_ID_LABEL = 'clerum.io/workflow-team-id'export const MAX_TTL_SECONDS_AFTER_FINISHED = 30 * 24 * 60 * 60+/** Mirrors the CRD enum on `schedule.concurrencyPolicy` and the DB CHECK. */+export type ScheduleConcurrencyPolicy = 'Forbid' | 'Replace' | 'Allow'+export const DEFAULT_SCHEDULE_CONCURRENCY_POLICY: ScheduleConcurrencyPolicy = 'Forbid'+const SCHEDULE_CONCURRENCY_POLICIES: ReadonlySet<string> = new Set(['Forbid', 'Replace', 'Allow'])++/** Omitted or unknown values resolve to the CRD default, `Forbid`. */+export function resolveScheduleConcurrencyPolicy(value: unknown): ScheduleConcurrencyPolicy {+ return typeof value === 'string' && SCHEDULE_CONCURRENCY_POLICIES.has(value)+ ? (value as ScheduleConcurrencyPolicy)+ : DEFAULT_SCHEDULE_CONCURRENCY_POLICY+}+/** Actor types that may trigger a run. Mirrors the check constraint on `workflow_runs.actor_type`. */export type TriggerAllowedActor = 'user' | 'autonomous' | 'scheduled'@@ -119,6 +134,7 @@ export async function reconcileScheduling(const ttlSecondsAfterFinished = resolveTtlSecondsAfterFinished(recipe.spec.runRetention?.ttlSecondsAfterFinished ?? null)+ const concurrencyPolicy = resolveScheduleConcurrencyPolicy(sched.concurrencyPolicy)// Fetch current row so we can emit semantic actions (created/updated/…) and// decide whether to reset next_fire_at. One SELECT + one UPSERT per tick.@@ -130,9 +146,11 @@ export async function reconcileScheduling(allowed_actors: TriggerAllowedActor[] | nullmax_duration_seconds: number | nullttl_seconds_after_finished: number | null+ concurrency_policy: string | null}>(`SELECT cron_expression, timezone, enabled, team_id::text AS team_id,- allowed_actors, max_duration_seconds, ttl_seconds_after_finished+ allowed_actors, max_duration_seconds, ttl_seconds_after_finished,+ concurrency_policyFROM workflow_schedulesWHERE recipe_namespace = $1 AND recipe_name = $2`,[ns, name]@@ -146,8 +164,8 @@ export async function reconcileScheduling(`INSERT INTO workflow_schedules(recipe_namespace, recipe_name, team_id, cron_expression, timezone,next_fire_at, enabled, allowed_actors, max_duration_seconds,- ttl_seconds_after_finished, created_at, updated_at)- VALUES ($1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9, $10, now(), now())`,+ ttl_seconds_after_finished, concurrency_policy, created_at, updated_at)+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9, $10, $11, now(), now())`,[ns,name,@@ -159,6 +177,7 @@ export async function reconcileScheduling(allowedActors,maxDurationSeconds,ttlSecondsAfterFinished,+ concurrencyPolicy,])return { action: 'created' }@@ -171,6 +190,7 @@ export async function reconcileScheduling(const actorsChanged = !sameActorList(prev.allowed_actors, recipe.spec.allowedActors ?? null)const durationChanged = prev.max_duration_seconds !== maxDurationSecondsconst ttlChanged = prev.ttl_seconds_after_finished !== ttlSecondsAfterFinished+ const policyChanged = prev.concurrency_policy !== concurrencyPolicy// Reset next_fire_at only when the schedule itself shifted or we're waking// a suspended schedule — the worker's advancement of next_fire_at is the@@ -186,8 +206,9 @@ export async function reconcileScheduling(allowed_actors = $6::jsonb,max_duration_seconds = $7,ttl_seconds_after_finished = $8,+ concurrency_policy = $9,updated_at = now()- WHERE recipe_namespace = $9 AND recipe_name = $10`,+ WHERE recipe_namespace = $10 AND recipe_name = $11`,[sched.cron,timezone,@@ -197,6 +218,7 @@ export async function reconcileScheduling(allowedActors,maxDurationSeconds,ttlSecondsAfterFinished,+ concurrencyPolicy,ns,name,]@@ -207,7 +229,8 @@ export async function reconcileScheduling(teamChanged ||actorsChanged ||durationChanged ||- ttlChanged+ ttlChanged ||+ policyChanged) {await pool.query(`UPDATE workflow_schedules@@ -216,9 +239,19 @@ export async function reconcileScheduling(allowed_actors = $3::jsonb,max_duration_seconds = $4,ttl_seconds_after_finished = $5,+ concurrency_policy = $6,updated_at = now()- WHERE recipe_namespace = $6 AND recipe_name = $7`,- [enabled, teamId, allowedActors, maxDurationSeconds, ttlSecondsAfterFinished, ns, name]+ WHERE recipe_namespace = $7 AND recipe_name = $8`,+ [+ enabled,+ teamId,+ allowedActors,+ maxDurationSeconds,+ ttlSecondsAfterFinished,+ concurrencyPolicy,+ ns,+ name,+ ])} else {return { action: 'skipped' }diff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.tsindex bee490e01..44f51ec5a 100644--- a/workflow-recipes/src/workflow/workflowReconciler.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.ts@@ -3064,6 +3064,7 @@ export class WorkflowReconciler {? {cron: scheduleTrigger.cron,timezone: scheduleTrigger.timezone,+ concurrencyPolicy: scheduleTrigger.concurrencyPolicy,suspend: scheduleTrigger.suspend,}: spec.schedulingdiff --git a/workflow-recipes/tests/unit/workflow/schedulingHandler.test.ts b/workflow-recipes/tests/unit/workflow/schedulingHandler.test.tsindex 4847c7bc3..2e9317c2d 100644--- a/workflow-recipes/tests/unit/workflow/schedulingHandler.test.ts+++ b/workflow-recipes/tests/unit/workflow/schedulingHandler.test.ts@@ -47,6 +47,7 @@ function makePool(selectRows: Array<Record<string, unknown>> = []): {allowed_actors: null,max_duration_seconds: null,ttl_seconds_after_finished: 2_592_000,+ concurrency_policy: 'Forbid',...rawRow,},]@@ -277,6 +278,88 @@ describe('reconcileScheduling', () => {expect(calls[1].params[4]).toBe(3600)})+ it('writes concurrency_policy = Forbid on INSERT when the spec omits it (CRD default)', async () => {+ const { pool, calls } = makePool([])+ const result = await reconcileScheduling(pool, baseRecipe)+ expect(result.action).toBe('created')+ expect(calls[0].sql).toMatch(/concurrency_policy/)+ expect(calls[1].sql).toMatch(/INSERT INTO workflow_schedules/)+ expect(calls[1].sql).toMatch(/concurrency_policy/)+ expect(calls[1].params[10]).toBe('Forbid')+ })++ it('writes an explicit concurrencyPolicy on INSERT', async () => {+ const { pool, calls } = makePool([])+ const recipe: SchedulingRecipe = {+ ...baseRecipe,+ spec: { scheduling: { cron: '*/5 * * * *', timezone: 'UTC', concurrencyPolicy: 'Allow' } },+ }+ await reconcileScheduling(pool, recipe)+ expect(calls[1].params[10]).toBe('Allow')+ })++ it('falls back to Forbid for a value outside the CRD enum', async () => {+ const { pool, calls } = makePool([])+ const recipe = {+ ...baseRecipe,+ spec: {+ scheduling: { cron: '*/5 * * * *', timezone: 'UTC', concurrencyPolicy: 'Sometimes' },+ },+ } as unknown as SchedulingRecipe+ await reconcileScheduling(pool, recipe)+ expect(calls[1].params[10]).toBe('Forbid')+ })++ it('issues an UPDATE when only concurrencyPolicy drifts, without resetting next_fire_at', async () => {+ const { pool, calls } = makePool([+ {+ cron_expression: '0 9 * * *',+ timezone: 'America/New_York',+ enabled: true,+ concurrency_policy: 'Forbid',+ },+ ])+ const recipe: SchedulingRecipe = {+ ...baseRecipe,+ spec: {+ scheduling: {+ cron: '0 9 * * *',+ timezone: 'America/New_York',+ concurrencyPolicy: 'Allow',+ },+ },+ }+ const result = await reconcileScheduling(pool, recipe)+ expect(result.action).toBe('updated')+ expect(calls[1].sql).toMatch(/UPDATE workflow_schedules/)+ expect(calls[1].sql).toMatch(/concurrency_policy = \$6/)+ expect(calls[1].sql).not.toMatch(/next_fire_at/)+ expect(calls[1].params[5]).toBe('Allow')+ expect(calls[1].params.slice(6)).toEqual(['sandbox-recipes', 'daily-report'])+ })++ it('carries concurrency_policy on the cron-change UPDATE', async () => {+ const { pool, calls } = makePool([+ { cron_expression: '0 8 * * *', timezone: 'America/New_York', enabled: true },+ ])+ const recipe: SchedulingRecipe = {+ ...baseRecipe,+ spec: {+ scheduling: {+ cron: '0 9 * * *',+ timezone: 'America/New_York',+ concurrencyPolicy: 'Replace',+ },+ },+ }+ const result = await reconcileScheduling(pool, recipe)+ expect(result.action).toBe('updated')+ expect(calls[1].sql).toMatch(/next_fire_at/)+ expect(calls[1].sql).toMatch(/concurrency_policy = \$9/)+ expect(calls[1].params[8]).toBe('Replace')+ expect(calls[1].params.slice(9)).toEqual(['sandbox-recipes', 'daily-report'])+ })+it('fails closed when a scheduled recipe has no workflow team label', async () => {const { pool } = makePool([])await expect(diff --git a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.tsindex bf5228fe1..2364c645d 100644--- a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts+++ b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts@@ -8446,6 +8446,58 @@ describe('WorkflowReconciler — reconcile loop', () => {expect((insertCall?.[1] as unknown[] | undefined)?.[9]).toBe(3600)})+ it('mirrors triggers.schedule.concurrencyPolicy into workflow_schedules', async () => {+ const { pool: pgPool, query: pgQuery } = makePgPool()+ const reconciler = new WorkflowReconciler(makeDeps({ pgPool }))++ await reconciler.reconcile(+ 'test-wf',+ 'uid-123',+ 'sandbox-recipes',+ makeSpec({+ triggers: {+ schedule: { cron: '*/5 * * * *', timezone: 'UTC', concurrencyPolicy: 'Allow' },+ },+ }),+ undefined,+ undefined,+ undefined,+ undefined,+ '11111111-1111-4111-8111-111111111111'+ )++ const insertCall = pgQuery.mock.calls.find(([sql]) =>+ String(sql).includes('INSERT INTO workflow_schedules')+ )+ expect(insertCall).toBeDefined()+ expect(String(insertCall?.[0])).toContain('concurrency_policy')+ expect((insertCall?.[1] as unknown[] | undefined)?.[10]).toBe('Allow')+ })++ it('defaults concurrency_policy to Forbid when triggers.schedule omits it', async () => {+ const { pool: pgPool, query: pgQuery } = makePgPool()+ const reconciler = new WorkflowReconciler(makeDeps({ pgPool }))++ await reconciler.reconcile(+ 'test-wf',+ 'uid-123',+ 'sandbox-recipes',+ makeSpec({ triggers: { schedule: { cron: '*/5 * * * *', suspend: true } } }),+ undefined,+ undefined,+ undefined,+ undefined,+ '11111111-1111-4111-8111-111111111111'+ )++ const insertCall = pgQuery.mock.calls.find(([sql]) =>+ String(sql).includes('INSERT INTO workflow_schedules')+ )+ expect((insertCall?.[1] as unknown[] | undefined)?.[10]).toBe('Forbid')+ // suspend still maps to enabled = false alongside the policy.+ expect((insertCall?.[1] as unknown[] | undefined)?.[6]).toBe(false)+ })+it('calls tokenFactory to generate coordinator tokens (WRC→mcp-host tokens are now signed per-request, not on reconcile)', async () => {const reconciler = new WorkflowReconciler(deps)await reconciler.reconcile('test-wf', 'uid-123', 'sandbox-recipes', makeSpec())