Skip to content

The agent that grows with you

fix(desktop): route session list REST through the active profile

Brooklyn Nicholson02c7ae956e42
diff --git a/apps/desktop/src/api/sessions.ts b/apps/desktop/src/api/sessions.ts
index 9bd5adfba12..f938dc23817 100644
--- a/apps/desktop/src/api/sessions.ts
+++ b/apps/desktop/src/api/sessions.ts
@@ -8,7 +8,7 @@ import type {
SessionSearchResponse
} from '@/types/hermes'
-import { capabilityScoped, hermesApi, type ProfileScope } from './client'
+import { capabilityScoped, hermesApi, type ProfileScope, profileScoped } from './client'
const SESSION_LIST_REQUEST_TIMEOUT_MS = 60_000
@@ -59,6 +59,7 @@ export async function listSessions(
order: 'created' | 'recent' = 'recent'
): Promise<PaginatedSessions> {
const result = await hermesApi<PaginatedSessions>({
+ ...profileScoped(),
path:
`/api/sessions?limit=${limit}&offset=0&min_messages=${Math.max(0, minMessages)}` +
`&archived=${archived}&order=${order}`,
@@ -100,6 +101,7 @@ export async function listAllProfileSessions(
: ''
const result = await hermesApi<PaginatedSessions>({
+ ...profileScoped(),
path:
`/api/profiles/sessions?limit=${limit}&offset=0&min_messages=${Math.max(0, minMessages)}` +
`&archived=${archived}&order=${order}&profile=${encodeURIComponent(profile)}${sourceParam}${excludeParam}`,
@@ -248,6 +250,7 @@ export async function listSidebarSessions(req: SidebarSessionsRequest): Promise<
try {
result = await hermesApi<SidebarSessionsResponse>({
+ ...profileScoped(),
path: `/api/profiles/sessions/sidebar?${params.toString()}`,
timeoutMs: SESSION_LIST_REQUEST_TIMEOUT_MS
})
diff --git a/apps/desktop/src/hermes.test.ts b/apps/desktop/src/hermes.test.ts
index 5936f1d9b94..00611c6f68a 100644
--- a/apps/desktop/src/hermes.test.ts
+++ b/apps/desktop/src/hermes.test.ts
@@ -140,6 +140,57 @@ describe('Hermes REST helpers', () => {
expect(api).toHaveBeenCalledWith(expect.objectContaining({ connectionId: 'local', path: '/api/profiles' }))
})
+ it('routes the batched sidebar refresh through the active backend scope', async () => {
+ setApiRequestConnection('cubi')
+ setApiRequestProfile('default')
+ api.mockResolvedValue({ recents: { sessions: [] }, cron: { sessions: [] }, messaging: { sessions: [] } })
+
+ await listSidebarSessions({
+ recentsProfile: 'default',
+ recentsLimit: 20,
+ recentsExclude: ['cron'],
+ cronLimit: 50,
+ messagingLimit: 100,
+ messagingExclude: ['cron', 'desktop']
+ })
+
+ expect(api).toHaveBeenCalledWith(
+ expect.objectContaining({
+ connectionId: 'cubi',
+ profile: 'default',
+ path: expect.stringContaining('/api/profiles/sessions/sidebar?recents_profile=default')
+ })
+ )
+ })
+
+ it('routes legacy profile-session slices through the active backend scope', async () => {
+ setApiRequestConnection('cubi')
+ setApiRequestProfile('default')
+
+ await listAllProfileSessions(20, 1, 'exclude', 'recent', 'default')
+
+ expect(api).toHaveBeenCalledWith(
+ expect.objectContaining({
+ connectionId: 'cubi',
+ profile: 'default',
+ path: expect.stringContaining('/api/profiles/sessions?')
+ })
+ )
+ })
+
+ it('does not stamp ambient profile onto unscoped helpers', async () => {
+ setApiRequestProfile('iris')
+
+ await getProfiles()
+
+ expect(api).toHaveBeenCalledWith(
+ expect.objectContaining({
+ path: '/api/profiles'
+ })
+ )
+ expect(api.mock.calls[0][0]).not.toHaveProperty('profile')
+ })
+
it('preserves ambient and explicit-local ownership for session and profile requests', async () => {
setApiRequestConnection('remote-a')