Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

test(eve): repro retryable stream status for an expired session (#4722)

roboeve[bot]7f5a5e6bf571
diff --git a/.changeset/expired-session-stream.md b/.changeset/expired-session-stream.md
new file mode 100644
index 000000000..f99b6f595
--- /dev/null
+++ b/.changeset/expired-session-stream.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Reading a session stream whose history passed the World's retention now returns `410` with `code: "session_expired"` instead of a retryable `503` or `404`. The TypeScript client fails on the first response instead of retrying for about 38 seconds.
diff --git a/docs/channels/eve.mdx b/docs/channels/eve.mdx
index 599d5bad6..078f3039d 100644
--- a/docs/channels/eve.mdx
+++ b/docs/channels/eve.mdx
@@ -203,6 +203,8 @@ Stream a session as newline-delimited JSON from `GET /eve/v1/session/:sessionId/
Following a stranded session's stream returns `409 session_stranded`, just like a send. The TypeScript client reports `ClientSessionStrandedError` without retrying. Pass `follow=false` to read the recorded history instead: the response ends at the durable tail, carries the `x-eve-stream-tail-index` header, and never inspects or changes the session, so it works before a reset. A reset attempts to append `session.failed` with code `session_stranded` and close the stream. Existing readers finish when they receive that terminal event.
+After a session ends, the World keeps its stream only for its retention period. Reading a stream past that point returns `410 session_expired`. The history is gone, so the TypeScript client fails on the first response with a `ClientError` whose `code` is `"session_expired"`, without retrying.
+
### Cancel a turn
Post to `/eve/v1/session/:sessionId/cancel` to request cancellation of the active turn. You can include the observed `turnId` to keep a late request from cancelling a newer turn. Cancellation is asynchronous; confirm the turn boundary on the stream as `turn.cancelled` followed by `session.waiting`.
diff --git a/packages/eve/src/client/open-stream.test.ts b/packages/eve/src/client/open-stream.test.ts
index f7e9794f7..60152cf27 100644
--- a/packages/eve/src/client/open-stream.test.ts
+++ b/packages/eve/src/client/open-stream.test.ts
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { followStreamIterable, openStreamBody } from "./open-stream.js";
-import { ClientSessionStrandedError } from "#client/client-error.js";
+import { ClientError, ClientSessionStrandedError } from "#client/client-error.js";
import type { StreamReconnectPolicy } from "#client/types.js";
import {
EVE_MESSAGE_STREAM_VERSION,
@@ -70,6 +70,26 @@ describe("openStreamBody", () => {
expect(fetchMock).toHaveBeenCalledOnce();
});
+ it("stops on the first response when the session history expired", async () => {
+ const fetchMock = vi.fn(async () =>
+ Response.json(
+ { code: "session_expired", error: "Session history is no longer available.", ok: false },
+ { status: 410 },
+ ),
+ );
+ vi.stubGlobal("fetch", fetchMock);
+ const stream = followStreamIterable({
+ host: "https://agent.example",
+ path: "/eve/v1/session/session_1/stream",
+ resolveHeaders: async () => new Headers(),
+ startIndex: 0,
+ });
+ const error = await stream.next().catch((caught: unknown) => caught);
+ expect(error).toBeInstanceOf(ClientError);
+ expect(error).toMatchObject({ code: "session_expired", status: 410 });
+ expect(fetchMock).toHaveBeenCalledOnce();
+ });
+
it("advertises support for versioned stream controls", async () => {
let requestUrl: URL | undefined;
vi.stubGlobal(
diff --git a/packages/eve/src/eve-channel/request.ts b/packages/eve/src/eve-channel/request.ts
index c7d0f0805..559661b95 100644
--- a/packages/eve/src/eve-channel/request.ts
+++ b/packages/eve/src/eve-channel/request.ts
@@ -11,7 +11,10 @@ import type { Session } from "#channel/session.js";
import { strandedSessionResponse } from "#eve-channel/support.js";
import { parseSessionCallback } from "#channel/session-callback.js";
import { hasInternalRefScheme } from "#internal/attachments/url-refs.js";
-import { isMissingWorkflowRunError } from "#internal/workflow/is-inactive-workflow-run-error.js";
+import {
+ isExpiredWorkflowRunError,
+ isMissingWorkflowRunError,
+} from "#internal/workflow/is-inactive-workflow-run-error.js";
import {
EVE_MESSAGE_STREAM_CONTENT_TYPE,
EVE_MESSAGE_STREAM_FORMAT,
@@ -344,6 +347,12 @@ export async function createSessionStreamResponse(
} catch (error) {
const stranded = strandedSessionResponse(error);
if (stranded !== undefined) return stranded;
+ if (isExpiredWorkflowRunError(error)) {
+ return Response.json(
+ { code: "session_expired", error: "Session history is no longer available.", ok: false },
+ { headers: { "cache-control": "no-store" }, status: 410 },
+ );
+ }
const notFound = isMissingWorkflowRunError(error);
return Response.json(
{ error: notFound ? "Session not found." : "Session stream unavailable.", ok: false },
diff --git a/packages/eve/src/internal/workflow/is-inactive-workflow-run-error.ts b/packages/eve/src/internal/workflow/is-inactive-workflow-run-error.ts
index c38f36bd8..980021d51 100644
--- a/packages/eve/src/internal/workflow/is-inactive-workflow-run-error.ts
+++ b/packages/eve/src/internal/workflow/is-inactive-workflow-run-error.ts
@@ -1,10 +1,18 @@
import {
EntityConflictError,
RunExpiredError,
+ StreamExpiredError,
WorkflowRunNotFoundError,
} from "#compiled/@workflow/errors/index.js";
import { walkCauseChain } from "#shared/errors.js";
+/** The run's data passed the World's retention; retrying cannot bring it back. */
+export function isExpiredWorkflowRunError(error: unknown): boolean {
+ return [...walkCauseChain(error)].some(
+ (cause) => RunExpiredError.is(cause) || StreamExpiredError.is(cause),
+ );
+}
+
export function isMissingWorkflowRunError(error: unknown): boolean {
return [...walkCauseChain(error)].some(
(cause) => WorkflowRunNotFoundError.is(cause) || RunExpiredError.is(cause),
diff --git a/packages/eve/src/public/channels/eve.test.ts b/packages/eve/src/public/channels/eve.test.ts
index 87760e430..e1aa1c69b 100644
--- a/packages/eve/src/public/channels/eve.test.ts
+++ b/packages/eve/src/public/channels/eve.test.ts
@@ -1,7 +1,11 @@
import type { FilePart, UserContent } from "ai";
import { REMOTE_AGENT_PROTOCOL_VERSION } from "#protocol/remote-agent-protocol.js";
import { describe, expect, it, vi } from "vitest";
-import { WorkflowRunNotFoundError } from "#compiled/@workflow/errors/index.js";
+import {
+ RunExpiredError,
+ StreamExpiredError,
+ WorkflowRunNotFoundError,
+} from "#compiled/@workflow/errors/index.js";
import { buildAdapterContext } from "#channel/adapter-context.js";
import { callAdapterEventHandler, type ChannelAdapter } from "#channel/adapter.js";
@@ -644,6 +648,19 @@ describe("eveChannel — stream cursor", () => {
expect(await response.json()).toEqual({ error: "Session not found.", ok: false });
});
+ it.each([
+ ["stream", new StreamExpiredError("Stream expired.", "test-session-id")],
+ ["run", new RunExpiredError("Run expired.", "test-session-id")],
+ ])("returns a terminal 410 when the session %s passed retention", async (_, error) => {
+ const handler = createEveStreamHandler({ auth: none() });
+ handler.getStreamTailIndex.mockRejectedValueOnce(error);
+
+ const response = await handler.fetch("https://eve.test/eve/v1/session/test-session-id/stream");
+
+ expect(response.status).toBe(410);
+ expect(await response.json()).toMatchObject({ code: "session_expired", ok: false });
+ });
+
it("cancels the early-opened event stream when the tail lookup fails", async () => {
const handler = createEveStreamHandler({ auth: none() });
const cancelled = vi.fn();