Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): stop recording cancelled model calls as failed steps (#5025)

Matan Kushnerfc4dbd055405
diff --git a/.changeset/cancelled-turn-step-not-error.md b/.changeset/cancelled-turn-step-not-error.md
new file mode 100644
index 000000000..2ce6d656c
--- /dev/null
+++ b/.changeset/cancelled-turn-step-not-error.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Cancelling a turn while the model is responding no longer marks its `agent.step` span as an error, so user-initiated stops stop showing up as failures in error tracking.
diff --git a/packages/eve/src/harness/model-call/call.ts b/packages/eve/src/harness/model-call/call.ts
index ef4d67a62..ad4acf220 100644
--- a/packages/eve/src/harness/model-call/call.ts
+++ b/packages/eve/src/harness/model-call/call.ts
@@ -402,7 +402,8 @@ export class ModelCaller {
await attempt?.complete();
return result;
} catch (error) {
- if (generation.interrupted) await attempt?.complete();
+ // A steered or cancelled generation stopped on purpose; only other failures are errors.
+ if (generation.interrupted || generation.signal.aborted) await attempt?.complete();
else await attempt?.fail(error);
generation.check();
// Only the output timeout above aborts the stream without aborting our signal.
diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.ts
index db4bee450..6894483c8 100644
--- a/packages/eve/src/harness/tool-loop.test.ts
+++ b/packages/eve/src/harness/tool-loop.test.ts
@@ -10291,6 +10291,46 @@ describe("createToolLoopHarness", () => {
);
});
+ it("completes rather than fails the attempt when the turn is cancelled mid-call", async () => {
+ const abortController = new AbortController();
+ vi.mocked(ToolLoopAgent).mockImplementation(function (this: ToolLoopAgent) {
+ this.stream = vi.fn().mockImplementation(async () => {
+ // A cancellation can reach the step without its reason, so the stream
+ // rejects with the platform's plain AbortError.
+ abortController.abort();
+ throw abortController.signal.reason;
+ });
+ return this;
+ } as MockAgentConstructor);
+ const attemptCompleted = vi.fn();
+ const attemptFailed = vi.fn();
+ const hooks = createInstrumentationHooks([
+ {
+ events: {
+ "step.attempt.completed": attemptCompleted,
+ "step.attempt.failed": attemptFailed,
+ },
+ name: "attempt",
+ },
+ ]);
+ const runStep = createToolLoopHarness(
+ createTestConfig(undefined, {
+ abortSignal: abortController.signal,
+ instrumentation: bindHookInstrumentation(hooks),
+ }),
+ );
+
+ await expect(runStep(createTestSession(), { message: "hi" })).rejects.toBeInstanceOf(
+ TurnCancelledError,
+ );
+
+ expect(attemptFailed).not.toHaveBeenCalled();
+ expect(attemptCompleted).toHaveBeenCalledExactlyOnceWith(
+ expect.objectContaining({ type: "step.attempt.completed" }),
+ expect.anything(),
+ );
+ });
+
it("publishes a delegation action when the AI SDK skips execution callbacks", async () => {
setupMockAgent({
finishReason: "tool-calls",