The Open Framework for Building Agents
fix(eve): end a steered step with step.completed (#4282)
e0-gh-vercel-connect[bot]0c0c1e5a17a0
diff --git a/.changeset/steered-step-completed.md b/.changeset/steered-step-completed.mdnew file mode 100644index 000000000..b1bc27865--- /dev/null+++ b/.changeset/steered-step-completed.md@@ -0,0 +1,5 @@+---+"eve": patch+---++A step interrupted by a steering message now ends with `step.completed` (`finishReason: "other"`, with any usage the provider reported) before the next step starts, instead of leaving its `step.started` open.diff --git a/docs/concepts/sessions-runs-and-streaming.md b/docs/concepts/sessions-runs-and-streaming.mdindex e71f94714..11e52ca50 100644--- a/docs/concepts/sessions-runs-and-streaming.md+++ b/docs/concepts/sessions-runs-and-streaming.md@@ -225,6 +225,8 @@ A structured response matches any currently pending request by ID, not only theOne delivery can answer requests from several batches. eve resumes approval-bearing batches in durable order and carries later answers forward until each batch can resume. If you answer only some approvals in a batch, eve saves those responses until the remaining approvals are answered. Meanwhile, unrelated messages can run tools and receive a completed reply. The saved partial responses neither block that reply nor trigger another model call after it.+When steering interrupts pending model generation, the interrupted step still ends with `step.completed`, carrying `finishReason: "other"` and any usage the provider reported. The correction's `message.received` and the next `step.started` for the same `turnId` follow.+Multiple steering messages retain their durable arrival order and may be folded into one input at the next boundary. A message accepted after turn settlement starts the next turn. See [message delivery and steering](./execution-model-and-durability#message-delivery-and-steering).## Cancel the in-flight turndiff --git a/packages/eve/src/harness/tool-loop-steering.integration.test.ts b/packages/eve/src/harness/tool-loop-steering.integration.test.tsindex 272fd351e..b6e3e5da1 100644--- a/packages/eve/src/harness/tool-loop-steering.integration.test.ts+++ b/packages/eve/src/harness/tool-loop-steering.integration.test.ts@@ -268,6 +268,54 @@ describe("generation steering with the real AI SDK", () => {expect(JSON.stringify(doStream.mock.calls[1]?.[0].prompt)).not.toContain("Stale");});+ it("ends the superseded step with a terminal step event before the next step starts", async () => {+ const steering = new AbortController();+ const pending = Promise.withResolvers<void>();+ const events: UnstampedMessageStreamEvent[] = [];+ const doStream = vi+ .fn<MockLanguageModelV3["doStream"]>()+ .mockImplementationOnce(async () => {+ pending.resolve();+ return { stream: new ReadableStream<Part>() };+ })+ .mockImplementationOnce(async () => ({+ stream: new ReadableStream<Part>({+ start(controller) {+ finish(controller, "Corrected 2025 report");+ },+ }),+ }));+ const model = new MockLanguageModelV3({ doStream });+ const createStep = (signal?: AbortSignal) =>+ createToolLoopHarness({+ resolveModel: async () => model,+ tools: new Map(),+ steeringSignal: signal,+ handleEvent: async (event) => {+ events.push(event);+ },+ });+ const running = createStep(steering.signal)(session(), {+ message: "Alice is preparing the 2026 report.",+ });+ await pending.promise;+ steering.abort();+ const interrupted = await running;+ expect(interrupted.steered).toBe(true);+ await createStep()(interrupted.session, {+ message: "Alice corrected the report year to 2025.",+ });+ const stepEvents = events+ .filter((event) => ["step.started", "step.completed", "step.failed"].includes(event.type))+ .map((event) => `${event.type}:${(event.data as { stepIndex: number }).stepIndex}`);+ expect(stepEvents).toEqual([+ "step.started:0",+ expect.stringMatching(/^step\.(completed|failed):0$/),+ "step.started:1",+ "step.completed:1",+ ]);+ });+it("finishes a local tool once and preserves its result for the corrected model call", async () => {const steering = new AbortController();const executing = Promise.withResolvers<void>();diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.tsindex a92c37357..66ba6bea6 100644--- a/packages/eve/src/harness/tool-loop.ts+++ b/packages/eve/src/harness/tool-loop.ts@@ -179,6 +179,7 @@ import {createAuthorizationCompletedEvent,createAuthorizationRequiredEvent,createMessageCompletedEvent,+ createStepCompletedEvent,createStepStartedEvent,} from "#protocol/message.js";import {@@ -1262,7 +1263,7 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {};let currentMessages = createRequestMessages();let interruptedUsage: TokenUsageDelta | undefined;- const finishSteeredStep = (): StepResult => {+ const finishSteeredStep = async (): Promise<StepResult> => {throwIfTurnAborted(config.abortSignal);ctx?.set(HistoryStateKey, currentMessages.historyState);if (interruptedUsage !== undefined) {@@ -1275,6 +1276,17 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {}),);}+ // The superseded step already published `step.started`. `emit` refuses+ // events once generation is interrupted, so close the step directly.+ await instrumentedEmit?.(+ createStepCompletedEvent({+ finishReason: "other",+ sequence: emissionState.sequence,+ stepIndex: emissionState.stepIndex,+ turnId: emissionState.turnId,+ usage: interruptedUsage,+ }),+ );return {steered: true,next: runStep,diff --git a/packages/eve/src/protocol/message.ts b/packages/eve/src/protocol/message.tsindex d3ff6b8a4..71108e3bf 100644--- a/packages/eve/src/protocol/message.ts+++ b/packages/eve/src/protocol/message.ts@@ -43,7 +43,8 @@ export const EVE_STREAM_LEASE_ENDED_CONTROL = {** `tool-calls` is the only non-terminal assistant step in the current* tool-loop harness. All other values indicate the assistant step ended the- * current turn.+ * current turn, except a step superseded by a steering message: it completes+ * with `other` and the turn continues with the next step.*/export type AssistantStepFinishReason =| "content-filter"