Skip to content

The agent that grows with you

fix(desktop): drop legacy tiles missing connectionId and guard partial routes

Finn763108783b44daa
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.ts
index 89700a06251..1f172546225 100644
--- a/apps/desktop/src/sdk/index.ts
+++ b/apps/desktop/src/sdk/index.ts
@@ -721,10 +721,8 @@ export const host = {
: undefined
)
- // The profile is gone. Drop its persisted tiles NOW: a leftover Bot Mode
- // tile restores on relaunch and dials the deleted profile's backend, whose
- // ensure_hermes_home() re-creates the profile directory the delete just
- // removed (hermes-agent#94235).
+ // The profile is gone. Drop its persisted tiles now — a leftover tile
+ // restores on relaunch and re-creates the deleted profile (hermes-agent#94235).
dropTilesForProfile(
route ? route.profile : name,
route
diff --git a/apps/desktop/src/store/session-states.test.ts b/apps/desktop/src/store/session-states.test.ts
index a059c8f094e..7780872ba46 100644
--- a/apps/desktop/src/store/session-states.test.ts
+++ b/apps/desktop/src/store/session-states.test.ts
@@ -12,6 +12,7 @@ import {
} from '@/components/pane-shell/workspace-scope'
import { $activeGatewayProfile } from '@/store/profile'
import { $activeSessionId, $connection, $selectedStoredSessionId, setSessions } from '@/store/session'
+import type { SessionProfileRoute } from '@/store/session-request-router'
import type { SessionTile } from '@/store/session-states'
import type * as SessionStatesModule from '@/store/session-states'
import {
@@ -432,6 +433,8 @@ describe('closeAllOpenSessionTiles persists Bot Mode Close All (#94137)', () =>
)
closeAllOpenSessionTiles('workspace')
expect($sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['keep'])
+ })
+})
describe('dropTilesForProfile', () => {
const TILES_KEY = 'hermes.desktop.sessionTiles.v2'
@@ -619,6 +622,77 @@ describe('dropTilesForProfile', () => {
expect(mod.$sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['bot-local', 'bot-routed'])
})
+
+ it('drops a legacy Bot tile whose ownerRoute predates the connectionId field', () => {
+ // Tiles persisted before ownerRoute.connectionId existed (pre-#94235) carry
+ // no connection id at all. `String(undefined ?? '').trim()` yields '', so a
+ // local-delete branch comparing against `=== 'local'` never matches and the
+ // tile survives every delete, resurrecting the deleted profile on relaunch
+ // (hermes-agent#94235). The branch must treat a missing id as local.
+ mod.openSessionTile('bot-legacy', 'right', undefined, undefined, {
+ ownerRoute: { mode: 'local' as const, profile: 'press-bot' } as unknown as SessionProfileRoute,
+ workspaceMode: 'bots' as const,
+ workspaceOwnerKey: 'press-bot'
+ })
+
+ mod.dropTilesForProfile('press-bot')
+
+ expect(mod.$sessionTiles.get().map(tile => tile.storedSessionId)).toEqual([])
+ expect(storedTiles()).not.toHaveProperty(BOTS_BUCKET)
+ })
+
+ it("treats a missing connectionId as the canonical 'local' spelling", () => {
+ // The local-delete branch compares ownerConnection to 'local', and
+ // local-mode owner routes record that same spelling. No renderer-importable
+ // constant exists (LOCAL_CONNECTION_ID lives in the electron main process),
+ // so this pins the two spellings together: legacy (no id), canonical
+ // ('local'), and divergent ('Local') tiles differ only in this field, and
+ // only the first two may be dropped by a local delete. Renaming either side
+ // fails the suite before it can silently orphan local Bot tiles
+ // (Enough1122 review of #94426).
+ mod.openSessionTile('bot-legacy', 'right', undefined, undefined, {
+ ownerRoute: { mode: 'local' as const, profile: 'press-bot' } as unknown as SessionProfileRoute,
+ workspaceMode: 'bots' as const,
+ workspaceOwnerKey: 'press-bot'
+ })
+ mod.openSessionTile('bot-canonical', 'right', undefined, undefined, {
+ ownerRoute: { connectionId: 'local', mode: 'local' as const, profile: 'press-bot' },
+ workspaceMode: 'bots' as const,
+ workspaceOwnerKey: 'press-bot'
+ })
+ mod.openSessionTile('bot-divergent', 'right', undefined, undefined, {
+ ownerRoute: { connectionId: 'Local', mode: 'local' as const, profile: 'press-bot' },
+ workspaceMode: 'bots' as const,
+ workspaceOwnerKey: 'press-bot'
+ })
+
+ mod.dropTilesForProfile('press-bot')
+
+ expect(mod.$sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['bot-divergent'])
+ })
+
+ it('throws on a route without profile instead of silently falling into the local-delete branch', () => {
+ // A caller passing a route with only connectionId/targetProfile would
+ // silently take the local branch and start requiring
+ // `ownerConnection === 'local'` — dropping nothing remotely owned while
+ // appearing to succeed. Both current call sites always populate profile, so
+ // refuse the malformed shape loudly (Enough1122 review of #94426).
+ mod.openSessionTile('bot-remote', 'right', undefined, undefined, {
+ ownerRoute: {
+ connectionId: 'work-vps',
+ mode: 'remote' as const,
+ profile: 'copilot',
+ targetProfile: 'copilot'
+ },
+ workspaceMode: 'bots' as const,
+ workspaceOwnerKey: 'work-vps::copilot'
+ })
+
+ expect(() => mod.dropTilesForProfile('copilot', { connectionId: 'work-vps', targetProfile: 'copilot' })).toThrow(
+ /route without profile/
+ )
+ expect(mod.$sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['bot-remote'])
+ })
})
describe('releaseSessionTranscript', () => {
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.ts
index a3b9e2bc1ee..6a387f7d2a9 100644
--- a/apps/desktop/src/store/session-states.ts
+++ b/apps/desktop/src/store/session-states.ts
@@ -56,7 +56,7 @@ import {
setSessions
} from './session'
import { assertSessionOwnerResolved } from './session-owner-resolution'
-import { requestForSessionProfile, type SessionOwnerRoute, type SessionOwnerScope } from './session-request-router'
+import { requestForSessionProfile, type SessionOwnerRoute, type SessionOwnerScope, type SessionProfileRoute } from './session-request-router'
import { ackStoredSessionId, markSessionUnreadFinished } from './session-unread'
import { isBrowserWindow, isSecondaryWindow } from './windows'
@@ -1599,6 +1599,16 @@ export function dropTilesForProfile(
profile: string,
route?: { connectionId?: string; profile?: string; targetProfile?: string }
): void {
+ // A route without profile has no owner side to match: it would silently fall
+ // into the local-delete branch below and require `ownerConnection === 'local'`,
+ // dropping nothing remotely owned while appearing to succeed. Both current
+ // call sites always populate profile, so refuse the malformed shape loudly
+ // instead of letting a future caller misuse the optional route (Enough1122
+ // review of #94426).
+ if (route && !route.profile?.trim()) {
+ throw new Error('dropTilesForProfile: route without profile cannot be scoped')
+ }
+
const name = normalizeProfileKey(profile)
// Route fields go through the SAME canonicalization as `name` below — a
// source-scoped delete must not be defeated by stray whitespace around a
@@ -1633,8 +1643,12 @@ export function dropTilesForProfile(
// Desktop-local delete: also require the tile's owner connection to be the
// LOCAL connection. A same-named bot on another connection is a different
// agent — the deleted local profile never owned it, and dropping its tile
- // would orphan a live conversation (hermes-agent#94235).
- return (ownerProfile === name || ownerTarget === name) && ownerConnection === 'local'
+ // would orphan a live conversation (hermes-agent#94235). Tiles persisted
+ // before ownerRoute.connectionId existed carry no id; that empty string IS
+ // the local connection (the only source a pre-connectionId tile could have
+ // been opened on), so treat it as 'local' — otherwise those legacy tiles
+ // survive every local delete and resurrect the profile on relaunch.
+ return (ownerProfile === name || ownerTarget === name) && (ownerConnection || 'local') === 'local'
}
// The profile's own sessions bucket (Bot tiles live in the shared bucket
@@ -1659,7 +1673,13 @@ export function dropTilesForProfile(
const live = $sessionTiles.get()
const next = live.filter(tile =>
- tile.workspaceMode === 'bots' ? !ownerMatches(tile.ownerRoute) : profileKey() !== name
+ // Bot tiles map to the shared Bot bucket (keyed by ownerRoute here): drop
+ // the deleted profile's bots, matched by owner.
+ tile.workspaceMode === 'bots'
+ ? !ownerMatches(tile.ownerRoute)
+ : // Session tiles map to the owning profile's own bucket: drop only when
+ // the deleted profile IS the live gateway's profile.
+ profileKey() !== name
)
if (next.length !== live.length) {