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(switchdash): scope room state to the server on screen (CHOO-1943)
Louis Amaudruz885709351719
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/command-palette/command-palette-modal.tsx b/dash/apps/switchdash-desktop/src/renderer/features/command-palette/command-palette-modal.tsxindex 31e476d0a..456878d96 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/command-palette/command-palette-modal.tsx+++ b/dash/apps/switchdash-desktop/src/renderer/features/command-palette/command-palette-modal.tsx@@ -230,6 +230,12 @@ export function CommandPaletteModal({return () => appState.resourceMonitor.dispose();}, [view]);+ // Search spans every server, but the sidebar only loads the one it is showing+ // — so the others' rooms are pulled here, by the feature that needs them.+ useEffect(() => {+ void switchRoomsStore.loadRoomsOnAllServers();+ }, []);+// Prefetch recents immediately on mount so the empty-query view is instant.useEffect(() => {void queryClient.prefetchQuery({diff --git a/dash/apps/switchdash-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx b/dash/apps/switchdash-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsxindex 86a010cb4..f1bfbe7ee 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx+++ b/dash/apps/switchdash-desktop/src/renderer/features/sidebar/sidebar-grouped-list.tsx@@ -62,17 +62,21 @@ export const SidebarGroupedList = observer(function SidebarGroupedList() {const onFocus = () => void loadSidebarState(true);window.addEventListener('focus', onFocus);- // A server that was not connected when the rooms were loaded contributed- // none, and signing in does not re-run the load by itself — so the rooms of- // a server you just signed into would be missing until the next focus.- const stopWatchingConnections = reaction(- () =>- switchServersStore.servers+ // Two things make the loaded state wrong without any mutation here:+ // signing in to a server (its rooms were skipped while disconnected, and+ // nothing re-ran the load), and switching which server is active — only the+ // server on screen is loaded, so the one you switch to may never have been.+ const stopWatchingServers = reaction(+ () => ({+ active: switchServersStore.activeServerId,+ connected: switchServersStore.servers.filter((s) => switchServersStore.isConnected(s.id)).map((s) => s.id).sort().join(','),- () => void loadSidebarState(true)+ }),+ () => void loadSidebarState(true),+ { equals: (a, b) => a.active === b.active && a.connected === b.connected });// Nothing pushes room state to the app: a membership changed from Slack,@@ -86,7 +90,7 @@ export const SidebarGroupedList = observer(function SidebarGroupedList() {return () => {window.removeEventListener('focus', onFocus);- stopWatchingConnections();+ stopWatchingServers();clearInterval(reconcile);};}, []);diff --git a/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts b/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.tsindex f2b70a62d..8672a7fc9 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts+++ b/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts@@ -135,6 +135,60 @@ describe('listed rooms', () => {expect(store.unreadableServerNames).toEqual(['Alpha']);});+ it('asks only the active server for its rooms', async () => {+ serversStore.servers = [+ { id: 'srv-a', name: 'Alpha' },+ { id: 'srv-b', name: 'Beta' },+ ];+ serversStore.activeServerId = 'srv-b';+ listRemoteRooms.mockImplementation(async () => []);++ const store = new SwitchRoomsStore();+ await store.loadRoomNames();++ expect(listRemoteRooms).toHaveBeenCalledExactlyOnceWith('srv-b');+ });++ it('does not report another server’s failure against the one you are viewing', async () => {+ // Each server is its own world. A server you are not looking at being down+ // says nothing about the one you are, and warning about it trains you to+ // ignore the warning.+ serversStore.servers = [+ { id: 'srv-a', name: 'Alpha' },+ { id: 'srv-b', name: 'Beta' },+ ];+ listRemoteRooms.mockImplementation(async (serverId: string) => {+ if (serverId === 'srv-a') throw new Error('unreachable');+ return [room('srv-b-room', 'user-of-srv-b')];+ });+ const store = new SwitchRoomsStore();++ // Search loads every server, so Alpha's failure is on the record...+ await store.loadRoomsOnAllServers();+ expect(store.unreadableServerNames).toEqual(['Alpha']);++ // ...but it must not surface while Beta is the server on screen.+ serversStore.activeServerId = 'srv-b';+ expect(store.roomStateIncomplete).toBe(false);+ expect(store.unreadableServerNames).toEqual([]);+ });++ it('does not report a disconnected server you are not viewing', async () => {+ serversStore.servers = [+ { id: 'srv-a', name: 'Alpha' },+ { id: 'srv-b', name: 'Beta' },+ ];+ serversStore.activeServerId = 'srv-b';+ serversStore.isConnected = (serverId: string) => serverId !== 'srv-a';+ listRemoteRooms.mockImplementation(async () => []);++ const store = new SwitchRoomsStore();+ await store.loadRoomsOnAllServers();++ expect(store.unreadableServerNames).toEqual([]);+ serversStore.isConnected = () => true;+ });+it('counts a server it never asked as unknown, not as having no rooms', async () => {serversStore.servers = [{ id: 'srv-a', name: 'Alpha' },diff --git a/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts b/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.tsindex 582445504..d0abb426e 100644--- a/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts+++ b/dash/apps/switchdash-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts@@ -195,7 +195,21 @@ export class SwitchRoomsStore {}/**- * Refresh the room catalogue from every connected server's room list.+ * The servers whose state is on screen: the active one, or all of them when+ * none is active (the same scope rule the room and location lists follow).+ *+ * Each server is its own world — its own rooms, its own agents, its own+ * connection. Reading or reporting on one you are not looking at is both+ * wasted work and, worse, someone else's problem presented as yours.+ */+ private get serverIdsInScope(): string[] {+ const activeServerId = switchServersStore.activeServerId;+ if (activeServerId) return [activeServerId];+ return switchServersStore.servers.map((s) => s.id);+ }++ /**+ * Refresh the room catalogue for the servers on screen.** A server that cannot be read keeps its last-known rooms rather than losing* them, but the failure is recorded in {@link roomListErrors} instead of being@@ -203,16 +217,32 @@ export class SwitchRoomsStore {* worse than showing nothing.*/async loadRoomNames(): Promise<void> {- const connected = switchServersStore.servers.filter((s) =>- switchServersStore.isConnected(s.id)- );+ await this.loadRoomsFrom(this.serverIdsInScope);+ }++ /**+ * Refresh the room catalogue for **every** server.+ *+ * Only for cross-server search, which is deliberately not scoped — you search+ * because you do not know where a thing is. Everything else loads the servers+ * it is actually showing.+ */+ async loadRoomsOnAllServers(): Promise<void> {+ await this.loadRoomsFrom(switchServersStore.servers.map((s) => s.id));+ }++ private async loadRoomsFrom(serverIds: string[]): Promise<void> {+ const servers = switchServersStore.servers.filter((s) => serverIds.includes(s.id));+ const connected = servers.filter((s) => switchServersStore.isConnected(s.id));runInAction(() => {// Not being connected is not a failure — there is simply nothing to ask// right now — but the rooms on that server are equally unknown, and the// sidebar has to be able to say so.- this.unreachableServerIds = switchServersStore.servers- .filter((s) => !switchServersStore.isConnected(s.id))- .map((s) => s.id);+ const asked = new Set(serverIds);+ this.unreachableServerIds = [+ ...this.unreachableServerIds.filter((id) => !asked.has(id)),+ ...servers.filter((s) => !switchServersStore.isConnected(s.id)).map((s) => s.id),+ ];});await Promise.all(connected.map(async (server) => {@@ -259,12 +289,21 @@ export class SwitchRoomsStore {* this is what stops it from passing them off as current.*/get roomStateIncomplete(): boolean {- return this.roomListErrors.size > 0 || this.unreachableServerIds.length > 0;+ return this.unreadableServerNames.length > 0;}- /** Names of the servers behind {@link roomStateIncomplete}, for disclosure. */+ /**+ * Names of the servers behind {@link roomStateIncomplete}, for disclosure.+ *+ * Scoped to the servers on screen. A server you are not looking at being+ * unreachable says nothing about what you are looking at, and reporting it+ * teaches you to ignore the warning.+ */get unreadableServerNames(): string[] {- const ids = [...new Set([...this.roomListErrors.keys(), ...this.unreachableServerIds])];+ const inScope = new Set(this.serverIdsInScope);+ const ids = [...new Set([...this.roomListErrors.keys(), ...this.unreachableServerIds])].filter(+ (id) => inScope.has(id)+ );return ids.map((id) => switchServersStore.servers.find((s) => s.id === id)?.name ?? id).sort((a, b) => a.localeCompare(b));