@devries-cameron20 / composio-1 / commits / 9545806a6
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(telemetry): bound telemetry requests with an AbortSignal timeout

sendMetric and sendErrorLog awaited fetch() with no timeout, so a stalled telemetry endpoint could leave an awaited SDK call pending indefinitely. Bound both best-effort requests with an AbortController and a cleared timer via a shared postWithTimeout helper, mirroring the npm version-check bound in utils/version.ts. The existing catch still swallows the abort, preserving the never-throws contract.

Rohit committed Aug 13, 2026 at 13:42 UTC 9545806a62c3c3e63b94ca19f373f568360fa3d6
3 files changed +104 -14
.changeset/bound-telemetry-request-timeout.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Bound the best-effort telemetry requests with a timeout so a stalled telemetry endpoint cannot leave an SDK call pending indefinitely.
ts/packages/core/src/services/telemetry/TelemetryService.ts
+25 -14
@@ -2,8 +2,31 @@ import logger from '../../utils/logger';
2 import { TelemetryMetricPayloadBody, TelemetryPayload } from './TelemetryService.types';
3
4 const TELEMETRY_URL = 'https://telemetry.composio.dev/v1';
5 +const TELEMETRY_TIMEOUT_MS = 3_000;
6
7 export class TelemetryService {
8 + /**
9 + * POSTs a best-effort telemetry payload, bounding the request so a stalled
10 + * endpoint cannot leave it pending indefinitely.
11 + *
12 + * A hand-rolled timer rather than AbortSignal.timeout so it can be cleared the
13 + * moment the response lands: an uncleared timer is itself pending work, which on
14 + * workerd pins the request context open for the full timeout on every successful
15 + * send. Mirrors the bound applied to the npm version check.
16 + */
17 + private static postWithTimeout(url: string, payload: unknown) {
18 + const controller = new AbortController();
19 + const timer = setTimeout(() => controller.abort(), TELEMETRY_TIMEOUT_MS);
20 + return fetch(url, {
21 + method: 'POST',
22 + headers: {
23 + 'Content-Type': 'application/json',
24 + },
25 + body: JSON.stringify(payload),
26 + signal: controller.signal,
27 + }).finally(() => clearTimeout(timer));
28 + }
29 +
30 /**
31 * Sends a metric to the Telemetry API.
32 * @param payload - The payload to send to the Telemetry API.
@@ -11,13 +34,7 @@ export class TelemetryService {
34 */
35 static async sendMetric(payload: TelemetryMetricPayloadBody) {
36 try {
14 - const result = await fetch(`${TELEMETRY_URL}/metrics/invocations`, {
15 - method: 'POST',
16 - headers: {
17 - 'Content-Type': 'application/json',
18 - },
19 - body: JSON.stringify(payload),
20 - });
37 + const result = await this.postWithTimeout(`${TELEMETRY_URL}/metrics/invocations`, payload);
38 return result;
39 } catch (error) {
40 // ignore error for now; telemetry failures should never affect SDK calls
@@ -32,13 +49,7 @@ export class TelemetryService {
49 */
50 static async sendErrorLog(payload: TelemetryPayload) {
51 try {
35 - const result = await fetch(`${TELEMETRY_URL}/errors`, {
36 - method: 'POST',
37 - headers: {
38 - 'Content-Type': 'application/json',
39 - },
40 - body: JSON.stringify(payload),
41 - });
52 + const result = await this.postWithTimeout(`${TELEMETRY_URL}/errors`, payload);
53 return result;
54 } catch (error) {
55 // ignore error for now; telemetry failures should never affect SDK calls
ts/packages/core/test/telemetry/TelemetryService.test.ts
+74
@@ -437,6 +437,80 @@ describe('TelemetryTransport', () => {
437 });
438 });
439
440 +describe('TelemetryService network bounding', () => {
441 + afterEach(() => {
442 + vi.useRealTimers();
443 + vi.restoreAllMocks();
444 + vi.unstubAllGlobals();
445 + });
446 +
447 + it('bounds sendMetric with an abort signal and clears the timer once it responds', async () => {
448 + vi.useFakeTimers();
449 + const fetchMock = vi.fn<typeof fetch>(async () => Response.json({ ok: true }));
450 + vi.stubGlobal('fetch', fetchMock);
451 +
452 + await TelemetryService.sendMetric([createPayload()]);
453 +
454 + expect(fetchMock).toHaveBeenCalledWith(
455 + 'https://telemetry.composio.dev/v1/metrics/invocations',
456 + expect.objectContaining({ method: 'POST', signal: expect.any(AbortSignal) })
457 + );
458 + // A timer left pending after the fetch resolved keeps a workerd request context
459 + // open for the full timeout on every successful send.
460 + expect(vi.getTimerCount()).toBe(0);
461 + });
462 +
463 + it('swallows a sendMetric timeout when the endpoint never responds', async () => {
464 + vi.useFakeTimers();
465 + const fetchMock = vi.fn<typeof fetch>(
466 + (_input, init) =>
467 + new Promise<Response>((_resolve, reject) => {
468 + init?.signal?.addEventListener('abort', () => reject(init.signal?.reason), {
469 + once: true,
470 + });
471 + })
472 + );
473 + vi.stubGlobal('fetch', fetchMock);
474 +
475 + const send = TelemetryService.sendMetric([createPayload()]);
476 + await vi.advanceTimersByTimeAsync(3_000);
477 +
478 + await expect(send).resolves.toBeUndefined();
479 + });
480 +
481 + it('bounds sendErrorLog with an abort signal and clears the timer once it responds', async () => {
482 + vi.useFakeTimers();
483 + const fetchMock = vi.fn<typeof fetch>(async () => Response.json({ ok: true }));
484 + vi.stubGlobal('fetch', fetchMock);
485 +
486 + await TelemetryService.sendErrorLog(createPayload());
487 +
488 + expect(fetchMock).toHaveBeenCalledWith(
489 + 'https://telemetry.composio.dev/v1/errors',
490 + expect.objectContaining({ method: 'POST', signal: expect.any(AbortSignal) })
491 + );
492 + expect(vi.getTimerCount()).toBe(0);
493 + });
494 +
495 + it('swallows a sendErrorLog timeout when the endpoint never responds', async () => {
496 + vi.useFakeTimers();
497 + const fetchMock = vi.fn<typeof fetch>(
498 + (_input, init) =>
499 + new Promise<Response>((_resolve, reject) => {
500 + init?.signal?.addEventListener('abort', () => reject(init.signal?.reason), {
501 + once: true,
502 + });
503 + })
504 + );
505 + vi.stubGlobal('fetch', fetchMock);
506 +
507 + const send = TelemetryService.sendErrorLog(createPayload());
508 + await vi.advanceTimersByTimeAsync(3_000);
509 +
510 + await expect(send).resolves.toBeUndefined();
511 + });
512 +});
513 +
514 beforeAll(() => {
515 // Save the original NODE_ENV
516 process.env._ORIGINAL_NODE_ENV = process.env.NODE_ENV;