Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): preserve cancelled turns with attachments (#3041)

Ben Pankow7db230f60a6f
diff --git a/.changeset/olive-moons-cancel.md b/.changeset/olive-moons-cancel.md
new file mode 100644
index 000000000..01d1f96d2
--- /dev/null
+++ b/.changeset/olive-moons-cancel.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Keep the cancelled-turn epilogue inside the eve context. Cancelling a turn whose message carried an attachment failed `turnStep` with "No active eve context" — the harness step's ALS scope had already closed, so staging the preserved message's file parts threw, and the retries made it a terminal session failure.
diff --git a/packages/eve/src/execution/workflow-steps.test.ts b/packages/eve/src/execution/workflow-steps.test.ts
index 1f78b1be5..386dad153 100644
--- a/packages/eve/src/execution/workflow-steps.test.ts
+++ b/packages/eve/src/execution/workflow-steps.test.ts
@@ -191,6 +191,22 @@ const threadContextAdapter: ChannelAdapter = {
const thread = adapterCtx.ctx.ensure(ThreadKey, () => "unset");
const message = payload.message ?? "";
+ // `attach:` delivers structured UserContent carrying a FilePart, the
+ // shape real channels produce for an uploaded image or document.
+ if (typeof message === "string" && message.startsWith("attach:")) {
+ return {
+ message: [
+ { text: `thread=${thread}; user=${message.slice("attach:".length)}`, type: "text" },
+ {
+ data: new URL("https://files.example/diagram.png"),
+ filename: "diagram.png",
+ mediaType: "image/png",
+ type: "file",
+ },
+ ],
+ };
+ }
+
return { message: `thread=${thread}; user=${message}` };
},
};
@@ -1542,6 +1558,56 @@ describe("turnStep", () => {
]);
});
+ it("preserves a cancelled turn message that carries an attachment", async () => {
+ const session = createStubSession();
+ installSessionStoreMocks([session]);
+ vi.mocked(getCompiledRuntimeAgentBundle).mockResolvedValue({
+ adapterRegistry: {
+ adaptersByKind: new Map([[threadContextAdapter.kind, threadContextAdapter]]),
+ },
+ compiledArtifactsSource: {},
+ graph: {
+ nodesByNodeId: new Map(),
+ root: {
+ sandboxRegistry: { sandbox: null },
+ turnAgent: TestTurnAgent,
+ },
+ },
+ moduleMap: { nodes: {} },
+ hookRegistry: createEmptyHookRegistry(),
+ resolvedAgent: { config: {} },
+ subagentRegistry: {},
+ toolRegistry: {},
+ turnAgent: TestTurnAgent,
+ } as never);
+ vi.mocked(createExecutionNodeStep).mockImplementation(() => {
+ return async (): Promise<StepResult> => {
+ throw new TurnCancelledError();
+ };
+ });
+
+ const result = await turnStep({
+ input: {
+ kind: "deliver",
+ payloads: [{ message: "attach:look at this" }],
+ },
+ parentWritable: createTestWritable(),
+ serializedContext: createSerializedContext(),
+ sessionState: createStubSessionState(),
+ });
+
+ expect(result).toMatchObject({ action: "cancelled" });
+ expect(result.sessionState.snapshot?.session.history).toEqual([
+ {
+ content: [
+ { text: "thread=unset; user=look at this", type: "text" },
+ expect.objectContaining({ filename: "diagram.png", type: "file" }),
+ ],
+ role: "user",
+ },
+ ]);
+ });
+
it("rejects task completion while input requests remain pending", async () => {
const session = appendPendingInputBatch({
requests: [
diff --git a/packages/eve/src/execution/workflow-steps.ts b/packages/eve/src/execution/workflow-steps.ts
index 1abf98021..126dd40d4 100644
--- a/packages/eve/src/execution/workflow-steps.ts
+++ b/packages/eve/src/execution/workflow-steps.ts
@@ -553,9 +553,13 @@ export async function turnStep(rawInput: TurnStepInput): Promise<DurableStepResu
// again after this cancellation settles.
const interrupted = serializeContext(ctx);
const retained = readRetainedBackgroundToolResult(ctx);
- const cancelledSession = await preserveCancelledTurnMessage(
- retained?.backgroundTaskSession ?? initialSession,
- resolved,
+ // Runs inside the ALS scope: preserving the message stages its
+ // attachments, and `stageAttachmentsToSandbox` reads the sandbox off the
+ // active context. The harness step's own scope closed when it threw, so
+ // without this the cancellation epilogue fails with "No active eve
+ // context" whenever the discarded turn carried a file part.
+ const cancelledSession = await contextStorage.run(ctx, () =>
+ preserveCancelledTurnMessage(retained?.backgroundTaskSession ?? initialSession, resolved),
);
return {
action: "cancelled",