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(device): lock a run to the explicitly selected device, never offer device-switching (#15914)

Arvin Xu5c5a719186b0
diff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts
index 20b3908ba85..8fc761a9b2f 100644
--- a/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts
+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/__tests__/index.test.ts
@@ -659,6 +659,59 @@ describe('createServerAgentToolsEngine', () => {
expect(result.enabledToolIds).not.toContain(RemoteDeviceManifest.identifier);
});
+ it('should disable RemoteDevice when a device is explicitly bound (locked to the selection)', () => {
+ // A user-selected (bound) device locks the run to that device β€” the
+ // activate-device tool is never offered, so the model cannot switch.
+ const context = createMockContext();
+ const engine = createServerAgentToolsEngine(context, {
+ agentConfig: { plugins: [RemoteDeviceManifest.identifier] },
+ canUseDevice: true,
+ deviceContext: {
+ autoActivated: true,
+ boundDeviceId: 'device-001',
+ deviceOnline: true,
+ gatewayConfigured: true,
+ },
+ model: 'gpt-4',
+ provider: 'openai',
+ });
+
+ const result = engine.generateToolsDetailed({
+ toolIds: [RemoteDeviceManifest.identifier],
+ model: 'gpt-4',
+ provider: 'openai',
+ });
+
+ expect(result.enabledToolIds).not.toContain(RemoteDeviceManifest.identifier);
+ });
+
+ it('should disable RemoteDevice when the bound device is OFFLINE β€” no silent hop to another machine', () => {
+ // The bound device going offline makes the plan device-unrouted, so
+ // `autoActivated` is false. Without the `boundDeviceId` gate the tool
+ // would resurface and let the model activate a *different* online device.
+ // The explicit selection must keep the run locked instead.
+ const context = createMockContext();
+ const engine = createServerAgentToolsEngine(context, {
+ agentConfig: { plugins: [RemoteDeviceManifest.identifier] },
+ canUseDevice: true,
+ deviceContext: {
+ boundDeviceId: 'device-001',
+ deviceOnline: true,
+ gatewayConfigured: true,
+ },
+ model: 'gpt-4',
+ provider: 'openai',
+ });
+
+ const result = engine.generateToolsDetailed({
+ toolIds: [RemoteDeviceManifest.identifier],
+ model: 'gpt-4',
+ provider: 'openai',
+ });
+
+ expect(result.enabledToolIds).not.toContain(RemoteDeviceManifest.identifier);
+ });
+
it('should enable RemoteDevice in bot conversations when caller is trusted (canUseDevice=true)', () => {
// The `!isBotConversation` clause was dropped in β€” the
// confused-deputy concern that motivated it is now handled at a
diff --git a/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts b/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts
index 0706258f74e..46196452a3d 100644
--- a/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts
+++ b/apps/server/src/modules/Mecha/AgentToolsEngine/index.ts
@@ -231,12 +231,20 @@ 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 for device-capable targets when the
- // server has a proxy but no specific device is auto-activated yet (user
- // must pick). External bot senders never reach it: the plan degrades
- // denied targets to `none` (β†’ not deviceCapable) and the physical
- // manifest walls drop it for `canUseDevice=false` turns.
+ // server has a proxy, no specific device is auto-activated yet, AND the
+ // user has NOT explicitly selected a device. Once a device is explicitly
+ // selected (`boundDeviceId`), the run is locked to it: we never expose the
+ // activate-device tool, so the model can never switch to another machine β€”
+ // not even when the selected device is offline (the run stays unrouted
+ // until that device comes back, rather than silently hopping elsewhere).
+ // External bot senders never reach it: the plan degrades denied targets to
+ // `none` (β†’ not deviceCapable) and the physical manifest walls drop it for
+ // `canUseDevice=false` turns.
[RemoteDeviceManifest.identifier]:
- deviceCapable && hasDeviceProxy && !deviceContext?.autoActivated,
+ deviceCapable &&
+ hasDeviceProxy &&
+ !deviceContext?.autoActivated &&
+ !deviceContext?.boundDeviceId,
[AgentDocumentsManifest.identifier]: hasAgentDocuments,
[WebBrowsingManifest.identifier]: isSearchEnabled,
};