The Open Framework for Building Agents
fix(eve): persist session sends as the durable deliver envelope (#1752)
Rui2a141f0a8173
diff --git a/.changeset/calm-hooks-deliver.md b/.changeset/calm-hooks-deliver.mdnew file mode 100644index 000000000..730a0e5f2--- /dev/null+++ b/.changeset/calm-hooks-deliver.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Keep sessions resumable across eve deployment upgrades: sends now cross durable session hooks as the established `deliver` envelope (with a transitional single-payload mirror for sessions pinned to 0.30.3–0.30.8), and consumers keep accepting payloads persisted by those versions.diff --git a/e2e/fixtures/agent-channels/evals/custom-channels/continuation-wire.eval.ts b/e2e/fixtures/agent-channels/evals/custom-channels/continuation-wire.eval.tsnew file mode 100644index 000000000..530da9530--- /dev/null+++ b/e2e/fixtures/agent-channels/evals/custom-channels/continuation-wire.eval.ts@@ -0,0 +1,125 @@+import { existsSync, readdirSync, readFileSync } from "node:fs";+import { join, resolve } from "node:path";+import { zstdDecompressSync } from "node:zlib";++import { defineEval } from "eve/evals";+import { equals, satisfies } from "eve/evals/expect";++import { postChannel } from "./shared";++type MessageResponse = { ok: boolean; sessionId?: string };++const WORKFLOW_EVENTS_DIR = resolve(".eve", ".workflow-data", "events");++/**+ * A channel-address follow-up crosses the durable continuation-hook boundary,+ * and the persisted hook payload must stay on the frozen `deliver` envelope+ * with the transitional single-payload mirror (`payload` alongside+ * `payloads`) that keeps eve 0.30.3–0.30.8 parked consumers receiving+ * messages. Drop the mirror assertion together with the encoder mirror once+ * that cohort has aged out (30-day session timeout).+ *+ * The behavioral half (a same-version follow-up turn) passes even if producer+ * and consumer change the wire together — exactly how the 0.30.3 `send`+ * regression shipped. The byte-level half closes that hole: on worlds with a+ * local event log, the eval decodes the persisted `hook_received` payload and+ * fails loudly when the envelope shape drifts.+ */+export default defineEval({+ description: "Custom channel continuation preserves the durable delivery wire protocol.",++ async test(t) {+ const sessionRef = crypto.randomUUID();+ const first = await postChannel<MessageResponse>(t.target, "/webhook", {+ message: "Reply with exactly: first-turn",+ sessionRef,+ });+ await t.require(+ first,+ satisfies(+ (value: MessageResponse) => value.ok === true && typeof value.sessionId === "string",+ "initial channel delivery creates a session",+ ),+ );++ const initialTurn = await t.target.watchTurn(first.sessionId!).result();+ initialTurn.notEvent("session.failed");++ const followUpTurn = t.target.watchTurn(first.sessionId!, {+ startIndex: initialTurn.events.length,+ });+ const second = await postChannel<MessageResponse>(t.target, "/webhook", {+ message: "Reply with exactly: second-turn",+ sessionRef,+ });+ await t.require(second.sessionId, equals(first.sessionId));++ const followUp = await followUpTurn.result();+ followUp.notEvent("session.failed");+ followUp.event("message.completed");+ followUp.messageIncludes("second-turn");++ // Byte-level wire pin. Only worlds persisting a local event log expose the+ // durable payload; remote worlds (Vercel, Postgres) skip this half.+ if (!existsSync(WORKFLOW_EVENTS_DIR)) {+ t.log("No local workflow event log; skipping the persisted wire-format assertion.");+ return;+ }++ const payloads = readSessionHookPayloads(first.sessionId!);+ if (payloads.length === 0) {+ // A stale local event log can coexist with a remote world; only assert+ // when this session's continuation actually persisted locally.+ t.log("No locally persisted hook_received for this session; skipping the wire assertion.");+ return;+ }+ for (const payload of payloads) {+ await t.require(+ payload,+ satisfies(+ (text: string) => text.includes('"deliver"') && text.includes('"payloads"'),+ "the persisted continuation payload uses the frozen `deliver` envelope",+ ),+ );+ await t.require(+ payload,+ satisfies(+ // `"payload"` never matches inside `"payloads"`: the closing quote+ // pins the exact key.+ (text: string) => /"payload"/.test(text),+ "the persisted envelope mirrors `payload` for 0.30.3–0.30.8 parked consumers",+ ),+ );+ }+ },+});++/**+ * Decoded devalue text of every session-level `hook_received` payload for one+ * run. Turn-control hooks are runtime-internal and excluded; only the channel+ * continuation hook carries the cross-deployment delivery envelope.+ */+function readSessionHookPayloads(sessionId: string): string[] {+ const payloads: string[] = [];+ for (const name of readdirSync(WORKFLOW_EVENTS_DIR)) {+ if (!name.startsWith(`${sessionId}-`)) continue;+ const event = JSON.parse(readFileSync(join(WORKFLOW_EVENTS_DIR, name), "utf8")) as {+ eventType?: string;+ eventData?: { token?: string; payload?: { data?: string } };+ };+ if (event.eventType !== "hook_received") continue;+ const token = event.eventData?.token ?? "";+ if (token.includes(":turn-control:") || token.endsWith(":auth")) continue;+ const data = event.eventData?.payload?.data;+ if (data === undefined) continue;+ payloads.push(decodeSerializedPayload(Buffer.from(data, "base64")));+ }+ return payloads;+}++/** Undoes the workflow serde codec prefix: `zstd` wraps the `devl` bytes. */+function decodeSerializedPayload(bytes: Buffer): string {+ const prefix = bytes.subarray(0, 4).toString("utf8");+ const body = prefix === "zstd" ? zstdDecompressSync(bytes.subarray(4)) : bytes;+ return body.toString("utf8");+}diff --git a/packages/eve/src/execution/parked-delivery-wait.ts b/packages/eve/src/execution/parked-delivery-wait.tsindex 84c0fb1a2..c779057a9 100644--- a/packages/eve/src/execution/parked-delivery-wait.ts+++ b/packages/eve/src/execution/parked-delivery-wait.ts@@ -1,7 +1,8 @@-import type { DeliverHookPayload, DeliverPayload, SessionCommand } from "#channel/types.js";+import type { DeliverHookPayload, DeliverPayload } from "#channel/types.js";import type { DurableSessionState } from "#execution/durable-session-store.js";import { routeDeliverToChildren } from "#execution/route-child-delivery.js";import type { SessionCommandInbox } from "#execution/session-command-inbox.js";+import { sendCommandToDelivery } from "#execution/session-command-wire.js";import { coalesceDeliveries } from "#harness/messages.js";type NextSessionAction =@@ -119,20 +120,12 @@ async function waitForNextSessionAction(input: {continue;}- return { delivery: commandToDelivery(first.value), kind: "delivery" };- }-}+ if (first.value.kind === "deliver") {+ return { delivery: first.value, kind: "delivery" };+ }-function commandToDelivery(- command: Extract<SessionCommand, { readonly kind: "send" }>,-): DeliverHookPayload {- return {- auth: command.auth,- caller: command.caller,- kind: "deliver",- payloads: [command.payload],- requestId: command.requestId,- };+ return { delivery: sendCommandToDelivery(first.value), kind: "delivery" };+ }}function takeBufferedTurnDelivery(bufferedDeliveries: DeliverHookPayload[]): DeliverHookPayload {diff --git a/packages/eve/src/execution/session-command-inbox.integration.test.ts b/packages/eve/src/execution/session-command-inbox.integration.test.tsindex 55f06fab1..8fcf473e8 100644--- a/packages/eve/src/execution/session-command-inbox.integration.test.ts+++ b/packages/eve/src/execution/session-command-inbox.integration.test.ts@@ -1,11 +1,61 @@import { describe, expect, it } from "vitest";+import { createWorkflowRuntime } from "#execution/workflow-runtime.js";import { sessionCommandInboxWorkflow } from "#internal/testing/session-command-inbox-workflow.js";+import { legacySessionDeliveryWorkflow } from "#internal/testing/legacy-session-delivery-workflow.js";+import { midCohortSessionDeliveryWorkflow } from "#internal/testing/mid-cohort-session-delivery-workflow.js";import { waitForHook } from "#internal/testing/workflow-test-helpers.js";import { getWorld, resumeHook, start } from "#internal/workflow/runtime.js";import { sessionCommandHookToken } from "#execution/session-command-token.js";+import type { RuntimeCompiledArtifactsSource } from "#runtime/compiled-artifacts-source.js";describe("session command inbox integration", () => {+ it("resumes a legacy delivery-only workflow from a current send command", async () => {+ const token = "http:session-command-inbox:legacy-delivery";+ const run = await start(legacySessionDeliveryWorkflow, [{ token }]);++ try {+ await waitForHook({ runId: run.runId }, { token });+ const runtime = createWorkflowRuntime({+ compiledArtifactsSource: {} as RuntimeCompiledArtifactsSource,+ });++ await expect(+ runtime.dispatchContinuation({+ command: { kind: "send", payload: { message: "legacy-compatible" } },+ continuationToken: token,+ }),+ ).resolves.toEqual({ sessionId: run.runId, status: "accepted" });+ await expect(run.returnValue).resolves.toBe("legacy-compatible");+ } finally {+ const status = await run.status;+ if (status === "pending" || status === "running") await run.cancel();+ }+ });++ it("resumes a 0.30.3–0.30.8 parked consumer from a current send command", async () => {+ const token = "http:session-command-inbox:mid-cohort-delivery";+ const run = await start(midCohortSessionDeliveryWorkflow, [{ token }]);++ try {+ await waitForHook({ runId: run.runId }, { token });+ const runtime = createWorkflowRuntime({+ compiledArtifactsSource: {} as RuntimeCompiledArtifactsSource,+ });++ await expect(+ runtime.dispatchContinuation({+ command: { kind: "send", payload: { message: "mid-cohort-compatible" } },+ continuationToken: token,+ }),+ ).resolves.toEqual({ sessionId: run.runId, status: "accepted" });+ await expect(run.returnValue).resolves.toBe("mid-cohort-compatible");+ } finally {+ const status = await run.status;+ if (status === "pending" || status === "running") await run.cancel();+ }+ });+it("accepts commands alternately through the stable ID and channel aliases", async () => {const channelToken = "http:session-command-inbox:both-aliases";const run = await start(sessionCommandInboxWorkflow, [{ token: channelToken }]);@@ -18,7 +68,10 @@ describe("session command inbox integration", () => {]);await resumeHook(stableToken, { kind: "send", payload: { message: "by id" } });- await resumeHook(channelToken, { kind: "send", payload: { message: "by channel" } });+ await resumeHook(channelToken, {+ kind: "deliver",+ payloads: [{ message: "by channel" }],+ });await expect(run.returnValue).resolves.toEqual(["by id", "by channel"]);} finally {diff --git a/packages/eve/src/execution/session-command-inbox.ts b/packages/eve/src/execution/session-command-inbox.tsindex a17a0e35b..12ef3fcad 100644--- a/packages/eve/src/execution/session-command-inbox.ts+++ b/packages/eve/src/execution/session-command-inbox.ts@@ -1,10 +1,22 @@import { createHook, type Hook } from "#compiled/@workflow/core/index.js";-import type { SessionCommand, SessionTimeoutHookPayload } from "#channel/types.js";+import type {+ DeliverHookPayload,+ SessionCommand,+ SessionTimeoutHookPayload,+} from "#channel/types.js";import { claimHookOwnership, disposeHook } from "#execution/hook-ownership.js";-/** Payloads accepted by a session driver's stable and channel command aliases. */-export type SessionInboxPayload = SessionCommand | SessionTimeoutHookPayload;+/**+ * Payloads accepted by a session driver's stable and channel aliases.+ *+ * `DeliverHookPayload` is the only delivery format producers persist. The+ * `send` member of `SessionCommand` stays accepted solely for payloads+ * persisted by eve 0.30.3–0.30.8, which wrote the command shape directly;+ * sessions are bounded by the 30-day default timeout, so the decode can be+ * dropped once runs created on those versions have aged out.+ */+export type SessionInboxPayload = DeliverHookPayload | SessionCommand | SessionTimeoutHookPayload;interface HookRead {readonly order: number;diff --git a/packages/eve/src/execution/session-command-wire.test.ts b/packages/eve/src/execution/session-command-wire.test.tsnew file mode 100644index 000000000..1acb3b08d--- /dev/null+++ b/packages/eve/src/execution/session-command-wire.test.ts@@ -0,0 +1,34 @@+import { describe, expect, it } from "vitest";++import { sendCommandToDelivery } from "#execution/session-command-wire.js";++describe("sendCommandToDelivery", () => {+ it("emits the deliver envelope with the single-payload compat mirror", () => {+ const payload = { message: "hello" };++ const caller = {+ callId: "call-1",+ replyTo: { kind: "hook", token: "parent-tok" },+ subagentName: "child",+ } as const;+ const wire = sendCommandToDelivery({+ auth: null,+ caller,+ kind: "send",+ payload,+ requestId: "req-1",+ });++ expect(wire).toEqual({+ auth: null,+ caller,+ kind: "deliver",+ payload,+ payloads: [payload],+ requestId: "req-1",+ });+ // The 0.30.3–0.30.8 parked decode reads `.payload`; everything else reads+ // `payloads`. Both views must reference the same delivery.+ expect(wire.payloads[0]).toBe(wire.payload);+ });+});diff --git a/packages/eve/src/execution/session-command-wire.ts b/packages/eve/src/execution/session-command-wire.tsnew file mode 100644index 000000000..5198e7539--- /dev/null+++ b/packages/eve/src/execution/session-command-wire.ts@@ -0,0 +1,35 @@+import type { DeliverHookPayload, DeliverPayload, SessionCommand } from "#channel/types.js";++/**+ * The durable delivery envelope plus a transitional single-payload mirror.+ *+ * Consumers pinned to eve 0.30.3–0.30.8 cast any non-control inbox payload to+ * a `send` command and read its `payload` field, so the mirror is what keeps+ * their parked sessions receiving messages. Sessions are bounded by the+ * 30-day default timeout; once runs created on those versions have aged out,+ * drop the mirror and return plain `DeliverHookPayload`.+ */+export interface WireDeliverHookPayload extends DeliverHookPayload {+ readonly payload: DeliverPayload;+}++/**+ * Encodes a caller-side `send` command as the durable delivery envelope.+ *+ * `DeliverHookPayload` is the only wire format persisted to session hooks.+ * Hooks outlive deployments, so every producer must emit this envelope and+ * every consumer must keep accepting it; `send` never crosses the durable+ * boundary itself.+ */+export function sendCommandToDelivery(+ command: Extract<SessionCommand, { readonly kind: "send" }>,+): WireDeliverHookPayload {+ return {+ auth: command.auth,+ caller: command.caller,+ kind: "deliver",+ payload: command.payload,+ payloads: [command.payload],+ requestId: command.requestId,+ };+}diff --git a/packages/eve/src/execution/turn-control-receiver.test.ts b/packages/eve/src/execution/turn-control-receiver.test.tsindex f8c84d9e1..3668d0b42 100644--- a/packages/eve/src/execution/turn-control-receiver.test.ts+++ b/packages/eve/src/execution/turn-control-receiver.test.ts@@ -108,7 +108,7 @@ describe("TurnControlReceiver", () => {await expect(runReceiver([])).rejects.toThrow("boom");});- it("buffers sends and context controls that arrive during a turn", async () => {+ it("buffers current and legacy sends that arrive during a turn", async () => {installControlHook([parkResult()], true);const bufferedDeliveries: DeliverHookPayload[] = [];const bufferedSessionControls: Array<"clear" | "compact" | "expired" | "reset"> = [];@@ -117,6 +117,7 @@ describe("TurnControlReceiver", () => {bufferedSessionControls,commandInbox: createCommandInbox([{ kind: "send", payload: { message: "follow up" } },+ { kind: "deliver", payloads: [{ message: "legacy follow up" }] },{ kind: "clear" },{ kind: "compact" },{ kind: "session-timeout" },@@ -129,9 +130,11 @@ describe("TurnControlReceiver", () => {auth: undefined,caller: undefined,kind: "deliver",+ payload: { message: "follow up" },payloads: [{ message: "follow up" }],requestId: undefined,},+ { kind: "deliver", payloads: [{ message: "legacy follow up" }] },]);expect(bufferedSessionControls).toEqual(["clear", "compact", "expired"]);});diff --git a/packages/eve/src/execution/turn-control-receiver.ts b/packages/eve/src/execution/turn-control-receiver.tsindex 16e2203ba..ce96d52bc 100644--- a/packages/eve/src/execution/turn-control-receiver.ts+++ b/packages/eve/src/execution/turn-control-receiver.ts@@ -1,12 +1,13 @@import { createHook, type Hook } from "#compiled/@workflow/core/index.js";-import type { DeliverHookPayload, SessionCommand } from "#channel/types.js";+import type { DeliverHookPayload } from "#channel/types.js";import { forwardTurnCancellationStep } from "#execution/forward-turn-cancellation-step.js";import type { TurnControlPayload } from "#execution/turn-control-protocol.js";import { forwardTurnDeliveryStep } from "#execution/forward-turn-delivery-step.js";import { closeHookIterator, disposeHook } from "#execution/hook-ownership.js";import type { NextDriverAction } from "#execution/next-driver-action.js";import type { SessionCommandInbox, SessionInboxPayload } from "#execution/session-command-inbox.js";+import { sendCommandToDelivery } from "#execution/session-command-wire.js";import { turnCancellationHookToken } from "#execution/turn-cancellation-token.js";import { rebuildSerializableError } from "#execution/workflow-errors.js";@@ -71,8 +72,12 @@ export class TurnControlReceiver {private async handleSessionCommand(command: SessionInboxPayload,): Promise<TurnDriverAction | undefined> {+ if (command.kind === "deliver") {+ this.bufferedDeliveries.push(command);+ return undefined;+ }if (command.kind === "send") {- this.bufferedDeliveries.push(commandToDelivery(command));+ this.bufferedDeliveries.push(sendCommandToDelivery(command));return undefined;}if (command.kind === "clear" || command.kind === "compact") {@@ -192,8 +197,12 @@ export class TurnControlReceiver {}this.commandInbox.consumeNext();+ if (winner.value.value.kind === "deliver") {+ delivery = winner.value.value;+ continue;+ }if (winner.value.value.kind === "send") {- delivery = commandToDelivery(winner.value.value);+ delivery = sendCommandToDelivery(winner.value.value);continue;}const terminal = await this.handleSessionCommand(winner.value.value);@@ -264,15 +273,3 @@ export class TurnControlReceiver {function unsupportedSessionCommand(command: never): never {throw new Error(`Unsupported session command: ${JSON.stringify(command)}`);}--function commandToDelivery(- command: Extract<SessionCommand, { readonly kind: "send" }>,-): DeliverHookPayload {- return {- auth: command.auth,- caller: command.caller,- kind: "deliver",- payloads: [command.payload],- requestId: command.requestId,- };-}diff --git a/packages/eve/src/execution/workflow-entry.test.ts b/packages/eve/src/execution/workflow-entry.test.tsindex a4aab7980..e751f3d32 100644--- a/packages/eve/src/execution/workflow-entry.test.ts+++ b/packages/eve/src/execution/workflow-entry.test.ts@@ -920,8 +920,12 @@ describe("workflowEntry", () => {expect(dispatchTurnStep).toHaveBeenCalledTimes(1);expect(resumeHook).toHaveBeenCalledWith("turn-inbox", {delivery: {+ auth: undefined,+ caller: undefined,kind: "deliver",+ payload: { inputResponses: [{ optionId: "approve", requestId: "req-1" }] },payloads: [{ inputResponses: [{ optionId: "approve", requestId: "req-1" }] }],+ requestId: undefined,},kind: "driver-delivery",requestId: "delivery-1",diff --git a/packages/eve/src/execution/workflow-runtime.test.ts b/packages/eve/src/execution/workflow-runtime.test.tsindex d4dbc5455..9cc9d70bc 100644--- a/packages/eve/src/execution/workflow-runtime.test.ts+++ b/packages/eve/src/execution/workflow-runtime.test.ts@@ -75,7 +75,7 @@ describe("createWorkflowRuntime command dispatch", () => {return createWorkflowRuntime({ compiledArtifactsSource });}- it("dispatches send commands directly through a continuation alias", async () => {+ it("preserves the legacy delivery payload through a continuation alias", async () => {resumeHookMock.mockResolvedValue({ runId: "driver-run" });const caller = {callId: "call-1",@@ -99,8 +99,9 @@ describe("createWorkflowRuntime command dispatch", () => {expect(resumeHookMock).toHaveBeenCalledWith("test:token", {auth: null,caller,- kind: "send",+ kind: "deliver",payload: { message: "hello" },+ payloads: [{ message: "hello" }],requestId: "req_deliver",});expect(getHookByTokenMock).not.toHaveBeenCalled();@@ -122,6 +123,26 @@ describe("createWorkflowRuntime command dispatch", () => {expect(getHookByTokenMock).not.toHaveBeenCalled();});+ it("preserves the delivery payload through the stable session inbox", async () => {+ resumeHookMock.mockResolvedValue({ runId: "session-1" });++ await expect(+ buildRuntime().dispatchSession({+ command: { kind: "send", payload: { message: "hello" } },+ sessionId: "session-1",+ }),+ ).resolves.toEqual({ sessionId: "session-1", status: "accepted" });++ expect(resumeHookMock).toHaveBeenCalledWith(sessionCommandHookToken("session-1"), {+ auth: undefined,+ caller: undefined,+ kind: "deliver",+ payload: { message: "hello" },+ payloads: [{ message: "hello" }],+ requestId: undefined,+ });+ });+it.each([{ command: { kind: "send" as const, payload: {} }, status: "session_not_active" },{ command: { kind: "compact" as const }, status: "no_active_session" },diff --git a/packages/eve/src/execution/workflow-runtime.ts b/packages/eve/src/execution/workflow-runtime.tsindex a4aea51a6..c229f7524 100644--- a/packages/eve/src/execution/workflow-runtime.ts+++ b/packages/eve/src/execution/workflow-runtime.ts@@ -8,6 +8,7 @@ import {import type {CancelTurnInput,CancelTurnResult,+ DeliverHookPayload,DispatchContinuationInput,DispatchSessionInput,GetEventStreamOptions,@@ -48,6 +49,7 @@ import { RuntimeSessionOwnershipConflictError } from "#execution/runtime-errors.import type { WorkflowEntryInput } from "#execution/workflow-entry.js";import { walkCauseChain } from "#shared/errors.js";import { sessionCommandHookToken } from "#execution/session-command-token.js";+import { sendCommandToDelivery } from "#execution/session-command-wire.js";import type { DynamicSubagentAgentConfig } from "#runtime/subagents/dynamic-agent-config.js";const WORKFLOW_ENTRY_NAME = "workflowEntry";@@ -254,7 +256,7 @@ async function dispatchWorkflowCommand<TCommand extends SessionCommand>(): Promise<SessionCommandResult<TCommand>> {let hook: WorkflowHookRecord;try {- hook = normalizeWorkflowHook(await resumeHook(token, command));+ hook = normalizeWorkflowHook(await resumeHook(token, sessionHookPayload(command)));} catch (error) {if (isInactiveCommandTarget(error)) {return inactiveCommandResult(command);@@ -273,6 +275,10 @@ async function dispatchWorkflowCommand<TCommand extends SessionCommand>(return activeCommandResult(command, hook.runId);}+function sessionHookPayload(command: SessionCommand): SessionCommand | DeliverHookPayload {+ return command.kind === "send" ? sendCommandToDelivery(command) : command;+}+function activeCommandResult<TCommand extends SessionCommand>(command: TCommand,sessionId: string,diff --git a/packages/eve/src/execution/workflow-steps.test.ts b/packages/eve/src/execution/workflow-steps.test.tsindex e4c9b992a..6e6859582 100644--- a/packages/eve/src/execution/workflow-steps.test.ts+++ b/packages/eve/src/execution/workflow-steps.test.ts@@ -241,10 +241,13 @@ describe("routeProxiedDeliverStep", () => {expect(resumeHookMock).toHaveBeenCalledWith("child-token", {auth,- kind: "send",+ caller: undefined,+ kind: "deliver",payload: {inputResponses: [{ optionId: "approve", requestId: "request-1" }],},+ payloads: [{ inputResponses: [{ optionId: "approve", requestId: "request-1" }] }],+ requestId: undefined,});});});diff --git a/packages/eve/src/execution/workflow-steps.ts b/packages/eve/src/execution/workflow-steps.tsindex 0105a4162..4d9ee6590 100644--- a/packages/eve/src/execution/workflow-steps.ts+++ b/packages/eve/src/execution/workflow-steps.ts@@ -1,6 +1,6 @@import { buildAdapterContext } from "#channel/adapter-context.js";import { callAdapterEventHandler, defaultDeliverResult } from "#channel/adapter.js";-import type { DeliverPayload, SessionAuthContext, SessionCommand } from "#channel/types.js";+import type { DeliverPayload, SessionAuthContext } from "#channel/types.js";import { dispatchStreamEventHooks } from "#context/hook-lifecycle.js";import { dispatchDynamicInstructionEvent } from "#context/dynamic-instruction-lifecycle.js";import { dispatchDynamicModelEvent } from "#context/dynamic-model-lifecycle.js";@@ -28,6 +28,7 @@ import { preserveSerializedAgentTraceState } from "#tracing/agent-trace-context-import { readTurnSleepDurationMs } from "#harness/turn-sleep.js";import { isTurnCancellation, throwIfTurnAborted } from "#harness/turn-cancellation.js";import { setChannelContext } from "#execution/channel-context.js";+import { sendCommandToDelivery } from "#execution/session-command-wire.js";import { hasPendingInputBatch } from "#harness/input-requests.js";import { coalesceTurnInputs } from "#harness/messages.js";import {@@ -646,12 +647,12 @@ export async function routeProxiedDeliverStep(input: {});for (const forChild of routed.forChildren) {- const command = {- auth: input.auth,- kind: "send",- payload: forChild.payload,- } satisfies SessionCommand;- await resumeHook(forChild.childContinuationToken, command);+ // Children are pinned to their own deployments, so proxied deliveries+ // must cross this hook in the same durable envelope as channel sends.+ await resumeHook(+ forChild.childContinuationToken,+ sendCommandToDelivery({ auth: input.auth, kind: "send", payload: forChild.payload }),+ );}return routed.parentAction ?? { kind: "continue", remainder: routed.forSelf };diff --git a/packages/eve/src/internal/testing/legacy-session-delivery-workflow.ts b/packages/eve/src/internal/testing/legacy-session-delivery-workflow.tsnew file mode 100644index 000000000..24fd9a75b--- /dev/null+++ b/packages/eve/src/internal/testing/legacy-session-delivery-workflow.ts@@ -0,0 +1,18 @@+import { createHook } from "#compiled/@workflow/core/index.js";++import type { DeliverHookPayload } from "#channel/types.js";++/** Models the continuation consumer shipped before SessionCommand existed. */+export async function legacySessionDeliveryWorkflow(input: {+ readonly token: string;+}): Promise<string> {+ "use workflow";++ const deliveries = createHook<DeliverHookPayload>({ token: input.token });+ for await (const delivery of deliveries) {+ if (delivery.kind !== "deliver") continue;+ const message = delivery.payloads[0]?.message;+ return typeof message === "string" ? message : "";+ }+ return "";+}diff --git a/packages/eve/src/internal/testing/mid-cohort-session-delivery-workflow.ts b/packages/eve/src/internal/testing/mid-cohort-session-delivery-workflow.tsnew file mode 100644index 000000000..eddcf6526--- /dev/null+++ b/packages/eve/src/internal/testing/mid-cohort-session-delivery-workflow.ts@@ -0,0 +1,38 @@+import { createHook } from "#compiled/@workflow/core/index.js";++import type { DeliverPayload } from "#channel/types.js";++/**+ * Models the parked-session consumer shipped in eve 0.30.3–0.30.8.+ *+ * Frozen copy of that cohort's inbox decode (`waitForNextSessionAction` ++ * `commandToDelivery` at 0.30.7): every payload that is not a control kind is+ * cast to a `send` command and re-wrapped by reading its `payload` field. A+ * producer envelope without that field therefore delivers `undefined` and the+ * message is lost — which is exactly what the current wire encoder's+ * single-payload mirror exists to prevent.+ */+export async function midCohortSessionDeliveryWorkflow(input: {+ readonly token: string;+}): Promise<string> {+ "use workflow";++ const inbox = createHook<{ readonly kind: string }>({ token: input.token });+ for await (const value of inbox) {+ if (+ value.kind === "session-timeout" ||+ value.kind === "clear" ||+ value.kind === "compact" ||+ value.kind === "reset" ||+ value.kind === "cancel"+ ) {+ continue;+ }++ const command = value as { readonly payload?: DeliverPayload };+ const payloads = [command.payload];+ const message = payloads[0]?.message;+ return typeof message === "string" ? message : "";+ }+ return "";+}diff --git a/packages/eve/src/internal/testing/session-command-inbox-workflow.ts b/packages/eve/src/internal/testing/session-command-inbox-workflow.tsindex 2e7591929..c71eaf015 100644--- a/packages/eve/src/internal/testing/session-command-inbox-workflow.ts+++ b/packages/eve/src/internal/testing/session-command-inbox-workflow.ts@@ -42,4 +42,7 @@ function collectMessage(command: SessionInboxPayload, messages: string[]): voidif (command.kind === "send" && typeof command.payload.message === "string") {messages.push(command.payload.message);}+ if (command.kind === "deliver" && typeof command.payloads[0]?.message === "string") {+ messages.push(command.payloads[0].message);+ }}