Skip to content

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

TypeScript

test(desktop): keep a Host's rename budget when another Host's poll arrives

Alfredo Lopez46c8dbea164b
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx
index 277b57abc..909ead555 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx
@@ -381,6 +381,65 @@ describe('per-Host Latest sessions publication', () => {
).toBe('Renamed B')
})
+ it("does not spend another Host's rename budget when the selected Host's poll arrives", async () => {
+ // Every A read shares one deferred page; B's reads never resolve, so B's own
+ // arrival cannot retry B's rename.
+ const pendingA = deferred<SessionsListResult>()
+ clerum.chat.getIndex.mockImplementation(async (agentRef: string) =>
+ localIndex([{ id: `${agentRef}-chat`, title: `${agentRef} original` }])
+ )
+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>
+ agentRef === HOST_A ? pendingA.promise : new Promise<SessionsListResult>(() => undefined)
+ )
+ const failed = new Set<string>()
+ clerum.rpc.renameSession.mockImplementation(
+ async (agentRef: string, _agent: string, _chatId: string, title: string) => {
+ if (!failed.has(agentRef)) {
+ failed.add(agentRef)
+ throw new Error('fetch failed')
+ }
+ return { title }
+ }
+ )
+ const controller = renderController({ selectedAgent: HOST_A, agentNames: HOSTS })
+ await waitFor(() =>
+ expect(clerum.rpc.listSessions).toHaveBeenCalledWith(HOST_A, undefined, expect.anything())
+ )
+ const attemptsFor = (agentRef: string) =>
+ clerum.rpc.renameSession.mock.calls.filter(call => call[0] === agentRef).length
+
+ for (const agentRef of HOSTS) {
+ await act(async () => {
+ await controller.result.current.handleRenameChatForAgent(
+ agentRef,
+ `${agentRef}-chat`,
+ `Renamed ${agentRef}`
+ )
+ })
+ }
+ expect(attemptsFor(HOST_A)).toBe(1)
+ expect(attemptsFor(HOST_B)).toBe(1)
+
+ await act(async () => {
+ pendingA.resolve(serverSessions([{ agent: HOST_A, chatId: 'a-remote', title: 'Server A' }]))
+ await pendingA.promise
+ })
+ // Liveness: the selected Host's poll was applied and retried its own rename.
+ await waitFor(() =>
+ expect(controller.result.current.chatList.map(chat => chat.id)).toContain('a-remote')
+ )
+ await waitFor(() => expect(attemptsFor(HOST_A)).toBe(2))
+ // B's queued rename kept its budget: A's poll did not PATCH it.
+ expect(attemptsFor(HOST_B)).toBe(1)
+
+ // A reconnect retries every Host's offline rename.
+ await act(async () => {
+ window.dispatchEvent(new Event('online'))
+ })
+ await waitFor(() => expect(attemptsFor(HOST_B)).toBe(2))
+ expect(attemptsFor(HOST_A)).toBe(2)
+ })
+
it('filters a confirmed tombstone created while that Host response is pending', async () => {
const pendingB = deferred<SessionsListResult>()
clerum.chat.getIndex.mockResolvedValue(localIndex([]))
diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.ts
index 24f6b65ed..2099b2f52 100644
--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts
+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts
@@ -43,7 +43,8 @@ async function readSessionCatalog(
}
// R1-M1: an 'offline' pending rename (a genuine network / 5xx failure) retries on
-// every listSessions poll and every `window 'online'` event. A deterministic 5xx
+// its own Host's listSessions polls and on every `window 'online'` event; another
+// Host's poll does not spend its budget. A deterministic 5xx
// / 501 would otherwise re-issue the PATCH forever, so cap the auto-retries per
// entry: 5 rides out a transient blip and a few poll cycles before giving up,
// while keeping the request volume bounded. Only 'offline' failures count toward