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 Ephemeral Agent Selections on Optimistic Hydration (#13433)

Danny Avilafd5d44162a45
diff --git a/client/src/store/__tests__/agents.spec.tsx b/client/src/store/__tests__/agents.spec.tsx
new file mode 100644
index 0000000000..0d28ccca75
--- /dev/null
+++ b/client/src/store/__tests__/agents.spec.tsx
@@ -0,0 +1,48 @@
+import React from 'react';
+import { RecoilRoot, useRecoilValue } from 'recoil';
+import { renderHook, act, waitFor } from '@testing-library/react';
+
+import { ephemeralAgentByConvoId, useApplyNewAgentTemplate } from '../agents';
+
+jest.mock('~/utils', () => ({
+ logger: {
+ log: jest.fn(),
+ warn: jest.fn(),
+ error: jest.fn(),
+ },
+}));
+
+const Wrapper = ({ children }: { children: React.ReactNode }) => (
+ <RecoilRoot>{children}</RecoilRoot>
+);
+
+const useAgentTemplateHarness = (conversationId: string) => {
+ const applyTemplate = useApplyNewAgentTemplate();
+ const ephemeralAgent = useRecoilValue(ephemeralAgentByConvoId(conversationId));
+ return { applyTemplate, ephemeralAgent };
+};
+
+describe('useApplyNewAgentTemplate', () => {
+ it('applies an explicit ephemeral agent when optimistic hydration makes source and target match', async () => {
+ const conversationId = 'convo-123';
+ const agent = {
+ mcp: ['chrome-devtools'],
+ skills: true,
+ artifacts: 'default',
+ web_search: true,
+ file_search: true,
+ execute_code: true,
+ };
+ const { result } = renderHook(() => useAgentTemplateHarness(conversationId), {
+ wrapper: Wrapper,
+ });
+
+ await act(async () => {
+ await result.current.applyTemplate(conversationId, conversationId, agent);
+ });
+
+ await waitFor(() => {
+ expect(result.current.ephemeralAgent).toEqual(agent);
+ });
+ });
+});
diff --git a/client/src/store/agents.ts b/client/src/store/agents.ts
index 13136ef34e..139a76f07d 100644
--- a/client/src/store/agents.ts
+++ b/client/src/store/agents.ts
@@ -43,7 +43,7 @@ export function useApplyNewAgentTemplate() {
const sourceId = _sourceId || Constants.NEW_CONVO;
logger.log('agents', `Attempting to apply template from "${sourceId}" to "${targetId}"`);
- if (targetId === sourceId) {
+ if (targetId === sourceId && ephemeralAgentState == null) {
logger.warn('agents', `Attempted to apply template to itself ("${sourceId}"). Skipping.`);
return;
}