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 chat timelines from skipping messages across a gap (CHOO-3783)
raullopez-sandboxcefcf29444bb
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.tsindex 8cbc1cabc..34d2434a4 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chat-timeline-store.ts@@ -165,10 +165,19 @@ export class ChatTimeline {if (this.loading) return;this.loading = true;this.loadError = null;+ const held = this.newestSeq;try {- const page = await this.api.messages(this.roomId, null, PAGE_SIZE);+ let page = await this.api.messages(this.roomId, null, PAGE_SIZE);+ const fetched = [...page.messages];+ // Page back until the newest held message, so a gap since the last load is not skipped.+ let oldest = Math.min(...page.messages.map((message) => message.seq));+ while (held !== null && page.hasMore && page.messages.length && oldest > held) {+ page = await this.api.messages(this.roomId, oldest, PAGE_SIZE);+ fetched.push(...page.messages);+ oldest = Math.min(oldest, ...page.messages.map((message) => message.seq));+ }runInAction(() => {- for (const message of page.messages) this.apply(message);+ for (const message of fetched) this.apply(message);if (!this.loaded) this.hasMore = page.hasMore;this.loaded = true;this.notMember = false;@@ -381,10 +390,11 @@ export class ChatTimelines {return this.timelines.get(`${serverId}\u0000${roomId}`);}- /** Load again each of the server's timelines whose last load failed. */- reloadFailed(serverId: string): void {+ /** Load again each of the server's timelines that loaded or failed to, catching up to the live feed. */+ reload(serverId: string): void {for (const [key, timeline] of this.timelines)- if (key.startsWith(`${serverId}\u0000`) && timeline.loadError) void timeline.load();+ if (key.startsWith(`${serverId}\u0000`) && (timeline.loaded || timeline.loadError))+ void timeline.load();}/** Forget everything held for a server: signed out, or the tenant changed. */diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.tsindex bc77fb053..a952c0ef1 100644--- a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/chats-store.ts@@ -103,7 +103,7 @@ export class ChatsStore {// A first load that failed while the server was down is not retried by anything else.if (state !== 'live') return;if (this.userId === null || this.listError) void this.connect(serverId);- this.timelines.reloadFailed(serverId);+ this.timelines.reload(serverId);});events.onReset(({ serverId }) => this.reset(serverId));}diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.tsindex 02bfaab29..47f19248e 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chat-timeline-store.test.ts@@ -227,4 +227,24 @@ describe('ChatTimeline', () => {expect(timeline.notMember).toBe(true);expect(timeline.loadError).toBeNull();});++ it('pages back to what it holds when loading again, so a gap is not skipped', async () => {+ let head = 3;+ const { value } = api({+ messages: async (_room, before, limit) => {+ const top = Math.min(before ?? head + 1, head + 1);+ const from = Math.max(1, top - limit);+ const seqs = Array.from({ length: top - from }, (_, i) => from + i);+ return { messages: seqs.map((seq) => message(seq)), headSeq: head, hasMore: from > 1 };+ },+ });+ const timeline = new ChatTimeline('room-1', value);+ await timeline.load();+ head = 130;+ await timeline.load();+ expect(timeline.messages.map((m) => m.seq)).toEqual(+ Array.from({ length: 130 }, (_, i) => i + 1)+ );+ expect(timeline.hasMore).toBe(false);+ });});diff --git a/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts b/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.tsindex a3c7d400a..d2d472605 100644--- a/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/tests/chats-store.test.ts@@ -246,6 +246,20 @@ describe('ChatsStore', () => {expect(timeline.accessLost).toBe(false);});+ it('catches an open timeline up to the feed once it is live', async () => {+ let page = [message('r1', 1)];+ const messages = vi.fn(async () => ({ messages: page, headSeq: page.length, hasMore: false }));+ const { store, live } = setup(async () => [summary('r1', 1)], { messages });+ await store.connect('s1');+ const timeline = store.timelines.get('s1', 'r1');+ await timeline.load();++ // Posted before the feed took its cursor: the feed will never deliver it.+ page = [message('r1', 1), message('r1', 2)];+ live();+ await vi.waitFor(() => expect(timeline.messages.map((m) => m.seq)).toEqual([1, 2]));+ });+it('revokes a chat unlisted earlier once access is lost', async () => {const { store } = setup(async () => [summary('r1', 1)]);await store.connect('s1');