The Open Framework for Building Agents
fix(eve): workflow - enable precondition guard (#995)
Andrew Barbaeaaf6d65e15c
diff --git a/.changeset/bright-workflows-guard.md b/.changeset/bright-workflows-guard.mdnew file mode 100644index 000000000..d60b828c2--- /dev/null+++ b/.changeset/bright-workflows-guard.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Enable Workflow's optimistic concurrency precondition guard in every generated Vercel workflow function so stale replays reload concurrent events before committing.diff --git a/docs/guides/deployment/vercel.mdx b/docs/guides/deployment/vercel.mdxindex 7a42f8244..38023de39 100644--- a/docs/guides/deployment/vercel.mdx+++ b/docs/guides/deployment/vercel.mdx@@ -60,7 +60,7 @@ eve deployVercel uses the generated output to configure these services:- **Web runtime**: serves health, session, stream, channel, callback, and schedule routes-- **Vercel Workflow**: persists and resumes durable runs+- **Vercel Workflow**: persists and resumes durable runs, with optimistic replay preconditions enabled so stale event-log snapshots reload before they can commit- **Vercel Cron**: invokes authored schedules- **Vercel Sandbox**: runs sandbox sessions selected by `defaultBackend()`diff --git a/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts b/packages/eve/src/internal/workflow-bundle/builder.scenario.test.tsindex 38abfeff2..3982fa7a7 100644--- a/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts+++ b/packages/eve/src/internal/workflow-bundle/builder.scenario.test.ts@@ -391,6 +391,7 @@ describe("WorkflowBundleBuilder", () => {{environment: {EVE_EXISTING_FLAG: "kept",+ WORKFLOW_PRECONDITION_GUARD: "0",},handler: "index.js",launcherType: "Nodejs",@@ -436,6 +437,7 @@ describe("WorkflowBundleBuilder", () => {expect(flowConfig.environment).toEqual({EVE_EXISTING_FLAG: "kept",NODE_OPTIONS: "--experimental-require-module",+ WORKFLOW_PRECONDITION_GUARD: "1",});const generatedFlowFunctionSource = await readFile(join(outputDir, "functions", ".well-known", "workflow", "v1", "flow.func", "index.js"),diff --git a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.ts b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.tsindex 59ca5d4d3..fbd92e9cf 100644--- a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.ts+++ b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.scenario.test.ts@@ -279,6 +279,7 @@ describe("emitBundledWorkflowFunctionDirectory", () => {expect(config.supportsResponseStreaming).toBe(true);expect(config.environment).toEqual({NODE_OPTIONS: "--experimental-require-module",+ WORKFLOW_PRECONDITION_GUARD: "1",});});diff --git a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.ts b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.tsindex 31f6e3f39..de2b9e9b6 100644--- a/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.ts+++ b/packages/eve/src/internal/workflow-bundle/vercel-workflow-output.ts@@ -40,6 +40,7 @@ export const WORKFLOW_STEP_EXTERNAL_PACKAGES = [export const WORKFLOW_BUILDER_DEFERRED_PACKAGES = ["@chat-adapter/slack", "chat"] as const;const WORKFLOW_FUNCTION_NODE_OPTIONS = "--experimental-require-module";+const WORKFLOW_PRECONDITION_GUARD_ENABLED = "1";/*** Builds the environment block every generated Vercel workflow function needs.@@ -51,6 +52,8 @@ export function createWorkflowFunctionEnvironment(environment?: unknown): RecordObject.assign(nextEnvironment, environment);}+ // Reject replay decisions made from an event log that missed a concurrent wake.+ nextEnvironment.WORKFLOW_PRECONDITION_GUARD = WORKFLOW_PRECONDITION_GUARD_ENABLED;nextEnvironment.NODE_OPTIONS = WORKFLOW_FUNCTION_NODE_OPTIONS;return nextEnvironment;}