diff --git a/src/client/SideChatView.tsx b/src/client/SideChatView.tsx index 826ae4a8..0032bd9f 100644 --- a/src/client/SideChatView.tsx +++ b/src/client/SideChatView.tsx @@ -889,14 +889,14 @@ export function SideChatView(props: { // loadLastThreads) reattaches to the thread the session was last in instead // of leaving yet another orphan "Side: New thread" session behind. useEffect(() => { - if (threadId !== undefined || !autoCreate || !visible) return + if (threadId !== undefined || !visible) return const reattach = reattachTarget() if (reattach !== undefined) { // Name the seat session: the same native id names a tab in every session. ctx.get('betterSidebar')?.updateTab(tab.id, { meta: { threadId: reattach } }, scope.sessionId) return } - void startThread() + if (autoCreate) void startThread() }, [threadId, autoCreate, visible, startThread, reattachTarget, ctx, tab.id, scope.sessionId]) // Remember the thread this tab holds, so reopening the panel (or a restart) diff --git a/tests/sidechat-image-composer.spec.tsx b/tests/sidechat-image-composer.spec.tsx index d11663a3..6b302ed1 100644 --- a/tests/sidechat-image-composer.spec.tsx +++ b/tests/sidechat-image-composer.spec.tsx @@ -133,6 +133,16 @@ describe('sidechat image composer', () => { expect(calls).toHaveLength(1) }) + it('reattaches a restored native tab to the remembered thread without sending again', async () => { + await harness.flush() + const snapshot = { byId: { root: { id: 'root', displayTitle: 'root', running: false }, t1: { id: 't1', displayTitle: 'Side: thread', origin: 'subagent', parentId: 'root', running: false } } } + const ctx = { get: (key: string) => key === 'betterSidebar' ? harness.host : undefined, sessions: { list: { subscribe: () => () => {}, getSnapshot: () => snapshot } } } as unknown as Context + mounted.rerender(createElement(SideChatView, { ctx, scope: { sessionId: 'root', cwd: '/p' }, tab: { id: 'restored', type: 'sidechat', title: 'Side Chat' }, visible: true })) + await harness.flush() + expect(harness.host.updateTab).toHaveBeenCalledWith('restored', { meta: { threadId: 't1' } }, 'root') + expect(calls).toEqual([]) + }) + it('renders saved and cold pending images by occurrence, disables cold dequeue and cleans loaded URLs', async () => { harness.wire.events = [{ type: 'user/message', seq: 1, time: 1, data: { id: 'saved', source: { kind: 'user' }, content: [{ type: 'image', attachment: { mediaType: 'image/png', bytes: 3, width: 1, height: 1, name: 'saved.png' } }] } }] harness.wire.pending = [{ id: 'queued', target: 'next-turn', text: '', removable: false, images: [{ blockIndex: 0, mediaType: 'image/png', bytes: 3, width: 1, height: 1, name: 'queued.png' }] }]