Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): store the server title when a server-only chat is opened
Alfredo Lopeze4166fcd5f96
diff --git a/desktop-app/src/__tests__/chatStore.test.ts b/desktop-app/src/__tests__/chatStore.test.tsindex 5e45588e8..8aae5f881 100644--- a/desktop-app/src/__tests__/chatStore.test.ts+++ b/desktop-app/src/__tests__/chatStore.test.ts@@ -3034,3 +3034,88 @@ describe('upsertServerSessions', () => {expect(saveIndex).toHaveBeenCalledTimes(1)})})++// ── server-only titles reach the index at hydration (A19.1) ───────────────────++describe('createChat after a catalog page reported the session', () => {+ function rememberedTitles(): Map<string, Map<string, string>> {+ return (store as unknown as { serverOnlyTitles: Map<string, Map<string, string>> })+ .serverOnlyTitles+ }++ it('stores the server title on disk when a server-only chat is opened', async () => {+ await store.upsertServerSessions('agent-1', [{ chatId: 'remote', title: 'Quarterly plan' }])++ const meta = await store.createChat('agent-1', 'remote')++ expect(meta.title).toBe('Quarterly plan')+ const chats = await new ChatStore(tempDir).listChats('agent-1')+ expect(chats.map(c => [c.id, c.title])).toEqual([['remote', 'Quarterly plan']])+ })++ it('keeps New Chat for an id the catalog never reported', async () => {+ await store.upsertServerSessions('agent-1', [{ chatId: 'remote', title: 'Remote' }])++ const fresh = await store.createChat('agent-1', 'fresh')+ // Witness: the reported id in the same store does get its title.+ const remote = await store.createChat('agent-1', 'remote')++ expect(fresh.title).toBe('New Chat')+ expect(remote.title).toBe('Remote')+ })++ it('forgets the remembered title when the session arrives without one', async () => {+ await store.upsertServerSessions('agent-1', [+ { chatId: 'renamed', title: 'Before rename' },+ { chatId: 'kept', title: 'Kept' },+ ])+ // A pending local rename: the renderer omits the title for that chat only.+ await store.upsertServerSessions('agent-1', [+ { chatId: 'renamed' },+ { chatId: 'kept', title: 'Kept' },+ ])++ const renamed = await store.createChat('agent-1', 'renamed')+ // Witness: the sibling sent with a title in the same call keeps it.+ const kept = await store.createChat('agent-1', 'kept')++ expect(renamed.title).toBe('New Chat')+ expect(kept.title).toBe('Kept')+ })++ it('keeps remembered titles per agent', async () => {+ await store.upsertServerSessions('agent-1', [{ chatId: 'shared-id', title: 'Agent one' }])++ const other = await store.createChat('agent-2', 'shared-id')+ // Witness: the owning agent gets its title.+ const own = await store.createChat('agent-1', 'shared-id')++ expect(other.title).toBe('New Chat')+ expect(own.title).toBe('Agent one')+ })++ it('does not reopen a chat deleted locally', async () => {+ await store.createChat('agent-1', 'gone')+ await store.deleteChat('agent-1', 'gone', TEAM_A_SCOPE)+ await store.upsertServerSessions('agent-1', [+ { chatId: 'gone', title: 'Deleted' },+ { chatId: 'live', title: 'Live' },+ ])++ await expect(store.createChat('agent-1', 'gone')).rejects.toThrow('Chat was deleted locally')+ // Witness: the live sibling from the same catalog page is created with its title.+ expect((await store.createChat('agent-1', 'live')).title).toBe('Live')+ const chats = await new ChatStore(tempDir).listChats('agent-1')+ expect(chats.map(c => [c.id, c.title])).toEqual([['live', 'Live']])+ })++ it('drops the remembered title once hydration used it', async () => {+ await store.upsertServerSessions('agent-1', [{ chatId: 'remote', title: 'Remote' }])+ // Witness: the title is held before the chat is opened.+ expect(rememberedTitles().get('agent-1')?.get('remote')).toBe('Remote')++ await store.createChat('agent-1', 'remote')++ expect(rememberedTitles().get('agent-1')?.has('remote')).toBe(false)+ })+})diff --git a/desktop-app/src/chatStore.ts b/desktop-app/src/chatStore.tsindex 7fbe0810b..069bb326a 100644--- a/desktop-app/src/chatStore.ts+++ b/desktop-app/src/chatStore.ts@@ -462,6 +462,14 @@ export class ChatStore {private compatibilityWindows = new Map<string, ChatMessage[]>()private compatibilityWindowBytes = new Map<string, number>()private compatibilityWindowsTotalBytes = 0+ /**+ * Server titles of sessions the catalog reported before they were in the+ * index, keyed by agent then chat. `createChat` reads (and drops) the entry+ * when the user opens such a chat, so hydration stores the title the+ * catalog already showed instead of the 'New Chat' placeholder. Written and+ * read only inside `serializeIndex` for the agent.+ */+ private serverOnlyTitles = new Map<string, Map<string, string>>()private dropCompatibilityWindow(key: string): void {this.compatibilityWindows.delete(key)@@ -1778,10 +1786,13 @@ export class ChatStore {const existing = index.chats.find(c => c.id === chatId)if (existing) return existing+ const rememberedTitles = this.serverOnlyTitles.get(agentRef)+ const serverTitle = rememberedTitles?.get(chatId)+ rememberedTitles?.delete(chatId)const now = new Date().toISOString()const meta: ChatMetadata = {id: chatId,- title: 'New Chat',+ title: serverTitle ?? 'New Chat',createdAt: now,updatedAt: now,messageCount: 0,@@ -2250,7 +2261,8 @@ export class ChatStore {* Deliberately does NOT create entries for server-only sessions: the sidebar's* in-memory merge (`useChatListController`) already surfaces those, and a local* `deleteChat` doesn't remove the server session — eagerly re-persisting it- * would resurrect a chat the user just deleted.+ * would resurrect a chat the user just deleted. Their titles are only kept in+ * memory (`serverOnlyTitles`) so `createChat` can use them on first open.** `title`, when present, is the server's own title for the session. It is* stored so a cold start paints the last title the server reported instead of@@ -2271,7 +2283,13 @@ export class ChatStore {let changed = 0for (const session of sessions) {const chat = byId.get(session.chatId)- if (!chat) continue // server-only session — do not resurrect a local delete+ if (!chat) {+ // Server-only session: never create an entry (that would resurrect a+ // local delete). Remember its title for `createChat`; a session sent+ // without one (e.g. a pending local rename) forgets the old title.+ this.rememberServerOnlyTitle(agentRef, session.chatId, session.title)+ continue+ }let chatChanged = falseconst lastActivityAt = session.lastActivityAtif (@@ -2292,6 +2310,19 @@ export class ChatStore {})}+ private rememberServerOnlyTitle(agentRef: string, chatId: string, title?: string): void {+ let titles = this.serverOnlyTitles.get(agentRef)+ if (!title) {+ titles?.delete(chatId)+ return+ }+ if (!titles) {+ titles = new Map()+ this.serverOnlyTitles.set(agentRef, titles)+ }+ titles.set(chatId, title)+ }+/** Clear the unread-terminal flag (D.5), e.g. when the user opens the chat. */async clearUnreadTerminal(agentRef: string, chatId: string): Promise<void> {return this.serializeIndex(agentRef, async () => {