Skip to content

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

TypeScript

fix(workflow-recipes): reap the oauth token early only after a token ADDED

Alfredo Lopez5d23ee6076f5
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index 486a03e71..931536e58 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.414",
+ "version": "0.1.415",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.414",
+ "version": "0.1.415",
"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 b7207d280..bf5cae8c4 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.414",
+ "version": "0.1.415",
"description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface",
"main": "dist/main.js",
"engines": {
diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.ts
index e1d2a5549..cc0a16561 100644
--- a/workflow-recipes/src/reconciler/reconciler.test.ts
+++ b/workflow-recipes/src/reconciler/reconciler.test.ts
@@ -15728,6 +15728,118 @@ describe('WorkflowRecipeReconciler', () => {
expect(secretDeletes()).toBe(1)
})
})
+
+ function shortCircuitWorkflowRecipe(
+ spec: Partial<WorkflowRecipeCRD['spec']>,
+ status: WorkflowRecipeCRD['status'],
+ labels: Record<string, string>
+ ): WorkflowRecipeCRD {
+ return makeRecipe({
+ spec: {
+ agent: { provider: 'zai', model: 'glm-4.7' },
+ workloads: [],
+ steps: [{ id: 'run-qa', instruction: 'Validate the QA API workload.' }],
+ ...spec,
+ },
+ metadata: {
+ name: 'test-recipe',
+ namespace: 'sandbox-recipes',
+ uid: 'uid-123',
+ generation: 4,
+ labels,
+ },
+ status,
+ })
+ }
+
+ const RUN_LABEL = { 'clerum.io/workflow-run-id': 'run-123' }
+
+ describe.each([
+ {
+ label: 'awaiting-trigger',
+ recipe: () =>
+ shortCircuitWorkflowRecipe(
+ { triggers: { onDemand: { allowedActors: ['user'] } } },
+ { phase: 'active' },
+ {}
+ ),
+ expected: { phase: 'active', message: 'Workflow trigger infrastructure registered' },
+ },
+ {
+ label: 'active',
+ recipe: () =>
+ shortCircuitWorkflowRecipe(
+ {},
+ { phase: 'active', workflowExecution: { phase: 'running' } },
+ RUN_LABEL
+ ),
+ expected: { phase: 'active', message: 'Workflow running' },
+ },
+ {
+ label: 'in-progress',
+ recipe: () =>
+ shortCircuitWorkflowRecipe(
+ {},
+ { phase: 'deploying', workflowExecution: { phase: 'running' } },
+ RUN_LABEL
+ ),
+ expected: { phase: 'active', message: 'Workflow running' },
+ },
+ {
+ label: 'terminal',
+ recipe: () =>
+ shortCircuitWorkflowRecipe(
+ {},
+ { phase: 'active', workflowExecution: { phase: 'completed' } },
+ RUN_LABEL
+ ),
+ expected: { phase: 'active', message: 'Workflow completed' },
+ },
+ {
+ label: 'dryRun',
+ recipe: () => shortCircuitWorkflowRecipe({ dryRun: true }, { phase: 'approved' }, {}),
+ expected: {
+ phase: 'candidate',
+ message: 'Dry-run: preview generated, no resources created',
+ },
+ },
+ ])('R2-L2: the $label workflow short-circuit on a fresh process', ({ recipe, expected }) => {
+ it('sends no token DELETE until a token ADDED arrives, then exactly one', async () => {
+ const workflowReconcile = vi.fn()
+ ;(
+ reconciler as unknown as {
+ workflowReconciler: {
+ reconcile: typeof workflowReconcile
+ validateWorkflowSpec: () => undefined
+ ensureMcpHostRuntimeCredentials?: () => Promise<void>
+ }
+ }
+ ).workflowReconciler = {
+ reconcile: workflowReconcile,
+ validateWorkflowSpec: () => undefined,
+ ensureMcpHostRuntimeCredentials: vi.fn().mockResolvedValue(undefined),
+ }
+ const current = recipe()
+
+ // A restarted process: no token ADDED has been observed for the recipe.
+ for (let pass = 0; pass < 3; pass++) {
+ const result = await reconciler.reconcile(current)
+ // Witness that each pass took the short-circuit under test.
+ expect(result).toMatchObject(expected)
+ }
+ expect(workflowReconcile).not.toHaveBeenCalled()
+ expect(secretDeletes()).toBe(0)
+
+ // The watch relist replays ADDED for a token that really exists.
+ reconciler.invalidateOAuthBrokerSecretLedger('test-recipe')
+ await reconciler.reconcile(current)
+ expect(secretDeletes()).toBe(1)
+
+ // The ledger bounds it: the next pass of the same generation skips.
+ await reconciler.reconcile(current)
+ expect(secretDeletes()).toBe(1)
+ })
+ })
})
describe('G2 skipStatusPatch must not leave GFS deleted', () => {
diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
index f484840f6..399df8df8 100644
--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts
@@ -1971,8 +1971,14 @@ export class WorkflowRecipeReconciler {
// ensureOAuthBrokerTokenSecret, so the token-ADDED re-reconcile would
// never reach the reap. Only the delete branch runs here (issuance stays
// on the first-deploy path and the rotation loop), and the delete ledger
- // bounds it to one DELETE per generation or ADDED.
- if (!rb.recipeHasBackgroundAccessClient(recipe)) {
+ // bounds it to one DELETE per generation or ADDED. It runs only once a
+ // token ADDED was observed for the recipe: a fresh process would otherwise
+ // send one DELETE per recipe, and the Secret watch's initial list replays
+ // ADDED for every token that exists.
+ if (
+ !rb.recipeHasBackgroundAccessClient(recipe) &&
+ this.oauthBrokerDeleteLedger.secretEpoch(recipe.metadata.name) !== 0
+ ) {
await this.ensureOAuthBrokerTokenSecret(recipe)
}