Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(python): prevent double modifier application on remote multi-execute
_route_multi_execute no longer accepts or passes modifiers to the remote execution path. The outer routing_execute already applies before_execute/after_execute modifiers, so passing them into the inner _wrap_execute_tool_for_tool_router would cause double application. Addresses Cursor Bugbot High severity finding. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dhawal Upadhyay committed
Mar 23, 2026 at 16:31 UTC
d817b26617adc9e49a162aedb356a725bf21493a
2 files changed
+8
-13
python/composio/core/models/tool_router_session.py
+7
-9
@@ -184,9 +184,7 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
184
)
185
processed_arguments = modified.get("arguments", arguments)
186
187
- result = self._route_multi_execute(
188
- processed_arguments, tools_model, modifiers
189
- )
187
+ result = self._route_multi_execute(processed_arguments, tools_model)
188
189
# Apply after_execute modifiers
190
if modifiers is not None:
@@ -226,19 +224,20 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
224
self,
225
input_args: t.Dict[str, t.Any],
226
tools_model: t.Any,
229
- modifiers: t.Optional["Modifiers"],
227
) -> t.Dict[str, t.Any]:
228
"""Route a COMPOSIO_MULTI_EXECUTE_TOOL call.
229
230
Splits the tools[] array into local and remote, executes each
231
appropriately, and merges results preserving original order.
232
+
233
+ Note: modifiers are NOT applied here — the caller (routing_execute)
234
+ handles before_execute/after_execute to avoid double application.
235
"""
236
tool_items = input_args.get("tools")
237
if not isinstance(tool_items, list) or len(tool_items) == 0:
238
- # Fallback: send to backend as-is
238
+ # Fallback: send to backend as-is (no modifiers — caller handles them)
239
return tools_model._wrap_execute_tool_for_tool_router(
240
session_id=self.session_id,
241
- modifiers=modifiers,
241
)(COMPOSIO_MULTI_EXECUTE_TOOL, input_args)
242
243
parsed = [self._parse_tool_item(item) for item in tool_items]
@@ -253,11 +252,10 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
252
else:
253
remote_indices.append(i)
254
256
- # All remote — just forward entire payload
255
+ # All remote — just forward entire payload (no modifiers — caller handles them)
256
if not local_items:
257
return tools_model._wrap_execute_tool_for_tool_router(
258
session_id=self.session_id,
260
- modifiers=modifiers,
259
)(COMPOSIO_MULTI_EXECUTE_TOOL, input_args)
260
261
ctx = self._session_context
@@ -280,13 +278,13 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
278
local_futures.append((idx, future))
279
280
# Submit remote batch (single call) if any
281
+ # No modifiers here — the outer routing_execute handles them
282
remote_future = None
283
if remote_indices:
284
remote_tool_items = [tool_items[i] for i in remote_indices]
285
remote_input = {**input_args, "tools": remote_tool_items}
286
execute_fn = tools_model._wrap_execute_tool_for_tool_router(
287
session_id=self.session_id,
289
- modifiers=modifiers,
288
)
289
remote_future = pool.submit(
290
execute_fn,
python/tests/test_custom_tools.py
+1
-4
@@ -537,7 +537,6 @@ class TestMultiExecuteRouting:
537
result = s._route_multi_execute(
538
{"tools": [{"tool_slug": "GREP", "arguments": {"pattern": "x"}}]},
539
MagicMock(),
540
- None,
540
)
541
assert result["successful"] is True
542
assert result["data"]["matches"] == ["x"]
@@ -548,7 +547,7 @@ class TestMultiExecuteRouting:
547
remote = {"data": {"results": []}, "error": None, "successful": True}
548
tm._wrap_execute_tool_for_tool_router.return_value = lambda slug, args: remote
549
result = s._route_multi_execute(
551
- {"tools": [{"tool_slug": "REMOTE", "arguments": {}}]}, tm, None
550
+ {"tools": [{"tool_slug": "REMOTE", "arguments": {}}]}, tm
551
)
552
assert result == remote
553
@@ -573,7 +572,6 @@ class TestMultiExecuteRouting:
572
]
573
},
574
tm,
576
- None,
575
)
576
assert len(result["data"]["results"]) == 2
577
@@ -597,7 +595,6 @@ class TestMultiExecuteRouting:
595
]
596
},
597
MagicMock(),
600
- None,
598
)
599
assert result["successful"] is False
600
assert "1 out of 2" in result["error"]