@devries-cameron20 / composio-1 / commits / 4c3a32155
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.

fix(core): disable retries on non-idempotent `tools.execute`/`proxyExecute` (#3716)

This PR: - Closes https://github.com/ComposioHQ/composio/issues/3586 - disables client retries on `tools.execute` and `tools.proxyExecute` — the two non-idempotent writes — so a request that succeeds server-side but times out client-side is no longer silently replayed (the cause of duplicate `GMAIL_SEND_EMAIL` sends) - routes both through a sibling client built with `withOptions({ maxRetries: 0 })`; reads keep the client's default retries (`maxRetries: 2`) - caches that sibling per `Tools` instance (`clientWithoutRetries`) since `withOptions` constructs a fresh client and execute/proxy is the hottest path; mirrors the Python SDK's `client.without_retries` - adds regression tests asserting both paths route through `maxRetries: 0` and that the sibling is built once across multiple executes ## Context The original hang on attachments larger than ~25 KB was a backend defect and has already been fixed server-side. The remaining gap was a cross-SDK parity one: the Python SDK already disabled retries on these non-idempotent writes, but `@composio/core` still inherited the client default of 2 retries (3 attempts total), with no public knob to turn them off. This is the TypeScript parity port — scoped to exactly `tools.execute` / `tools.proxy`, leaving `toolRouter.session.execute` and all reads on their default retry behaviour, matching Python.

Alberto Schiabel committed Jun 30, 2026 at 21:53 UTC 4c3a3215508afc25f663df3e8cd7f3a88a112029
4 files changed +108 -3
.changeset/disable-retries-execute-proxy.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Disable client retries on `tools.execute` and `tools.proxyExecute`. These are non-idempotent writes, so a silent retry after a read timeout could duplicate the side effect (e.g. send the same email more than once). Both now route through a sibling client built with `maxRetries: 0`; reads keep the default retry behaviour.
ts/packages/core/src/models/Tools.ts
+32 -2
@@ -114,6 +114,11 @@ export class Tools<
114 */
115 private readonly warnedAutoUploadDisabledForTool = new Set<string>();
116
117 + /**
118 + * Lazily-built sibling client with retries disabled; see `clientWithoutRetries`.
119 + */
120 + private clientWithoutRetriesCache?: ComposioClient;
121 +
122 constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
123 if (!client) {
124 throw new Error('ComposioClient is required');
@@ -146,6 +151,27 @@ export class Tools<
151 telemetry.instrument(this, 'Tools');
152 }
153
154 + /**
155 + * A cached sibling client that never retries requests, mirroring Python's
156 + * `client.without_retries`.
157 + *
158 + * Used for non-idempotent writes (`tools.execute` / `tools.proxy`), where a
159 + * silent retry after a read timeout can duplicate a side effect (e.g. send an
160 + * email twice). Reads keep the default retry behaviour, and so do other writes
161 + * (`toolRouter.session.execute`, auth-config and connected-account mutations):
162 + * the durable fix there is backend-honoured idempotency keys, tracked
163 + * separately.
164 + *
165 + * Cached rather than rebuilt per call because `withOptions` constructs a fresh
166 + * client; its options never change, so one per `Tools` instance suffices.
167 + */
168 + private get clientWithoutRetries(): ComposioClient {
169 + if (!this.clientWithoutRetriesCache) {
170 + this.clientWithoutRetriesCache = this.client.withOptions({ maxRetries: 0 });
171 + }
172 + return this.clientWithoutRetriesCache;
173 + }
174 +
175 /**
176 * Transforms tool data from snake_case API format to camelCase for internal SDK use.
177 *
@@ -919,7 +945,9 @@ export class Tools<
945 text: body.text,
946 };
947 const result = await withCancellation(
922 - () => this.client.tools.execute(tool.slug, executeBody, requestOptions),
948 + // Disable retries: tool execution is a non-idempotent write, and a
949 + // silent retry after a read timeout can duplicate the side effect.
950 + () => this.clientWithoutRetries.tools.execute(tool.slug, executeBody, requestOptions),
951 requestOptions?.signal
952 );
953 // transform the response to the ToolExecuteResponse format
@@ -1253,7 +1281,9 @@ export class Tools<
1281 custom_connection_data: toolProxyParams.data.customConnectionData,
1282 } as ComposioToolProxyParams;
1283 return withCancellation(
1256 - () => this.client.tools.proxy(proxyBody, requestOptions),
1284 + // Disable retries: a proxied call is a non-idempotent write, and a silent
1285 + // retry after a read timeout can duplicate the side effect.
1286 + () => this.clientWithoutRetries.tools.proxy(proxyBody, requestOptions),
1287 requestOptions?.signal
1288 );
1289 }
ts/packages/core/test/tools/tools.test.ts
+59
@@ -2403,3 +2403,62 @@ describe('Tools', () => {
2403 });
2404 });
2405 });
2406 +
2407 +describe('retries disabled on non-idempotent writes', () => {
2408 + // Regression: a timed-out, non-idempotent tools.execute / tools.proxy must not
2409 + // be silently retried — a retry after a server-side success duplicates the side
2410 + // effect (e.g. sends the same email up to 3 times). Both route through a sibling
2411 + // client built with maxRetries: 0; reads keep the client's default retries.
2412 + // See https://github.com/ComposioHQ/composio/issues/3586 (TS parity with Python).
2413 + const context = createTestContext();
2414 + setupTest(context);
2415 +
2416 + it('routes tools.execute through a client with maxRetries: 0', async () => {
2417 + await mockToolExecution(context.tools);
2418 +
2419 + await context.tools.execute('COMPOSIO_TOOL', {
2420 + userId: 'test-user',
2421 + arguments: { query: 'test' },
2422 + dangerouslySkipVersionCheck: true,
2423 + });
2424 +
2425 + expect(mockClient.withOptions).toHaveBeenCalledWith({ maxRetries: 0 });
2426 + expect(mockClient.tools.execute).toHaveBeenCalledTimes(1);
2427 + });
2428 +
2429 + it('routes tools.proxyExecute through a client with maxRetries: 0', async () => {
2430 + mockClient.tools.proxy.mockResolvedValueOnce({ data: {}, successful: true });
2431 +
2432 + await context.tools.proxyExecute({
2433 + endpoint: '/api/test',
2434 + method: 'POST' as const,
2435 + body: { data: 'test' },
2436 + connectedAccountId: 'test-account-id',
2437 + });
2438 +
2439 + expect(mockClient.withOptions).toHaveBeenCalledWith({ maxRetries: 0 });
2440 + expect(mockClient.tools.proxy).toHaveBeenCalledTimes(1);
2441 + });
2442 +
2443 + it('reuses one no-retries sibling client across executes (cached per instance)', async () => {
2444 + const { getRawComposioToolBySlugSpy } = await mockToolExecution(context.tools);
2445 +
2446 + await context.tools.execute('COMPOSIO_TOOL', {
2447 + userId: 'test-user',
2448 + arguments: { query: 'test' },
2449 + dangerouslySkipVersionCheck: true,
2450 + });
2451 +
2452 + // Queue a second execute; mockToolExecution only primed one response.
2453 + getRawComposioToolBySlugSpy.mockResolvedValueOnce(toolMocks.transformedTool as unknown as Tool);
2454 + mockClient.tools.execute.mockResolvedValueOnce(toolMocks.rawToolExecuteResponse);
2455 + await context.tools.execute('COMPOSIO_TOOL', {
2456 + userId: 'test-user',
2457 + arguments: { query: 'test again' },
2458 + dangerouslySkipVersionCheck: true,
2459 + });
2460 +
2461 + expect(mockClient.tools.execute).toHaveBeenCalledTimes(2);
2462 + expect(mockClient.withOptions).toHaveBeenCalledTimes(1);
2463 + });
2464 +});
ts/packages/core/test/utils/mocks/client.mock.ts
+12 -1
@@ -1,6 +1,6 @@
1 import { vi } from 'vitest';
2
3 -export const mockClient = {
3 +const mockClientBase = {
4 tools: {
5 list: vi.fn(),
6 retrieve: vi.fn(),
@@ -37,3 +37,14 @@ export const mockClient = {
37 },
38 },
39 };
40 +
41 +// `withOptions` returns the same mock so chained calls (e.g.
42 +// `client.withOptions({ maxRetries: 0 }).tools.execute(...)`) still record on
43 +// the same spies. Mirrors the real client's `withOptions`.
44 +//
45 +// This implementation is load-bearing: tests rely on `vi.clearAllMocks()`
46 +// (which preserves implementations), not `vi.resetAllMocks()` (which would wipe
47 +// it and make chained `.tools.*` calls throw on `undefined`).
48 +export const mockClient = Object.assign(mockClientBase, {
49 + withOptions: vi.fn(() => mockClientBase),
50 +});