From d7eea8086f5a3c6472b2f2d727aa6f2d6b896249 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Thu, 19 Nov 2026 09:40:11 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=B0=EF=B8=8F=20fix:=20Send=20a=20Side?= =?UTF-8?q?=20Chat's=20Turns=20as=20Temporary=20Only=20When=20Its=20Own=20?= =?UTF-8?q?Conversation=20Is=20(#18455)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🕰️ fix: Send a Side Chat's Turns as Temporary Only When Its Own Conversation Is * 🧹 chore: Sort the Turn Services' Imports --- .../services.readCodeInputs.spec.tsx | 32 +++++++++++++- client/src/hooks/Chat/services.ts | 16 +++++-- .../scenarios/side-chat-open-beside.spec.ts | 42 +++++++++++++++++++ 3 files changed, 86 insertions(+), 4 deletions(-) diff --git a/client/src/hooks/Chat/__tests__/services.readCodeInputs.spec.tsx b/client/src/hooks/Chat/__tests__/services.readCodeInputs.spec.tsx index 74897495e5..41cc57887a 100644 --- a/client/src/hooks/Chat/__tests__/services.readCodeInputs.spec.tsx +++ b/client/src/hooks/Chat/__tests__/services.readCodeInputs.spec.tsx @@ -1,6 +1,6 @@ import { renderHook } from '@testing-library/react'; -import { QueryKeys, EModelEndpoint } from 'librechat-data-provider'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { QueryKeys, RetentionMode, EModelEndpoint } from 'librechat-data-provider'; import type { CodeApprovalModeInputs, CodeWorkspaceInputs } from '@librechat/chat'; import type { TConversation } from 'librechat-data-provider'; import type { ReactNode } from 'react'; @@ -118,6 +118,36 @@ describe('useTurnServices readCodeInputs', () => { expect(mockComparisons).toEqual({ workspace: null, approval: null }); }); + it("sends another pane's turns as temporary when its conversation is, not when main chat is", () => { + /** The page's setting follows the conversation main chat shows: here, a temporary one. */ + settings = { ...settings, isTemporary: true }; + const saved = conversation({ conversationId: 'saved', isTemporary: false }); + const turns = (index: number, held: TConversation) => + renderHook(() => useTurnServices({ index, conversation: held }), { wrapper }).result.current; + + expect(turns(0, saved).isTemporary).toBe(true); + expect(turns(3, saved).isTemporary).toBe(false); + + /** And the other way round: a temporary conversation beside a saved one stays temporary. */ + settings = { ...settings, isTemporary: false }; + const temporary = conversation({ conversationId: 'temporary', isTemporary: true }); + expect(turns(0, saved).isTemporary).toBe(false); + expect(turns(3, temporary).isTemporary).toBe(true); + /** A record from before the flag was stored carries only its deadline. */ + const legacy = conversation({ + conversationId: 'legacy', + expiredAt: '2026-12-01T00:00:00.000Z', + }); + expect(turns(3, legacy).isTemporary).toBe(true); + + /** A deployment that keeps nothing makes every pane's turns temporary. */ + settings = { + ...settings, + config: { ...settings.config, retentionMode: RetentionMode.EPHEMERAL }, + }; + expect(turns(3, saved).isTemporary).toBe(true); + }); + it('checks the submitted target against current query data, not the rendered conversation', () => { const rendered = conversation({ endpoint: EModelEndpoint.openAI, model: 'gpt-5' }); const submitted = conversation({ endpoint: EModelEndpoint.agents, agent_id: 'agent_primary' }); diff --git a/client/src/hooks/Chat/services.ts b/client/src/hooks/Chat/services.ts index 742b580d7f..3b8b4d55dd 100644 --- a/client/src/hooks/Chat/services.ts +++ b/client/src/hooks/Chat/services.ts @@ -1,9 +1,9 @@ import { useRef, useEffect } from 'react'; import { useStore } from 'jotai'; import { useNavigate } from 'react-router-dom'; -import { QueryKeys } from 'librechat-data-provider'; import { useQueryClient } from '@tanstack/react-query'; import { launchedConversationFamily } from '@librechat/chat/react'; +import { QueryKeys, isForcedTemporaryRetention } from 'librechat-data-provider'; import type { ChatTurnsParams, TurnServices } from '@librechat/chat/react'; import type { TEndpointsConfig } from 'librechat-data-provider'; import { @@ -12,6 +12,7 @@ import { markPasteSubmitted, bindComposerLaunch, getRouteChatProjectId, + isTemporaryConversation, } from '~/utils'; import useGetConversation from '~/hooks/Conversations/useGetConversation'; import useDiscardPastedFiles from '~/hooks/Files/useDiscardPastedFiles'; @@ -36,13 +37,22 @@ export default function useTurnServices({ const setFilesToDelete = useSetFilesToDelete(); const agentsMap = useAgentsMapContext(); const settings = useChatSettings(); - const { isTemporary, config, auth, getEphemeralAgent } = settings; + const { config, auth, getEphemeralAgent } = settings; /** * The conversation main chat is being compared with rides along with main chat's turns, from * either of its panes. A conversation in any other pane is on its own: that comparison's * readiness, workspace and approvals have no say in what it can send. */ - const addedConversation = index === 0 || index === 1 ? settings.addedConversation : null; + const ridesMainChat = index === 0 || index === 1; + const addedConversation = ridesMainChat ? settings.addedConversation : null; + /** + * Whether main chat's turns are temporary is the page's setting, which the route keeps in step + * with the conversation on screen. A conversation in any other pane is not that conversation, + * so its turns are temporary when it is, or when the deployment makes every chat so. + */ + const isTemporary = ridesMainChat + ? settings.isTemporary + : isTemporaryConversation(conversation) || isForcedTemporaryRetention(config.retentionMode); const { getExpiry } = useUserKey(conversation?.endpoint ?? ''); const getConversation = useGetConversation(index); const codeWorkspaceState = useCodeWorkspace(conversation, addedConversation); diff --git a/e2e/specs/mock/scenarios/side-chat-open-beside.spec.ts b/e2e/specs/mock/scenarios/side-chat-open-beside.spec.ts index eb1ba277dc..3342fca3ea 100644 --- a/e2e/specs/mock/scenarios/side-chat-open-beside.spec.ts +++ b/e2e/specs/mock/scenarios/side-chat-open-beside.spec.ts @@ -269,3 +269,45 @@ test.describe('on a small screen', () => { await expect(composer).toHaveValue('Still reachable'); }); }); + +test('a saved conversation beside a temporary chat keeps its turns @scenario:side-chat-turn-is-not-temporary-beside-a-temporary-chat', async ({ + page, +}) => { + test.setTimeout(120_000); + const saved = uniqueLabel('saved'); + const followUp = uniqueLabel('kept'); + const savedUrl = await startChat(page, saved); + + /** The chat on screen is a new one the reader has made temporary. */ + await page.goto(NEW_CHAT_PATH, { timeout: 10_000 }); + await selectMockEndpoint(page, MOCK_ENDPOINTS[0]); + const temporary = page.getByRole('button', { name: 'Temporary Chat' }); + await temporary.click(); + await expect(temporary).toHaveAttribute('aria-pressed', 'true'); + + await openChatHistory(page); + const row = conversationRow(page, savedUrl); + await row.hover(); + await row.getByRole('button', { name: 'Conversation Menu Options' }).click(); + await page.getByRole('menuitem', { name: 'Open beside chat' }).click(); + const sideChat = page.getByRole('region', { name: 'Side chat' }); + await expect(sideChat).toContainText(replyText(saved), { timeout: 30_000 }); + + /** Temporary is what the chat on screen is, not the saved conversation beside it. */ + const composer = sideChat.getByRole('textbox', { name: 'Message input' }); + await composer.click(); + await page.keyboard.type(replyPrompt(followUp)); + const [start] = await Promise.all([ + page.waitForRequest( + (request) => + request.method() === 'POST' && + /\/api\/agents\/chat\/[^/]+$/.test(new URL(request.url()).pathname) && + !request.url().endsWith('/abort'), + ), + page.keyboard.press('Enter'), + ]); + const posted = start.postDataJSON() as { conversationId?: string; isTemporary?: boolean }; + expect(savedUrl).toContain(posted.conversationId ?? 'none'); + expect(posted.isTemporary).toBe(false); + await expect(sideChat).toContainText(replyText(followUp), { timeout: 30_000 }); +});