The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): delete tabs in the active connection scope
Teo | Nexcore70f869464b9f
diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex a564f9646ab..9276117824c 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -2571,7 +2571,11 @@ export function dropTilesForProfile(const routeProfile = route?.profile ? normalizeProfileKey(route.profile) : ''const routeTarget = route?.targetProfile ? normalizeProfileKey(route.targetProfile) : ''const routeConnection = String(route?.connectionId ?? '').trim()- const removedScope = backendScopeKey(routeConnection, routeProfile || name)+ // A route-less deletion targets the active backend, including legacy direct+ // remotes whose tile key uses the URL fallback. Reuse the writer's resolved+ // connection scope so deletion cannot erase same-named local tabs instead.+ const ambientConnection = tileConnectionId || LOCAL_CONNECTION_ID+ const removedScope = backendScopeKey(route ? routeConnection : ambientConnection, routeProfile || name)const ownerMatches = (owner: SessionProfileRoute | undefined): boolean => {if (!owner) {@@ -2596,15 +2600,13 @@ export function dropTilesForProfile(return !routeConnection || ownerConnection === routeConnection}- // 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). 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'+ // Ambient delete: only the active connection owns this profile. Legacy+ // owner routes without an id can be matched to local, but not guessed onto+ // an id-less remote — that would delete a same-named local Bot tab.+ return (+ (ownerProfile === name || ownerTarget === name) &&+ (ownerConnection || LOCAL_CONNECTION_ID) === ambientConnection+ )}// The profile's own sessions bucket (Bot tiles live in the shared bucketdiff --git a/apps/desktop/src/store/session-tiles-connection-scope.test.ts b/apps/desktop/src/store/session-tiles-connection-scope.test.tsindex ba70c4488ec..ba93924395a 100644--- a/apps/desktop/src/store/session-tiles-connection-scope.test.ts+++ b/apps/desktop/src/store/session-tiles-connection-scope.test.ts@@ -4,7 +4,13 @@ import type { HermesConnection } from '@/global'import { $activeGatewayProfile } from './profile'import { $selectedStoredSessionId, setConnection } from './session'-import { $sessionTiles, openSessionTile } from './session-states'+import {+ $sessionTiles,+ closeSessionTile,+ dropTilesForProfile,+ openSessionTile,+ reopenLastClosedTile+} from './session-states'const profile = 'connection-scope-regression'const local = {@@ -121,4 +127,66 @@ describe('session tiles across registered backend switches (#120106)', () => {'legacy-unknown-owner'])})++ it('drops an id-less remote profile without deleting same-named local tabs', () => {+ const name = 'direct-remote-delete-regression'+ const localProfile = { ...local, profile: name } as HermesConnection+ const directRemote = {+ baseUrl: 'https://legacy.example:8443',+ mode: 'remote',+ profile: name+ } as HermesConnection+ $activeGatewayProfile.set(name)+ setConnection(localProfile)+ openSessionTile('local-keep', 'right')+ openSessionTile('local-bot', 'right', undefined, undefined, {+ workspaceMode: 'bots',+ workspaceOwnerKey: `local::${name}`,+ ownerRoute: { connectionId: 'local', profile: name }+ })++ setConnection(directRemote)+ openSessionTile('remote-closed', 'right')+ closeSessionTile('remote-closed')+ openSessionTile('remote-open', 'right')++ dropTilesForProfile(name)+ expect($sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['local-bot'])+ reopenLastClosedTile()+ expect($sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['local-bot'])+ const persisted = JSON.parse(window.localStorage.getItem('hermes.desktop.sessionTiles.v2') || '{}')+ expect(persisted[`conn:url:${directRemote.baseUrl}::${name}`]).toBeUndefined()+ expect(persisted[name]?.map((tile: { storedSessionId: string }) => tile.storedSessionId)).toEqual(['local-keep'])+ expect(persisted.__bots_workspace__?.map((tile: { storedSessionId: string }) => tile.storedSessionId)).toEqual([+ 'local-bot'+ ])++ setConnection(localProfile)+ expect($sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['local-keep', 'local-bot'])+ })++ it('drops ambient registered-remote tabs and bots without touching local ones', () => {+ const name = 'ambient-remote-delete-regression'+ $activeGatewayProfile.set(name)+ setConnection({ ...local, profile: name } as HermesConnection)+ openSessionTile('local-keep', 'right')+ openSessionTile('local-bot', 'right', undefined, undefined, {+ workspaceMode: 'bots',+ workspaceOwnerKey: `local::${name}`,+ ownerRoute: { connectionId: 'local', profile: name }+ })++ setConnection({ ...remote, profile: name } as HermesConnection)+ openSessionTile('remote-open', 'right')+ openSessionTile('remote-bot', 'right', undefined, undefined, {+ workspaceMode: 'bots',+ workspaceOwnerKey: `homelab::${name}`,+ ownerRoute: { connectionId: 'homelab', profile: name }+ })++ dropTilesForProfile(name)+ expect($sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['local-bot'])+ setConnection({ ...local, profile: name } as HermesConnection)+ expect($sessionTiles.get().map(tile => tile.storedSessionId)).toEqual(['local-keep', 'local-bot'])+ })})