The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): preserve profile scope during session rename
StanleyStetsoncf6a457e2d52
diff --git a/apps/desktop/src/api/sessions.test.ts b/apps/desktop/src/api/sessions.test.tsindex 4717a5447ed..085af6481f9 100644--- a/apps/desktop/src/api/sessions.test.ts+++ b/apps/desktop/src/api/sessions.test.ts@@ -21,6 +21,7 @@ const {deleteSession,getSession,getLatestSessionMessages,+ renameSession,setSessionArchived,setSessionPinnedRemote,setSessionUnreadRemote,@@ -202,6 +203,36 @@ describe('setSessionPinnedRemote / setSessionUnreadRemote profile scoping', () =})})+describe('renameSession profile scoping', () => {+ it('carries the owning profile in the PATCH body and request', async () => {+ hermesApi.mockResolvedValue({ ok: true, title: 'Prep Butler' } as never)++ await renameSession('sess-r', 'Prep Butler', 'personal')++ expect(hermesApi.mock.calls[0][0]).toMatchObject({+ method: 'PATCH',+ path: '/api/sessions/sess-r',+ profile: 'personal',+ body: { title: 'Prep Butler', profile: 'personal' }+ })+ })++ it('falls back to the active request profile when the argument is omitted', async () => {+ hermesApi.mockResolvedValue({ ok: true, title: 'Prep Butler' } as never)+ vi.mocked(client.getApiRequestProfile).mockReturnValue('personal')++ await renameSession('sess-r2', 'Prep Butler')++ expect(hermesApi.mock.calls[0][0]).toMatchObject({+ method: 'PATCH',+ path: '/api/sessions/sess-r2',+ profile: 'personal',+ body: { title: 'Prep Butler', profile: 'personal' }+ })+ vi.mocked(client.getApiRequestProfile).mockReturnValue(null)+ })+})+describe('listSidebarSessions remote ownership', () => {it('stamps active remote rows so a later resume stays on their gateway', async () => {hermesApi.mockResolvedValue({diff --git a/apps/desktop/src/app/chat/index.tsx b/apps/desktop/src/app/chat/index.tsxindex ed43c27522a..f75d44ea69b 100644--- a/apps/desktop/src/app/chat/index.tsx+++ b/apps/desktop/src/app/chat/index.tsx@@ -143,7 +143,9 @@ function ChatHeader({const profiles = useStore($profiles)const activeStoredSession =- (selectedSessionId && sessions.find(session => sessionMatchesStoredId(session, selectedSessionId))) || null+ ((selectedSessionId || activeSessionId) &&+ sessions.find(session => sessionMatchesStoredId(session, selectedSessionId || activeSessionId || ''))) ||+ nullconst title = activeStoredSession ? sessionTitle(activeStoredSession) : NEW_SESSION_TITLE@@ -183,6 +185,7 @@ function ChatHeader({onDelete={selectedSessionId ? onDeleteSelectedSession : undefined}onPin={selectedSessionId ? onToggleSelectedPin : undefined}pinned={selectedIsPinned}+ profile={activeStoredSession?.profile}sessionId={selectedSessionId || activeSessionId || ''}sideOffset={8}title={title}diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.ts b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsindex ae7ad776d7b..9d088e5aefc 100644--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.ts+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.ts@@ -1,7 +1,7 @@import { atom } from 'nanostores'import { afterEach, describe, expect, it, vi } from 'vitest'-import { $activeSessionId, $selectedStoredSessionId } from '@/store/session'+import { $activeSessionId, $selectedStoredSessionId, $sessions } from '@/store/session'import { $sessionStates, $sessionTiles } from '@/store/session-states'import { renameSessionPreferringRpc } from './session-actions-menu'@@ -56,6 +56,7 @@ afterEach(() => {$selectedStoredSessionId.set(null)$sessionTiles.set([])$sessionStates.set({})+ $sessions.set([])})describe('renameSessionPreferringRpc', () => {@@ -70,6 +71,17 @@ describe('renameSessionPreferringRpc', () => {expect(result.title).toBe('rpc-title')})+ it('resolves the owning profile from $sessions when profile argument is omitted', async () => {+ $selectedStoredSessionId.set('some-other-active-session')+ $sessions.set([+ { id: STORED_ID, profile: 'personal', title: 'Own Google Docs document' } as never+ ])++ await renameSessionPreferringRpc(STORED_ID, 'Prep Butler')++ expect(renameSession).toHaveBeenCalledWith(STORED_ID, 'Prep Butler', 'personal')+ })+it('falls back to REST when the RPC fails (e.g. socket mid-reconnect)', async () => {$selectedStoredSessionId.set(STORED_ID)$activeSessionId.set(RUNTIME_ID)diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsxindex 9c96e368877..b7f97bb99c6 100644--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.test.tsx@@ -165,6 +165,38 @@ describe('SessionActionsMenu', () => {expect(document.activeElement).not.toBe(trigger)})+ it('passes profile to renameSession when submitting from RenameSessionDialog', async () => {+ const { renameSession } = await import('@/hermes')+ vi.mocked(renameSession).mockResolvedValue({ ok: true, title: 'Prep Butler' })++ render(+ <SessionActionsMenu profile="personal" sessionId="s1" title="My session">+ <button aria-label="Session actions" type="button">+ ⋮+ </button>+ </SessionActionsMenu>+ )++ const trigger = screen.getByRole('button', { name: 'Session actions' })+ fireEvent.pointerDown(trigger, { button: 0, pointerType: 'mouse' })+ fireEvent.pointerUp(trigger, { button: 0, pointerType: 'mouse' })+ fireEvent.click(trigger)++ const rename = await screen.findByRole('menuitem', { name: /rename/i })+ fireEvent.click(rename)++ const dialog = await screen.findByRole('dialog')+ const input = within(dialog).getByRole('textbox')+ fireEvent.change(input, { target: { value: 'Prep Butler' } })++ const save = within(dialog).getByRole('button', { name: /save/i })+ fireEvent.click(save)++ await waitFor(() => {+ expect(renameSession).toHaveBeenCalledWith('s1', 'Prep Butler', 'personal')+ })+ })+it('confirms before deleting — cancel keeps the session, confirm deletes it', async () => {const onDelete = vi.fn()render(diff --git a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsxindex 60a17d5df7e..6030943daca 100644--- a/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx+++ b/apps/desktop/src/app/chat/sidebar/session-actions-menu.tsx@@ -114,6 +114,10 @@ export async function renameSessionPreferringRpc(title: string,profile?: string): Promise<{ title?: string }> {+ const resolvedProfile =+ (profile ?? '').trim() ||+ $sessions.get().find(s => sessionMatchesStoredId(s, storedSessionId))?.profile ||+ undefinedconst runtimeId = resolveRuntimeIdForStored(storedSessionId)const gateway = activeGateway()@@ -134,7 +138,7 @@ export async function renameSessionPreferringRpc(}}- return renameSession(storedSessionId, title, profile)+ return renameSession(storedSessionId, title, resolvedProfile)}interface SessionActions {@@ -737,7 +741,11 @@ function RenameSessionDialog({ open, onOpenChange, sessionId, currentTitle, profsetSubmitting(true)try {- const result = await renameSessionPreferringRpc(sessionId, next, profile)+ const targetProfile =+ (profile ?? '').trim() ||+ $sessions.get().find(s => sessionMatchesStoredId(s, sessionId))?.profile ||+ undefined+ const result = await renameSessionPreferringRpc(sessionId, next, targetProfile)const finalTitle = result.title || next || ''// One write, every list: patch the main store AND the project surfaces.// Bare-id patching only the recents slice left project-scoped rowsdiff --git a/hermes_cli/web_routers/sessions.py b/hermes_cli/web_routers/sessions.pyindex 2db774b886e..64cd049f456 100644--- a/hermes_cli/web_routers/sessions.py+++ b/hermes_cli/web_routers/sessions.py@@ -381,6 +381,7 @@ async def search_sessions("output_tokens": row.get("output_tokens") or 0,"preview": row.get("preview"),"parent_session_id": row.get("parent_session_id"),+ "profile": _serving_profile(profile),"archived": bool(row.get("archived"))})else:payload["id"] = siddiff --git a/tests/hermes_cli/test_web_server_session_search.py b/tests/hermes_cli/test_web_server_session_search.pyindex ca5b0ac1d63..083ac1f594c 100644--- a/tests/hermes_cli/test_web_server_session_search.py+++ b/tests/hermes_cli/test_web_server_session_search.py@@ -171,3 +171,30 @@ def test_desktop_session_search_stamps_the_requested_profile(monkeypatch):(row["profile"], row["is_default_profile"])for row in response["results"]} == {("worker", False)}+++def test_desktop_session_search_attaches_profile_to_rich_results(monkeypatch):+ class _RichFakeSessionDB(_FakeSessionDB):+ def get_session_rich_row(self, session_id):+ return {+ "id": session_id,+ "source": "cli",+ "model": "claude",+ "title": "Custom Title",+ "started_at": 100,+ "ended_at": None,+ "last_active": 100,+ "message_count": 2,+ "tool_call_count": 0,+ "input_tokens": 10,+ "output_tokens": 20,+ "preview": "Test preview",+ "parent_session_id": None,+ "archived": False,+ }++ monkeypatch.setattr("hermes_state.SessionDB", _RichFakeSessionDB)+ monkeypatch.setattr("hermes_cli.profiles.profile_exists", lambda name: True)+ response = asyncio.run(_rt_sessions.search_sessions(q="20260603", limit=1, profile="personal"))+ assert response["results"][0]["profile"] == "personal"+ assert response["results"][0]["title"] == "Custom Title"diff --git a/web/src/pages/SessionsPage.tsx b/web/src/pages/SessionsPage.tsxindex 3ac34204d24..0779086211c 100644--- a/web/src/pages/SessionsPage.tsx+++ b/web/src/pages/SessionsPage.tsx@@ -517,7 +517,7 @@ function SessionRow({}setRenameSaving(true);try {- await onRename(session.id, value);+ await onRename(session.id, value, session.profile);setRenaming(false);} finally {setRenameSaving(false);@@ -1482,9 +1482,10 @@ export default function SessionsPage() {]);const handleRename = useCallback(- async (id: string, title: string) => {+ async (id: string, title: string, profile?: string) => {+ const targetProfile = profile ?? rowProfile(id);try {- await api.renameSession(id, title, rowProfile(id));+ await api.renameSession(id, title, targetProfile);setSessions((prev) =>prev.map((s) => (s.id === id ? { ...s, title } : s)),);@@ -2217,7 +2218,7 @@ interface SessionRowProps {isSelected: boolean;onDelete: () => void;onExport: (id: string) => void;- onRename: (id: string, title: string) => Promise<void>;+ onRename: (id: string, title: string, profile?: string) => Promise<void>;onSelectClick: (event: React.MouseEvent) => void;onToggle: () => void;resumeInChatEnabled: boolean;