Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop-ui): r7-l1 read live chat selection state

Josué1cd3e112a995
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx
index 7a99c0596..cdc56588e 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/selectionLoadingOwnership.r7.characterization.test.tsx
@@ -160,4 +160,56 @@ describe('Round 7 selection loading ownership', () => {
controller.unmount()
}
})
+
+ it('restores a same-tick chat switch when New chat creation fails', async () => {
+ await clerum.chat.create('agent-x', 'chat-b')
+ await clerum.chat.upsertMessages('agent-x', 'chat-b', [
+ { id: 'chat-b-message', role: 'user', content: 'chat B history', timestamp: 2 },
+ ])
+ const heldSwitch = holdLastActive('chat-b')
+ const controller = renderController({ loadMenuData: false })
+ const createError = new Error('local chat creation failed')
+ clerum.chat.create.mockRejectedValueOnce(createError)
+ let switchPromise!: Promise<void>
+ let createPromise!: Promise<void>
+ let observedError: unknown
+
+ try {
+ await waitFor(() => expect(controller.result.current.chatListLoading).toBe(false))
+ act(() => {
+ switchPromise = controller.result.current.handleSelectChat('chat-b')
+ createPromise = controller.result.current.handleCreateChat().catch(error => {
+ observedError = error
+ })
+ })
+ await act(async () => {
+ await heldSwitch.entered.promise
+ })
+ await act(async () => {
+ await createPromise
+ })
+ expect(observedError).toBe(createError)
+
+ await waitFor(() => {
+ expect(controller.result.current.activeChatId).toBe('chat-b')
+ expect(controller.result.current.chatMessages).toEqual(
+ expect.arrayContaining([expect.objectContaining({ id: 'chat-b-message' })])
+ )
+ expect(controller.result.current.chatMessagesLoading).toBe(false)
+ })
+
+ await act(async () => {
+ heldSwitch.release.resolve()
+ await switchPromise
+ })
+ expect(controller.result.current.activeChatId).toBe('chat-b')
+ expect(controller.result.current.chatMessagesLoading).toBe(false)
+ } finally {
+ heldSwitch.release.resolve()
+ await act(async () => {
+ await switchPromise?.catch(() => undefined)
+ })
+ controller.unmount()
+ }
+ })
})
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 9202c49c2..bd054ea81 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -1202,8 +1202,8 @@ export function useAgentChatController({
scrollChatToBottom,
dispatchSession,
clearComposerDraft,
- getActiveChatId: () => activeChatId,
- getChatMessagesLoading: () => chatMessagesLoading,
+ getActiveChatId: () => activeChatVisibilityRef.current.activeChatId,
+ getChatMessagesLoading: () => chatMessagesLoadingRef.current,
clearChatMessagesLoading: () => setChatMessagesLoading(false),
getAutoSelectedChatId: () => autoSelectedChatIdRef.current,
markAutoSelectedChat: chatId => {