Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): retrying New room's chat create resumes it, not a second chat

raullopez-sandboxd2029b6adbb7
diff --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.tsx
index a478eae18..60fced13b 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
@@ -33,7 +33,7 @@ import { DisclosureRow } from '@renderer/lib/ui/disclosure-row';
import { Input } from '@renderer/lib/ui/input';
import { Textarea } from '@renderer/lib/ui/textarea';
import type { RemoteAgentSummary } from '@shared/core/switch-servers/switch-servers';
-import { canCreate, roomCreateRequest } from './room-create-request';
+import { CreateRequestIds, canCreate, roomCreateRequest } from './room-create-request';
import { switchServersStore } from './switch-servers-store';
import { useMyIdentities } from './use-my-identities';
@@ -68,6 +68,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
const [agents, setAgents] = useState<RemoteAgentSummary[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState<string | null>(null);
+ const [requestIds] = useState(() => new CreateRequestIds(() => crypto.randomUUID()));
const bridgesQuery = useQuery({
queryKey: ['remote-bridges', workspaceId],
@@ -152,10 +153,15 @@ export const CreateRoomModal = observer(function CreateRoomModal({
description,
instructions,
agentIds: agents.map((a) => a.id),
- requestId: crypto.randomUUID(),
+ requestId: requestIds.for({
+ bridgeId: selectedBridge?.id ?? null,
+ name,
+ agentIds: agents.map((a) => a.id),
+ }),
});
if (request.kind === 'chat') {
const chat = await rpc.chats.create(request.params);
+ requestIds.succeeded();
chatsStore.add(serverId, chat);
sidebarStore.setGrouping('room');
openRoomView(chat.roomId);
@@ -205,6 +211,7 @@ export const CreateRoomModal = observer(function CreateRoomModal({
description,
instructions,
agents,
+ requestIds,
onSuccess,
setCloseGuard,
]);
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.ts
index 03a815987..7ab1a9a6a 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
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { canCreate, roomCreateRequest } from './room-create-request';
+import { CreateRequestIds, canCreate, roomCreateRequest } from './room-create-request';
const form = {
serverId: 's',
@@ -49,3 +49,17 @@ describe('canCreate', () => {
expect(canCreate({ bridgeId: null, name: ' ', description: 'd' })).toBe(false);
});
});
+
+describe('CreateRequestIds', () => {
+ it('reuses the id for an unchanged form and takes a new one on a change or a success', () => {
+ let n = 0;
+ const ids = new CreateRequestIds(() => `id-${++n}`);
+ const chatForm = { bridgeId: null, name: 'Ship review', agentIds: ['a1', 'a2'] };
+ const first = ids.for(chatForm);
+ expect(ids.for({ ...chatForm, name: ' Ship review ' })).toBe(first);
+ expect(ids.for({ ...chatForm, name: 'Ship reviews' })).not.toBe(first);
+ expect(ids.for({ ...chatForm, name: 'Ship reviews', agentIds: ['a1'] })).toBe('id-3');
+ ids.succeeded();
+ expect(ids.for({ ...chatForm, name: 'Ship reviews', agentIds: ['a1'] })).toBe('id-4');
+ });
+});
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.ts
index c8467dd66..166d10e70 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
@@ -64,3 +64,29 @@ export function roomCreateRequest(form: {
export function canCreate(form: { bridgeId: string | null; name: string; description: string }) {
return form.name.trim() !== '' && (form.bridgeId === null || form.description.trim() !== '');
}
+
+/**
+ * One request id per form, as the direct-chat starter keeps one per agent: a
+ * retry of an unchanged form after an answer that never arrived resumes the
+ * chat it may already have made instead of making a second; a changed form,
+ * or a create that succeeded, takes a new one.
+ */
+export class CreateRequestIds {
+ private key: string | null = null;
+ private id = '';
+
+ constructor(private readonly newId: () => string) {}
+
+ for(form: { bridgeId: string | null; name: string; agentIds: string[] }): string {
+ const key = JSON.stringify([form.bridgeId, form.name.trim(), form.agentIds]);
+ if (key !== this.key) {
+ this.key = key;
+ this.id = this.newId();
+ }
+ return this.id;
+ }
+
+ succeeded(): void {
+ this.key = null;
+ }
+}