From 774519e052fd869952cc5e05aca159e4bf978fa1 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Wed, 5 Aug 2026 14:46:21 +0900 Subject: fix(tabs): reconcile tab workspaceId from authoritative backend data A summoned conversation's tab can be stamped with the wrong workspace ('default') because the raced conversation.open message precedes the child's workspace persistence. Add setWorkspaceId to the tabs store and reconcile an already-open tab's workspace from authoritative sources: the backend conversation-list refresh and lifecycle status events. This corrects a stale tab (incl. one persisted to localStorage) once the DB has the right value. --- src/features/tabs/tabs-store.svelte.ts | 5 +++++ src/features/tabs/tabs.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) (limited to 'src/features/tabs') diff --git a/src/features/tabs/tabs-store.svelte.ts b/src/features/tabs/tabs-store.svelte.ts index d044b1f..acf56fe 100644 --- a/src/features/tabs/tabs-store.svelte.ts +++ b/src/features/tabs/tabs-store.svelte.ts @@ -8,6 +8,7 @@ import { selectTab as reduceSelectTab, setModel as reduceSetModel, setTitle as reduceSetTitle, + setWorkspaceId as reduceSetWorkspaceId, activeTab as selectActiveTab, } from "./tabs"; @@ -28,6 +29,7 @@ export interface TabsStore { closeTab(conversationId: string): void; setModel(conversationId: string, model: string): void; setTitle(conversationId: string, title: string): void; + setWorkspaceId(conversationId: string, workspaceId: string): void; } export function createTabsStore(storage: TabsStorage): TabsStore { @@ -69,5 +71,8 @@ export function createTabsStore(storage: TabsStorage): TabsStore { setTitle(conversationId: string, title: string): void { apply(reduceSetTitle(state, conversationId, title)); }, + setWorkspaceId(conversationId: string, workspaceId: string): void { + apply(reduceSetWorkspaceId(state, conversationId, workspaceId)); + }, }; } diff --git a/src/features/tabs/tabs.ts b/src/features/tabs/tabs.ts index 63cda35..9fc9306 100644 --- a/src/features/tabs/tabs.ts +++ b/src/features/tabs/tabs.ts @@ -82,6 +82,17 @@ export function setTitle(state: TabsState, conversationId: string, title: string return { tabs, activeConversationId: state.activeConversationId }; } +export function setWorkspaceId( + state: TabsState, + conversationId: string, + workspaceId: string, +): TabsState { + const tabs = state.tabs.map((t) => + t.conversationId === conversationId ? { ...t, workspaceId } : t, + ); + return { tabs, activeConversationId: state.activeConversationId }; +} + export function activeTab(state: TabsState): Tab | null { if (state.activeConversationId === null) return null; return state.tabs.find((t) => t.conversationId === state.activeConversationId) ?? null; -- cgit v1.2.3