Skip to content

The agent that grows with you

fix(desktop): route resolved sessions into their current slice

Yagna Vudathu52066564f2e6
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts
index cccb323317e..cea4b01c32f 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts
@@ -62,6 +62,19 @@ describe('resolveStoredSession profile ownership', () => {
expect($sessions.get()).toEqual([])
})
+ it('routes a moved resolve into its current slice instead of duplicating it', async () => {
+ // Cross-room /resume rewrote the row to source='matrix' (#113827): the
+ // stale regular-sessions copy must go and the row must land in messaging.
+ $sessions.set([session({ id: 's1' })])
+ mockGetSession.mockResolvedValueOnce(session({ id: 's1', profile: 'meta', source: 'matrix' }))
+
+ const resolved = await resolveStoredSession('s1')
+
+ expect(resolved?.source).toBe('matrix')
+ expect($sessions.get()).toEqual([])
+ expect($messagingSessions.get().map(s => s.id)).toEqual(['s1'])
+ })
+
it('treats a profile-less cache hit as unresolved when multiple profiles exist', async () => {
$sessions.set([session({ id: 's1' })])
mockGetSession.mockRejectedValueOnce(new Error('404: Session not found'))
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts
index 1d96404a576..82a07d83fc9 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts
@@ -1443,14 +1443,16 @@ export function dropListedSession(storedSessionId: string): void {
setUnlistedSessionOwnerRows(prev => prev.filter(keep))
}
+export function listedSliceTarget(session: SessionInfo): ListedSessionSlice {
+ return isMessagingSource(session.source)
+ ? 'messaging'
+ : normalizeSessionSource(session.source) === 'cron'
+ ? 'cron'
+ : 'sessions'
+}
+
export function restoreListedSession(session: SessionInfo, slice?: ListedSessionSlice): void {
- const target: ListedSessionSlice =
- slice ??
- (isMessagingSource(session.source)
- ? 'messaging'
- : normalizeSessionSource(session.source) === 'cron'
- ? 'cron'
- : 'sessions')
+ const target: ListedSessionSlice = slice ?? listedSliceTarget(session)
const prepend = (prev: SessionInfo[]) => [
session,
@@ -1475,7 +1477,7 @@ export function restoreListedSession(session: SessionInfo, slice?: ListedSession
function upsertResolvedSession(session: SessionInfo, storedSessionId: string) {
const lineage = session._lineage_root_id ?? session.id
- setSessions(prev => [
+ const prepend = (prev: SessionInfo[]) => [
session,
...prev.filter(existing => {
if (sessionMatchesStoredId(existing, storedSessionId)) {
@@ -1484,7 +1486,17 @@ function upsertResolvedSession(session: SessionInfo, storedSessionId: string) {
return (existing._lineage_root_id ?? existing.id) !== lineage
})
- ])
+ ]
+ // A resolve can observe a source move (cross-room /resume rewrites the row to
+ // source='matrix', #113827): the row belongs to its current slice, and the
+ // stale copy in every other slice must go or the session shows twice.
+ const evict = (prev: SessionInfo[]) =>
+ prev.filter(existing => !sessionMatchesStoredId(existing, storedSessionId))
+ const target = listedSliceTarget(session)
+
+ setSessions(target === 'sessions' ? prepend : evict)
+ setMessagingSessions(target === 'messaging' ? prepend : evict)
+ setCronSessions(target === 'cron' ? prepend : evict)
}
// Every session row reachable through the profile-scoped project tree —