Skip to content

The agent that grows with you

fix(desktop): scope messaging to active remote profile

David Dudok de Wite264b4839492
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 5e2180a152e..2776d84510a 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -217,6 +217,7 @@ import { FirstRunSetupResetError, runPrimaryBackendStartup } from './primary-bac
import { rehomePrimaryConnection } from './primary-connection-rehome'
import { decideProfileDeleteAction, profileNameFromDeleteRequest, resolveRouteProfile } from './profile-delete-routing'
import {
+ buildSidebarSessionSliceParams,
fetchPrimaryProfileSessions,
fetchRemoteProfileSessions,
mergeProfileSessionWindow
@@ -12382,36 +12383,7 @@ async function interceptSessionRequestForRemote(request) {
return undefined // local fast path → batched endpoint's single DB open
}
- const recentsProfile = (searchParams.get('recents_profile') || 'all').trim() || 'all'
-
- const sliceParams = (limitKey, defaultLimit, extra) => {
- const sp = new URLSearchParams({
- limit: searchParams.get(limitKey) || defaultLimit,
- offset: '0',
- min_messages: '1',
- archived: 'exclude',
- order: 'recent',
- ...extra
- })
-
- return sp
- }
-
- const recentsSp = sliceParams('recents_limit', '20', { profile: recentsProfile })
- const recentsExclude = searchParams.get('recents_exclude')
-
- if (recentsExclude) {
- recentsSp.set('exclude_sources', recentsExclude)
- }
-
- const cronSp = sliceParams('cron_limit', '50', { profile: 'all', source: 'cron' })
-
- const messagingSp = sliceParams('messaging_limit', '100', { profile: 'all' })
- const messagingExclude = searchParams.get('messaging_exclude')
-
- if (messagingExclude) {
- messagingSp.set('exclude_sources', messagingExclude)
- }
+ const { recents: recentsSp, cron: cronSp, messaging: messagingSp } = buildSidebarSessionSliceParams(searchParams)
const [recents, cron, messaging] = await Promise.all([
fetchProfilesSessionSlice(recentsSp, remoteProfiles),
diff --git a/apps/desktop/electron/profile-session-routing.test.ts b/apps/desktop/electron/profile-session-routing.test.ts
index a96c84d062f..e4d248edfc4 100644
--- a/apps/desktop/electron/profile-session-routing.test.ts
+++ b/apps/desktop/electron/profile-session-routing.test.ts
@@ -3,11 +3,41 @@ import assert from 'node:assert/strict'
import { test } from 'vitest'
import {
+ buildSidebarSessionSliceParams,
fetchPrimaryProfileSessions,
fetchRemoteProfileSessions,
mergeProfileSessionWindow
} from './profile-session-routing'
+test('remote sidebar slices all follow the selected profile', () => {
+ const slices = buildSidebarSessionSliceParams(
+ new URLSearchParams({
+ recents_profile: 'work-vps',
+ recents_limit: '30',
+ cron_limit: '40',
+ messaging_limit: '50',
+ recents_exclude: 'cron,signal',
+ messaging_exclude: 'desktop,cron'
+ })
+ )
+
+ assert.equal(slices.recents.get('profile'), 'work-vps')
+ assert.equal(slices.cron.get('profile'), 'work-vps')
+ assert.equal(slices.messaging.get('profile'), 'work-vps')
+ assert.equal(slices.recents.get('exclude_sources'), 'cron,signal')
+ assert.equal(slices.cron.get('source'), 'cron')
+ assert.equal(slices.messaging.get('exclude_sources'), 'desktop,cron')
+})
+
+test('remote sidebar slices preserve the explicit all-profiles scope', () => {
+ const slices = buildSidebarSessionSliceParams(new URLSearchParams({ recents_profile: 'all' }))
+
+ assert.deepEqual(
+ Object.values(slices).map(params => params.get('profile')),
+ ['all', 'all', 'all']
+ )
+})
+
test('primary session reads use the profile-aware request path', async () => {
const calls: Array<{ profile: string | null; path: string }> = []
const expected = { sessions: [{ id: 'session-1' }], total: 1, profile_totals: { default: 1 } }
diff --git a/apps/desktop/electron/profile-session-routing.ts b/apps/desktop/electron/profile-session-routing.ts
index dada65a7615..3af1bd95a6e 100644
--- a/apps/desktop/electron/profile-session-routing.ts
+++ b/apps/desktop/electron/profile-session-routing.ts
@@ -77,6 +77,47 @@ export function mergeProfileSessionWindow(rows: unknown[], offset: number, limit
return window
}
+export interface SidebarSessionSliceParams {
+ cron: URLSearchParams
+ messaging: URLSearchParams
+ recents: URLSearchParams
+}
+
+/** Build the three remote-profile sidebar reads from one workspace scope. */
+export function buildSidebarSessionSliceParams(searchParams: URLSearchParams): SidebarSessionSliceParams {
+ const profile = (searchParams.get('recents_profile') || 'all').trim() || 'all'
+
+ const slice = (limitKey: string, defaultLimit: string, extra: Record<string, string>) =>
+ new URLSearchParams({
+ limit: searchParams.get(limitKey) || defaultLimit,
+ offset: '0',
+ min_messages: '1',
+ archived: 'exclude',
+ order: 'recent',
+ ...extra
+ })
+
+ const recents = slice('recents_limit', '20', { profile })
+ const recentsExclude = searchParams.get('recents_exclude')
+
+ if (recentsExclude) {
+ recents.set('exclude_sources', recentsExclude)
+ }
+
+ const messaging = slice('messaging_limit', '100', { profile })
+ const messagingExclude = searchParams.get('messaging_exclude')
+
+ if (messagingExclude) {
+ messaging.set('exclude_sources', messagingExclude)
+ }
+
+ return {
+ cron: slice('cron_limit', '50', { profile, source: 'cron' }),
+ messaging,
+ recents
+ }
+}
+
export async function fetchPrimaryProfileSessions(
searchParams: URLSearchParams,
fetchJsonForProfile: FetchJsonForProfile
diff --git a/apps/desktop/src/app/chat/sidebar/index.tsx b/apps/desktop/src/app/chat/sidebar/index.tsx
index 8533b47fc52..ed41b199026 100644
--- a/apps/desktop/src/app/chat/sidebar/index.tsx
+++ b/apps/desktop/src/app/chat/sidebar/index.tsx
@@ -144,6 +144,7 @@ import { SidebarCronJobsSection } from './cron-jobs-section'
import { SidebarFilterMenu } from './filter-menu'
import { SidebarLoadMoreRow } from './load-more-row'
import { orderByIds, reconcileOrderIds, resolveManualSessionOrderIds, sameIds } from './order'
+import { filterSessionsByProfileScope } from './profile-scope'
import { ProfileRail } from './profile-switcher'
import { ProjectDialog } from './project-dialog'
import {
@@ -523,11 +524,21 @@ export function ChatSidebar({
[visibleSessions]
)
+ const visibleCronSessions = useMemo(
+ () => filterSessionsByProfileScope(cronSessions, profileScope),
+ [cronSessions, profileScope]
+ )
+
+ const visibleMessagingSessions = useMemo(
+ () => filterSessionsByProfileScope(messagingSessions, profileScope),
+ [messagingSessions, profileScope]
+ )
+
// Index sessions by every id a pin might be stored under — recents, cron,
// AND messaging, since all three can be pinned (see session-index.ts).
const sessionByAnyId = useMemo(
- () => buildSessionByAnyId(visibleSessions, cronSessions, messagingSessions),
- [visibleSessions, cronSessions, messagingSessions]
+ () => buildSessionByAnyId(visibleSessions, visibleCronSessions, visibleMessagingSessions),
+ [visibleSessions, visibleCronSessions, visibleMessagingSessions]
)
// Local pin ids first (hand-picked order), then server-flagged pins the
@@ -1160,7 +1171,7 @@ export function ChatSidebar({
// within a platform by recency. Per-platform totals (when a "load more" has
// resolved them) drive the count + whether more remain on disk.
const messagingGroups = useMemo<MessagingSection[]>(() => {
- if (!messagingSessions.length) {
+ if (!visibleMessagingSessions.length) {
return []
}
@@ -1170,7 +1181,7 @@ export function ChatSidebar({
// promises rows that will never appear.
const pinnedBySource = new Map<string, number>()
- for (const session of messagingSessions) {
+ for (const session of visibleMessagingSessions) {
const sourceId = normalizeSessionSource(session.source)
if (!sourceId) {
@@ -1207,7 +1218,7 @@ export function ChatSidebar({
}
})
.sort((a, b) => sessionTime(b.sessions[0]) - sessionTime(a.sessions[0]))
- }, [messagingSessions, messagingPlatformTotals, messagingTruncated, isPinnedSession])
+ }, [visibleMessagingSessions, messagingPlatformTotals, messagingTruncated, isPinnedSession])
// Grouping by profile: one collapsible group per profile, color on the header
// (not on every row). Default profile floats to the top, the rest alpha.
diff --git a/apps/desktop/src/app/chat/sidebar/profile-scope.test.ts b/apps/desktop/src/app/chat/sidebar/profile-scope.test.ts
new file mode 100644
index 00000000000..fdd1e1d9b29
--- /dev/null
+++ b/apps/desktop/src/app/chat/sidebar/profile-scope.test.ts
@@ -0,0 +1,29 @@
+import { describe, expect, it } from 'vitest'
+
+import { ALL_PROFILES } from '@/store/profile'
+import type { SessionInfo } from '@/types/hermes'
+
+import { filterSessionsByProfileScope } from './profile-scope'
+
+const row = (id: string, profile?: string): SessionInfo =>
+ ({ id, message_count: 1, profile, source: 'signal', started_at: 0, title: id }) as SessionInfo
+
+describe('filterSessionsByProfileScope', () => {
+ it('keeps only rows from the selected profile', () => {
+ const rows = [row('default-row', 'default'), row('work-row', 'work')]
+
+ expect(filterSessionsByProfileScope(rows, 'work').map(session => session.id)).toEqual(['work-row'])
+ })
+
+ it('treats legacy rows without a profile as default', () => {
+ const rows = [row('legacy-row'), row('work-row', 'work')]
+
+ expect(filterSessionsByProfileScope(rows, 'default').map(session => session.id)).toEqual(['legacy-row'])
+ })
+
+ it('preserves every row in the canonical all-profiles scope', () => {
+ const rows = [row('default-row', 'default'), row('work-row', 'work')]
+
+ expect(filterSessionsByProfileScope(rows, ALL_PROFILES)).toBe(rows)
+ })
+})
diff --git a/apps/desktop/src/app/chat/sidebar/profile-scope.ts b/apps/desktop/src/app/chat/sidebar/profile-scope.ts
new file mode 100644
index 00000000000..1e59fe37436
--- /dev/null
+++ b/apps/desktop/src/app/chat/sidebar/profile-scope.ts
@@ -0,0 +1,12 @@
+import { ALL_PROFILES, normalizeProfileKey } from '@/store/profile'
+import type { SessionInfo } from '@/types/hermes'
+
+export function filterSessionsByProfileScope(sessions: SessionInfo[], profileScope: string): SessionInfo[] {
+ if (profileScope === ALL_PROFILES) {
+ return sessions
+ }
+
+ const scope = normalizeProfileKey(profileScope)
+
+ return sessions.filter(session => normalizeProfileKey(session.profile) === scope)
+}
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.tsx
index 60517df41fd..42333099a57 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
@@ -4,11 +4,14 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { SessionInfo, SidebarSessionsResponse } from '@/hermes'
import {
$cronSessions,
+ $messagingPlatformTotals,
$messagingSessions,
$sessions,
$sessionsLoading,
setCronSessions,
+ setMessagingPlatformTotals,
setMessagingSessions,
+ setMessagingTruncated,
setSessions,
setSessionsLoading
} from '@/store/session'
@@ -55,6 +58,21 @@ const sidebar = (
const listSidebarSessions = vi.fn()
const listAllProfileSessions = vi.fn()
+interface Deferred<T> {
+ promise: Promise<T>
+ resolve: (value: T) => void
+}
+
+function deferred<T>(): Deferred<T> {
+ let resolve!: (value: T) => void
+
+ const promise = new Promise<T>(done => {
+ resolve = done
+ })
+
+ return { promise, resolve }
+}
+
vi.mock('@/hermes', async importOriginal => ({
...(await importOriginal<Record<string, unknown>>()),
getCronJobs: vi.fn(async () => []),
@@ -77,6 +95,8 @@ beforeEach(() => {
setSessions([])
setCronSessions([])
setMessagingSessions([])
+ setMessagingPlatformTotals({})
+ setMessagingTruncated(false)
setSessionsLoading(false)
})
@@ -84,6 +104,8 @@ afterEach(() => {
setSessions([])
setCronSessions([])
setMessagingSessions([])
+ setMessagingPlatformTotals({})
+ setMessagingTruncated(false)
setSessionsLoading(false)
})
@@ -283,3 +305,104 @@ describe('refreshSessions batches slices into one request', () => {
expect(getCronJobs).toHaveBeenLastCalledWith('all')
})
})
+
+describe('messaging profile scope', () => {
+ it('refreshes messaging sessions only for the active profile', async () => {
+ listAllProfileSessions.mockResolvedValue({
+ sessions: [row('m1', { profile: 'work', source: 'signal' })],
+ total: 1
+ })
+ const { result } = renderHook(() => useSessionListActions({ profileScope: 'work' }))
+
+ await act(async () => {
+ await result.current.refreshMessagingSessions()
+ })
+
+ expect(listAllProfileSessions).toHaveBeenCalledWith(
+ expect.any(Number),
+ 1,
+ 'exclude',
+ 'recent',
+ 'work',
+ expect.objectContaining({ excludeSources: expect.any(Array) })
+ )
+ expect($messagingSessions.get().map(s => s.id)).toEqual(['m1'])
+ })
+
+ it('keeps the explicit all-profiles view unified', async () => {
+ listAllProfileSessions.mockResolvedValue({ sessions: [], total: 0 })
+ const { result } = renderHook(() => useSessionListActions({ profileScope: '__all__' }))
+
+ await act(async () => {
+ await result.current.refreshMessagingSessions()
+ })
+
+ expect(listAllProfileSessions.mock.calls[0][4]).toBe('all')
+ })
+
+ it('keeps per-platform pagination on the active profile', async () => {
+ setMessagingSessions([row('m1', { profile: 'work', source: 'signal' })])
+ listAllProfileSessions.mockResolvedValue({
+ sessions: [row('m1', { profile: 'work', source: 'signal' }), row('m2', { profile: 'work', source: 'signal' })],
+ total: 2
+ })
+ const { result } = renderHook(() => useSessionListActions({ profileScope: 'work' }))
+
+ await act(async () => {
+ await result.current.loadMoreMessagingForPlatform('signal')
+ })
+
+ expect(listAllProfileSessions.mock.calls[0][4]).toBe('work')
+ expect($messagingSessions.get().map(s => s.id)).toEqual(['m1', 'm2'])
+ })
+
+ 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 }>()
+
+ listAllProfileSessions.mockImplementation((_limit, _min, _archived, _order, profile) =>
+ profile === 'work' ? work.promise : personal.promise
+ )
+
+ const { rerender, result } = renderHook(({ profileScope }) => useSessionListActions({ profileScope }), {
+ initialProps: { profileScope: 'work' }
+ })
+
+ const workRefresh = result.current.refreshMessagingSessions()
+ rerender({ profileScope: 'personal' })
+ const personalRefresh = result.current.refreshMessagingSessions()
+
+ await act(async () => {
+ personal.resolve({
+ sessions: [row('personal-message', { profile: 'personal', source: 'telegram' })],
+ total: 1
+ })
+ await personalRefresh
+ work.resolve({ sessions: [row('work-message', { profile: 'work', source: 'signal' })], total: 1 })
+ await workRefresh
+ })
+
+ expect(listAllProfileSessions.mock.calls.map(call => call[4])).toEqual(['work', 'personal'])
+ expect($messagingSessions.get().map(session => session.id)).toEqual(['personal-message'])
+ })
+
+ it('does not let a callback captured before a profile switch clear current totals', async () => {
+ listAllProfileSessions.mockResolvedValue({ sessions: [], total: 0 })
+ setMessagingPlatformTotals({ signal: 12 })
+
+ const { rerender, result } = renderHook(({ profileScope }) => useSessionListActions({ profileScope }), {
+ initialProps: { profileScope: 'work' }
+ })
+
+ const staleRefresh = result.current.refreshMessagingSessions
+
+ rerender({ profileScope: 'personal' })
+
+ await act(async () => {
+ await staleRefresh()
+ })
+
+ expect(listAllProfileSessions).not.toHaveBeenCalled()
+ expect($messagingPlatformTotals.get()).toEqual({ signal: 12 })
+ })
+})
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.ts
index 959edfc5a15..ecea0021c97 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
@@ -96,22 +96,48 @@ interface UseSessionListActionsArgs {
profileScope: string
}
+const sessionProfileForScope = (profileScope: string): string =>
+ profileScope === ALL_PROFILES ? 'all' : normalizeProfileKey(profileScope)
+
/** Owns the sidebar's session-list fetching + paging: recents, cron runs/jobs,
* and the per-platform messaging slices. Returns the callbacks the controller
* wires into the sidebar and refresh effects. */
export function useSessionListActions({ profileScope }: UseSessionListActionsArgs) {
+ const profileScopeRef = useRef(profileScope)
+ const refreshMessagingSessionsRequestRef = useRef(0)
const refreshSessionsRequestRef = useRef(0)
+ profileScopeRef.current = profileScope
// Messaging-platform sessions as their own slice, fetched separately from
// local recents so each platform renders a self-managed section and never
- // competes with local chats for the recents page budget. One combined fetch
- // seeds every platform; the sidebar splits the rows per source.
+ // competes with local chats for the recents page budget. Keep the fetch on
+ // the sidebar's profile scope; otherwise a remote-profile switch leaks one
+ // instance's Telegram/Signal sections into another instance's workspace.
const refreshMessagingSessions = useCallback(async () => {
+ const sessionProfile = sessionProfileForScope(profileScope)
+
+ // A callback captured before a profile switch may still be queued by an
+ // event subscription. Do not let it start a request or clear current totals.
+ if (sessionProfileForScope(profileScopeRef.current) !== sessionProfile) {
+ return
+ }
+
+ const requestId = refreshMessagingSessionsRequestRef.current + 1
+ refreshMessagingSessionsRequestRef.current = requestId
+ setMessagingPlatformTotals({})
+
try {
- const result = await listAllProfileSessions(MESSAGING_SECTION_LIMIT, 1, 'exclude', 'recent', 'all', {
+ const result = await listAllProfileSessions(MESSAGING_SECTION_LIMIT, 1, 'exclude', 'recent', sessionProfile, {
excludeSources: MESSAGING_EXCLUDED_SOURCES
})
+ if (
+ refreshMessagingSessionsRequestRef.current !== requestId ||
+ sessionProfileForScope(profileScopeRef.current) !== sessionProfile
+ ) {
+ return
+ }
+
// Drop any non-messaging source the broad exclude didn't catch (custom
// sources) — those stay in local recents, not a platform section.
const rows = dropTombstoned(result.sessions.filter(s => isMessagingSource(s.source)))
@@ -123,29 +149,50 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArg
} catch {
// Non-fatal: the messaging sections just stay empty/stale.
}
- }, [])
+ }, [profileScope])
// Page a single platform's section independently (mirrors the per-profile
// pager): fetch that source's next window and merge it back in place, leaving
// every other platform's rows untouched. Resolves the platform's exact total.
- const loadMoreMessagingForPlatform = useCallback(async (platform: string) => {
- const inPlatform = (s: SessionInfo) => normalizeSessionSource(s.source) === platform
- const loaded = $messagingSessions.get().filter(inPlatform).length
+ const loadMoreMessagingForPlatform = useCallback(
+ async (platform: string) => {
+ const sessionProfile = sessionProfileForScope(profileScope)
- const result = await listAllProfileSessions(loaded + SIDEBAR_SESSIONS_PAGE_SIZE, 1, 'exclude', 'recent', 'all', {
- source: platform
- })
+ if (sessionProfileForScope(profileScopeRef.current) !== sessionProfile) {
+ return
+ }
+
+ const inProfile = (s: SessionInfo) =>
+ sessionProfile === 'all' || normalizeProfileKey(s.profile) === sessionProfile
- const incoming = dropTombstoned(result.sessions.filter(s => normalizeSessionSource(s.source) === platform))
+ const inPlatform = (s: SessionInfo) => normalizeSessionSource(s.source) === platform && inProfile(s)
+ const loaded = $messagingSessions.get().filter(inPlatform).length
- setMessagingSessions(prev => [
- ...prev.filter(s => !inPlatform(s)),
- ...mergeSessionPage(prev.filter(inPlatform), incoming, sessionsToKeep())
- ])
+ const result = await listAllProfileSessions(
+ loaded + SIDEBAR_SESSIONS_PAGE_SIZE,
+ 1,
+ 'exclude',
+ 'recent',
+ sessionProfile,
+ { source: platform }
+ )
+
+ if (sessionProfileForScope(profileScopeRef.current) !== sessionProfile) {
+ return
+ }
- const total = result.total ?? incoming.length
- setMessagingPlatformTotals(prev => ({ ...prev, [platform]: Math.max(total, incoming.length) }))
- }, [])
+ const incoming = dropTombstoned(result.sessions.filter(inPlatform))
+
+ setMessagingSessions(prev => [
+ ...prev.filter(s => !inPlatform(s)),
+ ...mergeSessionPage(prev.filter(inPlatform), incoming, sessionsToKeep())
+ ])
+
+ const total = result.total ?? incoming.length
+ setMessagingPlatformTotals(prev => ({ ...prev, [platform]: Math.max(total, incoming.length) }))
+ },
+ [profileScope]
+ )
// Cron *jobs* drive the sidebar "Cron jobs" section. Jobs are created
// synchronously (agent tool call or the cron UI), so refreshing here right
@@ -156,7 +203,7 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArg
// own jobs; ALL_PROFILES keeps the unified view.
const refreshCronJobs = useCallback(async () => {
try {
- await refreshCronJobsStore(profileScope === ALL_PROFILES ? 'all' : profileScope)
+ await refreshCronJobsStore(sessionProfileForScope(profileScope))
} catch {
// Non-fatal: the cron section just keeps its last-known jobs.
}
@@ -184,11 +231,11 @@ export function useSessionListActions({ profileScope }: UseSessionListActionsArg
// Unified cross-profile list (served read-only off each profile's
// state.db; no per-profile backend is spawned). Single-profile users get
// the same rows tagged profile="default".
- // Scope recents to the active profile (not always 'all') so a profile
+ // Scope every sidebar slice to the active profile (not always 'all') so a profile
// with few recent sessions isn't windowed out of the cross-profile
- // recency page — the empty-history-on-profile-switch bug. Cron + messaging
- // stay cross-profile.
- const sessionProfile = profileScope === ALL_PROFILES ? 'all' : profileScope
+ // recency page and never inherits another profile's cron or messaging
+ // sections. ALL_PROFILES remains the explicit unified view.
+ const sessionProfile = sessionProfileForScope(profileScope)
// Batched: one request opens each profile DB once and returns all three
// source-scoped slices, instead of three separate listAllProfileSessions
diff --git a/apps/desktop/src/hermes.test.ts b/apps/desktop/src/hermes.test.ts
index f2ea9899ff6..c2664a37f82 100644
--- a/apps/desktop/src/hermes.test.ts
+++ b/apps/desktop/src/hermes.test.ts
@@ -156,7 +156,7 @@ describe('Hermes REST helpers', () => {
})
// Slices reassembled from the legacy per-slice route with the same
- // scoping: recents on the caller's profile, cron + messaging cross-profile.
+ // scoping: every section follows the caller's profile.
expect(result.recents.sessions.map(s => s.id)).toEqual(['recent-1'])
// One row back against a 30-row window: the profile is fully loaded, so
// the legacy path must not claim there's another page.
@@ -167,7 +167,10 @@ describe('Hermes REST helpers', () => {
const paths = api.mock.calls.map(call => (call[0] as { path: string }).path)
expect(paths.filter(p => p.startsWith('/api/profiles/sessions/sidebar'))).toHaveLength(1)
expect(paths.filter(p => p.startsWith('/api/profiles/sessions?'))).toHaveLength(3)
- expect(paths).toContainEqual(expect.stringContaining('profile=work'))
+ expect(
+ paths.filter(path => path.startsWith('/api/profiles/sessions?') && path.includes('profile=work'))
+ ).toHaveLength(3)
+ expect(paths.some(path => path.includes('profile=all'))).toBe(false)
expect(paths).toContainEqual(expect.stringContaining('source=cron'))
expect(paths).toContainEqual(expect.stringContaining('exclude_sources=cron%2Ctool'))
})
diff --git a/apps/desktop/src/hermes.ts b/apps/desktop/src/hermes.ts
index bb048755717..b186be21702 100644
--- a/apps/desktop/src/hermes.ts
+++ b/apps/desktop/src/hermes.ts
@@ -543,16 +543,16 @@ function isEndpointMissingError(err: unknown): boolean {
// Compatibility fallback: reassemble the three sidebar slices from the
// per-slice endpoint, mirroring the batched route's semantics (min_messages=1,
-// archived excluded, recency order; recents scoped to the caller's profile,
-// cron + messaging cross-profile). Rides the same Electron remote-splice
+// archived excluded, recency order; every slice scoped to the caller's profile).
+// Rides the same Electron remote-splice
// interception as the pre-batching desktop, so remote profiles stay correct.
async function listSidebarSessionsLegacy(req: SidebarSessionsRequest): Promise<SidebarSessionsResponse> {
const [recents, cron, messaging] = await Promise.all([
listAllProfileSessions(req.recentsLimit, 1, 'exclude', 'recent', req.recentsProfile, {
excludeSources: req.recentsExclude
}),
- listAllProfileSessions(req.cronLimit, 1, 'exclude', 'recent', 'all', { source: 'cron' }),
- listAllProfileSessions(req.messagingLimit, 1, 'exclude', 'recent', 'all', {
+ listAllProfileSessions(req.cronLimit, 1, 'exclude', 'recent', req.recentsProfile, { source: 'cron' }),
+ listAllProfileSessions(req.messagingLimit, 1, 'exclude', 'recent', req.recentsProfile, {
excludeSources: req.messagingExclude
})
])