Skip to content

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

TypeScript

test(workflow-recipes): cover SDK capability-removal publish + fix throttle comment (#375)

Alfredo Lopezbfc4ed1af27a
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index e00f27dd1..af8ad5a5d 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.289",
+ "version": "0.1.290",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.289",
+ "version": "0.1.290",
"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 71b9682c9..b577ff64f 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.289",
+ "version": "0.1.290",
"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 81fa3aab4..3f7e62f1e 100644
--- a/workflow-recipes/src/k8sClient.test.ts
+++ b/workflow-recipes/src/k8sClient.test.ts
@@ -598,6 +598,54 @@ describe('shouldPatchRecipeStatus', () => {
)
).toBe(true)
})
+
+ // Symmetric to #375 (computed-but-not-published): when a recipe DROPS
+ // spec.pluginWorkloadSdk while a capability is still persisted in status, the
+ // projection computes `capability === null` (clear the field). The
+ // `projected === null` branch is the ONLY thing that publishes that clear — a
+ // regression to `return false` there would leave a stale validated/
+ // awaiting_policy record proclaimed forever.
+ it('patches to clear status.pluginWorkloadSdk when the capability is removed from spec', () => {
+ expect(
+ shouldPatchRecipeStatus(
+ makeWorkflowRecipe({
+ spec: { steps: [] },
+ status: {
+ phase: 'active',
+ message: 'All workloads deployed',
+ pluginWorkloadSdk: {
+ state: 'validated',
+ promptBridge: true,
+ clientNotifications: false,
+ } as never,
+ },
+ }),
+ {
+ phase: 'active',
+ message: 'All workloads deployed',
+ workloadStatuses: [],
+ pluginWorkloadSdkProjection: { conditions: [], capability: null },
+ }
+ )
+ ).toBe(true)
+ })
+
+ it('does not patch when the capability is absent both in the projection and in status', () => {
+ expect(
+ shouldPatchRecipeStatus(
+ makeWorkflowRecipe({
+ spec: { steps: [] },
+ status: { phase: 'active', message: 'All workloads deployed' },
+ }),
+ {
+ phase: 'active',
+ message: 'All workloads deployed',
+ workloadStatuses: [],
+ pluginWorkloadSdkProjection: { conditions: [], capability: null },
+ }
+ )
+ ).toBe(false)
+ })
})
describe('infrastructure telemetry projections', () => {
diff --git a/workflow-recipes/src/k8sClient.ts b/workflow-recipes/src/k8sClient.ts
index ee22128ed..e7866edca 100644
--- a/workflow-recipes/src/k8sClient.ts
+++ b/workflow-recipes/src/k8sClient.ts
@@ -173,10 +173,14 @@ export function shouldPatchRecipeStatus(
* when the projection is otherwise identical, `verifiedAt` is refreshed on a
* throttle: patch only when the newly-computed `verifiedAt` is strictly NEWER
* than the persisted one AND the persisted one is older than
- * `VERIFIED_AT_REFRESH_MS` (see the inline INVARIANT). Loop-safety rests on that
- * strictly-newer guard alone: an equal-or-older projected timestamp can never
- * trigger a patch, and after any refresh the persisted value equals the
- * projected one, so the next pass is not strictly newer and returns false.
+ * `VERIFIED_AT_REFRESH_MS` (see the inline INVARIANT). The WINDOW clause is the
+ * primary loop-stopper: `verifiedAt` is recomputed fresh on essentially every
+ * proof parse (so the projected timestamp is normally NEWER, not equal), but
+ * right after a refresh `persisted ≈ now`, so `now - persisted` is under the
+ * threshold and no patch fires until the 5-min window reopens — bounding steady
+ * state to ≤1 patch / 5 min. The `projected > persisted` guard is NOT that
+ * bound; it only defends the edge where a future projection carries a STALE
+ * (equal-or-older) timestamp, which must never trigger a patch.
*
* A `undefined` projection (paths that do not run the SDK lane, e.g. the
* workload-status-only refresh) short-circuits to false — that pass has no SDK
@@ -214,11 +218,15 @@ function pluginWorkloadSdkProjectionChanged(
// signal stays current without a per-reconcile patch loop. INVARIANT: only
// refresh when the newly-computed verifiedAt is strictly NEWER than the
// persisted one AND the persisted one is older than VERIFIED_AT_REFRESH_MS.
- // Requiring projected > persisted is what makes this loop-proof even if a
- // future projection ever carried a STALE (equal or older) timestamp: such a
- // projection can never trigger a patch, so patch→reconcile→patch cannot
- // self-sustain. After any refresh the persisted value equals the projected
- // one, so the next pass is not strictly newer and returns false.
+ // The WINDOW clause (nowMs - persistedMs > VERIFIED_AT_REFRESH_MS) is the
+ // PRIMARY loop-stopper: verifiedAt is recomputed fresh on essentially every
+ // proof parse, so the projected timestamp is normally NEWER — the loop is not
+ // stopped by the two eventually becoming equal. It is stopped because right
+ // after a refresh persistedMs ≈ nowMs, so (nowMs - persistedMs) is under the
+ // threshold and no patch fires until the 5-min window reopens (≤1 patch/5min).
+ // The projectedMs > persistedMs guard is NOT that bound; it only defends the
+ // edge where a future projection carries a STALE (equal-or-older) timestamp,
+ // which must never trigger a patch.
if (!projected.verifiedAt) return false
if (!current.verifiedAt) return true
const projectedMs = Date.parse(projected.verifiedAt)