Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix: dispatch executor=client tools to desktop callers when DEVICE_GATEWAY is configured (#13793)

Arvin Xu46adf4345374
diff --git a/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts b/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts
index 7e11d97d4df..a99c3e45a15 100644
--- a/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts
+++ b/src/server/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts
@@ -586,5 +586,31 @@ describe('createServerAgentToolsEngine', () => {
expect(result.enabledToolIds).not.toContain(LocalSystemManifest.identifier);
});
+
+ it('suppresses RemoteDevice when caller is a desktop client', () => {
+ // Even when device-proxy is configured, a desktop caller has local IPC
+ // so the proxy is redundant. Otherwise the LLM might pick RemoteDevice
+ // first (via `listOnlineDevices` / `activateDevice`) and route tool calls
+ // to a *different* registered device instead of back to the caller.
+ const context = createMockContext();
+ const engine = createServerAgentToolsEngine(context, {
+ agentConfig: {
+ plugins: [LocalSystemManifest.identifier, RemoteDeviceManifest.identifier],
+ },
+ clientRuntime: 'desktop',
+ deviceContext: { gatewayConfigured: true },
+ model: 'gpt-4',
+ provider: 'openai',
+ });
+
+ const result = engine.generateToolsDetailed({
+ toolIds: [LocalSystemManifest.identifier, RemoteDeviceManifest.identifier],
+ model: 'gpt-4',
+ provider: 'openai',
+ });
+
+ expect(result.enabledToolIds).toContain(LocalSystemManifest.identifier);
+ expect(result.enabledToolIds).not.toContain(RemoteDeviceManifest.identifier);
+ });
});
});
diff --git a/src/server/modules/Mecha/AgentToolsEngine/index.ts b/src/server/modules/Mecha/AgentToolsEngine/index.ts
index 2738dd2c0dd..4663c885348 100644
--- a/src/server/modules/Mecha/AgentToolsEngine/index.ts
+++ b/src/server/modules/Mecha/AgentToolsEngine/index.ts
@@ -180,8 +180,11 @@ export const createServerAgentToolsEngine = (
// Only auto-enable in bot conversations; otherwise let user's plugin selection take effect
...(isBotConversation && { [MessageManifest.identifier]: true }),
// Remote-device proxy: shown only when the server has a proxy but
- // no specific device is auto-activated yet (user must pick).
- [RemoteDeviceManifest.identifier]: hasDeviceProxy && !deviceContext?.autoActivated,
+ // no specific device is auto-activated yet (user must pick). When
+ // the caller itself can execute `executor: 'client'` tools, the
+ // proxy is redundant β€” local-system goes directly to the caller.
+ [RemoteDeviceManifest.identifier]:
+ hasDeviceProxy && !deviceContext?.autoActivated && !hasClientExecutor,
[AgentDocumentsManifest.identifier]: hasAgentDocuments,
[WebBrowsingManifest.identifier]: isSearchEnabled,
},
diff --git a/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts b/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
index 5f2733f0f17..412ac383cb9 100644
--- a/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
+++ b/src/server/services/aiAgent/__tests__/execAgent.deviceToolPipeline.test.ts
@@ -389,6 +389,91 @@ describe('AiAgentService.execAgent - device tool pipeline (LOBE-5636)', () => {
});
});
+ describe('clientRuntime="desktop" bypasses the DEVICE_GATEWAY gate (Phase 6.4)', () => {
+ it('marks local-system as client when caller is desktop, even with DEVICE_GATEWAY configured', async () => {
+ // On cloud canary, DEVICE_GATEWAY is configured AND a remote Linux VM
+ // may be registered. Before this fix, `!gatewayConfigured` was false, so
+ // local-system was never stamped `executor='client'` β€” and dispatch fell
+ // through to the Remote Device proxy (which then tried to read the file
+ // on the wrong host). When clientRuntime='desktop', the caller itself is
+ // the execution target and wins.
+ const { deviceProxy } = await import('@/server/services/toolExecution/deviceProxy');
+ vi.spyOn(deviceProxy, 'isConfigured', 'get').mockReturnValue(true);
+ mockQueryDeviceList.mockResolvedValue([
+ { deviceId: 'dev-1', deviceName: 'Remote VM', platform: 'linux' },
+ ]);
+
+ mockGetEnabledPluginManifests.mockReturnValue(
+ new Map([[LocalSystemManifest.identifier, LocalSystemManifest]]),
+ );
+ mockGetAgentConfig.mockResolvedValue(createBaseAgentConfig());
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ clientRuntime: 'desktop',
+ prompt: 'Hello',
+ });
+
+ const executorMap = mockCreateOperation.mock.calls[0][0].toolSet.executorMap;
+ expect(executorMap[LocalSystemManifest.identifier]).toBe('client');
+ });
+
+ it('marks stdio MCP as client when caller is desktop, even with DEVICE_GATEWAY configured', async () => {
+ const stdioPlugin = {
+ customParams: { mcp: { type: 'stdio' } },
+ identifier: 'my-stdio-mcp',
+ } as any;
+ const stdioManifest = {
+ api: [{ description: 't', name: 'a', parameters: {} }],
+ identifier: 'my-stdio-mcp',
+ meta: { title: 'Stdio' },
+ };
+
+ const { deviceProxy } = await import('@/server/services/toolExecution/deviceProxy');
+ vi.spyOn(deviceProxy, 'isConfigured', 'get').mockReturnValue(true);
+ mockQueryDeviceList.mockResolvedValue([
+ { deviceId: 'dev-1', deviceName: 'Remote VM', platform: 'linux' },
+ ]);
+
+ mockPluginQuery.mockResolvedValue([stdioPlugin]);
+ mockGetEnabledPluginManifests.mockReturnValue(new Map([['my-stdio-mcp', stdioManifest]]));
+ mockGetAgentConfig.mockResolvedValue(createBaseAgentConfig({ plugins: ['my-stdio-mcp'] }));
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ clientRuntime: 'desktop',
+ prompt: 'Hello',
+ });
+
+ const executorMap = mockCreateOperation.mock.calls[0][0].toolSet.executorMap;
+ expect(executorMap['my-stdio-mcp']).toBe('client');
+ });
+
+ it('keeps legacy routing for web callers with DEVICE_GATEWAY configured', async () => {
+ // Web client + DEVICE_GATEWAY configured β†’ tools still route through
+ // Remote Device proxy; executor stays unset (legacy behaviour).
+ const { deviceProxy } = await import('@/server/services/toolExecution/deviceProxy');
+ vi.spyOn(deviceProxy, 'isConfigured', 'get').mockReturnValue(true);
+ mockQueryDeviceList.mockResolvedValue([
+ { deviceId: 'dev-1', deviceName: 'Remote VM', platform: 'linux' },
+ ]);
+
+ mockGetEnabledPluginManifests.mockReturnValue(
+ new Map([[LocalSystemManifest.identifier, LocalSystemManifest]]),
+ );
+ mockGetAgentConfig.mockResolvedValue(createBaseAgentConfig());
+
+ await service.execAgent({
+ agentId: 'agent-1',
+ clientRuntime: 'web',
+ prompt: 'Hello',
+ });
+
+ const executorMap = mockCreateOperation.mock.calls[0][0].toolSet.executorMap;
+ expect(executorMap[LocalSystemManifest.identifier]).toBeUndefined();
+ });
+ });
+
describe('toolManifestMap fully derived from ToolsEngine', () => {
it('should derive manifestMap entirely from getEnabledPluginManifests', async () => {
const mockManifest = {
diff --git a/src/server/services/aiAgent/index.ts b/src/server/services/aiAgent/index.ts
index 267d90f4a53..61f8da10c14 100644
--- a/src/server/services/aiAgent/index.ts
+++ b/src/server/services/aiAgent/index.ts
@@ -625,10 +625,21 @@ export class AiAgentService {
// require local IPC / subprocess capabilities:
// - local-system builtin: Electron IPC for file + command execution
// - stdio MCP plugins: subprocess lives on the user's machine
- // Only applies when gateway is NOT configured (standalone Electron). When
- // deviceContext is present, tools are routed via the RemoteDevice proxy,
- // so marking them as `client` would misdispatch through dispatchClientTool.
- if (!gatewayConfigured) {
+ //
+ // Two triggers, in priority order:
+ // (a) `clientRuntime === 'desktop'` β€” the caller itself is an Electron
+ // client on the Agent Gateway WS and is ready to receive
+ // `tool_execute`. This is the Phase 6.4 path and is authoritative
+ // regardless of whether DEVICE_GATEWAY (the legacy device-proxy) is
+ // also configured.
+ // (b) `!gatewayConfigured` β€” no DEVICE_GATEWAY configured on the server,
+ // so legacy Remote Device proxy isn't an option and any client
+ // tooling falls through to the Gateway WS (standalone Electron).
+ //
+ // When DEVICE_GATEWAY is configured AND the caller is a web client, we
+ // leave executor unset so tools route via RemoteDevice proxy.
+ const shouldDispatchToClient = clientRuntime === 'desktop' || !gatewayConfigured;
+ if (shouldDispatchToClient) {
if (manifestMap.has(LocalSystemManifest.identifier)) {
toolExecutorMap[LocalSystemManifest.identifier] = 'client';
}