Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

test(eve): reproduce per-event publishes during session resume (#3865)

e0-gh-vercel-connect[bot]8cac212f2257
diff --git a/.changeset/resume-publish-once.md b/.changeset/resume-publish-once.md
new file mode 100644
index 000000000..e0677c5d2
--- /dev/null
+++ b/.changeset/resume-publish-once.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Fix `useEveAgent({ resume: true })` crashing with React error #185 ("Maximum update depth exceeded") when a saved session replays more than ~50 events. The store now publishes once after catch-up instead of once per replayed event.
diff --git a/packages/eve/src/client/eve-agent-store.test.ts b/packages/eve/src/client/eve-agent-store.test.ts
index 8e7ded0d9..72a106480 100644
--- a/packages/eve/src/client/eve-agent-store.test.ts
+++ b/packages/eve/src/client/eve-agent-store.test.ts
@@ -985,6 +985,41 @@ describe("EveAgentStore session resume", () => {
},
);
+ it("publishes a replayed session once after catch-up instead of once per event", async () => {
+ // Regression for #3862: a notification per replayed event forces one React commit per
+ // event inside a single task, which trips React's nested update limit past ~50 events.
+ const events = stampTestEvents(
+ Array.from({ length: 25 }, (_, index) => [
+ createMessageReceivedEvent({
+ message: `Question ${index}`,
+ sequence: 0,
+ turnId: `turn_${index}`,
+ }),
+ createMessageCompletedEvent({
+ finishReason: "stop",
+ message: `Answer ${index}`,
+ sequence: 1,
+ stepIndex: 0,
+ turnId: `turn_${index}`,
+ }),
+ createSessionWaitingEvent(),
+ ]).flat() as UnstampedMessageStreamEvent[],
+ );
+ vi.spyOn(globalThis, "fetch").mockResolvedValueOnce(boundedStreamResponse(events));
+ const store = createStore({
+ initialSession: { sessionId: "session_1", streamIndex: events.length },
+ reducer: defaultMessageReducer(),
+ });
+ const published: string[] = [];
+ store.subscribe(() => {
+ published.push(`${store.snapshot.status}:${store.snapshot.events.length}`);
+ });
+
+ await store.resume();
+
+ expect(published).toEqual(["resuming:0", `ready:${events.length}`]);
+ });
+
it("finishes a settled replay without waiting for the probe stream to idle", async () => {
const events = turnEvents();
const probe = controlledStreamResponse();
diff --git a/packages/eve/src/client/eve-agent-store.ts b/packages/eve/src/client/eve-agent-store.ts
index 7d0c680cd..9fc046974 100644
--- a/packages/eve/src/client/eve-agent-store.ts
+++ b/packages/eve/src/client/eve-agent-store.ts
@@ -604,7 +604,9 @@ export class EveAgentStore<TData> {
if (this.#activeTurn === undefined && settled) this.#status = "ready";
}
this.#callbacks.onSessionChange?.(this.#session?.state);
- this.#publish();
+ // Catch-up publishes once when it ends; a notification per replayed event would force one
+ // React commit per event within a single task and trip React's nested update limit.
+ if (this.#status !== "resuming") this.#publish();
if (this.#activeTurn === undefined && wasStreaming && settled) {
this.#callbacks.onFinish?.(this.#snapshot);
}