Skip to content

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

TypeScript

fix(desktop-ui): r8-l1 keep failed New chat on the blank view

Josué76eaa95f4e91
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 0d104fcee..4584b3c63 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
@@ -546,72 +546,67 @@ describe('Round 7 selection loading ownership', () => {
}
})
- it.each(['latest', 'implicit'] as const)(
- 'restores the newest existing chat after a failed create during an unconsumed %s load',
- async mode => {
- await clerum.chat.create('agent-x', 'chat-older')
- await new Promise(resolve => setTimeout(resolve, 5))
- await clerum.chat.create('agent-x', 'chat-newest')
- await clerum.chat.upsertMessages('agent-x', 'chat-newest', [
- { id: 'newest-message', role: 'user', content: 'newest history', timestamp: 3 },
- ])
- clerum.chat.getIndex.mockImplementation(agentRef => clerum.readIndex(agentRef))
- const controller = renderController({ navItem: 'agents', loadMenuData: false })
- const createError = new Error('local chat creation failed')
- let observedError: unknown
- let createPromise!: Promise<void>
- const heldIndex = deferred<Awaited<ReturnType<typeof clerum.chat.getIndex>>>()
- let routeIndexReads = 0
-
- try {
- await waitFor(() => expect(controller.result.current.chatListLoading).toBe(false))
- clerum.chat.getIndex.mockImplementation(agentRef => {
- routeIndexReads += 1
- if (routeIndexReads === 1) return heldIndex.promise
- return clerum.readIndex(agentRef)
- })
- if (mode === 'latest') {
- act(() =>
- controller.result.current.setPendingChatSelection('agent-x', null, {
- selectLatest: true,
- })
- )
- }
- await act(async () => {
- controller.rerender({ navItem: 'chat' })
- })
- await waitFor(() => expect(routeIndexReads).toBe(1))
+ it('keeps a consumed blank view blank after create failure without reloading the sidebar', async () => {
+ await clerum.chat.create('agent-x', 'chat-newest')
+ await clerum.chat.upsertMessages('agent-x', 'chat-newest', [
+ { id: 'newest-message', role: 'user', content: 'newest history', timestamp: 3 },
+ ])
+ clerum.chat.getIndex.mockImplementation(agentRef => clerum.readIndex(agentRef))
+ const controller = renderController({ navItem: 'agents', loadMenuData: false })
+ const createError = new Error('local chat creation failed')
+ let observedError: unknown
+ let createPromise!: Promise<void>
- clerum.chat.create.mockRejectedValueOnce(createError)
- act(() => {
- createPromise = controller.result.current.handleCreateChat().catch(error => {
- observedError = error
- })
- })
- await act(async () => {
- await createPromise
- })
- expect(observedError).toBe(createError)
-
- await waitFor(() => {
- expect(controller.result.current.activeChatId).toBe('chat-newest')
- expect(controller.result.current.chatMessages).toEqual(
- expect.arrayContaining([expect.objectContaining({ id: 'newest-message' })])
- )
- expect(controller.result.current.chatMessagesLoading).toBe(false)
+ try {
+ await waitFor(() => {
+ expect(controller.result.current.chatListLoading).toBe(false)
+ expect(controller.result.current.chatList).toEqual(
+ expect.arrayContaining([expect.objectContaining({ id: 'chat-newest' })])
+ )
+ })
+ act(() => {
+ controller.result.current.setPendingChatSelection('agent-x', null, {
+ suppressAutoSelect: true,
})
+ })
+ await act(async () => {
+ controller.rerender({ navItem: 'chat' })
+ })
+ await waitFor(() => {
+ expect(controller.result.current.chatListLoading).toBe(false)
+ expect(controller.result.current.activeChatId).toBeNull()
+ expect(controller.result.current.chatMessages).toEqual([])
+ expect(controller.result.current.chatMessagesLoading).toBe(false)
+ })
- await act(async () => {
- heldIndex.resolve(await clerum.readIndex('agent-x'))
+ const indexReadsBeforeCreate = clerum.chat.getIndex.mock.calls.length
+ clerum.chat.getIndex.mockRejectedValue(new Error('unexpected latest-list reload'))
+ clerum.chat.create.mockRejectedValueOnce(createError)
+ await act(async () => {
+ createPromise = controller.result.current.handleCreateChat().catch(error => {
+ observedError = error
})
- expect(controller.result.current.activeChatId).toBe('chat-newest')
- expect(controller.result.current.chatMessagesLoading).toBe(false)
- } finally {
- heldIndex.resolve(await clerum.readIndex('agent-x'))
- controller.unmount()
- }
+ await createPromise
+ await new Promise(resolve => setTimeout(resolve, 350))
+ })
+
+ expect(observedError).toBe(createError)
+ expect(clerum.chat.getIndex).toHaveBeenCalledTimes(indexReadsBeforeCreate)
+ expect({
+ activeChatId: controller.result.current.activeChatId,
+ messages: controller.result.current.chatMessages,
+ loading: controller.result.current.chatMessagesLoading,
+ list: controller.result.current.chatList,
+ }).toEqual({
+ activeChatId: null,
+ messages: [],
+ loading: false,
+ list: expect.arrayContaining([expect.objectContaining({ id: 'chat-newest' })]),
+ })
+ } finally {
+ controller.unmount()
}
- )
+ })
it('keeps the chat blank after a failed create when no latest chat exists', async () => {
clerum.chat.getIndex.mockImplementation(agentRef => clerum.readIndex(agentRef))
@@ -649,14 +644,18 @@ describe('Round 7 selection loading ownership', () => {
expect(controller.result.current.activeChatId).toBeNull()
expect(controller.result.current.chatMessages).toEqual([])
expect(controller.result.current.chatMessagesLoading).toBe(false)
- expect(controller.result.current.chatListLoading).toBe(false)
+ expect(controller.result.current.chatListLoading).toBe(true)
})
await act(async () => {
heldIndex.resolve(await clerum.readIndex('agent-x'))
})
- expect(controller.result.current.activeChatId).toBeNull()
- expect(controller.result.current.chatMessages).toEqual([])
+ await waitFor(() => {
+ expect(controller.result.current.activeChatId).toBeNull()
+ expect(controller.result.current.chatMessages).toEqual([])
+ expect(controller.result.current.chatMessagesLoading).toBe(false)
+ expect(controller.result.current.chatListLoading).toBe(false)
+ })
} finally {
heldIndex.resolve(await clerum.readIndex('agent-x'))
controller.unmount()
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 40e715fcb..2fe2fbfcf 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -507,7 +507,6 @@ export function useAgentChatController({
latestChatSessionsLoading,
hideAgent,
loadChatList,
- getChatListRequestGeneration,
loadMoreChatSessions,
setChatListLoading,
clearList,
@@ -1207,63 +1206,12 @@ export function useAgentChatController({
handleDeleteChat,
handleDeleteChatForAgent,
} = chatListCtl
- const restoreLatestChatSelection = useCallback(
- async (agentRef: string) => {
- const visible = activeChatVisibilityRef.current
- if (
- selectedAgent !== agentRef ||
- navItem !== DESKTOP_ROUTES.chat ||
- visible.selectedAgent !== agentRef ||
- visible.activeChatId !== null ||
- isHostAccessBlocked(agentRef)
- )
- return
-
- const selectionIntentRevision = beginSelectionIntent(true)
- setChatListLoading(true)
- const listLoad = loadChatList(agentRef, selectionIntentRevision)
- const listRequestGeneration = getChatListRequestGeneration()
- const result = await listLoad
- if (getChatListRequestGeneration() !== listRequestGeneration) return
- if (
- selectionIntentRevisionRef.current !== selectionIntentRevision ||
- selectedAgent !== agentRef ||
- navItem !== DESKTOP_ROUTES.chat ||
- isHostAccessBlocked(agentRef)
- ) {
- setChatListLoading(false)
- return
- }
-
- setChatListLoading(false)
- const latest = result?.merged[0]
- if (!latest) {
- settleChatMessagesLoading(selectionIntentRevision)
- return
- }
-
- autoSelectedChatIdRef.current = latest.id
- await switchToChatForIntent(agentRef, latest.id, selectionIntentRevision)
- },
- [
- beginSelectionIntent,
- getChatListRequestGeneration,
- isHostAccessBlocked,
- loadChatList,
- navItem,
- selectedAgent,
- setChatListLoading,
- settleChatMessagesLoading,
- switchToChatForIntent,
- ]
- )
useEffect(() => {
chatListHostRef.current = {
switchToChat,
beginSelectionIntent,
getSelectionIntentRevision: () => selectionIntentRevisionRef.current,
clearPendingSelection,
- restoreLatestChatSelection,
scrollChatToBottom,
dispatchSession,
clearComposerDraft,
diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.ts
index cbaa31c0f..a0ae065fa 100644
--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts
+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts
@@ -104,7 +104,6 @@ export interface ChatListControllerHost {
beginSelectionIntent: () => number
getSelectionIntentRevision: () => number
clearPendingSelection: (agentRef: string, preserveSpecificChatId?: string) => void
- restoreLatestChatSelection: (agentRef: string) => Promise<void>
scrollChatToBottom: () => void
dispatchSession: (chatKey: string, event: SessionFsmEvent) => void
clearComposerDraft: (chatId: string) => void
@@ -1063,13 +1062,6 @@ export function useChatListController({
if (restoreChatId) {
const restore = host.current?.switchToChat(agentRef, restoreChatId)
void restore?.catch(() => undefined)
- } else if (
- pendingSelection?.mode !== 'none' &&
- activeChatIdAtCreate === null &&
- !chatMessagesLoadingAtCreate
- ) {
- const restoreLatest = host.current?.restoreLatestChatSelection(agentRef)
- void restoreLatest?.catch(() => undefined)
}
}
throw error
@@ -1770,8 +1762,6 @@ export function useChatListController({
// eslint-disable-next-line react-hooks/exhaustive-deps
[latestChatSessions, isHostAccessBlocked, hostAuthorityRevision]
)
- const getChatListRequestGeneration = useCallback(() => requestGenerationRef.current, [])
-
return {
// State (public contract, re-exported unchanged by the parent).
chatList: selectedAgent && isHostAccessBlocked(selectedAgent) ? [] : chatList,
@@ -1791,7 +1781,6 @@ export function useChatListController({
handleDeleteChatForAgent,
// Loader + list-loading control (parent agent-selection effect).
loadChatList,
- getChatListRequestGeneration,
loadMoreChatSessions,
setChatListLoading,
clearList,