The Open Framework for Building Agents
fix(eve): workflows - preserve concurrent subagent fan-out (#301)
Andrew Barbaa3d84413a22d
diff --git a/.changeset/brave-workflows-fan-out.md b/.changeset/brave-workflows-fan-out.mdnew file mode 100644index 000000000..cb2ec7ef4--- /dev/null+++ b/.changeset/brave-workflows-fan-out.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Fix dynamic `Workflow` fan-out so concurrent subagent calls dispatch together, replay in deterministic program order, and resume reliably across runtime isolates. Generated pnpm workspaces now exempt the bundled code-mode package from release-age gating so fresh eve releases install immediately.diff --git a/e2e/fixtures/agent-subagents/evals/dynamic-workflow.eval.ts b/e2e/fixtures/agent-subagents/evals/dynamic-workflow.eval.tsindex 4842ab877..c7a644e70 100644--- a/e2e/fixtures/agent-subagents/evals/dynamic-workflow.eval.ts+++ b/e2e/fixtures/agent-subagents/evals/dynamic-workflow.eval.ts@@ -28,13 +28,19 @@ export default defineEval({t.didNotFail();t.completed();t.calledTool("Workflow", { input: isFanOutProgram, times: 1 });- t.event(- (events) =>- events.filter(- (event) => event.type === "subagent.called" && event.data.name === "echo-marker",- ).length === 2,- "Workflow dispatched exactly two echo-marker children",- );+ t.event((events) => {+ const calledIndexes = events.flatMap((event, index) =>+ event.type === "subagent.called" && event.data.name === "echo-marker" ? [index] : [],+ );+ const firstCompletedIndex = events.findIndex(+ (event) => event.type === "subagent.completed" && event.data.subagentName === "echo-marker",+ );+ return (+ calledIndexes.length === 2 &&+ firstCompletedIndex >= 0 &&+ calledIndexes.every((index) => index < firstCompletedIndex)+ );+ }, "Workflow dispatched exactly two echo-marker children before either completed");t.calledSubagent("echo-marker", { output: /SUBAGENT_TOKEN=echo-marker-9F2X/ });t.messageIncludes(DOUBLE_SUBAGENT_TOKEN);t.noFailedActions();diff --git a/packages/eve/package.json b/packages/eve/package.jsonindex 1c521997d..5b2d21ef1 100644--- a/packages/eve/package.json+++ b/packages/eve/package.json@@ -320,7 +320,7 @@"commander": "14.0.3","emulate": "0.6.0","eventsource-parser": "3.0.8",- "experimental-ai-sdk-code-mode": "1.0.14",+ "experimental-ai-sdk-code-mode": "1.0.16","gray-matter": "4.0.3","jose": "6.2.3","jsonc-parser": "3.3.1",diff --git a/packages/eve/src/cli/commands/init.integration.test.ts b/packages/eve/src/cli/commands/init.integration.test.tsindex 7ab40afb1..c31105d49 100644--- a/packages/eve/src/cli/commands/init.integration.test.ts+++ b/packages/eve/src/cli/commands/init.integration.test.ts@@ -38,7 +38,7 @@ const BASE_VERSIONS = {} as const;const RELEASE_AGE_POLICY =- 'minimumReleaseAgeExclude:\n - "@ai-sdk/*"\n - "@rolldown/*"\n - "@vercel/*"\n - "@workflow/*"\n - ai\n - eve\n - nitro\n - rolldown\n - workflow\n';+ 'minimumReleaseAgeExclude:\n - "@ai-sdk/*"\n - "@rolldown/*"\n - "@vercel/*"\n - "@workflow/*"\n - ai\n - experimental-ai-sdk-code-mode\n - eve\n - nitro\n - rolldown\n - workflow\n';const WEB_VERSIONS = {...BASE_VERSIONS,diff --git a/packages/eve/src/execution/dispatch-workflow-runtime-actions-step.ts b/packages/eve/src/execution/dispatch-workflow-runtime-actions-step.tsindex cbd382e7a..829b90a6b 100644--- a/packages/eve/src/execution/dispatch-workflow-runtime-actions-step.ts+++ b/packages/eve/src/execution/dispatch-workflow-runtime-actions-step.ts@@ -8,7 +8,7 @@ import {import { hydrateDurableSession } from "#execution/session.js";import { getPendingWorkflowInterrupt } from "#harness/workflow-interrupt-state.js";import { setPendingRuntimeActionBatch } from "#harness/runtime-actions.js";-import { buildRuntimeActionFromWorkflowInterrupt } from "#harness/workflow-runtime-action-state.js";+import { buildRuntimeActionsFromWorkflowInterrupt } from "#harness/workflow-runtime-action-state.js";import { BundleKey } from "#runtime/sessions/runtime-context-keys.js";import type { RuntimeSubagentResultActionResult } from "#runtime/actions/types.js";@@ -28,7 +28,9 @@ export async function dispatchWorkflowRuntimeActionsStep(input: {const pending = getPendingWorkflowInterrupt(durableSession.state);if (pending === undefined) return { results: [], sessionState: input.sessionState };- const action = buildRuntimeActionFromWorkflowInterrupt(pending.interrupt);+ const actions = buildRuntimeActionsFromWorkflowInterrupt(pending.interrupt);+ if (actions.length === 0) return { results: [], sessionState: input.sessionState };+const ctx = await deserializeContext(input.serializedContext);const bundle = ctx.require(BundleKey);const session = hydrateDurableSession({@@ -40,7 +42,7 @@ export async function dispatchWorkflowRuntimeActionsStep(input: {});const sessionWithBatch = setPendingRuntimeActionBatch({- actions: [action],+ actions,event: { sequence: 0, stepIndex: 0, turnId: "workflow-dispatch" },responseMessages: [],session,diff --git a/packages/eve/src/execution/workflow-steps.ts b/packages/eve/src/execution/workflow-steps.tsindex a6b96d71c..55d45687f 100644--- a/packages/eve/src/execution/workflow-steps.ts+++ b/packages/eve/src/execution/workflow-steps.ts@@ -19,7 +19,7 @@ import { hasPendingInputBatch } from "#harness/input-requests.js";import { coalesceTurnInputs } from "#harness/messages.js";import { upsertProxyInputRequests } from "#harness/proxy-input-requests.js";import {- getRuntimeActionKeyFromWorkflowInterrupt,+ getRuntimeActionKeysFromWorkflowInterrupt,isWorkflowRuntimeActionInterrupt,} from "#harness/workflow-runtime-action-state.js";import { getPendingWorkflowInterrupt } from "#harness/workflow-interrupt-state.js";@@ -363,9 +363,9 @@ export async function turnStep(rawInput: TurnStepInput): Promise<DurableStepResu) {return {action: "dispatch-workflow-runtime-actions",- pendingRuntimeActionKeys: [- getRuntimeActionKeyFromWorkflowInterrupt(workflowInterrupt.interrupt),- ],+ pendingRuntimeActionKeys: getRuntimeActionKeysFromWorkflowInterrupt(+ workflowInterrupt.interrupt,+ ),serializedContext: nextSerializedContext,sessionState: nextState,};diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.tsindex 1c0b8798d..a7db4a9bb 100644--- a/packages/eve/src/harness/tool-loop.ts+++ b/packages/eve/src/harness/tool-loop.ts@@ -41,13 +41,20 @@ import {} from "#protocol/message.js";import type { InstrumentationDefinition } from "#public/instrumentation/index.js";import { ASK_QUESTION_TOOL_NAME } from "#runtime/framework-tools/ask-question.js";-import { isWorkflowRuntimeActionInterrupt } from "#harness/workflow-runtime-action-state.js";+import {+ getWorkflowRuntimeActionInterrupts,+ isWorkflowRuntimeActionInterrupt,+} from "#harness/workflow-runtime-action-state.js";import type { InputRequest } from "#runtime/input/types.js";import {hydrateSandboxAttachments,stageAttachmentsToSandbox,} from "#harness/attachment-staging.js";import { applyWorkflowTool, buildWorkflowHostTools } from "#harness/workflow-sandbox.js";+import {+ ensureWorkflowContinuationSecurity,+ getWorkflowContinuationSecurity,+} from "#harness/workflow-continuation-security.js";import { createWorkflowLifecycle } from "#harness/workflow-lifecycle.js";import {clearPendingWorkflowInterrupt,@@ -458,6 +465,9 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {}session = pending.session;+ if (config.workflow === true) {+ session = ensureWorkflowContinuationSecurity(session);+ }let messages: ModelMessage[] = pending.messages;if (stepInput.input?.context !== undefined) {@@ -642,6 +652,7 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {config.workflow === true? (await applyWorkflowTool({+ continuationSecurity: getWorkflowContinuationSecurity(session),harnessTools: config.tools,lifecycle:emit !== undefined@@ -1390,7 +1401,8 @@ async function handleStepResult(input: {};if (config.workflow === true) {- const workflowInterrupt = await getWorkflowSandboxInterrupt(result);+ const continuationSecurity = getWorkflowContinuationSecurity(baseSession);+ const workflowInterrupt = await getWorkflowSandboxInterrupt(result, continuationSecurity);if (workflowInterrupt !== undefined) {if (!isWorkflowRuntimeActionInterrupt(workflowInterrupt)) {throw new Error(`Unsupported Workflow interrupt kind "${workflowInterrupt.payload.kind}".`);@@ -1762,6 +1774,7 @@ async function continuePendingWorkflowInterrupt(input: {skipReplayed: true,tools: input.config.tools,});+ const continuationSecurity = getWorkflowContinuationSecurity(input.session);let continuationOutput: unknown;try {@@ -1777,17 +1790,25 @@ async function continuePendingWorkflowInterrupt(input: {// eslint-disable-next-line no-constant-conditionwhile (true) {continuationOutput = await continueWorkflowSandboxInterrupt({+ continuationSecurity,interrupt: currentInterrupt,lifecycle,resolution: childResults[resultIndex]?.output,tools: hostTools,});- const loopUnwrapped = await unwrapWorkflowSandboxResult(continuationOutput);+ const loopUnwrapped = await unwrapWorkflowSandboxResult(+ continuationOutput,+ continuationSecurity,+ );if (loopUnwrapped.status !== "interrupted") break;if (!isWorkflowRuntimeActionInterrupt(loopUnwrapped.interrupt)) break;if (resultIndex + 1 >= childResults.length) break;+ const nextInterrupt = getWorkflowRuntimeActionInterrupts(loopUnwrapped.interrupt)[0];+ if (nextInterrupt === undefined) {+ throw new Error("Workflow continuation contains no pending runtime-action interrupt.");+ }resultIndex++;- currentInterrupt = loopUnwrapped.interrupt;+ currentInterrupt = nextInterrupt;}} catch (error) {logError(log, "Workflow interrupt continuation failed", error);@@ -1798,7 +1819,7 @@ async function continuePendingWorkflowInterrupt(input: {};}- const unwrapped = await unwrapWorkflowSandboxResult(continuationOutput);+ const unwrapped = await unwrapWorkflowSandboxResult(continuationOutput, continuationSecurity);const finalOutput = unwrapped.status === "interrupted" ? unwrapped.interrupt : unwrapped.output;const baseMessages = [...input.session.history, ...pending.responseMessages];const replacedMessages = replaceWorkflowToolResult(@@ -1861,13 +1882,18 @@ function parkOnWorkflowInterrupt(input: {readonly promptMessages: readonly ModelMessage[];readonly responseMessages: readonly ModelMessage[];}): StepResult {+ const interrupt = getWorkflowRuntimeActionInterrupts(input.interrupt)[0];+ if (interrupt === undefined) {+ throw new Error("Workflow continuation contains no pending runtime-action interrupt.");+ }+const baseSession: HarnessSession = {...input.baseSession,history: [...input.promptMessages],};const parkedSession = setPendingWorkflowInterrupt({- interrupt: input.interrupt,+ interrupt,responseMessages: input.responseMessages,session: baseSession,});diff --git a/packages/eve/src/harness/workflow-continuation-security.test.ts b/packages/eve/src/harness/workflow-continuation-security.test.tsnew file mode 100644index 000000000..618dfaa6d--- /dev/null+++ b/packages/eve/src/harness/workflow-continuation-security.test.ts@@ -0,0 +1,51 @@+import { describe, expect, it } from "vitest";++import type { HarnessSession } from "#harness/types.js";+import {+ ensureWorkflowContinuationSecurity,+ getWorkflowContinuationSecurity,+} from "#harness/workflow-continuation-security.js";++function makeSession(state?: HarnessSession["state"]): HarnessSession {+ return {+ agent: {+ modelReference: { id: "test-model" },+ system: "",+ tools: [],+ },+ compaction: { recentWindowSize: 4, threshold: 1_000_000 },+ continuationToken: "test-token",+ history: [],+ sessionId: "test-session",+ state,+ };+}++describe("workflow continuation security", () => {+ it("persists one stable signing key on session state", () => {+ const initial = makeSession({ authored: "preserved" });++ const secured = ensureWorkflowContinuationSecurity(initial);+ const security = getWorkflowContinuationSecurity(secured);++ expect(secured).not.toBe(initial);+ expect(secured.state?.authored).toBe("preserved");+ expect(security.signingKey).toMatch(/^[A-Za-z0-9_-]{43}$/);+ expect(security.maxAgeMs).toBe(365 * 24 * 60 * 60 * 1000);+ expect(ensureWorkflowContinuationSecurity(secured)).toBe(secured);+ expect(getWorkflowContinuationSecurity(secured)).toEqual(security);+ });++ it("rejects malformed persisted security state", () => {+ const session = makeSession({+ "eve.harness.workflowContinuationSecurity": {+ signingKey: "not-a-256-bit-key",+ version: 1,+ },+ });++ expect(() => ensureWorkflowContinuationSecurity(session)).toThrow(+ "Workflow continuation security state is missing or invalid.",+ );+ });+});diff --git a/packages/eve/src/harness/workflow-continuation-security.ts b/packages/eve/src/harness/workflow-continuation-security.tsnew file mode 100644index 000000000..75e8fd378--- /dev/null+++ b/packages/eve/src/harness/workflow-continuation-security.ts@@ -0,0 +1,51 @@+import { randomBytes } from "node:crypto";++import type { HarnessSession } from "#harness/types.js";+import type { WorkflowSandboxContinuationSecurity } from "#shared/workflow-sandbox.js";++const WORKFLOW_CONTINUATION_SECURITY_KEY = "eve.harness.workflowContinuationSecurity";+const WORKFLOW_CONTINUATION_MAX_AGE_MS = 365 * 24 * 60 * 60 * 1000;++interface StoredWorkflowContinuationSecurity {+ readonly signingKey: string;+ readonly version: 1;+}++export function ensureWorkflowContinuationSecurity(session: HarnessSession): HarnessSession {+ if (session.state?.[WORKFLOW_CONTINUATION_SECURITY_KEY] !== undefined) {+ getWorkflowContinuationSecurity(session);+ return session;+ }++ return {+ ...session,+ state: {+ ...session.state,+ [WORKFLOW_CONTINUATION_SECURITY_KEY]: {+ signingKey: randomBytes(32).toString("base64url"),+ version: 1,+ } satisfies StoredWorkflowContinuationSecurity,+ },+ };+}++export function getWorkflowContinuationSecurity(+ session: HarnessSession,+): WorkflowSandboxContinuationSecurity {+ const stored = session.state?.[WORKFLOW_CONTINUATION_SECURITY_KEY];+ if (+ typeof stored !== "object" ||+ stored === null ||+ (stored as { version?: unknown }).version !== 1 ||+ typeof (stored as { signingKey?: unknown }).signingKey !== "string" ||+ !/^[A-Za-z0-9_-]{43}$/.test((stored as { signingKey: string }).signingKey)+ ) {+ throw new Error("Workflow continuation security state is missing or invalid.");+ }++ return {+ signingKey: (stored as StoredWorkflowContinuationSecurity).signingKey,+ // A parked workflow can legitimately wait far beyond code mode's one-hour default.+ maxAgeMs: WORKFLOW_CONTINUATION_MAX_AGE_MS,+ };+}diff --git a/packages/eve/src/harness/workflow-runtime-action-state.test.ts b/packages/eve/src/harness/workflow-runtime-action-state.test.tsnew file mode 100644index 000000000..e57b025c6--- /dev/null+++ b/packages/eve/src/harness/workflow-runtime-action-state.test.ts@@ -0,0 +1,96 @@+import { describe, expect, it } from "vitest";++import {+ buildRuntimeActionsFromWorkflowInterrupt,+ getRuntimeActionKeysFromWorkflowInterrupt,+ getWorkflowRuntimeActionInterrupts,+ WORKFLOW_RUNTIME_ACTION_INTERRUPT_KIND,+} from "#harness/workflow-runtime-action-state.js";+import type { WorkflowSandboxInterrupt } from "#shared/workflow-sandbox.js";++function concurrentWorkflowInterrupt(): WorkflowSandboxInterrupt {+ const continuation = {+ auth: {+ alg: "HMAC-SHA256" as const,+ expiresAtMs: 2,+ issuedAtMs: 1,+ nonce: "nonce",+ signature: "signature",+ },+ determinism: {+ dateNowMs: 1,+ randomSeed: "00000000000000000000000000000000",+ },+ js: "return Promise.all([])",+ ledger: ["alpha", "beta"].map((message, index) => {+ const toolCallId = `workflow-call:tool-${index + 1}`;+ return {+ inputJson: JSON.stringify({ message }),+ interruptId: `${toolCallId}:interrupt`,+ interruptPayload: {+ kind: WORKFLOW_RUNTIME_ACTION_INTERRUPT_KIND,+ runtimeAction: {+ kind: "subagent-call" as const,+ nodeId: "subagents/echo-marker",+ subagentName: "echo-marker",+ },+ toolInput: { message },+ toolName: "echo-marker",+ },+ kind: "tool" as const,+ name: "echo-marker",+ status: "interrupted" as const,+ toolCallId,+ };+ }),+ outerToolCallId: "workflow-call",+ version: 1 as const,+ };+ const returned = continuation.ledger[1]!;++ return {+ continuation,+ input: { message: "beta" },+ interruptId: returned.interruptId,+ outerToolCallId: continuation.outerToolCallId,+ payload: returned.interruptPayload,+ toolCallId: returned.toolCallId,+ toolName: returned.name,+ type: "code-mode-interrupt",+ };+}++describe("workflow runtime action state", () => {+ it("derives concurrent actions in ledger order when a later interrupt wins the race", () => {+ const interrupt = concurrentWorkflowInterrupt();++ const pending = getWorkflowRuntimeActionInterrupts(interrupt);+ expect(pending.map((entry) => entry.input)).toEqual([+ { message: "alpha" },+ { message: "beta" },+ ]);+ expect(pending.map((entry) => entry.toolCallId)).toEqual([+ "workflow-call:tool-1",+ "workflow-call:tool-2",+ ]);++ expect(buildRuntimeActionsFromWorkflowInterrupt(interrupt)).toMatchObject([+ {+ callId: "echo-marker_workflow-call_tool-1_interrupt",+ input: { message: "alpha" },+ kind: "subagent-call",+ subagentName: "echo-marker",+ },+ {+ callId: "echo-marker_workflow-call_tool-2_interrupt",+ input: { message: "beta" },+ kind: "subagent-call",+ subagentName: "echo-marker",+ },+ ]);+ expect(getRuntimeActionKeysFromWorkflowInterrupt(interrupt)).toEqual([+ "subagent-call:echo-marker:echo-marker_workflow-call_tool-1_interrupt",+ "subagent-call:echo-marker:echo-marker_workflow-call_tool-2_interrupt",+ ]);+ });+});diff --git a/packages/eve/src/harness/workflow-runtime-action-state.ts b/packages/eve/src/harness/workflow-runtime-action-state.tsindex cbeb8fa7a..46d20864a 100644--- a/packages/eve/src/harness/workflow-runtime-action-state.ts+++ b/packages/eve/src/harness/workflow-runtime-action-state.ts@@ -47,10 +47,46 @@ export function buildRuntimeActionFromWorkflowInterrupt(};}-export function getRuntimeActionKeyFromWorkflowInterrupt(+/** Returns every pending runtime-action interrupt in deterministic ledger order. */+export function getWorkflowRuntimeActionInterrupts(interrupt: WorkflowSandboxInterrupt,-): string {- return getRuntimeActionRequestKey(buildRuntimeActionFromWorkflowInterrupt(interrupt));+): WorkflowSandboxInterrupt[] {+ return interrupt.continuation.ledger.flatMap((entry) => {+ if (+ entry.kind !== "tool" ||+ entry.status !== "interrupted" ||+ entry.interruptPayload.kind !== WORKFLOW_RUNTIME_ACTION_INTERRUPT_KIND+ ) {+ return [];+ }++ return [+ {+ continuation: interrupt.continuation,+ input: entry.inputJson === "" ? undefined : JSON.parse(entry.inputJson),+ interruptId: entry.interruptId,+ outerToolCallId: interrupt.continuation.outerToolCallId,+ payload: entry.interruptPayload,+ toolCallId: entry.toolCallId,+ toolName: entry.name,+ type: "code-mode-interrupt" as const,+ },+ ];+ });+}++export function buildRuntimeActionsFromWorkflowInterrupt(+ interrupt: WorkflowSandboxInterrupt,+): RuntimeActionRequest[] {+ return getWorkflowRuntimeActionInterrupts(interrupt).map((pending) =>+ buildRuntimeActionFromWorkflowInterrupt(pending),+ );+}++export function getRuntimeActionKeysFromWorkflowInterrupt(+ interrupt: WorkflowSandboxInterrupt,+): string[] {+ return buildRuntimeActionsFromWorkflowInterrupt(interrupt).map(getRuntimeActionRequestKey);}function sanitizeCallId(id: string): string {diff --git a/packages/eve/src/harness/workflow-sandbox.scenario.test.ts b/packages/eve/src/harness/workflow-sandbox.scenario.test.tsnew file mode 100644index 000000000..5f87e8daa--- /dev/null+++ b/packages/eve/src/harness/workflow-sandbox.scenario.test.ts@@ -0,0 +1,138 @@+import { jsonSchema } from "ai";+import { describe, expect, it } from "vitest";++import type { HarnessToolDefinition } from "#harness/execute-tool.js";+import { getWorkflowRuntimeActionInterrupts } from "#harness/workflow-runtime-action-state.js";+import { applyWorkflowTool } from "#harness/workflow-sandbox.js";+import { buildToolSet } from "#harness/tools.js";+import type { HarnessToolMap } from "#harness/types.js";+import {+ continueWorkflowSandboxInterrupt,+ getWorkflowSandboxInterrupt,+ type WorkflowSandboxLifecycle,+ unwrapWorkflowSandboxResult,+} from "#shared/workflow-sandbox.js";++function orchestrationTools(): HarnessToolMap {+ return new Map<string, HarnessToolDefinition>([+ [+ "echo-marker",+ {+ description: "Echo one marker.",+ inputSchema: jsonSchema({+ properties: { message: { type: "string" } },+ required: ["message"],+ type: "object",+ }),+ name: "echo-marker",+ runtimeAction: {+ kind: "subagent-call",+ nodeId: "subagents/echo-marker",+ subagentName: "echo-marker",+ },+ },+ ],+ ]);+}++const concurrentProgram = `return await Promise.all([+ tools["echo-marker"]({ message: "alpha" }),+ tools["echo-marker"]({ message: "beta" }),+]);`;+const continuationSecurity = {+ maxAgeMs: 365 * 24 * 60 * 60 * 1000,+ signingKey: "workflow-sandbox-scenario-test-key",+};++describe("Workflow concurrent continuation", () => {+ it("collects promptly interrupted Promise.all siblings in one ledger", async () => {+ const tools = orchestrationTools();+ const { modelTools } = await applyWorkflowTool({+ continuationSecurity,+ harnessTools: tools,+ tools: buildToolSet({ tools }),+ });+ const execute = modelTools.Workflow?.execute as+ | ((input: { js: string }, options: { messages: []; toolCallId: string }) => Promise<unknown>)+ | undefined;++ const initialOutput = await execute!(+ { js: concurrentProgram },+ { messages: [], toolCallId: "workflow-call" },+ );+ const interrupt = await getWorkflowSandboxInterrupt(initialOutput, continuationSecurity);++ expect(interrupt!.continuation.auth.expiresAtMs - interrupt!.continuation.auth.issuedAtMs).toBe(+ continuationSecurity.maxAgeMs,+ );+ expect(getWorkflowRuntimeActionInterrupts(interrupt!).map((entry) => entry.input)).toEqual([+ { message: "alpha" },+ { message: "beta" },+ ]);+ });++ it("preserves and resolves sibling interrupts when a later call interrupts first", async () => {+ const tools = orchestrationTools();+ const lifecycle: WorkflowSandboxLifecycle = {+ async onNestedToolCall(event) {+ if ((event.input as { message?: string }).message === "alpha") {+ await new Promise((resolve) => setTimeout(resolve, 25));+ }+ },+ };+ const { hostTools, modelTools } = await applyWorkflowTool({+ continuationSecurity,+ harnessTools: tools,+ lifecycle,+ tools: buildToolSet({ tools }),+ });+ const execute = modelTools.Workflow?.execute as+ | ((input: { js: string }, options: { messages: []; toolCallId: string }) => Promise<unknown>)+ | undefined;+ expect(execute).toBeDefined();++ const initialOutput = await execute!(+ { js: concurrentProgram },+ { messages: [], toolCallId: "workflow-call" },+ );+ const racedInterrupt = await getWorkflowSandboxInterrupt(initialOutput, continuationSecurity);+ expect(racedInterrupt?.input).toEqual({ message: "beta" });++ const pending = getWorkflowRuntimeActionInterrupts(racedInterrupt!);+ expect(pending.map((interrupt) => interrupt.input)).toEqual([+ { message: "alpha" },+ { message: "beta" },+ ]);++ const firstContinuation = await continueWorkflowSandboxInterrupt({+ continuationSecurity,+ interrupt: pending[0]!,+ lifecycle,+ resolution: "alpha-result",+ tools: hostTools,+ });+ const firstUnwrapped = await unwrapWorkflowSandboxResult(+ firstContinuation,+ continuationSecurity,+ );+ expect(firstUnwrapped).toMatchObject({+ interrupt: { input: { message: "beta" } },+ status: "interrupted",+ });+ if (firstUnwrapped.status !== "interrupted") throw new Error("Expected second interrupt.");++ const finalContinuation = await continueWorkflowSandboxInterrupt({+ continuationSecurity,+ interrupt: firstUnwrapped.interrupt,+ lifecycle,+ resolution: "beta-result",+ tools: hostTools,+ });+ await expect(+ unwrapWorkflowSandboxResult(finalContinuation, continuationSecurity),+ ).resolves.toEqual({+ output: ["alpha-result", "beta-result"],+ status: "completed",+ });+ });+});diff --git a/packages/eve/src/harness/workflow-sandbox.test.ts b/packages/eve/src/harness/workflow-sandbox.test.tsindex c005e8c94..0a1a772e5 100644--- a/packages/eve/src/harness/workflow-sandbox.test.ts+++ b/packages/eve/src/harness/workflow-sandbox.test.ts@@ -6,6 +6,8 @@ import { applyWorkflowTool, buildWorkflowHostTools } from "#harness/workflow-sanimport { buildToolSet } from "#harness/tools.js";import type { HarnessToolMap } from "#harness/types.js";+const continuationSecurity = { signingKey: "workflow-sandbox-test-key" };+function orchestrationTools(): HarnessToolMap {return new Map<string, HarnessToolDefinition>([[@@ -51,7 +53,11 @@ describe("applyWorkflowTool", () => {it("adds only agent runtime actions to the sandbox", async () => {const harnessTools = orchestrationTools();const flatTools = buildToolSet({ tools: harnessTools });- const { hostTools, modelTools } = await applyWorkflowTool({ harnessTools, tools: flatTools });+ const { hostTools, modelTools } = await applyWorkflowTool({+ continuationSecurity,+ harnessTools,+ tools: flatTools,+ });expect(modelTools.Workflow).toBeDefined();expect(modelTools.researcher).toBeDefined();@@ -65,6 +71,7 @@ describe("applyWorkflowTool", () => {it("describes Workflow as an agents-only orchestrator", async () => {const harnessTools = orchestrationTools();const { modelTools } = await applyWorkflowTool({+ continuationSecurity,harnessTools,tools: buildToolSet({ tools: harnessTools }),});@@ -99,7 +106,11 @@ describe("applyWorkflowTool", () => {],]);const flatTools = buildToolSet({ tools: harnessTools });- const { hostTools, modelTools } = await applyWorkflowTool({ harnessTools, tools: flatTools });+ const { hostTools, modelTools } = await applyWorkflowTool({+ continuationSecurity,+ harnessTools,+ tools: flatTools,+ });expect(modelTools.Workflow).toBeUndefined();expect(modelTools.bash).toBeDefined();diff --git a/packages/eve/src/harness/workflow-sandbox.ts b/packages/eve/src/harness/workflow-sandbox.tsindex c71043591..f53efae4f 100644--- a/packages/eve/src/harness/workflow-sandbox.ts+++ b/packages/eve/src/harness/workflow-sandbox.ts@@ -8,6 +8,7 @@ import {createWorkflowSandboxTool,readWorkflowSandboxResolution,requestWorkflowSandboxInterrupt,+ type WorkflowSandboxContinuationSecurity,type WorkflowSandboxLifecycle,WORKFLOW_TOOL_NAME,} from "#shared/workflow-sandbox.js";@@ -22,6 +23,7 @@ interface WorkflowToolSet {* untouched. Only subagent and remote-agent runtime actions enter the sandbox.*/export async function applyWorkflowTool(input: {+ readonly continuationSecurity: WorkflowSandboxContinuationSecurity;readonly harnessTools: HarnessToolMap;readonly lifecycle?: WorkflowSandboxLifecycle;readonly tools: ToolSet;@@ -33,6 +35,7 @@ export async function applyWorkflowTool(input: {}const workflowTool = await createWorkflowSandboxTool({+ continuationSecurity: input.continuationSecurity,hostTools,lifecycle: input.lifecycle,});diff --git a/packages/eve/src/setup/primitives/pm/pnpm.ts b/packages/eve/src/setup/primitives/pm/pnpm.tsindex 6ba5b9ac1..d5bc7ad3b 100644--- a/packages/eve/src/setup/primitives/pm/pnpm.ts+++ b/packages/eve/src/setup/primitives/pm/pnpm.ts@@ -18,6 +18,7 @@ const RELEASE_AGE_EXCLUSIONS = ["@vercel/*","@workflow/*","ai",+ "experimental-ai-sdk-code-mode","eve","nitro","rolldown",diff --git a/packages/eve/src/setup/scaffold/index.integration.test.ts b/packages/eve/src/setup/scaffold/index.integration.test.tsindex 0b2ee16e3..e0d6255fd 100644--- a/packages/eve/src/setup/scaffold/index.integration.test.ts+++ b/packages/eve/src/setup/scaffold/index.integration.test.ts@@ -24,7 +24,7 @@ async function createTempDir(): Promise<string> {const TEST_EVE_PACKAGE = { version: "0.25.0", nodeEngine: ">=24" } as const;const LATEST_EVE_PACKAGE = { version: "latest", nodeEngine: ">=24" } as const;const RELEASE_AGE_POLICY =- 'minimumReleaseAgeExclude:\n - "@ai-sdk/*"\n - "@rolldown/*"\n - "@vercel/*"\n - "@workflow/*"\n - ai\n - eve\n - nitro\n - rolldown\n - workflow\n';+ 'minimumReleaseAgeExclude:\n - "@ai-sdk/*"\n - "@rolldown/*"\n - "@vercel/*"\n - "@workflow/*"\n - ai\n - experimental-ai-sdk-code-mode\n - eve\n - nitro\n - rolldown\n - workflow\n';const TEST_WEB_PACKAGE_VERSIONS = {evePackage: TEST_EVE_PACKAGE,@@ -483,7 +483,7 @@ describe("ensureChannel", () => {});await expect(readFile(pnpmWorkspacePath, "utf8")).resolves.toBe(- 'minimumReleaseAgeExclude:\n - react\n - "@ai-sdk/*"\n - "@rolldown/*"\n - "@vercel/*"\n - "@workflow/*"\n - ai\n - eve\n - nitro\n - rolldown\n - workflow\nallowBuilds:\n sharp: false\n',+ 'minimumReleaseAgeExclude:\n - react\n - "@ai-sdk/*"\n - "@rolldown/*"\n - "@vercel/*"\n - "@workflow/*"\n - ai\n - experimental-ai-sdk-code-mode\n - eve\n - nitro\n - rolldown\n - workflow\nallowBuilds:\n sharp: false\n',);expect(result.filesWritten).toContain(pnpmWorkspacePath);});diff --git a/packages/eve/src/shared/workflow-sandbox.ts b/packages/eve/src/shared/workflow-sandbox.tsindex 29cea8e79..1c9536270 100644--- a/packages/eve/src/shared/workflow-sandbox.ts+++ b/packages/eve/src/shared/workflow-sandbox.ts@@ -26,6 +26,8 @@ type WorkflowSandboxGlobal = typeof globalThis & {export type WorkflowSandboxInterrupt = CodeModeModule.CodeModeInterrupt;export type WorkflowSandboxLifecycle = NonNullable<CodeModeModule.CodeModeOptions["lifecycle"]>;+export type WorkflowSandboxContinuationSecurity =+ CodeModeModule.CodeModeContinuationSecurityOptions;let workflowSandboxModulePromise: Promise<WorkflowSandboxModule> | undefined;@@ -34,13 +36,14 @@ export function installWorkflowSandboxModule(module: WorkflowSandboxModule): voi}export async function createWorkflowSandboxTool(input: {+ readonly continuationSecurity: WorkflowSandboxContinuationSecurity;readonly hostTools: ToolSet;readonly lifecycle?: WorkflowSandboxLifecycle;}): Promise<ToolSet[string]> {const { createCodeModeTool } = await loadWorkflowSandboxModule();return createCodeModeTool(input.hostTools,- createWorkflowSandboxOptions(input.lifecycle),+ createWorkflowSandboxOptions(input.continuationSecurity, input.lifecycle),) as ToolSet[string];}@@ -56,12 +59,14 @@ export async function requestWorkflowSandboxInterrupt(input: {export async function getWorkflowSandboxInterrupt(result: unknown,+ continuationSecurity: WorkflowSandboxContinuationSecurity,): Promise<WorkflowSandboxInterrupt | undefined> {const { getCodeModeInterrupt } = await loadWorkflowSandboxModule();- return getCodeModeInterrupt(result as never);+ return getCodeModeInterrupt(result as never, continuationSecurity);}export async function continueWorkflowSandboxInterrupt(input: {+ readonly continuationSecurity: WorkflowSandboxContinuationSecurity;readonly interrupt: WorkflowSandboxInterrupt;readonly lifecycle?: WorkflowSandboxLifecycle;readonly resolution: unknown;@@ -70,7 +75,7 @@ export async function continueWorkflowSandboxInterrupt(input: {const { continueCodeModeInterrupt } = await loadWorkflowSandboxModule();return continueCodeModeInterrupt({interrupt: input.interrupt,- options: createWorkflowSandboxOptions(input.lifecycle),+ options: createWorkflowSandboxOptions(input.continuationSecurity, input.lifecycle),resolution: input.resolution,tools: input.tools,} as never);@@ -78,12 +83,13 @@ export async function continueWorkflowSandboxInterrupt(input: {export async function unwrapWorkflowSandboxResult(value: unknown,+ continuationSecurity: WorkflowSandboxContinuationSecurity,): Promise<| { readonly output: unknown; readonly status: "completed" }| { readonly interrupt: WorkflowSandboxInterrupt; readonly status: "interrupted" }> {const { unwrapCodeModeResult } = await loadWorkflowSandboxModule();- return unwrapCodeModeResult(value) as+ return unwrapCodeModeResult(value, continuationSecurity) as| { readonly output: unknown; readonly status: "completed" }| { readonly interrupt: WorkflowSandboxInterrupt; readonly status: "interrupted" };}@@ -96,9 +102,14 @@ export function readWorkflowSandboxResolution(options: unknown): unknown {}function createWorkflowSandboxOptions(+ continuationSecurity: WorkflowSandboxContinuationSecurity,lifecycle: WorkflowSandboxLifecycle | undefined,): CodeModeModule.CodeModeOptions {- return lifecycle === undefined ? {} : { lifecycle };+ const options: CodeModeModule.CodeModeOptions = {+ continuationSecurity,+ };+ if (lifecycle !== undefined) options.lifecycle = lifecycle;+ return options;}async function loadWorkflowSandboxModule(): Promise<WorkflowSandboxModule> {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ff839121d..ee4bbab74 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -851,8 +851,8 @@ importers:specifier: 3.0.8version: 3.0.8experimental-ai-sdk-code-mode:- specifier: 1.0.14- version: 1.0.14([email protected]([email protected]))+ specifier: 1.0.16+ version: 1.0.16([email protected]([email protected]))gray-matter:specifier: 4.0.3version: 4.0.3@@ -8380,8 +8380,8 @@ packages:resolution: {integrity: sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==}engines: {node: '>=12.0.0'}- resolution: {integrity: sha512-m2s9sgh65hzJly3XFlHtIJgvp4fGoew5Rsr11EZqeaHAHJzZh3xpiuJ5WpvQIIM03aojQbAkNSIWdWoXzN/ETQ==}+ resolution: {integrity: sha512-qkJhiQeRdhj4XQZBm+b1vr+qTFRBQ8xCNYkVigGsG9Qu0dC2gLO7UtJ9dtwvg8HJIR21cu/bpZyewffCkOz9yg==}engines: {node: '>=22.13.0'}peerDependencies:ai: ^6.0.0 || ^7.0.0-beta.0@@ -20725,7 +20725,7 @@ snapshots:dependencies:ai: 7.0.0([email protected])