Skip to content

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

TypeScript

fix(desktop): withdraw a remembered transcript only for its own selection intent

Alfredo Lopezcd9b9a5c734e
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.tsx
index f434a075a..d51919ad5 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
@@ -727,4 +727,58 @@ describe('switchToChat transcript memo (#1091 A9)', () => {
expect(clerum.chat.loadMessages.mock.calls.length).toBe(readsBefore)
}
)
+
+ it.each(HOSTS)(
+ "m. %s: a superseded click's failed write leaves the newer click's transcript and memo entry",
+ 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')
+ const firstWrite = deferred<void>()
+ const secondWrite = deferred<void>()
+ clerum.chat.setLastActive
+ .mockImplementationOnce(() => firstWrite.promise)
+ .mockImplementationOnce(() => secondWrite.promise)
+ const reopenStart = frames.length
+ let firstClick!: Promise<void>
+ let secondClick!: Promise<void>
+ await act(async () => {
+ firstClick = controller.result.current.switchToChat(host, 'chat-a').catch(() => undefined)
+ })
+ await act(async () => {
+ secondClick = controller.result.current.switchToChat(host, 'chat-a')
+ })
+ // Liveness: both clicks issued their own last-active write.
+ expect(
+ clerum.chat.setLastActive.mock.calls.filter(call => call[1] === 'chat-a').length
+ ).toBeGreaterThanOrEqual(3)
+ await act(async () => {
+ firstWrite.reject(new Error('last-active write failed'))
+ await firstClick
+ })
+ // The newer click still owns the view: its transcript stays on screen.
+ expectOnlyTranscript(frames.slice(reopenStart), 'chat-a', disk['chat-a'])
+ await act(async () => {
+ secondWrite.resolve()
+ await secondClick
+ })
+ // The memo entry survived: a later return paints it before the write.
+ await open(controller, host, 'chat-b')
+ const persisted = deferred<void>()
+ clerum.chat.setLastActive.mockImplementationOnce(() => persisted.promise)
+ const returnStart = frames.length
+ let returning!: Promise<void>
+ await act(async () => {
+ returning = controller.result.current.switchToChat(host, 'chat-a')
+ })
+ expectOnlyTranscript(frames.slice(returnStart), 'chat-a', disk['chat-a'])
+ await act(async () => {
+ persisted.resolve()
+ await returning
+ })
+ }
+ )
})
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 75895f3b4..8f99850d0 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -1122,11 +1122,18 @@ export function useAgentChatController({
// when that write fails or the chat stops being viewable meanwhile.
const remembered = canReuseActiveSwitch ? undefined : rememberedTranscript(agentRef, chatId)
if (!canReuseActiveSwitch) presentSelectedTranscript(remembered)
- // Clears the remembered transcript while this chat is still the visible
- // one; the loading state stays with whichever selection intent owns it.
+ // Clears the remembered transcript while this selection intent still owns
+ // the visible chat; a newer click on the same row owns it from then on.
const withdrawRemembered = () => {
const view = activeChatVisibilityRef.current
- if (!remembered || view.selectedAgent !== agentRef || view.activeChatId !== chatId) return
+ if (
+ !remembered ||
+ selectionIntentRevisionRef.current !== selectionIntentRevision ||
+ view.selectedAgent !== agentRef ||
+ view.activeChatId !== chatId
+ ) {
+ return
+ }
cancelOlderMessagesLoad()
chatMessagesRef.current = []
setChatMessages([])