Skip to content

The agent that grows with you

fix(webapp): Bot Mode create and duplicate drop a reused name's leftover prefs

unsupportedpastels07aa617860bd
diff --git a/apps/desktop/src/app/session/hooks/browser-profile-folder.test.ts b/apps/desktop/src/app/session/hooks/browser-profile-folder.test.ts
index f66f64f3a3a..e0b2d1b64ed 100644
--- a/apps/desktop/src/app/session/hooks/browser-profile-folder.test.ts
+++ b/apps/desktop/src/app/session/hooks/browser-profile-folder.test.ts
@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { installBrowserDesktopBridge } from '@/lib/browser-desktop-bridge'
import { createClientSessionState } from '@/lib/chat-runtime'
+import { host as pluginHost } from '@/sdk'
import { requestGatewayForAgent } from '@/store/gateway'
import {
$activeGatewayProfile,
@@ -188,4 +189,39 @@ describe('browser default folder follows the profile a new session belongs to',
...FOREGROUND_CREATE_DIAL
)
})
+
+ // Bot Mode creates and duplicates through its own profiles.create, then
+ // calls this door. A folder an older deletion left under the reused name
+ // must not become the new bot's.
+ it.each([
+ { connectionId: null, expected: '' },
+ { connectionId: 'local', expected: '' },
+ // Created on another machine: the name here still owns its folder.
+ { connectionId: 'studio', expected: '/srv/deleted-writer' }
+ ])(
+ 'a Bot Mode "+" after creating writer on $connectionId starts in "$expected"',
+ async ({ connectionId, expected }) => {
+ await saveFolderOn('writer', '/srv/deleted-writer')
+ vi.mocked(requestGatewayForAgent).mockResolvedValue(created('bot'))
+ const { result } = mountActions()
+ const route = { connectionId: 'local', profile: 'writer' }
+
+ pluginHost.dropLeftoverProfilePrefs('writer', connectionId)
+ // The window's own profile keeps its folder.
+ act(() => result.current.startFreshSessionDraft())
+ expect($currentCwd.get()).toBe('/srv/alpha')
+
+ await act(() =>
+ result.current.openNewSessionTile('center', {
+ listed: false,
+ route,
+ workspaceScope: { ownerRoute: route, workspaceMode: 'bots', workspaceOwnerKey: 'bot:local::writer' }
+ })
+ )
+
+ const params = vi.mocked(requestGatewayForAgent).mock.calls.find(([, , method]) => method === 'session.create')?.[3]
+ expect(params).toMatchObject({ profile: 'writer' })
+ expect((params as { cwd?: string } | undefined)?.cwd ?? '').toBe(expected)
+ }
+ )
})
diff --git a/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx b/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx
index 6cabb205771..815fb1f0082 100644
--- a/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/create-agent-lazy-profile.test.tsx
@@ -31,6 +31,7 @@ const mocks = vi.hoisted(() => ({
connections: vi.fn(async () => [] as { id: string; label: string }[]),
createCanonicalChat: vi.fn(async () => 'session-1'),
deleteBot: vi.fn(async () => undefined),
+ dropLeftoverProfilePrefs: vi.fn(),
/** Flipped off to model a desktop build that predates the live surface. */
hasCapabilitiesView: { value: true },
notify: vi.fn(),
@@ -59,6 +60,7 @@ vi.mock('@hermes/plugin-sdk', async importOriginal => {
host: {
...original.host,
connections: mocks.connections,
+ dropLeftoverProfilePrefs: mocks.dropLeftoverProfilePrefs,
notify: mocks.notify,
notifyError: mocks.notifyError,
request: mocks.request,
@@ -312,6 +314,64 @@ describe('materializing the draft profile', () => {
})
})
+// A create never lands on a live name, so a folder or startup profile stored
+// under the new bot's name was left by a deleted profile. Bot Mode creates
+// through its own RPC, so it has to drop them the way the profile dialog does.
+describe('leftover prefs under the new bot name', () => {
+ it('drops them once the create succeeded', async () => {
+ let created = false
+ const base = mocks.request.getMockImplementation()!
+ mocks.request.mockImplementation(async (method: string, params?: unknown) => {
+ if (method === 'profiles.create') {
+ created = true
+ }
+
+ return base(method, params)
+ })
+ mocks.dropLeftoverProfilePrefs.mockImplementationOnce(() => expect(created).toBe(true))
+
+ await renderDialog(true)
+ fireEvent.click(screen.getByRole('button', { name: 'Create Bot' }))
+
+ await waitFor(() => expect(mocks.createCanonicalChat).toHaveBeenCalledWith('inbox-triage', { kickoff: true }))
+ expect(mocks.dropLeftoverProfilePrefs.mock.calls).toEqual([['inbox-triage', null]])
+ })
+
+ it('names the machine a remote bot was created on', async () => {
+ mocks.connections.mockResolvedValue([
+ { id: 'local', label: 'This Mac' },
+ { id: 'studio', label: 'Studio' }
+ ])
+
+ await renderDialog(true)
+ await screen.findByText('Create on')
+ fireEvent.click(controlUnder('Create on'))
+ fireEvent.click(await screen.findByRole('option', { name: 'Studio' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Create Bot' }))
+
+ await waitFor(() => expect(mocks.dropLeftoverProfilePrefs).toHaveBeenCalled())
+ expect(mocks.dropLeftoverProfilePrefs.mock.calls).toEqual([['inbox-triage', 'studio']])
+ })
+
+ it('keeps them when the create fails', async () => {
+ const base = mocks.request.getMockImplementation()!
+ mocks.request.mockImplementation(async (method: string, params?: unknown) => {
+ if (method === 'profiles.create') {
+ throw new Error('disk full')
+ }
+
+ return base(method, params)
+ })
+
+ await renderDialog(true)
+ fireEvent.click(screen.getByRole('button', { name: 'Create Bot' }))
+
+ await waitFor(() => expect(createCalls()).toHaveLength(1))
+ await new Promise(resolve => setTimeout(resolve, 50))
+ expect(mocks.dropLeftoverProfilePrefs).not.toHaveBeenCalled()
+ })
+})
+
// #141623: the draft profile is minted before the dialog finishes. Cancelling
// must delete the draft THIS dialog created, on the machine it created it on,
// including one whose create or configure is still in flight when the user
diff --git a/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx b/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx
index 5e60262eecb..386e5878a57 100644
--- a/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx
@@ -544,6 +544,12 @@ export function CreateAgentDialog({ open, onClose, onConfigureModel, roster }: C
: {})
})
+ // Prefs a deleted profile left under this name must not become the new
+ // bot's. Older builds without the door keep them, as before.
+ if (typeof host.dropLeftoverProfilePrefs === 'function') {
+ host.dropLeftoverProfilePrefs(slug, target || null)
+ }
+
// Discarded mid-create: delete the profile this flight minted, configure nothing.
if (generation !== draftGenRef.current) {
discardDraftProfile(slug, target)
diff --git a/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts b/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts
index 58806433448..b82482cac12 100644
--- a/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/profile-ops.test.ts
@@ -19,6 +19,7 @@ const { ensureBotMetadataMock, faceOnlyMock, hostMock, storageMock } = vi.hoiste
ensureBotMetadataMock: vi.fn(),
faceOnlyMock: vi.fn((_data: string) => false),
hostMock: {
+ dropLeftoverProfilePrefs: vi.fn(),
request: vi.fn(),
requestProfile: vi.fn(),
state: { connectionId: { get: () => 'local' }, focusedSessionOwner: null, profile: { get: () => 'default' } }
@@ -147,6 +148,43 @@ describe('duplicating a bot', () => {
expect(await duplicateBot(bot, [bot, elsewhere])).toBe('ops-2')
})
+
+ // A create never lands on a live name, so prefs stored under the copy's name
+ // were left by a deleted profile. The source keeps its own.
+ it('drops the leftover prefs under the copy name once the create succeeded', async () => {
+ await duplicateBot({ name: 'writer' } as RosterRow, [{ name: 'writer' } as RosterRow])
+
+ expect(hostMock.dropLeftoverProfilePrefs.mock.calls).toEqual([['writer-2', undefined]])
+ })
+
+ it('names the connection the copy was created on', async () => {
+ const bot = {
+ connectionId: 'vera',
+ name: 'ops',
+ route: { connectionId: 'vera', mode: 'remote', profile: 'ops', targetProfile: 'ops' },
+ sourceScoped: true
+ } as RosterRow
+
+ hostMock.requestProfile.mockResolvedValue({ ok: true })
+ await duplicateBot(bot, [bot])
+
+ expect(hostMock.dropLeftoverProfilePrefs.mock.calls).toEqual([['ops-2', 'vera']])
+ })
+
+ it('keeps every pref when the create fails', async () => {
+ hostMock.request.mockImplementation(async (method: string) => {
+ if (method === 'profiles.create') {
+ throw new Error('disk full')
+ }
+
+ return { ok: true }
+ })
+
+ await expect(duplicateBot({ name: 'writer' } as RosterRow, [{ name: 'writer' } as RosterRow])).rejects.toThrow(
+ 'disk full'
+ )
+ expect(hostMock.dropLeftoverProfilePrefs).not.toHaveBeenCalled()
+ })
})
/**
diff --git a/apps/desktop/src/plugins/hermes-bots/profile-ops.ts b/apps/desktop/src/plugins/hermes-bots/profile-ops.ts
index 3f48e4ae1b1..960ea4e07df 100644
--- a/apps/desktop/src/plugins/hermes-bots/profile-ops.ts
+++ b/apps/desktop/src/plugins/hermes-bots/profile-ops.ts
@@ -380,6 +380,12 @@ export async function duplicateBot(bot: RosterRow, roster: RosterRow[]) {
description: bot.description || ''
})
+ // Prefs a deleted profile left under the copy's name must not become its.
+ // Older builds without the door keep them, as before.
+ if (typeof host.dropLeftoverProfilePrefs === 'function') {
+ host.dropLeftoverProfilePrefs(name, ownerRoute?.connectionId)
+ }
+
// Same look: avatar shape/color/image and a "(copy)" title so the two
// are tellable apart in the roster until the user renames. Do not copy
// chat or created. Those belong to the original bot.
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index 1a126f4d201..c1c31577f4b 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -47,6 +47,7 @@ import { onGatewayEvent } from '@/contrib/events'
import { registry } from '@/contrib/registry'
import type { WorkspaceMode } from '@/contrib/types'
import { deleteProfile, getLogs, getStatus, hermesApi, type HermesGateway } from '@/hermes'
+import { dropBrowserProfilePrefs } from '@/lib/browser-profile-prefs'
import { traceIdentityChange } from '@/lib/identity-trace'
import { completeMcpDesktopOAuth } from '@/lib/mcp-dashboard-oauth'
import {
@@ -674,6 +675,22 @@ export const host = {
prewarmProfileBackend(name)
},
+ /** Call after a plugin's own `profiles.create` succeeded, never before: a
+ * create never lands on a live profile's name, so a folder or startup
+ * profile this tab stored under it was left by a deleted profile. The same
+ * cleanup the core create dialog runs. A profile created on another
+ * connection (`connectionId` neither empty nor `local`) is not this tab's,
+ * so the name here keeps its prefs. No-op outside the browser-hosted app. */
+ dropLeftoverProfilePrefs: (profile: string, connectionId?: null | string): void => {
+ const connection = String(connectionId ?? '').trim()
+
+ if (connection && connection !== 'local') {
+ return
+ }
+
+ dropBrowserProfilePrefs(profile)
+ },
+
/** Delete a profile THROUGH the desktop's teardown-routed REST path — the
* same door core surfaces use (DeleteProfileDialog). Electron intercepts
* the DELETE, tears down that profile's pool/primary backend first, and