Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): drop the remembered transcript when the disk page is empty
Alfredo Lopez16d3c570cdce
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsxindex d8f573545..4b825f6f2 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.transcriptMemo.test.tsx@@ -195,6 +195,52 @@ describe('switchToChat transcript memo (#1091 A9)', () => {})+ it.each(HOSTS)(+ 'b2. %s: an empty disk page (a tombstone this session has not loaded) drops the remembered transcript',+ async host => {+ const disk = { 'chat-a': transcript('chat-a'), 'chat-b': transcript('chat-b') }+ serveDisk(disk)+ const controller = mount(host)+ await settleMount()+ await open(controller, host, 'chat-a')+ await open(controller, host, 'chat-b')+ // `ChatStore.loadMessages` returns [] once the index carries a tombstone+ // for the chat; the renderer's deleted-chat set has not been refreshed.+ disk['chat-a'] = []++ const diskRead = deferred<AgentChatMessage[]>()+ clerum.chat.loadMessages.mockImplementationOnce(() => diskRead.promise)+ const reopenStart = frames.length+ let reopen!: Promise<void>+ await act(async () => {+ reopen = controller.result.current.switchToChat(host, 'chat-a')+ })+ // Witnesses: the reopen was a memo hit and it read the disk page.+ expectOnlyTranscript(frames.slice(reopenStart), 'chat-a', transcript('chat-a'))+ expect(clerum.chat.loadMessages).toHaveBeenLastCalledWith(host, 'chat-a', 80, undefined)+ await act(async () => {+ diskRead.resolve([])+ await reopen+ })+ expect(controller.result.current.chatMessages).toEqual([])++ await open(controller, host, 'chat-b')+ const againStart = frames.length+ const chatARead = deferred<AgentChatMessage[]>()+ clerum.chat.loadMessages.mockImplementationOnce(() => chatARead.promise)+ let again!: Promise<void>+ await act(async () => {+ again = controller.result.current.switchToChat(host, 'chat-a')+ })+ // The entry is gone: the next open is blank behind the spinner, not remembered.+ expect(blankFrame(frames.slice(againStart), 'chat-a')).toBe(true)+ await act(async () => {+ chatARead.resolve([])+ await again+ })+ }+ )+it.each(HOSTS)('c. %s: when the disk page matches, the remembered list and paging offset are kept',async host => {diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex 49052e7d0..6d289b2b5 100644--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@ -1114,17 +1114,20 @@ export function useAgentChatController({} catch (error) {console.warn('[chat-history] failed to load local messages', { agentRef, chatId, error })}- // #1091 A9: the remembered transcript is already on screen. Keep it when- // the disk page is its newest part (or the disk read returned nothing);- // otherwise the disk page wins, e.g. a reply persisted while the chat was- // hidden. The Host reconcile below runs in both cases.+ // #1091 A9: the remembered transcript is already on screen. Keep it only+ // when the disk page is its newest part; otherwise the disk page wins,+ // e.g. a reply persisted while the chat was hidden. An empty page also+ // wins: `loadMessages` returns [] for a durably tombstoned chat, which+ // this session may not have loaded into `deletedChatIdsByAgentRef` yet,+ // and recording [] drops the memo entry. The Host reconcile below runs+ // in both cases.const keepRemembered =remembered !== undefined &&- (cached.length === 0 ||- sameMessageSequence(- remembered.messages.slice(-cached.length),- cached as AgentChatMessage[]- ))+ cached.length > 0 &&+ sameMessageSequence(+ remembered.messages.slice(-cached.length),+ cached as AgentChatMessage[]+ )if (keepRemembered) {cached = remembered.messages as typeof cachedif (!isStillActive()) return