The Open Framework for Building Agents
fix(eve): keep the cancelled delivery's caller when rolling back a turn (#4316)
e0-gh-vercel-connect[bot]cdad50a9e88d
diff --git a/.changeset/cancelled-turn-keeps-caller.md b/.changeset/cancelled-turn-keeps-caller.mdnew file mode 100644index 000000000..a7cf72bc9--- /dev/null+++ b/.changeset/cancelled-turn-keeps-caller.md@@ -0,0 +1,5 @@+---+"eve": patch+---++A follow-up message cancelled before its first model call now keeps its own sender as `ctx.session.auth.current`. Previously the cancelled turn reverted to the previous caller, even when the follow-up was anonymous, so `turn.cancelled` hooks saw the wrong identity.diff --git a/packages/eve/src/execution/cancelled-model-call-batch.ts b/packages/eve/src/execution/cancelled-model-call-batch.tsindex 55a513559..2381a23d0 100644--- a/packages/eve/src/execution/cancelled-model-call-batch.ts+++ b/packages/eve/src/execution/cancelled-model-call-batch.ts@@ -1,5 +1,5 @@import { contextStorage, type ContextContainer } from "#context/container.js";-import { TurnDeliveryIdsKey } from "#context/keys.js";+import { AuthKey, TurnDeliveryIdsKey } from "#context/keys.js";import { preserveSerializedSessionDynamicModelSelection } from "#context/serialized-dynamic-model-selection.js";import { serializeContext } from "#context/serialize.js";import { preserveCancelledTurnMessage } from "#execution/cancelled-turn-message.js";@@ -32,6 +32,7 @@ export async function createCancelledModelCallBatchResult(input: {: checkpointSession;const checkpointContext = {...(input.checkpoint?.serializedContext ?? input.beforeBatchContext),+ [AuthKey.name]: interruptedContext[AuthKey.name],[TurnDeliveryIdsKey.name]: interruptedContext[TurnDeliveryIdsKey.name],};diff --git a/packages/eve/src/execution/session/turn-step.test.ts b/packages/eve/src/execution/session/turn-step.test.tsindex eb9e211f6..b933a9964 100644--- a/packages/eve/src/execution/session/turn-step.test.ts+++ b/packages/eve/src/execution/session/turn-step.test.ts@@ -16,6 +16,7 @@ import {ContinuationHookTokensKey,ContinuationTokenKey,DynamicSubagentAgentConfigKey,+ InitiatorAuthKey,SessionDynamicSubagentRuntimeRevisionKey,SessionDynamicModelReferenceKey,SessionDynamicToolMetadataKey,@@ -1519,6 +1520,60 @@ describe("turnStep", () => {expect(observed).toEqual(expected);});+ it.each([+ {+ current: {+ attributes: {},+ authenticator: "test",+ issuer: "test",+ principalId: "bob",+ principalType: "user",+ subject: "bob",+ } satisfies SessionAuthContext,+ title: "the follow-up caller",+ },+ { current: null, title: "an anonymous follow-up caller" },+ ])("keeps $title current when cancelled before the first model call", async ({ current }) => {+ installSessionStoreMocks([createStubSession()]);+ const alice: SessionAuthContext = {+ attributes: {},+ authenticator: "test",+ issuer: "test",+ principalId: "alice",+ principalType: "user",+ subject: "alice",+ };+ vi.mocked(createExecutionNodeStep).mockImplementation(() => async () => {+ throw new TurnCancelledError();+ });++ const result = await turnStep({+ input: {+ auth: current,+ kind: "deliver",+ payloads: [{ message: "follow up" }],+ deliveryMetadata: [+ { channelKind: "eve", channelName: "eve", deliveryId: "delivery-b", payloadIndex: 0 },+ ],+ },+ sessionWritable: createTestWritable(),+ serializedContext: {+ ...createSerializedContext(),+ [AuthKey.name]: alice,+ [InitiatorAuthKey.name]: alice,+ [TurnDeliveryIdsKey.name]: ["delivery-a"],+ },+ sessionState: createStubSessionState(),+ });++ expect(result.action).toBe("cancelled");+ expect(result.serializedContext).toMatchObject({+ [AuthKey.name]: current,+ [InitiatorAuthKey.name]: alice,+ [TurnDeliveryIdsKey.name]: ["delivery-b"],+ });+ });+it("resumes a sign-in callback as the user who started it, not the last speaker", async () => {const alice: SessionAuthContext = {attributes: {},