diff --git a/src/features/chat/app-server/inbound/notification-plan.ts b/src/features/chat/app-server/inbound/notification-plan.ts index 422bf22f..d36b9627 100644 --- a/src/features/chat/app-server/inbound/notification-plan.ts +++ b/src/features/chat/app-server/inbound/notification-plan.ts @@ -214,13 +214,17 @@ const STREAM_UPDATE_PLANNERS = { } satisfies ServerNotificationStatePlannerMap; const TURN_LIFECYCLE_PLANNERS = { - "turn/started": (state, notification) => - actionPlan({ - type: "turn/started", - threadId: notification.params.threadId, - turnId: notification.params.turn.id, - items: messageStreamItemsWithPendingPromptSubmitHooks(state, notification.params.turn.id), - }), + "turn/started": (state, notification) => ({ + actions: [ + { + type: "turn/started", + threadId: notification.params.threadId, + turnId: notification.params.turn.id, + items: messageStreamItemsWithPendingPromptSubmitHooks(state, notification.params.turn.id), + }, + ], + effects: [{ type: "refresh-threads" }], + }), "turn/completed": (state, notification) => { if (activeTurnId(state) !== notification.params.turn.id) return EMPTY_PLAN; return { diff --git a/tests/features/chat/protocol/inbound/handler.test.ts b/tests/features/chat/protocol/inbound/handler.test.ts index eb67f57d..e780cbe6 100644 --- a/tests/features/chat/protocol/inbound/handler.test.ts +++ b/tests/features/chat/protocol/inbound/handler.test.ts @@ -466,7 +466,8 @@ describe("ChatInboundHandler", () => { status: "completed", }, ]); - const handler = handlerForState(state); + const refreshActiveThreads = vi.fn(); + const handler = handlerForState(state, { refreshActiveThreads }); handler.handleNotification({ method: "turn/started", @@ -488,6 +489,7 @@ describe("ChatInboundHandler", () => { expect(chatStateMessageStreamItems(handler.currentState()).map((item) => item.id)).toEqual(["local-user-1", "hook-hook-1-1"]); expect(chatStateMessageStreamItems(handler.currentState())[1]).toMatchObject({ id: "hook-hook-1-1", turnId: "turn-active" }); expect(pendingTurnStart(handler.currentState())).toBeNull(); + expect(refreshActiveThreads).toHaveBeenCalledOnce(); }); it("moves pre-turn hook runs after the optimistic user message when a turn id is assigned", () => {