@devries-cameron20 / composio Mirror · read-only / commits / e3999c4ee
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 09:45 UTC

fix(sdk): never retry session tool executions (#4718)

This PR: - is the SDK-only first step of https://github.com/ComposioHQ/composio/issues/3654 and supersedes https://github.com/ComposioHQ/composio/pull/4646, which covered one of the affected paths - stops retrying every remaining tool-execution path in both SDKs: `session.execute`, `session.proxyExecute` / `proxy_execute`, provider-wrapped session tools, and the `execute` / `proxyExecute` helpers passed to custom tools. These kept the client's default of two retries on timeouts, connection errors, and 408/409/429/5xx, so a retry after the backend already acted could repeat the side effect (e.g. send the same email twice) - TypeScript: adds an internal `withoutRetries(requestOptions)` helper that sets `maxRetries: 0` per request, and replaces the cloned `clientWithoutRetries` client in `Tools` with it, so `tools.execute` / `tools.proxyExecute` and the session paths share one mechanism - Python: routes the session paths through the existing `client.without_retries`, the same mechanism `tools.execute` / `tools.proxy` already use - CLI: `composio execute` (including meta tools) and `composio proxy` pass `maxRetries: 0` - adds transport-level regression tests in both SDKs: each execution path reaches the backend exactly once on a retryable error, while reads still retry. The new tests fail without the fix - does not add idempotency keys. The backend does not read `Idempotency-Key` on any execute endpoint today, so sending one would not prevent a duplicate; re-enabling retries is left to a follow-up once server-side dedup exists ## Context https://github.com/ComposioHQ/composio/pull/3657 (Python) and the TypeScript 0.14 release disabled retries for `tools.execute` and `tools.proxy` only. The session paths were left retrying, which is the path most agent integrations use. Checks run locally: `pnpm --filter @composio/core typecheck` and `test` (70 files, 1694 tests), `pnpm --filter @composio/cli typecheck` and `test` (132 files, 1451 tests), Python `nox -s chk` and the full pytest suite (2176 passed).

Alberto Schiabel committed Oct 1, 2026 at 16:42 UTC e3999c4eea1c8422a96fca69abcfc3f9c1544315
26 files changed +438 -205
.changeset/no-retry-session-execute.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Stop retrying session tool executions and proxied calls. `session.execute()`, `session.proxyExecute()`, provider-wrapped session tools, and the `execute` / `proxyExecute` helpers passed to custom tools no longer retry after a timeout, connection error, or 408/409/429/5xx response, so a retry can no longer repeat a side effect such as sending the same email twice. This matches `tools.execute()` and `tools.proxyExecute()`.
python/composio/client/__init__.py
+8 -6
@@ -483,15 +483,17 @@ class HttpClient(BaseComposio, WithLogger):
483 """
484 A cached sibling client that never retries requests.
485
486 - Used for non-idempotent writes (``tools.execute`` / ``tools.proxy``),
486 + Used for tool executions and proxied API calls (``tools.execute``,
487 + ``tools.proxy``, and the session ``execute`` / ``proxy_execute`` paths),
488 where a silent retry after a read timeout can duplicate a side effect
489 (e.g. send an email twice). Reads keep the default retry behaviour.
490
490 - Scope: only ``tools.execute`` / ``tools.proxy`` route through this today.
491 - Other non-idempotent writes (``auth_configs.create`` / ``update`` /
492 - ``delete``, ``mcp.update`` / ``delete``, ``connected_accounts.delete`` /
493 - ``refresh``, ``link.create``) keep the default retries — most are
494 - naturally idempotent on retry, and the durable fix is backend-honoured
491 + Scope: every execution path routes through this, because the backend
492 + does not deduplicate executions. Other non-idempotent writes
493 + (``auth_configs.create`` / ``update`` / ``delete``, ``mcp.update`` /
494 + ``delete``, ``connected_accounts.delete`` / ``refresh``,
495 + ``link.create``) keep the default retries — most are naturally
496 + idempotent on retry, and the durable fix is backend-honoured
497 idempotency keys.
498
499 The sibling is cached rather than rebuilt per call so a fresh client is
python/composio/core/models/session_context.py
+6 -2
@@ -82,7 +82,9 @@ def proxy_execute_impl(
82 )
83 )
84
85 - response = client.tool_router.session.proxy_execute(
85 + # Disable retries: a proxied call is a non-idempotent write, and a silent
86 + # retry after a read timeout can duplicate the side effect.
87 + response = client.without_retries.tool_router.session.proxy_execute(
88 session_id=session_id,
89 toolkit_slug=toolkit,
90 endpoint=endpoint,
@@ -165,7 +167,9 @@ class SessionContextImpl:
167 # Serialize any Pydantic model instances before sending to remote API
168 serialized = _serialize_arguments(arguments)
169
168 - return self._client.tool_router.session.execute(
170 + # Disable retries: a session execution is a non-idempotent write, and a
171 + # silent retry after a read timeout can duplicate the side effect.
172 + return self._client.without_retries.tool_router.session.execute(
173 session_id=self._session_id,
174 tool_slug=tool_slug,
175 arguments=serialized,
python/composio/core/models/tool_router_session.py
+3 -1
@@ -984,7 +984,9 @@ class ToolRouterSession(t.Generic[TTool, TToolCollection]):
984
985 assert_unambiguous_custom_tool_slug(self._custom_tools_map, tool_slug)
986
987 - response = self._client.tool_router.session.execute(
987 + # Disable retries: a session execution is a non-idempotent write, and a
988 + # silent retry after a read timeout can duplicate the side effect.
989 + response = self._client.without_retries.tool_router.session.execute(
990 session_id=self.session_id,
991 tool_slug=tool_slug,
992 arguments=arguments if arguments is not None else omit,
python/composio/core/models/tools.py
+3 -1
@@ -565,7 +565,9 @@ class Tools(Resource, t.Generic[TTool, TToolCollection]):
565 # Serialize any Pydantic model instances before sending to the API
566 processed_arguments = _serialize_arguments(processed_arguments)
567
568 - response = self._client.tool_router.session.execute(
568 + # Disable retries: a session execution is a non-idempotent write, and a
569 + # silent retry after a read timeout can duplicate the side effect.
570 + response = self._client.without_retries.tool_router.session.execute(
571 session_id=session_id,
572 tool_slug=slug,
573 arguments=processed_arguments,
python/tests/conftest.py
+8 -6
@@ -6,6 +6,7 @@ import hmac
6 import json
7 import os
8 from pathlib import Path
9 +import typing as t
10 from unittest.mock import Mock
11
12 import pytest
@@ -81,15 +82,16 @@ def load_golden_signatures() -> dict:
82 return json.load(f)
83
84
84 -def mock_http_client() -> Mock:
85 +def mock_http_client(mock_cls: t.Type[Mock] = Mock) -> Mock:
86 """Build a mock ``HttpClient`` for tool-execution tests.
87
87 - Production routes non-idempotent writes through ``client.without_retries``
88 - (a retry-disabled clone of the client). The mock mirrors that by returning
89 - itself for ``without_retries``, so assertions on ``client.tools.execute`` and
90 - ``client.tools.proxy`` still observe the call.
88 + Production routes tool executions and proxied calls through
89 + ``client.without_retries`` (a retry-disabled clone of the client). The mock
90 + mirrors that by returning itself for ``without_retries``, so assertions on
91 + ``client.tools.execute``, ``client.tools.proxy``, and the
92 + ``client.tool_router.session`` execution methods still observe the call.
93 """
92 - client = Mock()
94 + client = mock_cls()
95 client.without_retries = client
96 return client
97
python/tests/test_custom_tools.py
+19 -15
@@ -46,6 +46,7 @@ from composio.core.models.tool_router_session import (
46 ToolRouterSessionExecuteResponse,
47 )
48 from composio.exceptions import ValidationError
49 +from tests.conftest import mock_http_client
50
51 # ────────────────────────────────────────────────────────────────
52 # Fixtures
@@ -752,7 +753,10 @@ class TestSessionContextImpl:
753 def test_sibling_routing(self, grep_tool):
754 m = build_custom_tools_map([grep_tool])
755 ctx = SessionContextImpl(
755 - client=MagicMock(), user_id="u", session_id="s", custom_tools_map=m
756 + client=mock_http_client(MagicMock),
757 + user_id="u",
758 + session_id="s",
759 + custom_tools_map=m,
760 )
761 result = ctx.execute("GREP", {"pattern": "test"})
762 assert isinstance(result, SessionExecuteResponse)
@@ -769,7 +773,7 @@ class TestSessionContextImpl:
773 beta = ExperimentalToolkit(slug="BETA", name="Beta", description="Beta tools")
774 beta._tools.append(beta_tool)
775 m = build_custom_tools_map([], [alpha, beta])
772 - mock_client = MagicMock()
776 + mock_client = mock_http_client(MagicMock)
777 ctx = SessionContextImpl(
778 client=mock_client, user_id="u", session_id="s", custom_tools_map=m
779 )
@@ -783,7 +787,7 @@ class TestSessionContextImpl:
787
788 def test_remote_fallback(self, grep_tool):
789 m = build_custom_tools_map([grep_tool])
786 - mock_client = MagicMock()
790 + mock_client = mock_http_client(MagicMock)
791 mock_client.tool_router.session.execute.return_value = SessionExecuteResponse(
792 data={"remote": True}, error=None, log_id="log_123"
793 )
@@ -799,7 +803,7 @@ class TestSessionContextImpl:
803 )
804
805 def test_remote_fallback_passes_inline_custom_tools(self):
802 - mock_client = MagicMock()
806 + mock_client = mock_http_client(MagicMock)
807 mock_client.tool_router.session.execute.return_value = SessionExecuteResponse(
808 data={"remote": True}, error=None, log_id="log_123"
809 )
@@ -828,7 +832,7 @@ class TestSessionContextImpl:
832 )
833
834 def test_proxy_execute(self):
831 - mock_client = MagicMock()
835 + mock_client = mock_http_client(MagicMock)
836 mock_client.tool_router.session.proxy_execute.return_value = (
837 SessionProxyExecuteResponse(
838 status=200, data={"ok": True}, headers={}, binary_data=None
@@ -847,7 +851,7 @@ class TestSessionContextImpl:
851 Equality alone cannot catch the leak, because ``200 == 200.0``. Only the
852 type assertion distinguishes ``200`` from the ``200.0`` a raw read returns.
853 """
850 - mock_client = MagicMock()
854 + mock_client = mock_http_client(MagicMock)
855 mock_client.tool_router.session.proxy_execute.return_value = (
856 SessionProxyExecuteResponse(
857 status=200, data=None, headers=None, binary_data=None
@@ -861,7 +865,7 @@ class TestSessionContextImpl:
865 assert result == {"status": 200, "data": None, "headers": None}
866
867 def test_proxy_execute_projects_binary_data(self):
864 - mock_client = MagicMock()
868 + mock_client = mock_http_client(MagicMock)
869 mock_client.tool_router.session.proxy_execute.return_value = (
870 SessionProxyExecuteResponse(
871 status=200,
@@ -894,7 +898,7 @@ class TestSessionContextImpl:
898
899 def test_proxy_execute_binary_data_without_expiry(self):
900 """``expires_at`` is optional on the generated model; the key stays present."""
897 - mock_client = MagicMock()
901 + mock_client = mock_http_client(MagicMock)
902 mock_client.tool_router.session.proxy_execute.return_value = (
903 SessionProxyExecuteResponse(
904 status=200,
@@ -927,7 +931,7 @@ class TestSessionContextImpl:
931 @pytest.fixture
932 def mock_session_deps(grep_tool, email_tool, role_toolkit):
933 return {
930 - "client": MagicMock(),
934 + "client": mock_http_client(MagicMock),
935 "provider": MagicMock(),
936 "experimental": MagicMock(),
937 "tools_map": build_custom_tools_map([grep_tool, email_tool], [role_toolkit]),
@@ -1109,7 +1113,7 @@ class TestToolRouterSessionCustomTools:
1113 beta._tools.append(beta_tool)
1114 custom_tools_map = build_custom_tools_map([], [alpha, beta])
1115 s = ToolRouterSession(
1112 - client=MagicMock(),
1116 + client=mock_http_client(MagicMock),
1117 provider=MagicMock(),
1118 dangerously_allow_auto_upload_download_files=True,
1119 session_id="s",
@@ -1148,7 +1152,7 @@ class TestToolRouterSessionCustomTools:
1152 [], [alpha, beta], mock_exp
1153 )
1154 s = ToolRouterSession(
1151 - client=MagicMock(),
1155 + client=mock_http_client(MagicMock),
1156 provider=MagicMock(),
1157 dangerously_allow_auto_upload_download_files=True,
1158 session_id="s",
@@ -1172,7 +1176,7 @@ class TestToolRouterSessionCustomTools:
1176 beta = ExperimentalToolkit(slug="BETA", name="Beta", description="Beta tools")
1177 beta._tools.append(beta_tool)
1178 custom_tools_map = build_custom_tools_map([], [alpha, beta])
1175 - client = MagicMock()
1179 + client = mock_http_client(MagicMock)
1180 s = ToolRouterSession(
1181 client=client,
1182 provider=MagicMock(),
@@ -1195,7 +1199,7 @@ class TestToolRouterSessionCustomTools:
1199
1200 def test_empty_when_no_map(self):
1201 s = ToolRouterSession(
1198 - client=MagicMock(),
1202 + client=mock_http_client(MagicMock),
1203 provider=MagicMock(),
1204 dangerously_allow_auto_upload_download_files=True,
1205 session_id="s",
@@ -1214,7 +1218,7 @@ class TestMultiExecuteRouting:
1218 def _make_session(self, *tools, inline_custom_tools_payload=None):
1219 m = build_custom_tools_map(list(tools))
1220 return ToolRouterSession(
1217 - client=MagicMock(),
1221 + client=mock_http_client(MagicMock),
1222 provider=MagicMock(),
1223 dangerously_allow_auto_upload_download_files=True,
1224 session_id="s",
@@ -1243,7 +1247,7 @@ class TestMultiExecuteRouting:
1247 beta = ExperimentalToolkit(slug="BETA", name="Beta", description="Beta tools")
1248 beta._tools.append(beta_tool)
1249 s = ToolRouterSession(
1246 - client=MagicMock(),
1250 + client=mock_http_client(MagicMock),
1251 provider=MagicMock(),
1252 dangerously_allow_auto_upload_download_files=True,
1253 session_id="s",
python/tests/test_no_retry_writes.py
+92 -4
@@ -1,10 +1,14 @@
1 -"""Non-idempotent tool writes (``tools.execute`` / ``tools.proxy``) must not retry.
1 +"""Tool executions and proxied API calls must not retry.
2
3 A POST that times out while the backend is still processing it is unsafe to
4 retry: the request may already have taken effect, so a silent re-send can
5 -duplicate the side effect (e.g. send an email twice). ``Tools.execute`` and
6 -``Tools.proxy`` therefore route through ``client.without_retries`` (a
7 -retry-disabled clone), while reads keep the default retry behaviour.
5 +duplicate the side effect (e.g. send an email twice). The backend does not
6 +deduplicate executions, so every execution path (``tools.execute``,
7 +``tools.proxy``, and the session ``execute`` / ``proxy_execute`` paths) routes
8 +through ``client.without_retries`` (a retry-disabled clone), while reads keep
9 +the default retry behaviour.
10 +
11 +See https://github.com/ComposioHQ/composio/issues/3654.
12 """
13
14 import inspect
@@ -18,6 +22,8 @@ from composio_client import Composio as BaseComposio
22
23 from composio.client import HttpClient
24 from composio.core.models.base import allow_tracking
25 +from composio.core.models.session_context import SessionContextImpl
26 +from composio.core.models.tool_router_session import ToolRouterSession
27 from composio.core.models.tools import Tools
28
29
@@ -169,6 +175,88 @@ class TestWritePathDoesNotRetry:
175 assert len(attempts) == 1
176
177
178 +SESSION_ID = "sess_123"
179 +
180 +
181 +def _session(client: HttpClient) -> ToolRouterSession:
182 + return ToolRouterSession(
183 + client=client,
184 + provider=None,
185 + dangerously_allow_auto_upload_download_files=False,
186 + session_id=SESSION_ID,
187 + mcp=Mock(),
188 + experimental=Mock(),
189 + )
190 +
191 +
192 +def _provider_wrapped_session_tool(client: HttpClient) -> t.Any:
193 + tools = Tools(client=client, provider=Mock())
194 + # Avoid the (read) tool-schema lookup hitting the transport.
195 + mock_tool = Mock()
196 + mock_tool.toolkit.slug = "gmail"
197 + mock_tool.input_parameters = {}
198 + tools._tool_schemas["GMAIL_SEND_EMAIL"] = mock_tool
199 + execute = tools._wrap_execute_tool_for_tool_router(session_id=SESSION_ID)
200 + return execute("GMAIL_SEND_EMAIL", {"to": "test@test.com"})
201 +
202 +
203 +PROXY_KWARGS: t.Dict[str, t.Any] = {
204 + "toolkit": "github",
205 + "endpoint": "https://api.github.com/user/repos",
206 + "method": "POST",
207 + "body": {"name": "repo"},
208 +}
209 +
210 +SESSION_EXECUTION_PATHS: t.List[t.Tuple[str, t.Callable[[HttpClient], t.Any]]] = [
211 + ("provider_wrapped_session_tool", _provider_wrapped_session_tool),
212 + (
213 + "session_execute",
214 + lambda client: _session(client).execute(
215 + "GMAIL_SEND_EMAIL", arguments={"to": "test@test.com"}
216 + ),
217 + ),
218 + (
219 + "session_proxy_execute",
220 + lambda client: _session(client).proxy_execute(**PROXY_KWARGS),
221 + ),
222 + (
223 + "custom_tool_context_execute",
224 + lambda client: SessionContextImpl(client, "test-user", SESSION_ID).execute(
225 + "GMAIL_SEND_EMAIL", {"to": "test@test.com"}
226 + ),
227 + ),
228 + (
229 + "custom_tool_context_proxy_execute",
230 + lambda client: SessionContextImpl(
231 + client, "test-user", SESSION_ID
232 + ).proxy_execute(**PROXY_KWARGS),
233 + ),
234 +]
235 +
236 +
237 +class TestSessionExecutionDoesNotRetry:
238 + """Every session execution path must reach the transport exactly once."""
239 +
240 + @pytest.mark.parametrize(
241 + "run",
242 + [run for _, run in SESSION_EXECUTION_PATHS],
243 + ids=[name for name, _ in SESSION_EXECUTION_PATHS],
244 + )
245 + def test_does_not_retry_on_transient_error(
246 + self, run: t.Callable[[HttpClient], t.Any], no_sleep: None
247 + ) -> None:
248 + attempts: t.List[httpx.Request] = []
249 +
250 + def handler(request: httpx.Request) -> httpx.Response:
251 + attempts.append(request)
252 + return httpx.Response(500, json={"error": {"message": "boom"}})
253 +
254 + with pytest.raises(APIError):
255 + run(_client_with_transport(handler))
256 +
257 + assert len(attempts) == 1
258 +
259 +
260 class TestReadPathStillRetries:
261 """Reads keep the default retry behaviour — only writes are scoped to no-retry."""
262
python/tests/test_tool_router.py
+2 -1
@@ -40,6 +40,7 @@ from composio.exceptions import (
40 SessionConfigConflictError,
41 ValidationError,
42 )
43 +from tests.conftest import mock_http_client
44
45 experimental_api = ExperimentalAPI()
46
@@ -51,7 +52,7 @@ class GrepInput(BaseModel):
52 @pytest.fixture
53 def mock_client():
54 """Create a mock HTTP client."""
54 - client = MagicMock()
55 + client = mock_http_client(MagicMock)
56 client.api_key = "test-api-key"
57 client.user_api_key = None
58 client.base_url = httpx.URL("https://backend.composio.dev")
ts/packages/cli/src/commands/proxy.cmd.ts
+13 -7
@@ -353,13 +353,19 @@ export const proxyCmd = Command.make('proxy', {
353
354 return yield* Effect.tryPromise({
355 try: () =>
356 - client.toolRouter.session.proxyExecute(sessionId, {
357 - toolkit_slug: normalizedToolkit,
358 - endpoint,
359 - method: normalizedMethod,
360 - ...(parsedBody !== undefined ? { body: parsedBody } : {}),
361 - ...(headerParameters.length > 0 ? { parameters: headerParameters } : {}),
362 - }),
356 + client.toolRouter.session.proxyExecute(
357 + sessionId,
358 + {
359 + toolkit_slug: normalizedToolkit,
360 + endpoint,
361 + method: normalizedMethod,
362 + ...(parsedBody !== undefined ? { body: parsedBody } : {}),
363 + ...(headerParameters.length > 0 ? { parameters: headerParameters } : {}),
364 + },
365 + // Never retry a proxied call: a retry after the upstream API
366 + // already acted duplicates the side effect.
367 + { maxRetries: 0 }
368 + ),
369 catch: cause =>
370 new ProxyRequestError({
371 message: `Failed to proxy ${normalizedMethod} ${endpoint} via "${normalizedToolkit}".`,
ts/packages/cli/src/services/tools-executor.ts
+12 -8
@@ -213,17 +213,21 @@ export const ToolsExecutorLive = Layer.effect(
213
214 const raw: SessionExecuteResponse | SessionExecuteMetaResponse = yield* Effect.tryPromise(
215 {
216 + // Never retry an execution: a retry after the backend already acted
217 + // duplicates the side effect (e.g. sends the same email twice).
218 try: () => {
219 if (isMetaToolSlug(slug)) {
218 - return resolvedClient.toolRouter.session.executeMeta(sessionId, {
219 - slug,
220 - arguments: normalizedArguments,
221 - });
220 + return resolvedClient.toolRouter.session.executeMeta(
221 + sessionId,
222 + { slug, arguments: normalizedArguments },
223 + { maxRetries: 0 }
224 + );
225 }
223 - return resolvedClient.toolRouter.session.execute(sessionId, {
224 - tool_slug: slug,
225 - arguments: normalizedArguments,
226 - });
226 + return resolvedClient.toolRouter.session.execute(
227 + sessionId,
228 + { tool_slug: slug, arguments: normalizedArguments },
229 + { maxRetries: 0 }
230 + );
231 },
232 catch: cause => cause,
233 }
ts/packages/cli/test/__utils__/services/test-layer.ts
+12 -6
@@ -277,19 +277,25 @@ export interface TestLiveInput {
277 toolRouter?: {
278 /** Override `session.create`. Receives the create params. */
279 create?: (params: SessionCreateParams) => Promise<SessionCreateResponse>;
280 - /** Override `session.execute`. Receives sessionId and params. */
281 - execute?: (sessionId: string, params: SessionExecuteParams) => Promise<SessionExecuteResponse>;
282 - /** Override `session.executeMeta`. Receives sessionId and params. */
280 + /** Override `session.execute`. Receives sessionId, params, and request options. */
281 + execute?: (
282 + sessionId: string,
283 + params: SessionExecuteParams,
284 + options?: { maxRetries?: number }
285 + ) => Promise<SessionExecuteResponse>;
286 + /** Override `session.executeMeta`. Receives sessionId, params, and request options. */
287 executeMeta?: (
288 sessionId: string,
285 - params: SessionExecuteMetaParams
289 + params: SessionExecuteMetaParams,
290 + options?: { maxRetries?: number }
291 ) => Promise<SessionExecuteMetaResponse>;
292 /** Override `session.link`. Receives sessionId and params. */
293 link?: (sessionId: string, params: SessionLinkParams) => Promise<SessionLinkResponse>;
289 - /** Override `session.proxyExecute`. Receives sessionId and params. */
294 + /** Override `session.proxyExecute`. Receives sessionId, params, and request options. */
295 proxyExecute?: (
296 sessionId: string,
292 - params: SessionProxyExecuteParams
297 + params: SessionProxyExecuteParams,
298 + options?: { maxRetries?: number }
299 ) => Promise<SessionProxyExecuteResponse>;
300 /** Override `session.search`. Receives sessionId and params. */
301 search?: (sessionId: string, params: SessionSearchParams) => Promise<SessionSearchResponse>;
ts/packages/cli/test/src/commands/proxy.cmd.test.ts
+10 -1
@@ -47,6 +47,7 @@ describe('CLI: composio proxy', () => {
47 it.effect('forwards proxy execute params and prints the response', () =>
48 Effect.gen(function* () {
49 let createParams: SessionCreateParams | undefined;
50 + let proxyOptions: { maxRetries?: number } | undefined;
51 let proxyParams:
52 | {
53 sessionId: string;
@@ -117,8 +118,13 @@ describe('CLI: composio proxy', () => {
118 tool_router_tools: [],
119 };
120 },
120 - proxyExecute: async (sessionId: string, params: SessionProxyExecuteParams) => {
121 + proxyExecute: async (
122 + sessionId: string,
123 + params: SessionProxyExecuteParams,
124 + options?: { maxRetries?: number }
125 + ) => {
126 proxyParams = { sessionId, params };
127 + proxyOptions = options;
128 return {
129 status: 200,
130 data: {
@@ -173,6 +179,9 @@ describe('CLI: composio proxy', () => {
179 ],
180 },
181 });
182 + // A proxied call is never retried: a retry after the upstream API
183 + // already acted would duplicate the side effect.
184 + expect(proxyOptions).toEqual({ maxRetries: 0 });
185
186 expect(output).toContain('Status: 200');
187 expect(output).toContain('"ok": true');
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+13 -5
@@ -142,9 +142,11 @@ describe('CLI: composio execute', () => {
142
143 let recordedSessionCreateParams: Array<Record<string, unknown>> = [];
144 let recordedProjectToolkitScopes: Array<composioClients.ToolkitProjectScope | undefined> = [];
145 + let recordedExecuteOptions: Array<{ maxRetries?: number } | undefined> = [];
146 beforeEach(() => {
147 recordedSessionCreateParams = [];
148 recordedProjectToolkitScopes = [];
149 + recordedExecuteOptions = [];
150 });
151
152 layer(
@@ -337,11 +339,14 @@ describe('CLI: composio execute', () => {
339 tool_router_tools: ['COMPOSIO_SEARCH_TOOLS', 'COMPOSIO_MANAGE_CONNECTIONS'],
340 };
341 },
340 - execute: async (_sessionId, params) => ({
341 - data: { tool_slug: params.tool_slug, arguments: params.arguments },
342 - error: null,
343 - log_id: 'log_gmail_default',
344 - }),
342 + execute: async (_sessionId, params, options) => {
343 + recordedExecuteOptions.push(options);
344 + return {
345 + data: { tool_slug: params.tool_slug, arguments: params.arguments },
346 + error: null,
347 + log_id: 'log_gmail_default',
348 + };
349 + },
350 },
351 })
352 )('[Given] default alias exists [Then] execute pins the default connected account', it => {
@@ -358,6 +363,9 @@ describe('CLI: composio execute', () => {
363 expect(recordedSessionCreateParams[0]?.connected_accounts).toEqual({
364 gmail: 'con_gmail_default',
365 });
366 + // An execution is never retried: a retry after the backend already
367 + // acted would duplicate the side effect.
368 + expect(recordedExecuteOptions.at(-1)).toEqual({ maxRetries: 0 });
369 })
370 );
371
ts/packages/core/src/models/SessionContext.ts
+12 -2
@@ -27,6 +27,7 @@ import { transformExecuteResponse } from '../utils/transformers/toolRouterRespon
27 import type { SessionExecuteParams } from '@composio/client/resources/tool-router/session/session.mjs';
28 import { inlineCustomToolsExperimental } from './inlineCustomToolsPayload';
29 import { withCancellation } from '../utils/cancellation';
30 +import { withoutRetries } from '../utils/retries';
31
32 /**
33 * Concrete implementation of SessionContext.
@@ -100,7 +101,12 @@ export class SessionContextImpl implements SessionContext {
101 }
102
103 const response = await withCancellation(
103 - () => this.client.toolRouter.session.execute(this.sessionId, executeParams, requestOptions),
104 + () =>
105 + this.client.toolRouter.session.execute(
106 + this.sessionId,
107 + executeParams,
108 + withoutRetries(requestOptions)
109 + ),
110 requestOptions?.signal
111 );
112 return ToolRouterSessionExecuteResponseSchema.parse(transformExecuteResponse(response));
@@ -124,7 +130,11 @@ export class SessionContextImpl implements SessionContext {
130 const clientParams = transformProxyParams(validated.data);
131 const response = await withCancellation(
132 () =>
127 - this.client.toolRouter.session.proxyExecute(this.sessionId, clientParams, requestOptions),
133 + this.client.toolRouter.session.proxyExecute(
134 + this.sessionId,
135 + clientParams,
136 + withoutRetries(requestOptions)
137 + ),
138 requestOptions?.signal
139 );
140
ts/packages/core/src/models/ToolRouterSession.ts
+12 -2
@@ -4,6 +4,7 @@ import type { BaseComposioProvider } from '../provider/BaseProvider';
4 import type { ComposioConfig } from '../composio';
5 import type { ComposioRequestOptions } from '../types/requestOptions.types';
6 import { withCancellation } from '../utils/cancellation';
7 +import { withoutRetries } from '../utils/retries';
8 import { ComposioRequestCancelledError } from '../errors/SDKErrors';
9 import { ComposioSessionConfigConflictError } from '../errors/ToolRouterErrors';
10 import {
@@ -724,7 +725,12 @@ export class ToolRouterSession<
725 }
726
727 const response = await withCancellation(
727 - () => this.client.toolRouter.session.execute(this.sessionId, executeParams, requestOptions),
728 + () =>
729 + this.client.toolRouter.session.execute(
730 + this.sessionId,
731 + executeParams,
732 + withoutRetries(requestOptions)
733 + ),
734 requestOptions?.signal
735 );
736 const transformed = transformExecuteResponse(response);
@@ -750,7 +756,11 @@ export class ToolRouterSession<
756 const clientParams = transformProxyParams(validated.data);
757 const response = await withCancellation(
758 () =>
753 - this.client.toolRouter.session.proxyExecute(this.sessionId, clientParams, requestOptions),
759 + this.client.toolRouter.session.proxyExecute(
760 + this.sessionId,
761 + clientParams,
762 + withoutRetries(requestOptions)
763 + ),
764 requestOptions?.signal
765 );
766
ts/packages/core/src/models/Tools.ts
+9 -33
@@ -62,6 +62,7 @@ import {
62 import { dereferenceJsonSchema } from '../utils/jsonSchema';
63 import { ComposioRequestOptions } from '../types/requestOptions.types';
64 import { withCancellation } from '../utils/cancellation';
65 +import { withoutRetries } from '../utils/retries';
66 import { transformExecuteResponse } from '../utils/transformers/toolRouterResponseTransform';
67 import { ComposioRequestCancelledError } from '../errors/SDKErrors';
68
@@ -120,11 +121,6 @@ export class Tools<
121 */
122 private readonly warnedAutoUploadDisabledForTool = new Set<string>();
123
123 - /**
124 - * Lazily-built sibling client with retries disabled; see `clientWithoutRetries`.
125 - */
126 - private clientWithoutRetriesCache?: ComposioClient;
127 -
124 constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
125 if (!client) {
126 throw new Error('ComposioClient is required');
@@ -157,27 +153,6 @@ export class Tools<
153 telemetry.instrument(this, 'Tools');
154 }
155
160 - /**
161 - * A cached sibling client that never retries requests, mirroring Python's
162 - * `client.without_retries`.
163 - *
164 - * Used for non-idempotent writes (`tools.execute` / `tools.proxy`), where a
165 - * silent retry after a read timeout can duplicate a side effect (e.g. send an
166 - * email twice). Reads keep the default retry behaviour, and so do other writes
167 - * (`toolRouter.session.execute`, auth-config and connected-account mutations):
168 - * the durable fix there is backend-honoured idempotency keys, tracked
169 - * separately.
170 - *
171 - * Cached rather than rebuilt per call because `withOptions` constructs a fresh
172 - * client; its options never change, so one per `Tools` instance suffices.
173 - */
174 - private get clientWithoutRetries(): ComposioClient {
175 - if (!this.clientWithoutRetriesCache) {
176 - this.clientWithoutRetriesCache = this.client.withOptions({ maxRetries: 0 });
177 - }
178 - return this.clientWithoutRetriesCache;
179 - }
180 -
156 /**
157 * Transforms tool data from snake_case API format to camelCase for internal SDK use.
158 *
@@ -1022,9 +997,7 @@ export class Tools<
997 text: body.text,
998 };
999 const result = await withCancellation(
1025 - // Disable retries: tool execution is a non-idempotent write, and a
1026 - // silent retry after a read timeout can duplicate the side effect.
1027 - () => this.clientWithoutRetries.tools.execute(tool.slug, executeBody, requestOptions),
1000 + () => this.client.tools.execute(tool.slug, executeBody, withoutRetries(requestOptions)),
1001 requestOptions?.signal
1002 );
1003 // transform the response to the ToolExecuteResponse format
@@ -1254,7 +1227,12 @@ export class Tools<
1227 }
1228
1229 const response = await withCancellation(
1257 - () => this.client.toolRouter.session.execute(body.sessionId, executePayload, requestOptions),
1230 + () =>
1231 + this.client.toolRouter.session.execute(
1232 + body.sessionId,
1233 + executePayload,
1234 + withoutRetries(requestOptions)
1235 + ),
1236 requestOptions?.signal
1237 );
1238
@@ -1409,9 +1387,7 @@ export class Tools<
1387 custom_connection_data: toolProxyParams.data.customConnectionData,
1388 } as ComposioToolProxyParams;
1389 return withCancellation(
1412 - // Disable retries: a proxied call is a non-idempotent write, and a silent
1413 - // retry after a read timeout can duplicate the side effect.
1414 - () => this.clientWithoutRetries.tools.proxy(proxyBody, requestOptions),
1390 + () => this.client.tools.proxy(proxyBody, withoutRetries(requestOptions)),
1391 requestOptions?.signal
1392 );
1393 }
ts/packages/core/src/utils/retries.ts new
+20
@@ -0,0 +1,20 @@
1 +import type { ComposioRequestOptions } from '../types/requestOptions.types';
2 +
3 +/**
4 + * Request options for a call that executes a tool or proxies an API call: the
5 + * caller's options with retries disabled.
6 + *
7 + * These calls are non-idempotent writes. The client retries timeouts,
8 + * connection errors, and 408/409/429/5xx responses by default, and a retry
9 + * after the backend already acted duplicates the side effect (e.g. sends the
10 + * same email twice). The backend does not deduplicate executions, so every
11 + * execution path must go through this helper. Reads keep the default retries.
12 + * See https://github.com/ComposioHQ/composio/issues/3654.
13 + *
14 + * @internal
15 + */
16 +export function withoutRetries(
17 + requestOptions?: ComposioRequestOptions
18 +): ComposioRequestOptions & { maxRetries: 0 } {
19 + return { ...requestOptions, maxRetries: 0 };
20 +}
ts/packages/core/test/models/customTool.test.ts
+4 -4
@@ -812,7 +812,7 @@ describe('SessionContextImpl', () => {
812 tool_slug: 'GMAIL_SEND_EMAIL',
813 arguments: { to: 'test@test.com' },
814 },
815 - undefined
815 + { maxRetries: 0 }
816 );
817 expect(result).toEqual({
818 data: { result: 'ok' },
@@ -849,7 +849,7 @@ describe('SessionContextImpl', () => {
849 custom_tools: [expect.objectContaining({ slug: 'GREP' })],
850 },
851 },
852 - undefined
852 + { maxRetries: 0 }
853 );
854 });
855
@@ -889,7 +889,7 @@ describe('SessionContextImpl', () => {
889 method: 'GET',
890 parameters: [{ name: 'X-Custom', type: 'header', value: 'val' }],
891 },
892 - undefined
892 + { maxRetries: 0 }
893 );
894 expect(result).toEqual({
895 status: 200,
@@ -949,7 +949,7 @@ describe('SessionContextImpl', () => {
949 tool_slug: 'REMOTE_TOOL',
950 arguments: { key: 'val' },
951 },
952 - undefined
952 + { maxRetries: 0 }
953 );
954 expect(result).toEqual({ data: { remote: true }, error: null, logId: 'log_3' });
955 });
ts/packages/core/test/models/customToolRouting.test.ts
+3 -3
@@ -370,7 +370,7 @@ describe('ToolRouterSession execution routing', () => {
370 tool_slug: 'GMAIL_SEND_EMAIL',
371 arguments: { to: 'test@test.com' },
372 },
373 - undefined
373 + { maxRetries: 0 }
374 );
375 expect(localExecute).not.toHaveBeenCalled();
376 });
@@ -404,7 +404,7 @@ describe('ToolRouterSession execution routing', () => {
404 method: 'GET',
405 parameters: [{ name: 'X-Test', type: 'header', value: '1' }],
406 },
407 - undefined
407 + { maxRetries: 0 }
408 );
409 expect(result).toEqual({
410 status: 200,
@@ -452,7 +452,7 @@ describe('ToolRouterSession execution routing', () => {
452 tool_slug: 'GMAIL_SEND_EMAIL',
453 arguments: { to: 'test@test.com' },
454 },
455 - undefined
455 + { maxRetries: 0 }
456 );
457 });
458
ts/packages/core/test/models/noRetryExecution.test.ts new
+134
@@ -0,0 +1,134 @@
1 +import { describe, it, expect, vi } from 'vitest';
2 +import ComposioClient from '@composio/client';
3 +import { Tools } from '../../src/models/Tools';
4 +import { ToolRouterSession } from '../../src/models/ToolRouterSession';
5 +import { SessionContextImpl } from '../../src/models/SessionContext';
6 +import { MockProvider } from '../utils/mocks/provider.mock';
7 +import { toolMocks } from '../utils/mocks/data.mock';
8 +import type { Tool } from '../../src/types/tool.types';
9 +
10 +vi.mock('../../src/telemetry/Telemetry', () => ({
11 + telemetry: { instrument: vi.fn() },
12 +}));
13 +
14 +// Regression for https://github.com/ComposioHQ/composio/issues/3654: executing
15 +// a tool or proxying an API call is a non-idempotent write, and the backend does
16 +// not deduplicate executions. A retry after the backend already acted duplicates
17 +// the side effect (e.g. sends the same email twice), so every execution path
18 +// must reach the transport exactly once. Reads keep the client's default retries.
19 +//
20 +// These tests run a real client against a counting `fetch` so they observe the
21 +// retry loop itself, not just the options the SDK passes to it.
22 +
23 +const SESSION_ID = 'sess_123';
24 +
25 +/** A real client whose every request is answered with a retryable 503. */
26 +const createFailingClient = () => {
27 + const fetch = vi.fn<typeof globalThis.fetch>(
28 + async () =>
29 + new Response(JSON.stringify({ error: { message: 'unavailable' } }), {
30 + status: 503,
31 + // Keep the retry backoff out of the test's wall-clock time.
32 + headers: { 'content-type': 'application/json', 'retry-after-ms': '1' },
33 + })
34 + );
35 + const client = new ComposioClient({
36 + apiKey: 'test-api-key',
37 + baseURL: 'https://backend.invalid',
38 + fetch,
39 + });
40 + return { client, fetch };
41 +};
42 +
43 +const createTools = (client: ComposioClient) => new Tools(client, { provider: new MockProvider() });
44 +
45 +const createSession = (client: ComposioClient) =>
46 + new ToolRouterSession(client, { apiKey: 'key', provider: new MockProvider() }, SESSION_ID, {
47 + type: 'http' as const,
48 + url: `https://backend.invalid/api/v3/tool_router/session/${SESSION_ID}`,
49 + });
50 +
51 +const proxyParams = {
52 + toolkit: 'github',
53 + endpoint: 'https://api.github.com/user/repos',
54 + method: 'POST' as const,
55 + body: { name: 'repo' },
56 +};
57 +
58 +const executionPaths: Array<{
59 + name: string;
60 + run: (client: ComposioClient) => Promise<unknown>;
61 +}> = [
62 + {
63 + name: 'tools.execute',
64 + run: client => {
65 + const tools = createTools(client);
66 + // Keep the (read) tool-schema lookup off the transport.
67 + vi.spyOn(tools, 'getRawComposioToolBySlug').mockResolvedValue(
68 + toolMocks.transformedTool as unknown as Tool
69 + );
70 + return tools.execute('COMPOSIO_TOOL', {
71 + userId: 'test-user',
72 + arguments: { query: 'test' },
73 + dangerouslySkipVersionCheck: true,
74 + });
75 + },
76 + },
77 + {
78 + name: 'tools.proxyExecute',
79 + run: client =>
80 + createTools(client).proxyExecute({
81 + endpoint: '/api/test',
82 + method: 'POST',
83 + body: { data: 'test' },
84 + connectedAccountId: 'test-account-id',
85 + }),
86 + },
87 + {
88 + name: 'provider-wrapped session tool',
89 + run: client =>
90 + createTools(client).executeSessionTool('GMAIL_SEND_EMAIL', {
91 + sessionId: SESSION_ID,
92 + arguments: { to: 'test@test.com' },
93 + }),
94 + },
95 + {
96 + name: 'session.execute',
97 + run: client => createSession(client).execute('GMAIL_SEND_EMAIL', { to: 'test@test.com' }),
98 + },
99 + {
100 + name: 'session.proxyExecute',
101 + run: client => createSession(client).proxyExecute(proxyParams),
102 + },
103 + {
104 + name: 'custom tool context execute',
105 + run: client =>
106 + new SessionContextImpl(client, 'test-user', SESSION_ID).execute('GMAIL_SEND_EMAIL', {
107 + to: 'test@test.com',
108 + }),
109 + },
110 + {
111 + name: 'custom tool context proxyExecute',
112 + run: client =>
113 + new SessionContextImpl(client, 'test-user', SESSION_ID).proxyExecute(proxyParams),
114 + },
115 +];
116 +
117 +describe('tool execution is never retried', () => {
118 + it.each(executionPaths)('$name reaches the backend exactly once', async ({ run }) => {
119 + const { client, fetch } = createFailingClient();
120 +
121 + await expect(run(client)).rejects.toThrow();
122 +
123 + expect(fetch).toHaveBeenCalledTimes(1);
124 + });
125 +
126 + it('reads keep the default retries', async () => {
127 + const { client, fetch } = createFailingClient();
128 +
129 + await expect(createTools(client).getToolsEnum()).rejects.toThrow();
130 +
131 + // The first attempt plus the client's two default retries.
132 + expect(fetch).toHaveBeenCalledTimes(3);
133 + });
134 +});
ts/packages/core/test/models/toolRouter.test.ts
+4 -4
@@ -2896,7 +2896,7 @@ describe('ToolRouter', () => {
2896 tool_slug: 'GMAIL_SEND_EMAIL',
2897 arguments: { to: 'user@example.com', subject: 'Hi', body: 'Hello' },
2898 },
2899 - undefined
2899 + { maxRetries: 0 }
2900 );
2901 expect(result.data).toEqual({ tool_slug: 'GMAIL_SEND_EMAIL', id: 'msg_123' });
2902 expect(result.error).toBeNull();
@@ -2940,7 +2940,7 @@ describe('ToolRouter', () => {
2940 tool_slug: 'HACKERNEWS_GET_USER',
2941 arguments: {},
2942 },
2943 - undefined
2943 + { maxRetries: 0 }
2944 );
2945 });
2946
@@ -2958,7 +2958,7 @@ describe('ToolRouter', () => {
2958 arguments: { to: 'user@example.com' },
2959 account: 'work',
2960 },
2961 - undefined
2961 + { maxRetries: 0 }
2962 );
2963 });
2964
@@ -2997,7 +2997,7 @@ describe('ToolRouter', () => {
2997 custom_tools: [expect.objectContaining({ slug: 'GREP' })],
2998 },
2999 },
3000 - undefined
3000 + { maxRetries: 0 }
3001 );
3002 });
3003 });
ts/packages/core/test/tools/fileModifiers.test.ts
+3 -3
@@ -2135,7 +2135,7 @@ describe('Tools with dangerouslyAllowAutoUploadDownloadFiles', () => {
2135 arguments: { file: staged },
2136 enable_auto_workbench_offload: true,
2137 },
2138 - undefined
2138 + { maxRetries: 0 }
2139 );
2140 });
2141 });
@@ -2217,7 +2217,7 @@ describe('Tools with dangerouslyAllowAutoUploadDownloadFiles', () => {
2217 user_id: 'test-user',
2218 version: 'latest',
2219 },
2220 - undefined
2220 + { maxRetries: 0 }
2221 );
2222 });
2223
@@ -2394,7 +2394,7 @@ describe('Tools with dangerouslyAllowAutoUploadDownloadFiles', () => {
2394 arguments: { text: 'keep' },
2395 enable_auto_workbench_offload: true,
2396 },
2397 - undefined
2397 + { maxRetries: 0 }
2398 );
2399 });
2400
ts/packages/core/test/tools/modifiers.test.ts
+1 -1
@@ -99,7 +99,7 @@ describe('Tools Modifiers', () => {
99 expect.objectContaining({
100 arguments: { limit: 10 },
101 }),
102 - undefined
102 + { maxRetries: 0 }
103 );
104 });
105
ts/packages/core/test/tools/requestOptions.test.ts
+4 -5
@@ -160,11 +160,10 @@ describe('Cancellation — execute signal forwarding', () => {
160 requestOptions
161 );
162
163 - expect(mockClient.tools.execute).toHaveBeenCalledWith(
164 - 'COMPOSIO_TOOL',
165 - expect.any(Object),
166 - requestOptions
167 - );
163 + expect(mockClient.tools.execute).toHaveBeenCalledWith('COMPOSIO_TOOL', expect.any(Object), {
164 + ...requestOptions,
165 + maxRetries: 0,
166 + });
167 expect(getRawSpy).toHaveBeenCalledWith('COMPOSIO_TOOL', expect.any(Object), requestOptions);
168 });
169
ts/packages/core/test/tools/tools.test.ts
+26 -85
@@ -896,7 +896,7 @@ describe('Tools', () => {
896 version: 'latest',
897 text: undefined,
898 },
899 - undefined
899 + { maxRetries: 0 }
900 );
901 expect(result).toEqual(toolMocks.toolExecuteResponse);
902 });
@@ -926,7 +926,7 @@ describe('Tools', () => {
926 version: 'latest',
927 text: undefined,
928 },
929 - undefined
929 + { maxRetries: 0 }
930 );
931 expect(result).toEqual(toolMocks.toolExecuteResponse);
932 });
@@ -965,7 +965,7 @@ describe('Tools', () => {
965 version: 'latest',
966 text: undefined,
967 },
968 - undefined
968 + { maxRetries: 0 }
969 );
970 expect(result).toEqual(toolMocks.toolExecuteResponse);
971 });
@@ -998,7 +998,7 @@ describe('Tools', () => {
998 expect.objectContaining({
999 version: explicitVersion,
1000 }),
1001 - undefined
1001 + { maxRetries: 0 }
1002 );
1003 });
1004
@@ -1117,7 +1117,7 @@ describe('Tools', () => {
1117 },
1118 ],
1119 },
1120 - undefined
1120 + { maxRetries: 0 }
1121 );
1122
1123 expect(result).toEqual(expectedProxyResponse);
@@ -1169,7 +1169,7 @@ describe('Tools', () => {
1169 },
1170 ],
1171 },
1172 - undefined
1172 + { maxRetries: 0 }
1173 );
1174
1175 expect(result).toEqual(expectedProxyResponse);
@@ -1221,7 +1221,7 @@ describe('Tools', () => {
1221 },
1222 ],
1223 },
1224 - undefined
1224 + { maxRetries: 0 }
1225 );
1226
1227 expect(result).toEqual(expectedProxyResponse);
@@ -1252,7 +1252,7 @@ describe('Tools', () => {
1252 connected_account_id: 'test-account-id',
1253 parameters: [],
1254 },
1255 - undefined
1255 + { maxRetries: 0 }
1256 );
1257
1258 expect(result).toEqual(expectedProxyResponse);
@@ -1304,7 +1304,7 @@ describe('Tools', () => {
1304 },
1305 ],
1306 },
1307 - undefined
1307 + { maxRetries: 0 }
1308 );
1309
1310 expect(result).toEqual(expectedProxyResponse);
@@ -1355,7 +1355,7 @@ describe('Tools', () => {
1355 arguments: body.arguments,
1356 enable_auto_workbench_offload: true,
1357 },
1358 - undefined
1358 + { maxRetries: 0 }
1359 );
1360 expect(result).toEqual({
1361 data: { results: true },
@@ -1417,7 +1417,7 @@ describe('Tools', () => {
1417 custom_tools: [expect.objectContaining({ slug: 'GREP' })],
1418 },
1419 },
1420 - undefined
1420 + { maxRetries: 0 }
1421 );
1422 });
1423
@@ -1488,7 +1488,7 @@ describe('Tools', () => {
1488 arguments: { query: 'modified' },
1489 enable_auto_workbench_offload: true,
1490 },
1491 - undefined
1491 + { maxRetries: 0 }
1492 );
1493 });
1494
@@ -1651,7 +1651,7 @@ describe('Tools', () => {
1651 arguments: { query: 'test' },
1652 enable_auto_workbench_offload: true,
1653 },
1654 - undefined
1654 + { maxRetries: 0 }
1655 );
1656 expect(result).toEqual({
1657 data: { results: true },
@@ -1699,7 +1699,7 @@ describe('Tools', () => {
1699 arguments: { query: 'test', modified: true },
1700 enable_auto_workbench_offload: true,
1701 },
1702 - undefined
1702 + { maxRetries: 0 }
1703 );
1704 });
1705
@@ -1953,7 +1953,7 @@ describe('Tools', () => {
1953 version: 'latest', // should use latest as default
1954 text: undefined,
1955 },
1956 - undefined
1956 + { maxRetries: 0 }
1957 );
1958 });
1959
@@ -1984,7 +1984,7 @@ describe('Tools', () => {
1984 version: '20251201_03', // should use global version
1985 text: undefined,
1986 },
1987 - undefined
1987 + { maxRetries: 0 }
1988 );
1989 });
1990
@@ -2029,7 +2029,7 @@ describe('Tools', () => {
2029 version: '20251201_01', // should use test-toolkit-specific version
2030 text: undefined,
2031 },
2032 - undefined
2032 + { maxRetries: 0 }
2033 );
2034 });
2035
@@ -2072,7 +2072,7 @@ describe('Tools', () => {
2072 version: 'latest', // should fallback to latest for unknown toolkit
2073 text: undefined,
2074 },
2075 - undefined
2075 + { maxRetries: 0 }
2076 );
2077 });
2078
@@ -2108,7 +2108,7 @@ describe('Tools', () => {
2108 version: '20251201_03', // explicit version takes precedence
2109 text: undefined,
2110 },
2111 - undefined
2111 + { maxRetries: 0 }
2112 );
2113 });
2114
@@ -2170,7 +2170,7 @@ describe('Tools', () => {
2170 version: 'latest', // should fallback to latest for unknown toolkit
2171 text: undefined,
2172 },
2173 - undefined
2173 + { maxRetries: 0 }
2174 );
2175 });
2176 });
@@ -2340,7 +2340,7 @@ describe('Tools', () => {
2340 version: 'latest',
2341 text: undefined,
2342 },
2343 - undefined
2343 + { maxRetries: 0 }
2344 );
2345 });
2346
@@ -2383,7 +2383,7 @@ describe('Tools', () => {
2383 version: '20251201_01', // specific version should work without skip flag
2384 text: undefined,
2385 },
2386 - undefined
2386 + { maxRetries: 0 }
2387 );
2388 });
2389
@@ -2413,7 +2413,7 @@ describe('Tools', () => {
2413 version: '20251201_03',
2414 text: undefined,
2415 },
2416 - undefined
2416 + { maxRetries: 0 }
2417 );
2418 });
2419
@@ -2530,7 +2530,7 @@ describe('Tools', () => {
2530 version: 'latest',
2531 text: undefined,
2532 },
2533 - undefined
2533 + { maxRetries: 0 }
2534 );
2535 });
2536
@@ -2596,7 +2596,7 @@ describe('Tools', () => {
2596 expect(mockClient.tools.execute).toHaveBeenCalledWith(
2597 unknownToolSlug,
2598 expect.objectContaining({ user_id: userId, version: 'latest' }),
2599 - undefined
2599 + { maxRetries: 0 }
2600 );
2601 });
2602
@@ -2637,68 +2637,9 @@ describe('Tools', () => {
2637 expect(mockClient.tools.execute).toHaveBeenCalledWith(
2638 toolSlug,
2639 expect.objectContaining({ version: '20250101_00' }),
2640 - undefined
2640 + { maxRetries: 0 }
2641 );
2642 });
2643 });
2644 });
2645 });
2646 -
2647 -describe('retries disabled on non-idempotent writes', () => {
2648 - // Regression: a timed-out, non-idempotent tools.execute / tools.proxy must not
2649 - // be silently retried — a retry after a server-side success duplicates the side
2650 - // effect (e.g. sends the same email up to 3 times). Both route through a sibling
2651 - // client built with maxRetries: 0; reads keep the client's default retries.
2652 - // See https://github.com/ComposioHQ/composio/issues/3586 (TS parity with Python).
2653 - const context = createTestContext();
2654 - setupTest(context);
2655 -
2656 - it('routes tools.execute through a client with maxRetries: 0', async () => {
2657 - await mockToolExecution(context.tools);
2658 -
2659 - await context.tools.execute('COMPOSIO_TOOL', {
2660 - userId: 'test-user',
2661 - arguments: { query: 'test' },
2662 - dangerouslySkipVersionCheck: true,
2663 - });
2664 -
2665 - expect(mockClient.withOptions).toHaveBeenCalledWith({ maxRetries: 0 });
2666 - expect(mockClient.tools.execute).toHaveBeenCalledTimes(1);
2667 - });
2668 -
2669 - it('routes tools.proxyExecute through a client with maxRetries: 0', async () => {
2670 - mockClient.tools.proxy.mockResolvedValueOnce({ data: {}, successful: true });
2671 -
2672 - await context.tools.proxyExecute({
2673 - endpoint: '/api/test',
2674 - method: 'POST' as const,
2675 - body: { data: 'test' },
2676 - connectedAccountId: 'test-account-id',
2677 - });
2678 -
2679 - expect(mockClient.withOptions).toHaveBeenCalledWith({ maxRetries: 0 });
2680 - expect(mockClient.tools.proxy).toHaveBeenCalledTimes(1);
2681 - });
2682 -
2683 - it('reuses one no-retries sibling client across executes (cached per instance)', async () => {
2684 - const { getRawComposioToolBySlugSpy } = await mockToolExecution(context.tools);
2685 -
2686 - await context.tools.execute('COMPOSIO_TOOL', {
2687 - userId: 'test-user',
2688 - arguments: { query: 'test' },
2689 - dangerouslySkipVersionCheck: true,
2690 - });
2691 -
2692 - // Queue a second execute; mockToolExecution only primed one response.
2693 - getRawComposioToolBySlugSpy.mockResolvedValueOnce(toolMocks.transformedTool as unknown as Tool);
2694 - mockClient.tools.execute.mockResolvedValueOnce(toolMocks.rawToolExecuteResponse);
2695 - await context.tools.execute('COMPOSIO_TOOL', {
2696 - userId: 'test-user',
2697 - arguments: { query: 'test again' },
2698 - dangerouslySkipVersionCheck: true,
2699 - });
2700 -
2701 - expect(mockClient.tools.execute).toHaveBeenCalledTimes(2);
2702 - expect(mockClient.withOptions).toHaveBeenCalledTimes(1);
2703 - });
2704 -});