Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🍵 fix: Preserve Workspace Decisions in Warm Chat Caches (#16648)

lia-by-librechat[bot]369955701097
diff --git a/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts b/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
index 9d5f1d8b12..08c019bc6b 100644
--- a/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
+++ b/client/src/hooks/SSE/__tests__/useResumableSSE.spec.ts
@@ -1153,6 +1153,36 @@ describe('useResumableSSE', () => {
unmount();
});
+ it.each([
+ {
+ codeEnvironmentMode: 'attached' as const,
+ codeWorkspaces: [{ environmentId: 'vm', workspaceId: 'project' }],
+ },
+ { codeWorkspaces: [{ environmentId: 'vm', workspaceId: 'project' }] },
+ { codeEnvironmentMode: 'without_attached' as const },
+ ])('caches the acknowledged code decision for navigation: %j', async (decision) => {
+ const submission = {
+ ...buildSubmission({ conversation: { conversationId: String(Constants.NEW_CONVO) } }),
+ ...decision,
+ };
+ const { unmount } = renderHook(() => useResumableSSE(submission, buildChatHelpers()));
+ await flushMicrotasks();
+
+ const cacheWrite = mockSetQueryData.mock.calls.find(
+ ([key]) => key[0] === QueryKeys.conversation && key[1] === 'stream-123',
+ );
+ expect(cacheWrite).toBeDefined();
+ const cached = cacheWrite![1](undefined);
+ expect(cached).toMatchObject({
+ conversationId: 'stream-123',
+ codeEnvironmentMode: decision.codeEnvironmentMode ?? 'attached',
+ });
+ expect(cached.codeWorkspaces).toEqual(decision.codeWorkspaces);
+ const newer = { ...cached, codeEnvironmentMode: 'without_attached', codeWorkspaces: undefined };
+ expect(cacheWrite![1](newer)).toBe(newer);
+ unmount();
+ });
+
it('replaces the new-chat URL when the stream id is known despite a stale parent id', async () => {
window.history.pushState({}, '', '/c/new');
const submission = buildSubmission({
diff --git a/client/src/hooks/SSE/useResumableSSE.ts b/client/src/hooks/SSE/useResumableSSE.ts
index 265da6c426..6b68f37b7e 100644
--- a/client/src/hooks/SSE/useResumableSSE.ts
+++ b/client/src/hooks/SSE/useResumableSSE.ts
@@ -97,6 +97,7 @@ import useEventHandlers, {
} from './useEventHandlers';
import { drainAfterAbortByIndex, queuedMessagesByConvoId, runEndByIndex } from '~/hooks/Chat/queue';
import { pendingApprovalActionFamily } from '~/components/Chat/approval/state';
+import { withSubmittedCodeDecision } from '~/hooks/Agents/codeDecision';
import { useChatTransport } from '~/Providers/ChatTransportContext';
import useSteerConvert from '~/hooks/Chat/useSteerConvert';
import { liveAppliedSteerIdsAtom } from '~/store/steer';
@@ -581,7 +582,7 @@ const buildOptimisticConversation = (
submission.initialResponse?.messageId,
].filter((messageId): messageId is string => typeof messageId === 'string' && messageId !== '');
- return {
+ const conversation = {
...submission.conversation,
conversationId,
endpoint: submission.conversation.endpoint ?? null,
@@ -595,6 +596,7 @@ const buildOptimisticConversation = (
* when true, leaving the legacy `expiredAt` inference untouched otherwise. */
...(submission.isTemporary === true ? { isTemporary: true } : {}),
} as TConversation;
+ return withSubmittedCodeDecision(conversation, submission)!;
};
const hydrateSubmissionMessages = (