Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
perf(desktop): publish each Host's latest sessions as its catalog arrives
Alfredo Lopezb319b516eaf8
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsxnew file mode 100644index 000000000..126ba08cd--- /dev/null+++ b/desktop-app/ui/src/hooks/domain/__tests__/chatListPerHostPublication.test.tsx@@ -0,0 +1,369 @@+// @vitest-environment jsdom+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { act, cleanup, waitFor } from '@testing-library/react'+import type { SessionsListResult } from '../../../../../src/types'+import { MAX_RENAME_SYNC_ATTEMPTS } from '../useChatListController'+import { deferred, localIndex, serverSessions } from './__fixtures__/catalogFixtures'+import { renderController } from './__fixtures__/controllerHarness'+import { ipcHttpError } from './__fixtures__/ipcErrors'+import { type MockClerum, installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++const HOST_A = 'stateful-host'+const HOST_B = 'stateless-host'+const HOSTS = [HOST_A, HOST_B]++let clerum: MockClerum++beforeEach(() => {+ clerum = installMockClerum()+ // Keep the real catalog cache's five-second TTL stable across rerenders.+ vi.useFakeTimers({ toFake: ['Date'] })+ vi.setSystemTime(new Date('2026-10-14T12:00:00.000Z'))+})++afterEach(() => {+ cleanup()+ vi.useRealTimers()+ vi.restoreAllMocks()+ uninstallMockClerum()+})++describe('per-Host Latest sessions publication', () => {+ it.each([+ [HOST_A, HOST_B],+ [HOST_B, HOST_A],+ ])('publishes %s while %s is pending and preserves its rows on arrival', async (first, last) => {+ const pendingLast = deferred<SessionsListResult>()+ let lastResolved = false+ clerum.chat.getIndex.mockResolvedValue(localIndex([]))+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>+ agentRef === last+ ? pendingLast.promise.then(page => {+ lastResolved = true+ return page+ })+ : Promise.resolve(+ serverSessions([{ agent: first, chatId: 'shared-id', title: `${first} chat` }])+ )+ )+ const controller = renderController({ selectedAgent: null, agentNames: HOSTS })++ // Both reads were dispatched; the second Host really is still pending.+ await waitFor(() =>+ expect(clerum.rpc.listSessions).toHaveBeenCalledWith(last, undefined, {+ agent: last,+ limit: 50,+ })+ )+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.agentRef)).toEqual([+ first,+ ])+ )+ expect(lastResolved).toBe(false)+ expect(controller.result.current.latestChatSessionsLoading).toBe(false)+ const firstRow = controller.result.current.latestChatSessions[0]!+ expect(firstRow.remote).toBe(true)+ expect(firstRow.title).toBe(`${first} chat`)++ await act(async () => {+ pendingLast.resolve(+ serverSessions([{ agent: last, chatId: 'shared-id', title: `${last} chat` }])+ )+ await pendingLast.promise+ })++ await waitFor(() => expect(controller.result.current.latestChatSessions).toHaveLength(2))+ expect(lastResolved).toBe(true)+ expect(controller.result.current.latestChatSessions.find(chat => chat.agentRef === first)).toBe(+ firstRow+ )+ expect(+ controller.result.current.latestChatSessions.find(chat => chat.agentRef === last)+ ).toMatchObject({+ id: 'shared-id',+ title: `${last} chat`,+ remote: true,+ })+ })++ it('discards a cancelled Host response while retaining the remaining Host rows', async () => {+ const pendingB = deferred<SessionsListResult>()+ let bResolved = false+ clerum.chat.getIndex.mockResolvedValue(localIndex([]))+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>+ agentRef === HOST_B+ ? pendingB.promise.then(page => {+ bResolved = true+ return page+ })+ : Promise.resolve(serverSessions([{ agent: HOST_A, chatId: 'remote-a' }]))+ )+ const controller = renderController({ selectedAgent: null, agentNames: HOSTS })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([+ 'remote-a',+ ])+ )+ expect(clerum.rpc.listSessions).toHaveBeenCalledWith(HOST_B, undefined, {+ agent: HOST_B,+ limit: 50,+ })++ controller.rerender({ selectedAgent: null, agentNames: [HOST_A] })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([+ 'remote-a',+ ])+ )+ await act(async () => {+ pendingB.resolve(serverSessions([{ agent: HOST_B, chatId: 'cancelled-b' }]))+ await pendingB.promise+ })++ expect(bResolved).toBe(true)+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual(['remote-a'])+ })++ it('discards an earlier authority scope response while retaining current Host rows', async () => {+ const pendingOldB = deferred<SessionsListResult>()+ const pendingCurrentB = deferred<SessionsListResult>()+ let oldBResolved = false+ let bReads = 0+ clerum.chat.getIndex.mockResolvedValue(localIndex([]))+ clerum.rpc.listSessions.mockImplementation((agentRef: string) => {+ if (agentRef === HOST_A) {+ return Promise.resolve(serverSessions([{ agent: HOST_A, chatId: 'remote-a' }]))+ }+ bReads += 1+ return bReads === 1+ ? pendingOldB.promise.then(page => {+ oldBResolved = true+ return page+ })+ : pendingCurrentB.promise+ })+ const controller = renderController({ selectedAgent: null, agentNames: HOSTS })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([+ 'remote-a',+ ])+ )+ expect(bReads).toBe(1)++ controller.rerender({+ selectedAgent: null,+ agentNames: HOSTS,+ currentTeamId: 'team-2',+ chatAuthorityTeamId: 'team-2',+ })+ await waitFor(() => expect(bReads).toBe(2))+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([+ 'remote-a',+ ])+ )+ await act(async () => {+ pendingOldB.resolve(serverSessions([{ agent: HOST_B, chatId: 'old-scope-b' }]))+ await pendingOldB.promise+ })+ expect(oldBResolved).toBe(true)+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual(['remote-a'])++ await act(async () => {+ pendingCurrentB.resolve(serverSessions([{ agent: HOST_B, chatId: 'current-scope-b' }]))+ await pendingCurrentB.promise+ })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toContain(+ 'current-scope-b'+ )+ )+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).not.toContain(+ 'old-scope-b'+ )+ })++ it('discards a response after that Host authority epoch advances', async () => {+ const pendingB = deferred<SessionsListResult>()+ let bEpoch = 0+ let bResolved = false+ clerum.chat.getIndex.mockResolvedValue(localIndex([]))+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>+ agentRef === HOST_B+ ? pendingB.promise.then(page => {+ bResolved = true+ return page+ })+ : Promise.resolve(serverSessions([{ agent: HOST_A, chatId: 'remote-a' }]))+ )+ const controller = renderController({+ selectedAgent: null,+ agentNames: HOSTS,+ getHostAuthorityEpoch: agentRef => (agentRef === HOST_B ? bEpoch : 0),+ })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([+ 'remote-a',+ ])+ )+ expect(clerum.rpc.listSessions).toHaveBeenCalledWith(HOST_B, undefined, {+ agent: HOST_B,+ limit: 50,+ })+ bEpoch += 1+ await act(async () => {+ pendingB.resolve(serverSessions([{ agent: HOST_B, chatId: 'old-epoch-b' }]))+ await pendingB.promise+ })+ expect(bResolved).toBe(true)+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual(['remote-a'])+ })++ it('flushes only the arriving Host offline renames without spending another Host retry budget', async () => {+ const pendingA = deferred<SessionsListResult>()+ const pendingB = 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 : pendingB.promise+ )+ clerum.rpc.renameSession.mockRejectedValue(new Error('fetch failed'))+ const controller = renderController({ selectedAgent: null, agentNames: HOSTS })+ await waitFor(() => expect(clerum.rpc.listSessions).toHaveBeenCalledTimes(2))+ const attemptsFor = (agentRef: string) =>+ clerum.rpc.renameSession.mock.calls.filter(call => call[0] === agentRef).length++ await act(async () => {+ await controller.result.current.handleRenameChatForAgent(+ HOST_A,+ `${HOST_A}-chat`,+ 'Renamed A'+ )+ await controller.result.current.handleRenameChatForAgent(+ HOST_B,+ `${HOST_B}-chat`,+ 'Renamed B'+ )+ })+ expect(attemptsFor(HOST_A)).toBe(1)+ expect(attemptsFor(HOST_B)).toBe(1)++ await act(async () => {+ pendingA.resolve(+ serverSessions([{ agent: HOST_A, chatId: `${HOST_A}-chat`, title: 'Server A' }])+ )+ await pendingA.promise+ })+ // A really flushed and failed again; B remains at its first offline failure.+ await waitFor(() => expect(attemptsFor(HOST_A)).toBe(2))+ expect(attemptsFor(HOST_B)).toBe(1)+ expect(+ controller.result.current.latestChatSessions.find(chat => chat.agentRef === HOST_A)?.title+ ).toBe('Renamed A')++ // Reconnect still retries every offline Host. B retains all four remaining+ // failures before exhausting its budget, proving A did not increment it.+ for (let attempt = 1; attempt < MAX_RENAME_SYNC_ATTEMPTS; attempt += 1) {+ await act(async () => {+ window.dispatchEvent(new Event('online'))+ })+ await waitFor(() => expect(attemptsFor(HOST_B)).toBe(attempt + 1))+ }+ await act(async () => {+ pendingB.resolve(+ serverSessions([{ agent: HOST_B, chatId: `${HOST_B}-chat`, title: 'Server B' }])+ )+ await pendingB.promise+ window.dispatchEvent(new Event('online'))+ })+ expect(attemptsFor(HOST_B)).toBe(MAX_RENAME_SYNC_ATTEMPTS)+ expect(+ controller.result.current.latestChatSessions.find(chat => chat.agentRef === HOST_B)?.title+ ).toBe('Renamed B')+ })++ it('filters a confirmed tombstone created while that Host response is pending', async () => {+ const pendingB = deferred<SessionsListResult>()+ clerum.chat.getIndex.mockResolvedValue(localIndex([]))+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>+ agentRef === HOST_B+ ? pendingB.promise+ : Promise.resolve(serverSessions([{ agent: HOST_A, chatId: 'remote-a' }]))+ )+ const controller = renderController({ selectedAgent: null, agentNames: HOSTS })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toEqual([+ 'remote-a',+ ])+ )+ expect(clerum.rpc.listSessions).toHaveBeenCalledWith(HOST_B, undefined, {+ agent: HOST_B,+ limit: 50,+ })++ await act(async () => {+ const deletion = await controller.result.current.captureChatDeleteFence(HOST_B)+ await controller.result.current.handleDeleteChatForAgent(HOST_B, 'deleted-b', deletion)+ })+ expect(clerum.chat.delete).toHaveBeenCalledWith(+ HOST_B,+ 'deleted-b',+ expect.objectContaining({ version: 1, bindingGeneration: 1 })+ )+ await act(async () => {+ pendingB.resolve(+ serverSessions([+ { agent: HOST_B, chatId: 'deleted-b' },+ { agent: HOST_B, chatId: 'kept-b' },+ ])+ )+ await pendingB.promise+ })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toContain('kept-b')+ )+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toContain('remote-a')+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).not.toContain(+ 'deleted-b'+ )+ })++ it('keeps cached rows after one Host fails while another Host publishes remote rows', async () => {+ const pendingB = deferred<SessionsListResult>()+ const unavailable = await ipcHttpError('rpc:listSessions', 503, 'Service Unavailable', {+ error: 'upstream unavailable',+ })+ clerum.chat.getIndex.mockImplementation(async (agentRef: string) =>+ agentRef === HOST_B ? localIndex([{ id: 'saved-b', title: 'Saved B' }]) : localIndex([])+ )+ clerum.rpc.listSessions.mockImplementation((agentRef: string) =>+ agentRef === HOST_B+ ? pendingB.promise+ : Promise.resolve(serverSessions([{ agent: HOST_A, chatId: 'remote-a' }]))+ )+ const controller = renderController({ selectedAgent: null, agentNames: HOSTS })+ await waitFor(() =>+ expect(controller.result.current.latestChatSessions.map(chat => chat.id)).toContain(+ 'remote-a'+ )+ )+ await act(async () => {+ pendingB.reject(unavailable)+ })+ // The existing outage toast witnesses that B's rejection was handled.+ await waitFor(() =>+ expect(controller.spies.pushToast).toHaveBeenCalledWith(+ `Chat list for ${HOST_B} is offline. Showing saved chats.`,+ 'info'+ )+ )+ expect(controller.result.current.latestChatSessions.map(chat => chat.id).sort()).toEqual([+ 'remote-a',+ 'saved-b',+ ])+ })+})diff --git a/desktop-app/ui/src/hooks/domain/useChatListController.ts b/desktop-app/ui/src/hooks/domain/useChatListController.tsindex bd1b6a3b3..7cb3a65b8 100644--- a/desktop-app/ui/src/hooks/domain/useChatListController.ts+++ b/desktop-app/ui/src/hooks/domain/useChatListController.ts@@ -370,7 +370,9 @@ export function useChatListController({// Indirection so the catalog loaders (defined above the queue) can trigger a// retry of pending renames after a listSessions poll without depending on the// queue's identity. Wired in an effect once the queue is defined.- const flushPendingRenamesRef = useRef<(serverChatKeys?: Set<string>) => void>(() => {})+ const flushPendingRenamesRef = useRef<(serverChatKeys?: Set<string>, agentRef?: string) => void>(+ () => {}+ )useEffect(() => {requestGenerationRef.current += 1@@ -613,7 +615,10 @@ export function useChatListController({// §2.5: a rename that 404'd (session not yet server-side) retries now that// the poll reports which sessions exist.- flushPendingRenamesRef.current(new Set(serverSessions.map(s => `${agentRef}:${s.chatId}`)))+ flushPendingRenamesRef.current(+ new Set(serverSessions.map(s => `${agentRef}:${s.chatId}`)),+ agentRef+ )const latestServerSession = serverSessions[0]// A mode:none request suppresses this one deferred catalog result. Consume@@ -1223,12 +1228,13 @@ export function useChatListController({* session to materialize server-side) is retried ONLY when a listSessions poll* reports its session present (`serverChatKeys` has the key) — a reconnect does* not make the session exist, so a bare `window 'online'` event (no keys) never- * retries it. 'offline' entries (a network / 5xx failure) retry unconditionally,- * which is exactly the reconnect case.+ * retries it. 'offline' entries (a network / 5xx failure) retry for the arriving+ * Host, or for every Host on reconnect when no agent filter is supplied.*/const flushPendingRenames = useCallback(- async (serverChatKeys?: Set<string>) => {+ async (serverChatKeys?: Set<string>, agentRef?: string) => {for (const entry of [...pendingRenamesRef.current.values()]) {+ if (agentRef !== undefined && entry.agentRef !== agentRef) continue// FIX 1: skip a key with a PATCH already in flight (attemptRenameRpc// guards this too, but skipping avoids spawning a no-op).if (entry.sending) continue@@ -1317,8 +1323,8 @@ export function useChatListController({}, [flushPendingRenames])useEffect(() => {- flushPendingRenamesRef.current = (serverChatKeys?: Set<string>) => {- void flushPendingRenames(serverChatKeys)+ flushPendingRenamesRef.current = (serverChatKeys?: Set<string>, agentRef?: string) => {+ void flushPendingRenames(serverChatKeys, agentRef)}}, [flushPendingRenames])@@ -1539,25 +1545,28 @@ export function useChatListController({)setLatestChatSessionsLoading(false)- const sessionGroups = await Promise.all(+ await Promise.all(requestedAgentNames.map(async agentRef => {+ const requestStillCurrent = () =>+ !cancelled &&+ authorityScopeGenerationRef.current === authorityScopeGeneration &&+ currentAuthorityScopeRef.current === authorityScopeAtRequest &&+ getHostAuthorityEpoch(agentRef) === hostAuthorityEpochByAgent.get(agentRef) &&+ !isHostAccessBlocked(agentRef)// This feeds only the cross-agent sidebar preview. Do not follow// cursors here; the selected-agent session list exposes explicit// on-demand pagination through `loadMoreChatSessions`.- let serverResult: SessionsListResult+ let serverSessions: SessionsListResult['items'] = []try {- serverResult = await readSessionCatalog(chatStore, agentRef, {+ const serverResult = await readSessionCatalog(chatStore, agentRef, {agent: agentRef,limit: SESSION_CATALOG_PAGE_LIMIT,})+ if (!requestStillCurrent()) return+ reportCatalogOnline(agentRef, authorityScopeGeneration)+ serverSessions = serverResult.items} catch (error) {- if (- !cancelled &&- authorityScopeGenerationRef.current === authorityScopeGeneration &&- currentAuthorityScopeRef.current === authorityScopeAtRequest &&- getHostAuthorityEpoch(agentRef) === hostAuthorityEpochByAgent.get(agentRef) &&- !isHostAccessBlocked(agentRef)- ) {+ if (requestStillCurrent()) {if (isConfirmedHostAccessRevoked(error)) onHostAccessRevoked(agentRef)else if (isAuthorizationError(error)) onHostAuthorityUncertain(agentRef)if (@@ -1568,105 +1577,63 @@ export function useChatListController({reportCatalogOffline(agentRef)}}- return { agentRef, sessions: [] as SessionsListResult['items'] }}- if (- cancelled ||- authorityScopeGenerationRef.current !== authorityScopeGeneration ||- currentAuthorityScopeRef.current !== authorityScopeAtRequest ||- getHostAuthorityEpoch(agentRef) !== hostAuthorityEpochByAgent.get(agentRef) ||- isHostAccessBlocked(agentRef)- ) {- return { agentRef, sessions: [] as SessionsListResult['items'] }- }- reportCatalogOnline(agentRef, authorityScopeGeneration)- return {- agentRef,- sessions: serverResult.items.filter(+ if (!requestStillCurrent()) return+ const sessions: LatestCatalogSession[] = serverSessions+ .filter(session =>session.agent === agentRef &&- !isHostAccessBlocked(agentRef) &&!deletedChatIdsByAgentRef.current.get(agentRef)?.has(session.chatId)- ),- }- })- )- if (cancelled || currentAuthorityScopeRef.current !== authorityScopeAtRequest) return- for (const group of sessionGroups) {- if (- getHostAuthorityEpoch(group.agentRef) !==- hostAuthorityEpochByAgent.get(group.agentRef) ||- isHostAccessBlocked(group.agentRef)- )- continue- seedSessionSnapshots(- fsm,- group.agentRef,- group.sessions.filter(- session => !deletedChatIdsByAgentRef.current.get(group.agentRef)?.has(session.chatId)- )- )- }- setLatestChatSessions(previous => {- const sessions: LatestCatalogSession[] = []- for (const group of sessionGroups) {- if (- getHostAuthorityEpoch(group.agentRef) !==- hostAuthorityEpochByAgent.get(group.agentRef) ||- isHostAccessBlocked(group.agentRef)- )- continue- for (const session of group.sessions) {- if (deletedChatIdsByAgentRef.current.get(group.agentRef)?.has(session.chatId))- continue- sessions.push({ ...session, agentRef: group.agentRef })- }- }- const cached = previous.filter(- item =>- getHostAuthorityEpoch(item.agentRef) ===- hostAuthorityEpochByAgent.get(item.agentRef) &&- !isHostAccessBlocked(item.agentRef) &&- !deletedChatIdsByAgentRef.current.get(item.agentRef)?.has(item.id)- )- // §2.2 precedence (cases A-F) lives in `mergeCatalogPage`; Latest keys- // entries by (agentRef, chatId) and uses the "Remote · <id>" placeholder.- return mergeCatalogPage<LatestSidebarChatEntry, LatestCatalogSession>({- cached,- sessions,- entryKey: item => `${item.agentRef}:${item.id}`,- sessionKey: session => `${session.agentRef}:${session.chatId}`,- entryPendingRename: item => pendingRenameStateFor(item.agentRef, item.id),- sessionPendingRename: session =>- pendingRenameStateFor(session.agentRef, session.chatId),- placeholderFor: remotePlaceholder,- serverOnlyEntry: (session, title) => ({- id: session.chatId,- title,- createdAt: session.lastActivityAt,- updatedAt: session.lastActivityAt,- messageCount: knownServerMessageCount(session),- remote: true,- agentRef: session.agentRef,- }),- })- })-- // §2.5: retry any rename that 404'd, now that this cross-agent poll- // reports which sessions exist server-side.- flushPendingRenamesRef.current(- new Set(- sessionGroups.flatMap(group =>- isHostAccessBlocked(group.agentRef)- ? []- : group.sessions+ )+ .map(session => ({ ...session, agentRef }))+ seedSessionSnapshots(fsm, agentRef, sessions)+ setLatestChatSessions(previous => {+ if (!requestStillCurrent()) return previous+ const deleted = deletedChatIdsByAgentRef.current.get(agentRef)+ const cached = previous.filter(+ item => item.agentRef === agentRef && !deleted?.has(item.id)+ )+ // §2.2 precedence (cases A-F) lives in `mergeCatalogPage`; merge+ // only this Host's entries so another Host's arrival preserves them.+ const merged = mergeCatalogPage<LatestSidebarChatEntry, LatestCatalogSession>({+ cached,+ sessions: sessions.filter(session => !deleted?.has(session.chatId)),+ entryKey: item => `${item.agentRef}:${item.id}`,+ sessionKey: session => `${session.agentRef}:${session.chatId}`,+ entryPendingRename: item => pendingRenameStateFor(item.agentRef, item.id),+ sessionPendingRename: session =>+ pendingRenameStateFor(session.agentRef, session.chatId),+ placeholderFor: remotePlaceholder,+ serverOnlyEntry: (session, title) => ({+ id: session.chatId,+ title,+ createdAt: session.lastActivityAt,+ updatedAt: session.lastActivityAt,+ messageCount: knownServerMessageCount(session),+ remote: true,+ agentRef: session.agentRef,+ }),+ })+ return [...merged, ...previous.filter(item => item.agentRef !== agentRef)].sort(+ byUpdatedDesc+ )+ })++ // §2.5: retry only this Host's pending renames as its poll settles.+ if (requestStillCurrent()) {+ flushPendingRenamesRef.current(+ new Set(+ sessions.filter(session =>- !deletedChatIdsByAgentRef.current.get(group.agentRef)?.has(session.chatId)+ !deletedChatIdsByAgentRef.current.get(agentRef)?.has(session.chatId))- .map(session => `${group.agentRef}:${session.chatId}`)- )- )+ .map(session => `${agentRef}:${session.chatId}`)+ ),+ agentRef+ )+ }+ }))} finally {if (!cancelled) {