Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): settle a superseded rename whose local write fails
Alfredo Lopez1c24949dcd2c
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/chatListRenameCatalogOrder.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/chatListRenameCatalogOrder.test.tsxindex f9af97a3a..aeefce0c2 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/chatListRenameCatalogOrder.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/chatListRenameCatalogOrder.test.tsx@@ -512,4 +512,55 @@ describe('re-renames', () => {// Nothing is pending any more, so a later server title is accepted.await expectFreshPageAccepted(view)})++ it('T6d: two overlapping failed local writes leave no stuck pending rename', async () => {+ serveImmediately()+ const view = await mountWithOldTitle()+ const firstPatch = deferred()+ gatePatch(firstPatch.promise)+ let first: Promise<void> | undefined+ await act(async () => {+ first = view.result.current.handleRenameChatForAgent(AGENT, 'c1', 'first')+ })+ await waitFor(() => expect(patchTitles).toEqual(['first']))++ const secondReply = deferred()+ const thirdReply = deferred()+ renameIpcBehaviour.set('second', { gate: secondReply.promise, fail: true })+ renameIpcBehaviour.set('third', { gate: thirdReply.promise, fail: true })+ let second: Promise<void> | undefined+ let third: Promise<void> | undefined+ await act(async () => {+ second = view.result.current.handleRenameChatForAgent(AGENT, 'c1', 'second')+ })+ await waitFor(() => expect(renameIpcTitles).toEqual(['first', 'second']))+ await act(async () => {+ third = view.result.current.handleRenameChatForAgent(AGENT, 'c1', 'third')+ })+ await waitFor(() => expect(renameIpcTitles).toEqual(['first', 'second', 'third']))++ // The superseded second write fails first, then the current third one.+ const errors: unknown[] = []+ await act(async () => {+ secondReply.resolve()+ await second?.catch(error => errors.push(error))+ })+ await act(async () => {+ thirdReply.resolve()+ await third?.catch(error => errors.push(error))+ })+ expect(errors).toHaveLength(2)++ await act(async () => {+ firstPatch.resolve()+ await first+ })+ // Witness: only the first rename reached the server.+ expect(patchTitles).toEqual(['first'])+ expect(serverTitle).toBe('first')+ expect(await diskTitleAfterRestart()).toBe('first')++ // No failed rename is left pending, so a later server title is accepted.+ await expectFreshPageAccepted(view)+ })})diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.tsindex 7e424bb8c..e1e21b191 100644--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts@@ -1422,12 +1422,13 @@ export function useChatListController({try {await applyLocalTitleOnly(agentRef, chatId, newTitle)} catch (error) {- // The local title did not change. Hand the key back to the rename this- // one replaced while that rename is still unsettled, so its PATCH keeps- // protecting its title; otherwise the key has no pending rename left.- if (pendingRenamesRef.current.get(key) === entry) {- if (existing && !existing.settled) pendingRenamesRef.current.set(key, existing)- else settlePendingRename(key, entry)+ // The local title did not change, so this rename is over. When it is+ // still current, hand the key back to the rename it replaced while that+ // rename is unsettled, so its PATCH keeps protecting its title.+ if (pendingRenamesRef.current.get(key) === entry && existing && !existing.settled) {+ pendingRenamesRef.current.set(key, existing)+ } else {+ settlePendingRename(key, entry)}throw error}