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
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🪴 fix: Restore Native Workspace Selection (#15771)
Danny Avila2c07e28311bf
diff --git a/client/src/hooks/Agents/__tests__/useCodeWorkspace.test.tsx b/client/src/hooks/Agents/__tests__/useCodeWorkspace.test.tsxindex fe80485cda..5ef93d4913 100644--- a/client/src/hooks/Agents/__tests__/useCodeWorkspace.test.tsx+++ b/client/src/hooks/Agents/__tests__/useCodeWorkspace.test.tsx@@ -119,14 +119,40 @@ describe('useCodeWorkspace', () => {expect(result.current.state).toBe('unavailable');});- it.each([false, undefined])('rejects non-stateful worker support: %s', (statefulWorkspace) => {- const statuses = mockStatus();- statuses[0].data.statefulWorkspace = statefulWorkspace;- const selection = { environmentId: 'personal-vm', workspaceId: 'project-a' };- const { result } = renderHook(() => useCodeWorkspace(conversation([selection])));+ it.each([false, undefined])(+ 'selects native roots without runtime sessions: %s',+ (statefulWorkspace) => {+ const statuses = mockStatus();+ statuses[0].data.statefulWorkspace = statefulWorkspace;+ const selection = { environmentId: 'personal-vm', workspaceId: 'project-a' };+ const { result } = renderHook(() => useCodeWorkspace(conversation([selection])));+ expect(result.current.state).toBe('ready');+ expect(result.current.selections).toEqual([selection]);+ expect(result.current.resolveSelections([selection])).toEqual([selection]);+ },+ );++ it('automatically selects a sole native root without runtime sessions', () => {+ mockStatus()[0].data.statefulWorkspace = false;+ const { result } = renderHook(() => useCodeWorkspace(conversation()));+ expect(result.current.state).toBe('ready');+ expect(result.current.selections).toEqual([+ { environmentId: 'personal-vm', workspaceId: 'project-a' },+ ]);+ });++ it.each(['offline', 'starting'])('rejects a native worker that is %s', (status) => {+ Object.assign(mockStatus()[0].data, { status, statefulWorkspace: false });+ const { result } = renderHook(() => useCodeWorkspace(conversation()));expect(result.current.state).toBe('unavailable');expect(result.current.selections).toBeUndefined();- expect(result.current.resolveSelections([selection])).toBeUndefined();+ });++ it('rejects a ready native worker without advertised roots', () => {+ Object.assign(mockStatus()[0].data, { statefulWorkspace: false, workspaces: undefined });+ const { result } = renderHook(() => useCodeWorkspace(conversation()));+ expect(result.current.state).toBe('unsupported');+ expect(result.current.selections).toBeUndefined();});it('requires an explicit choice when several workspaces are advertised', () => {diff --git a/client/src/hooks/Agents/useCodeWorkspace.ts b/client/src/hooks/Agents/useCodeWorkspace.tsindex 91315bf40c..2a987c4d54 100644--- a/client/src/hooks/Agents/useCodeWorkspace.ts+++ b/client/src/hooks/Agents/useCodeWorkspace.ts@@ -70,12 +70,7 @@ function resolveEnvironmentSelection({stored?: CodeWorkspaceSelection;hasStoredSelections: boolean;}): CodeWorkspaceSelection | undefined {- if (- status?.status !== 'ready' ||- status.statefulWorkspace !== true ||- status.environmentId !== environment.id- )- return undefined;+ if (status?.status !== 'ready' || status.environmentId !== environment.id) return undefined;if (stored != null && workspaces.some(({ id }) => id === stored.workspaceId)) {return { environmentId: environment.id, workspaceId: stored.workspaceId };}@@ -160,7 +155,6 @@ export default function useCodeWorkspace(else if (status.isError ||status.data?.status !== 'ready' ||- status.data.statefulWorkspace !== true ||status.data.environmentId !== environment.id) {state = 'unavailable';diff --git a/packages/api/src/code/capabilities.spec.ts b/packages/api/src/code/capabilities.spec.tsindex 14b6d9902d..4bf08e2b5c 100644--- a/packages/api/src/code/capabilities.spec.ts+++ b/packages/api/src/code/capabilities.spec.ts@@ -283,7 +283,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => {delete process.env.TEST_CODE_CAPABILITY_TOKEN;});- function workspaceStatus(workspaces: unknown[]): Response {+ function workspaceStatus(workspaces: unknown[], statefulWorkspace: boolean = true): Response {return new Response(JSON.stringify({protocolVersion: 1,@@ -292,7 +292,7 @@ describe('resolveCodeExecutionWorkspaceContext', () => {ready: true,leaseExpiresInMs: 45_000,capabilities: {- statefulWorkspace: true,+ statefulWorkspace,sandboxProfile: 'native-srt',runtimes: ['bash'],workspaceTools: {@@ -333,6 +333,55 @@ describe('resolveCodeExecutionWorkspaceContext', () => {});});+ it('admits native workspace tools without enabling programmatic runtime execution', async () => {+ jest+ .spyOn(globalThis, 'fetch')+ .mockResolvedValue(workspaceStatus([{ id: 'docs', operations: ['read_file'] }], false));+ const resolved = await resolveCodeExecutionWorkspaceContext({+ context,+ requestedSelections: [{ environmentId: 'personal', workspaceId: 'docs' }],+ environments,+ getAppConfig,+ });+ expect(resolved.codeWorkspace).toEqual({+ environmentId: 'personal',+ workspaceId: 'docs',+ operations: ['read_file'],+ });+ expect(await supportsProgrammaticCodeExecution(context, environments, getAppConfig)).toBe(+ false,+ );+ expect(await supportsProgrammaticCodeExecution(resolved, environments, getAppConfig)).toBe(+ false,+ );+ });++ it.each([false, true])(+ 'fails closed without native workspace capabilities (ready: %s)',+ async (ready) => {+ jest.spyOn(globalThis, 'fetch').mockResolvedValue(+ new Response(+ JSON.stringify({+ protocolVersion: 1,+ workerId: 'worker',+ online: true,+ ready,+ leaseExpiresInMs: 45_000,+ capabilities: { statefulWorkspace: false, sandboxProfile: 'native-srt', runtimes: [] },+ }),+ ),+ );+ await expect(+ resolveCodeExecutionWorkspaceContext({+ context,+ requestedSelections: [{ environmentId: 'personal', workspaceId: 'docs' }],+ environments,+ getAppConfig,+ }),+ ).rejects.toMatchObject({ reason: ready ? 'unsupported' : 'worker_unavailable' });+ },+ );+it.each(['worker', 'replacement', undefined])('pins deployment worker identity: %s',async (workerId) => {diff --git a/packages/api/src/code/capabilities.ts b/packages/api/src/code/capabilities.tsindex 34722ed40d..1b02553a8b 100644--- a/packages/api/src/code/capabilities.ts+++ b/packages/api/src/code/capabilities.ts@@ -138,7 +138,8 @@ export async function resolveCodeExecutionWorkspaceContext({);throw new CodeWorkspaceSelectionError('worker_unavailable');}- if (status.status !== 'ready' || status.statefulWorkspace !== true) {+ /** Named workspace tools enforce their roots independently of runtime sessions. */+ if (status.status !== 'ready') {throw new CodeWorkspaceSelectionError('worker_unavailable');}if (!status.workspaces || !status.operations) {