From 4959f8ae5dcbb24fb5a8cc6b8246f024bf506914 Mon Sep 17 00:00:00 2001 From: Guilhem Lemouel Date: Fri, 30 Oct 2026 05:59:59 -0700 Subject: [PATCH] fix: keep a sending home draft in the workspace it was sent from Co-Authored-By: Claude Opus 5.5 --- .../components/sessions/sessionState.svelte.ts | 7 ++++--- .../components/sessions/sessionState.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/sessions/sessionState.svelte.ts b/frontend/src/lib/components/sessions/sessionState.svelte.ts index 137457e2ab..5007e3d4bc 100644 --- a/frontend/src/lib/components/sessions/sessionState.svelte.ts +++ b/frontend/src/lib/components/sessions/sessionState.svelte.ts @@ -1080,12 +1080,13 @@ if (BROWSER) { // Home's draft acts on the workspace the page header names, so a switch to another // workspace of its family takes the draft along. A switch to another family leaves -// it where it was: Home shows that family's own draft. Not a touch, so the draft's -// last activity stays when the user last worked on it. +// it where it was: Home shows that family's own draft. A draft already sending stays +// too: its send commits the workspace it started in, but only after the pre-flight. +// Not a touch, so the draft's last activity stays when the user last worked on it. function followHomeDraft(): void { const s = homeDraft.id ? sessionState.sessions.find((x) => x.id === homeDraft.id) : undefined const ws = get(workspaceStore) - if (!s || !ws || s.workspace_id) return + if (!s || !ws || s.workspace_id || sendUnderWay(s.id)) return if (s.pending_workspace_id === ws && !s.pending_fork) return if (s.pending_workspace_id && workspaceRootId(ws, get(userWorkspaces)) !== sessionRootId(s)) { return diff --git a/frontend/src/lib/components/sessions/sessionState.test.ts b/frontend/src/lib/components/sessions/sessionState.test.ts index 4a9cc9d718..946e4b2f34 100644 --- a/frontend/src/lib/components/sessions/sessionState.test.ts +++ b/frontend/src/lib/components/sessions/sessionState.test.ts @@ -735,6 +735,24 @@ describe('homeStarterSession', () => { } }) + it('keeps a draft whose first send is under way in the workspace it was sent from', () => { + const restore = withTwoFamilies('forkA') + sessionState.sessions.push(session({ id: 'sending-draft', pending_workspace_id: 'forkA' })) + const sendingNow = () => sessionState.sessions.find((s) => s.id === 'sending-draft') + try { + holdHomeDraft('sending-draft') + setSendUnderWayCheck((id) => id === 'sending-draft') + workspaceStore.set('rootA') + holdHomeDraft('sending-draft') + expect(sendingNow()?.pending_workspace_id).toBe('forkA') + } finally { + setSendUnderWayCheck(() => false) + homeDraft.id = undefined + sessionState.sessions = sessionState.sessions.filter((s) => s.id !== 'sending-draft') + restore() + } + }) + it('lets go of its blank once a hand-off reuses it for an item', () => { const restore = withTwoFamilies('forkA') const prevCurrent = sessionState.currentSessionId