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: Keep Host Tool Loading Independent of Worker Status (#17628)
lia-by-librechat[bot]99fb03cb9338
diff --git a/api/server/services/ToolService.js b/api/server/services/ToolService.jsindex eb2a1d2b74..450f9ebbb9 100644--- a/api/server/services/ToolService.js+++ b/api/server/services/ToolService.js@@ -64,6 +64,7 @@ const {withRequestCodeInputs,resolveAgentCodeExecution,resolveCodeExecutionWorkspaceContext,+ requiresCodeWorkspaceCapabilities,resolveRunFileCodeExecutionContext,resolveCallerCapabilityProjectionSnapshot,CREATE_FILE_TOOL_NAME,@@ -2284,6 +2285,7 @@ async function loadToolsForExecution({);const codeExecutionContext = await resolveCodeExecutionWorkspaceContext({context: baseCodeExecutionContext,+ requiresLiveCapabilities: requiresCodeWorkspaceCapabilities(toolNames),requestedSelections: runtimeRequestBody?.codeWorkspaces,persistedSelections: req.resolvedConversation?.codeWorkspaces,environments: req.config?.endpoints?.agents?.statefulCodeSessions?.environments,diff --git a/api/server/services/__tests__/ToolService.spec.js b/api/server/services/__tests__/ToolService.spec.jsindex abb25d2443..0872784d06 100644--- a/api/server/services/__tests__/ToolService.spec.js+++ b/api/server/services/__tests__/ToolService.spec.js@@ -3723,6 +3723,56 @@ describe('ToolService - Action Capability Gating', () => {});});+ it('loads a skill and MCP tool without probing the attached worker', async () => {+ const capabilities = [+ AgentCapabilities.tools,+ AgentCapabilities.skills,+ AgentCapabilities.execute_code,+ AgentCapabilities.stateful_code_sessions,+ ];+ const req = createMockReq(capabilities);+ req.body = {+ codeWorkspaces: [{ environmentId: 'personal-machine', workspaceId: 'project-a' }],+ };+ req.config.endpoints.agents.statefulCodeSessions = {+ environments: [attachedEnvironment()],+ };+ mockGetEndpointsConfig.mockResolvedValue(createEndpointsConfig(capabilities));+ mockResolveCodeExecutionWorkspaceContext.mockImplementationOnce(+ jest.requireActual('@librechat/api').resolveCodeExecutionWorkspaceContext,+ );+ const fetchSpy = jest+ .spyOn(globalThis, 'fetch')+ .mockRejectedValue(new DOMException('Status request timed out', 'TimeoutError'));++ try {+ const result = await loadToolsForExecution({+ req,+ res: {},+ agent: {+ id: 'attached-agent',+ tools: [Tools.execute_code],+ stateful_code_sessions: true,+ code_environment_id: 'personal-machine',+ },+ toolNames: [AgentConstants.SKILL_TOOL, 'lookup_mcp_example'],+ });++ expect(result.configurable.codeExecutionContext).toMatchObject({+ environmentType: 'attached',+ environmentId: 'personal-machine',+ bridgeWorkerId: 'worker-abc',+ baseUrl: 'http://attached-code.test/v1',+ });+ expect(fetchSpy).not.toHaveBeenCalled();+ expect(mockLoadToolsUtil).toHaveBeenCalledWith(+ expect.objectContaining({ tools: ['lookup_mcp_example'] }),+ );+ } finally {+ fetchSpy.mockRestore();+ }+ });+it('resolves stateful routing when handle_skill is the only requested tool', async () => {const capabilities = [AgentCapabilities.tools,diff --git a/packages/api/src/agents/tools.ts b/packages/api/src/agents/tools.tsindex 0b01410574..e4e1b57dd2 100644--- a/packages/api/src/agents/tools.ts+++ b/packages/api/src/agents/tools.ts@@ -71,6 +71,11 @@ export function isCodeSessionToolName();}+/** Host-only tool batches do not need live workspace capability discovery. */+export function requiresCodeWorkspaceCapabilities(toolNames: readonly string[]): boolean {+ return toolNames.some((name) => isCodeFileToolName(name) || isCodeSessionToolName(name));+}+/** Tools that consume shared code, search, or image resources need current file records. */export function isFileResourceToolName(name: string): boolean {return (diff --git a/packages/api/src/code/capabilities.spec.ts b/packages/api/src/code/capabilities.spec.tsindex 818ac53d5d..50437c0552 100644--- a/packages/api/src/code/capabilities.spec.ts+++ b/packages/api/src/code/capabilities.spec.ts@@ -7,6 +7,7 @@ import {resolveCodeExecutionWorkspaceContext,supportsProgrammaticCodeExecution,} from './capabilities';+import { requiresCodeWorkspaceCapabilities } from '~/agents/tools';const context: CodeExecutionContext = {baseUrl: 'https://bridge.example',@@ -380,6 +381,74 @@ describe('resolveCodeExecutionWorkspaceContext', () => {);}+ it.each([+ ['skill'],+ ['tool_search'],+ ['web_search'],+ ['lookup_mcp_example'],+ ['skill', 'lookup_mcp_example'],+ [],+ ])('does not probe worker status for host-only tools: %j', async (...toolNames) => {+ const fetchSpy = jest+ .spyOn(globalThis, 'fetch')+ .mockRejectedValue(new DOMException('Status request timed out', 'TimeoutError'));++ await expect(+ resolveCodeExecutionWorkspaceContext({+ context,+ requiresLiveCapabilities: requiresCodeWorkspaceCapabilities(toolNames),+ persistedSelections: [{ environmentId: 'personal', workspaceId: 'project-a' }],+ environments,+ getAppConfig,+ }),+ ).resolves.toBe(context);+ expect(fetchSpy).not.toHaveBeenCalled();+ expect(getAppConfig).not.toHaveBeenCalled();+ });++ it.each([+ 'bash_tool',+ 'execute_code',+ 'run_tools_with_bash',+ 'run_tools_with_code',+ 'read_file',+ 'create_file',+ 'edit_file',+ 'search_workspace',+ 'list_workspace_files',+ ])('still validates live workspace capabilities for %s', async (toolName) => {+ const fetchSpy = jest+ .spyOn(globalThis, 'fetch')+ .mockRejectedValue(new DOMException('Status request timed out', 'TimeoutError'));++ await expect(+ resolveCodeExecutionWorkspaceContext({+ context,+ requiresLiveCapabilities: requiresCodeWorkspaceCapabilities(['skill', toolName]),+ persistedSelections: [{ environmentId: 'personal', workspaceId: 'project-a' }],+ environments,+ getAppConfig,+ }),+ ).rejects.toMatchObject({ reason: 'worker_unavailable' });+ expect(fetchSpy).toHaveBeenCalledTimes(2);+ });++ it('still enforces the sealed selection for host-only tools', async () => {+ const fetchSpy = jest.spyOn(globalThis, 'fetch');++ await expect(+ resolveCodeExecutionWorkspaceContext({+ context,+ requiresLiveCapabilities: false,+ requestedSelections: [{ environmentId: 'personal', workspaceId: 'project-b' }],+ persistedSelections: [{ environmentId: 'personal', workspaceId: 'project-a' }],+ environments,+ getAppConfig,+ }),+ ).rejects.toMatchObject({ reason: 'locked' });+ expect(fetchSpy).not.toHaveBeenCalled();+ });+it('binds the exact advertised workspace and its operation ceiling', async () => {jest.spyOn(globalThis, 'fetch').mockResolvedValue(workspaceStatus(diff --git a/packages/api/src/code/capabilities.ts b/packages/api/src/code/capabilities.tsindex f6d128bf7a..837e689dd0 100644--- a/packages/api/src/code/capabilities.ts+++ b/packages/api/src/code/capabilities.ts@@ -104,12 +104,15 @@ export async function resolveCodeExecutionWorkspaceContext({context,requestedSelections,persistedSelections,+ requiresLiveCapabilities = true,environments,getAppConfig,}: {context: CodeExecutionContext;requestedSelections?: unknown;persistedSelections?: unknown;+ /** Only host-side execution batches may skip discovery; initialization requires it. */+ requiresLiveCapabilities?: boolean;environments?: readonly CodeEnvironmentConfig[];getAppConfig?: CodeCapabilityConfigLoader;}): Promise<CodeExecutionContext> {@@ -135,6 +138,8 @@ export async function resolveCodeExecutionWorkspaceContext({);if (selection == null) throw new CodeWorkspaceSelectionError('required');+ if (!requiresLiveCapabilities) return context;+let status: CodeBridgeWorkerStatus;try {status = await readAuthorizedAttachedWorkerStatus(context, environments, getAppConfig);