Skip to content

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

TypeScript

fix(desktop): retire a provisional mark superseded by a newer selection intent

Alfredo Lopezf1f8f720e561
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.provisionalSelection.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.provisionalSelection.test.tsx
index 9d3ecf15c..5853c22d1 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.provisionalSelection.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/switchToChat.provisionalSelection.test.tsx
@@ -5,8 +5,9 @@
* it confirms or withdraws it; an invalidation withdraws it at once; New chat
* restores it; paging and send refuse it. Rows 1, 2 and 4 of the A17 table are
* tests j, k and m in `switchToChat.transcriptMemo.test.tsx`; row 14 (blank
- * path) is #976's `createChatFailure*` suites. Every case runs for a stateful
- * and a stateless Host.
+ * path) is #976's `createChatFailure*` suites. Row 15 covers a newer selection
+ * intent that supersedes the click without switching. Every case runs for a
+ * stateful and a stateless Host.
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { act, cleanup, waitFor } from '@testing-library/react'
@@ -422,4 +423,36 @@ describe('provisional selection (#1091 A17)', () => {
expect(shows(controller)).toContain('hello')
}
)
+
+ it.each(HOSTS)(
+ '15. %s: a same-chat notification whose catalog load fails leaves no stale mark that refuses send',
+ async host => {
+ const { controller } = await rememberA(host)
+ const { write, click } = await clickHeld(controller, host)
+ const getIndexCalls = clerum.chat.getIndex.mock.calls.length
+ clerum.chat.getIndex.mockRejectedValue(new Error('catalog unavailable'))
+ // A notification for the same chat from another route, then the route change.
+ act(() => controller.result.current.setPendingChatSelection(host, 'chat-a'))
+ act(() => controller.rerender({ navItem: 'chat' }))
+ // Witness: the selection effect tried the catalog and settled without a switch.
+ await waitFor(() =>
+ expect(clerum.chat.getIndex.mock.calls.length).toBeGreaterThan(getIndexCalls)
+ )
+ await waitFor(() => expect(controller.result.current.chatMessagesLoading).toBe(false))
+ await act(async () => {
+ write.resolve()
+ await click
+ })
+ clerum.chat.getIndex.mockResolvedValue({ chats: [], lastActiveChatId: null } as never)
+ expect(controller.result.current.activeChatId).toBe('chat-a')
+ expect(shows(controller)).toEqual([])
+ act(() => setComposerDraft('chat-a', 'hello', host))
+ await act(async () => {
+ await controller.result.current.handleSendAgentMessage('hello')
+ })
+ // The superseded click no longer owns a provisional mark, so send dispatches.
+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)
+ expect(getComposerDraft('chat-a', host)).toBe('')
+ }
+ )
})
diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
index 256866c3c..3ea5744a4 100644
--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts
@@ -559,12 +559,15 @@ export function useAgentChatController({
// #1091 A17: a chat shown from memory before its last-active write and first
// local page settled. Without the memo this state was the blank view with the
// spinner, and every path below relied on that. `revision` is the selection
- // intent that owns it; a same-row click takes it over.
+ // intent that owns it; a same-row click takes it over. A newer intent that
+ // never reaches a switch (a pending selection whose catalog load fails) leaves
+ // the mark in place, so the revision check retires it for the guards.
const provisionalSelectionRef = useRef<ProvisionalSelection | null>(null)
const provisionalSelectionFor = useCallback((agentRef: string | null, chatId: string | null) => {
const selection = provisionalSelectionRef.current
return selection &&
selection.request === activeChatSwitchRequestRef.current &&
+ selection.revision === selectionIntentRevisionRef.current &&
selection.agentRef === agentRef &&
selection.chatId === chatId
? selection