Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): preserve coalesced delivery inputs (#1049)

vercel-gh-bot-2[bot]6ded22e48b56
diff --git a/.changeset/calm-messages-coalesce.md b/.changeset/calm-messages-coalesce.md
new file mode 100644
index 000000000..faa1f2818
--- /dev/null
+++ b/.changeset/calm-messages-coalesce.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Preserve every queued delivery's message, context, and input responses when eve batches payloads before routing.
diff --git a/e2e/fixtures/agent-tools/evals/channel-events/batched-delivery.eval.ts b/e2e/fixtures/agent-tools/evals/channel-events/batched-delivery.eval.ts
new file mode 100644
index 000000000..c63093e40
--- /dev/null
+++ b/e2e/fixtures/agent-tools/evals/channel-events/batched-delivery.eval.ts
@@ -0,0 +1,28 @@
+import { defineEval } from "eve/evals";
+import { equals } from "eve/evals/expect";
+
+// @ts-ignore TS6059: this eval intentionally exercises the workspace source implementation.
+import { coalesceDeliverPayloads } from "../../../../../packages/eve/src/execution/deliver-payloads.js";
+
+export default defineEval({
+ description: "Delivery batching smoke: queued messages and context coalesce in arrival order.",
+ async test(t) {
+ const firstMessage = "Remember synthetic marker BATCH-FIRST.";
+ const secondMessage = "Remember synthetic marker BATCH-SECOND.";
+ const firstContext = "Synthetic context: first delivery.";
+ const secondContext = "Synthetic context: second delivery.";
+
+ await t.require(
+ coalesceDeliverPayloads([
+ { context: [firstContext], message: firstMessage },
+ { context: [secondContext], message: secondMessage },
+ ]),
+ equals({
+ context: [firstContext, secondContext],
+ message: `${firstMessage}\n\n${secondMessage}`,
+ }),
+ );
+
+ t.succeeded();
+ },
+});
diff --git a/packages/eve/src/execution/deliver-payloads.test.ts b/packages/eve/src/execution/deliver-payloads.test.ts
new file mode 100644
index 000000000..6ca529bef
--- /dev/null
+++ b/packages/eve/src/execution/deliver-payloads.test.ts
@@ -0,0 +1,64 @@
+import { describe, expect, it } from "vitest";
+import { coalesceDeliverPayloads } from "#execution/deliver-payloads.js";
+
+const FIRST_MESSAGE = "Please summarize the synthetic release checklist before the rollout.";
+const SECOND_MESSAGE = "Proceed after the synthetic health check passes.";
+const FIRST_CALLBACK_CONTEXT = "Release policy: use the synthetic staging environment only.";
+const SECOND_CALLBACK_CONTEXT = "Release policy: wait for the synthetic health check.";
+
+describe("coalesceDeliverPayloads", () => {
+ it("preserves messages and authored callback context in arrival order", () => {
+ const result = coalesceDeliverPayloads([
+ {
+ context: [FIRST_CALLBACK_CONTEXT],
+ message: FIRST_MESSAGE,
+ },
+ {
+ context: [SECOND_CALLBACK_CONTEXT],
+ message: SECOND_MESSAGE,
+ },
+ ]);
+
+ expect(result).toEqual({
+ context: [FIRST_CALLBACK_CONTEXT, SECOND_CALLBACK_CONTEXT],
+ message: `${FIRST_MESSAGE}\n\n${SECOND_MESSAGE}`,
+ });
+ });
+
+ it("omits blank messages after preserving adapter fields", () => {
+ const result = coalesceDeliverPayloads([
+ { adapterMetadata: { deliverySequence: 1 }, message: " " },
+ { message: "\n" },
+ ]);
+
+ expect(result).toEqual({ adapterMetadata: { deliverySequence: 1 } });
+ });
+
+ it("preserves queued input responses and adapter fields", () => {
+ const result = coalesceDeliverPayloads([
+ {
+ adapterMetadata: { callbackKind: "button", deliverySequence: 1 },
+ inputResponses: [{ optionId: "approve", requestId: "approval_synthetic_release" }],
+ preservedAdapterMetadata: { source: "synthetic-callback" },
+ },
+ {
+ adapterMetadata: { callbackKind: "message", deliverySequence: 2 },
+ inputResponses: [
+ { requestId: "question_synthetic_rollout", text: "Begin with the synthetic canary." },
+ ],
+ nextAdapterMetadata: { callbackVersion: 2 },
+ preservedAdapterMetadata: undefined,
+ },
+ ]);
+
+ expect(result).toEqual({
+ adapterMetadata: { callbackKind: "message", deliverySequence: 2 },
+ inputResponses: [
+ { optionId: "approve", requestId: "approval_synthetic_release" },
+ { requestId: "question_synthetic_rollout", text: "Begin with the synthetic canary." },
+ ],
+ nextAdapterMetadata: { callbackVersion: 2 },
+ preservedAdapterMetadata: { source: "synthetic-callback" },
+ });
+ });
+});
diff --git a/packages/eve/src/execution/deliver-payloads.ts b/packages/eve/src/execution/deliver-payloads.ts
index 123e38092..8aeff8087 100644
--- a/packages/eve/src/execution/deliver-payloads.ts
+++ b/packages/eve/src/execution/deliver-payloads.ts
@@ -1,25 +1,29 @@
import type { DeliverPayload } from "#channel/types.js";
-import type { InputResponse } from "#runtime/input/types.js";
+import { coalesceTurnInputs } from "#harness/messages.js";
+import type { StepInput } from "#harness/types.js";
-/** Coalesces channel payloads while preserving every structured input response. */
+const COALESCED_DELIVER_FIELDS = ["context", "inputResponses", "message", "outputSchema"] as const;
+
+/** Coalesces channel payloads while preserving turn input and adapter-specific fields. */
export function coalesceDeliverPayloads(payloads: readonly DeliverPayload[]): DeliverPayload {
if (payloads.length === 0) return {};
if (payloads.length === 1) return payloads[0] ?? {};
const merged: Record<string, unknown> = {};
- const inputResponses: InputResponse[] = [];
+ let turnInput: StepInput = {};
for (const payload of payloads) {
for (const [key, value] of Object.entries(payload)) {
- if (key !== "inputResponses" && value !== undefined) {
+ if (value !== undefined) {
merged[key] = value;
}
}
- if (payload.inputResponses !== undefined) {
- inputResponses.push(...payload.inputResponses);
- }
+ turnInput = coalesceTurnInputs(turnInput, payload);
+ }
+
+ for (const field of COALESCED_DELIVER_FIELDS) {
+ delete merged[field];
}
- if (inputResponses.length > 0) merged.inputResponses = inputResponses;
- return merged as DeliverPayload;
+ return Object.assign(merged, turnInput);
}