The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): ignore stale messaging page responses
David Dudok de Wita0f22234bca5
diff --git a/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx b/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsxindex ac8104d4780..fbaf3c7d79d 100644--- a/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx+++ b/apps/desktop/src/app/session/hooks/use-session-list-actions.test.tsx@@ -394,6 +394,47 @@ describe('messaging profile scope', () => {expect($messagingPlatformTotals.get()['work:signal']).toBe(42)})+ it('ignores an older overlapping load-more response for the same profile and platform', async () => {+ const older = deferred<{ sessions: SessionInfo[]; total: number }>()+ const newer = deferred<{ sessions: SessionInfo[]; total: number }>()++ setMessagingSessions([row('m1', { profile: 'work', source: 'signal' })])+ listAllProfileSessions.mockImplementationOnce(() => older.promise).mockImplementationOnce(() => newer.promise)++ const { result } = renderHook(() => useSessionListActions({ profileScope: 'work' }))+ const olderLoad = result.current.loadMoreMessagingForPlatform('signal')++ setMessagingSessions([+ row('m1', { profile: 'work', source: 'signal' }),+ row('m2', { profile: 'work', source: 'signal' })+ ])+ const newerLoad = result.current.loadMoreMessagingForPlatform('signal')++ await act(async () => {+ newer.resolve({+ sessions: [+ row('m1', { profile: 'work', source: 'signal' }),+ row('m2', { profile: 'work', source: 'signal' }),+ row('m3', { profile: 'work', source: 'signal' })+ ],+ total: 3+ })+ await newerLoad++ older.resolve({+ sessions: [+ row('m1', { profile: 'work', source: 'signal' }),+ row('m2', { profile: 'work', source: 'signal' })+ ],+ total: 2+ })+ await olderLoad+ })++ expect($messagingSessions.get().map(session => session.id)).toEqual(['m1', 'm2', 'm3'])+ expect($messagingPlatformTotals.get()).toEqual({ 'work:signal': 3 })+ })+it('ignores an in-flight response after the active profile changes', async () => {const work = deferred<{ sessions: SessionInfo[]; total: number }>()const personal = deferred<{ sessions: SessionInfo[]; total: number }>()diff --git a/apps/desktop/src/app/session/hooks/use-session-list-actions.ts b/apps/desktop/src/app/session/hooks/use-session-list-actions.tsindex 471d5098b71..72e497142db 100644--- a/apps/desktop/src/app/session/hooks/use-session-list-actions.ts+++ b/apps/desktop/src/app/session/hooks/use-session-list-actions.ts@@ -101,6 +101,7 @@ interface UseSessionListActionsArgs {* wires into the sidebar and refresh effects. */export function useSessionListActions({ profileScope }: UseSessionListActionsArgs) {const profileScopeRef = useRef(profileScope)+ const loadMoreMessagingRequestRef = useRef<Record<string, number>>({})const refreshMessagingSessionsRequestRef = useRef(0)const refreshSessionsRequestRef = useRef(0)profileScopeRef.current = profileScope@@ -158,6 +159,10 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArgreturn}+ const requestKey = messagingTotalsKey(sessionProfile, platform)+ const requestId = (loadMoreMessagingRequestRef.current[requestKey] ?? 0) + 1+ loadMoreMessagingRequestRef.current[requestKey] = requestId+const inProfile = (s: SessionInfo) =>sessionProfile === 'all' || normalizeProfileKey(s.profile) === sessionProfile@@ -173,7 +178,10 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArg{ source: platform })- if (messagingProfileFor(profileScopeRef.current) !== sessionProfile) {+ if (+ loadMoreMessagingRequestRef.current[requestKey] !== requestId ||+ messagingProfileFor(profileScopeRef.current) !== sessionProfile+ ) {return}@@ -185,9 +193,8 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArg])const total = result.total ?? incoming.length- const totalsKey = messagingTotalsKey(sessionProfile, platform)- setMessagingPlatformTotals(prev => ({ ...prev, [totalsKey]: Math.max(total, incoming.length) }))+ setMessagingPlatformTotals(prev => ({ ...prev, [requestKey]: Math.max(total, incoming.length) }))},[profileScope])