Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(console): stop tracking moved agents' rooms; refresh rooms on server push; keep the starting agent
raullopez-sandbox75cf36518c1c
diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.tsindex a707db14a..73810584f 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/managed-identities.test.ts@@ -5,7 +5,35 @@ const servers = vi.hoisted(() => ({user: 'user-1' as string | null,}));-vi.mock('@renderer/lib/ipc', () => ({ events: { on: vi.fn() }, rpc: {} }));+const local = vi.hoisted(() => ({+ agents: [] as { id: string; workspaceId: string; switchAgentId: string }[],+ moved: new Set<string>(),+ ensure: vi.fn(async (_ids: unknown) => {}),+ listeners: [] as ((event: unknown) => void)[],+}));++vi.mock('@renderer/lib/ipc', () => ({+ events: {+ on: (_channel: unknown, listener: (event: unknown) => void) => {+ local.listeners.push(listener);+ return () => {};+ },+ },+ rpc: { workspaces: { backfillAgentIcons: async () => ({}) } },+}));+vi.mock('@renderer/features/locations/stores/agents-store', () => ({+ agentsStore: {+ load: async () => {},+ byLocation: { get: () => local.agents },+ isMoved: (id: string) => local.moved.has(id),+ },+}));+vi.mock('@renderer/lib/stores/app-state', () => ({+ sidebarStore: { orderedLocations: [{ id: 'loc' }] },+}));+vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({+ switchRoomsStore: { ensureMembershipsFor: local.ensure, loadRoomNames: async () => {} },+}));vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({switchServersStore: {get servers() {@@ -18,7 +46,12 @@ vi.mock('@renderer/features/workspaces/workspaces-store', () => ({workspacesStore: { idOnServerInScope: () => 'ws-a' },}));-const { managedIdentities } = await import('./sidebar-tree-data');+const {+ managedIdentities,+ refreshSidebarOnRoomChanges,+ refreshSidebarRoomState,+ switchIdentities,+} = await import('./sidebar-tree-data');const { queryClient } = await import('@renderer/lib/query-client');describe('managedIdentities', () => {@@ -50,3 +83,40 @@ describe('managedIdentities', () => {expect(managedIdentities()).toEqual([{ workspaceId: 'ws-a', switchAgentId: 'mine' }]);});});++describe('local membership tracking', () => {+ beforeEach(() => {+ queryClient.clear();+ servers.user = 'user-1';+ local.agents = [{ id: 'moved-row', workspaceId: 'ws-a', switchAgentId: 'gone' }];+ local.moved = new Set(['moved-row']);+ local.ensure.mockClear();+ });++ it('does not track a moved local row, so an empty managed list leaves its rooms unlisted', async () => {+ queryClient.setQueryData(['managed-agents', 'srv', 'ws-a', 'user-1'], []);+ expect(switchIdentities()).toEqual([]);+ await refreshSidebarRoomState(true);+ expect(local.ensure).toHaveBeenCalledWith([], { force: true });+ });++ it('refreshes when a server says a room changed, and not for other kinds', async () => {+ local.listeners = [];+ refreshSidebarOnRoomChanges();+ const [listener] = local.listeners;+ listener({+ type: 'changed',+ serverId: 'srv',+ workspaceId: null,+ changes: [{ kind: 'machine', id: 'm' }],+ });+ expect(local.ensure).not.toHaveBeenCalled();+ listener({+ type: 'changed',+ serverId: 'srv',+ workspaceId: null,+ changes: [{ kind: 'room', id: 'r' }],+ });+ await vi.waitFor(() => expect(local.ensure).toHaveBeenCalledTimes(1));+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsxindex 5841efcc1..91201083c 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx@@ -23,7 +23,11 @@ import { SessionDiscoveryStatus } from './session-discovery-status';import { SessionsSectionHeader } from './sessions-section-header';import { useScrollSelectionIntoView } from './sidebar-auto-scroll';import { showsAgentsAndRooms, sidebarEmptyState } from './sidebar-empty-state';-import { agentsInActiveScope, refreshSidebarRoomState } from './sidebar-tree-data';+import {+ agentsInActiveScope,+ refreshSidebarOnRoomChanges,+ refreshSidebarRoomState,+} from './sidebar-tree-data';/*** How often the room state is reconciled against the servers while the window@@ -90,8 +94,11 @@ export const SidebarGroupedList = observer(function SidebarGroupedList() {void loadSidebarState(true);}, ROOM_STATE_RECONCILE_MS);+ const stopRoomChanges = refreshSidebarOnRoomChanges();+return () => {window.removeEventListener('focus', onFocus);+ stopRoomChanges();stopWatchingServers();clearInterval(reconcile);};diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-icon-backfill-toast.test.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-icon-backfill-toast.test.tsindex 56c19dd1b..bbc066556 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-icon-backfill-toast.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-icon-backfill-toast.test.ts@@ -27,6 +27,7 @@ const AGENT = {vi.mock('@renderer/lib/hooks/use-toast', () => ({ toast }));vi.mock('@renderer/lib/ipc', () => ({+ events: { on: () => () => {} },rpc: { workspaces: { backfillAgentIcons } },}));vi.mock('@renderer/features/locations/stores/agents-store', () => ({@@ -34,6 +35,7 @@ vi.mock('@renderer/features/locations/stores/agents-store', () => ({load: vi.fn().mockResolvedValue(undefined),byLocation: new Map([[LOCATION.id, [AGENT]]]),agentsInWorkspaceAtLocation: () => [AGENT],+ isMoved: () => false,},}));vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({diff --git a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.tsindex a7af70acd..c4617e6b6 100644--- a/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/sidebar/sidebar-tree-data.ts@@ -7,13 +7,14 @@ import { switchRoomsStore } from '@renderer/features/switch-servers/switch-roomsimport { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';import { toast } from '@renderer/lib/hooks/use-toast';-import { rpc } from '@renderer/lib/ipc';+import { events, rpc } from '@renderer/lib/ipc';import { queryClient } from '@renderer/lib/query-client';import { sidebarStore } from '@renderer/lib/stores/app-state';import { log } from '@renderer/utils/logger';import type { Agent } from '@shared/core/agents/agents';import type { ManagedAgentView } from '@shared/core/managed-agents/managed-agents';import type { AgentIconBackfill } from '@shared/core/switch-servers/switch-servers';+import { userChangesChannel } from '@shared/events/userChangesEvents';/*** What the two sidebar trees agree on: which agents are in scope and which@@ -103,7 +104,8 @@ export function agentSessions(entry: AgentEntry): SessionStore[] {export function switchIdentities(): { workspaceId: string; switchAgentId: string }[] {const identities: { workspaceId: string; switchAgentId: string }[] = [];for (const { agent } of agentsInActiveScope()) {- if (agent.workspaceId && agent.switchAgentId) {+ // A moved agent's rooms come from the managed list, which drops them once it is gone.+ if (agent.workspaceId && agent.switchAgentId && !agentsStore.isMoved(agent.id)) {identities.push({ workspaceId: agent.workspaceId, switchAgentId: agent.switchAgentId });}}@@ -166,6 +168,15 @@ export async function refreshSidebarRoomState(force: boolean): Promise<void> {void giveExistingAgentsAnIcon();}+/** Refresh as soon as a server says a room of this user's changed, ahead of the reconcile timer. */+export function refreshSidebarOnRoomChanges(): () => void {+ return events.on(userChangesChannel, (event) => {+ if (event.type === 'changed' && event.changes.some((change) => change.kind === 'room')) {+ void refreshSidebarRoomState(true);+ }+ });+}+/*** Gaps between the passes {@link refreshSidebarRoomStateAfterOnboarding} makes.* Spread over a few seconds rather than fired once, because the state beingdiff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsxindex b852f2ef0..693c8385a 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/CreateRoomModal.tsx@@ -38,6 +38,7 @@ import { MessagingAppSelector, SWITCH_CONSOLE } from './messaging-app-selector';import {CreateRequestIds,canCreate,+ dropsStartingAgent,roomCreateRequest,startingAgentResolution,} from './room-create-request';@@ -147,18 +148,18 @@ export const CreateRoomModal = observer(function CreateRoomModal({personParticipant),];- // The agent the room is made from shows picked once the agents are read, until the- // picks are changed by hand (removing it then leaves it out).- const [touched, setTouched] = useState(false);+ // The agent the room is made from shows picked once the agents are read, whatever+ // else is edited meanwhile, until its chip is removed.+ const [startDropped, setStartDropped] = useState(false);const startChip =- startingAgentId === undefined || touched+ startingAgentId === undefined || startDropped? null: (candidates.find((each) => each.kind === 'agent' && each.id === startingAgentId) ?? null);const shownPicked = startChip? [startChip, ...picked.filter((each) => each.id !== startChip.id)]: picked;const changePicks = (next: Participant[]) => {- setTouched(true);+ if (dropsStartingAgent(startChip, next)) setStartDropped(true);setPicked(next);};const agentIds = shownPicked.filter((each) => each.kind === 'agent').map((each) => each.id);@@ -169,7 +170,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({// a quick Create would otherwise make the room without it.const startingAgentState = startingAgentResolution({startingAgentId,- applied: touched || startChip !== null,+ applied: startDropped || startChip !== null,failed: agentsQuery.isError || (!selectedBridge && allowedQuery.isError),loaded:agentsQuery.isSuccess &&diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.tsindex 28fddb66f..b83d24ada 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';import {CreateRequestIds,canCreate,+ dropsStartingAgent,roomCreateRequest,startingAgentResolution,} from './room-create-request';@@ -97,3 +98,28 @@ describe('startingAgentResolution', () => {expect(startingAgentResolution({ ...base, loaded: true })).toBe('unavailable');});});++describe('dropsStartingAgent', () => {+ const agent = { kind: 'agent', id: 'a1' };+ const person = { kind: 'person', id: 'u2' };++ it('keeps the starting agent through edits made while it loads, then applies it', () => {+ // Picking a person, or switching app, before the agent resolves: nothing is shown yet.+ expect(dropsStartingAgent(null, [person])).toBe(false);+ expect(dropsStartingAgent(null, [])).toBe(false);+ const waiting = { startingAgentId: 'a1', applied: false, failed: false, loaded: false };+ expect(startingAgentResolution(waiting)).toBe('pending');+ // Resolved: its chip is shown, so it is applied.+ expect(startingAgentResolution({ ...waiting, loaded: true, applied: true })).toBe('resolved');+ });++ it('keeps it when other picks change or a bridged app keeps only agents', () => {+ expect(dropsStartingAgent(agent, [agent, person])).toBe(false);+ expect(dropsStartingAgent(agent, [agent])).toBe(false);+ });++ it('leaves it out only when its chip is removed', () => {+ expect(dropsStartingAgent(agent, [person])).toBe(true);+ expect(dropsStartingAgent(agent, [{ kind: 'person', id: 'a1' }])).toBe(true);+ });+});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.tsindex ed4fe7485..75677cc33 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-create-request.ts@@ -107,6 +107,17 @@ export class CreateRequestIds {}}+/**+ * Whether a change to the picks removes the starting agent the dialog shows: only+ * that leaves it out. Other edits, made before or after it resolves, keep it.+ */+export function dropsStartingAgent(+ shown: { kind: string; id: string } | null,+ next: { kind: string; id: string }[]+): boolean {+ return shown !== null && !next.some((each) => each.kind === shown.kind && each.id === shown.id);+}+/*** Where the agent a room is made from stands: no such agent or already picked* (`resolved`), the agents still loading (`pending`, when Create waits), or itdiff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsxindex 45bb7a8d4..d4f62f60a 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx@@ -27,6 +27,7 @@ vi.mock('@renderer/features/locations/stores/agents-store', () => ({loaded: true,load: async () => {},agentsOnServer: () => [{ switchAgentId: 'a' }, { switchAgentId: 'b' }],+ isMoved: () => false,},}));