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/app/store.svelte.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/app') diff --git a/src/app/store.svelte.ts b/src/app/store.svelte.ts index 629e6c6..8997ce0 100644 --- a/src/app/store.svelte.ts +++ b/src/app/store.svelte.ts @@ -1106,8 +1106,15 @@ export function createAppStore(opts?: CreateAppStoreOptions): AppStore { workspaceId: conv.workspaceId, }); } else { - // Already open — update the title from the backend if it differs. + // Already open — reconcile title + workspace from the authoritative + // backend list. A raced `conversation.open` (summon) may have stamped + // the tab with the wrong workspace ("default"); the backend's + // authoritative conversation record is the source of truth, so a + // differing tab workspace is corrected here. tabsStore.setTitle(conv.id, conv.title); + if (tabsStore.tabs.find((t) => t.conversationId === conv.id)?.workspaceId !== conv.workspaceId) { + tabsStore.setWorkspaceId(conv.id, conv.workspaceId); + } } } @@ -1146,6 +1153,17 @@ export function createAppStore(opts?: CreateAppStoreOptions): AppStore { // `queued` = the turn is in flight but waiting for a concurrency slot // (broadcast-only, never persisted — CR-13); the tab shows a ring. conversationStatuses = new Map(conversationStatuses).set(conversationId, status); + // Reconcile the already-open tab's workspace from this authoritative + // lifecycle event (the payload workspace is the conversation's actual + // persisted workspace). A raced `conversation.open` may have stamped the + // wrong workspace ("default") — correct it here. + if ( + chatStores.has(conversationId) && + (tabsStore.tabs.find((t) => t.conversationId === conversationId)?.workspaceId ?? + workspaceId) !== workspaceId + ) { + tabsStore.setWorkspaceId(conversationId, workspaceId); + } // If this is a new active OR queued conversation we don't have a tab for, // open one — so a cross-device turn (incl. one waiting in the concurrency // queue) is visible. `idle` never opens a tab. -- cgit v1.2.3