@devries-cameron20 / composio-1 / commits / 2ac6ad320
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): complete version check timeout guard

jkomyno committed Aug 3, 2026 at 18:53 UTC 2ac6ad320ad6b0e893b885eec192850e6ca9ec19
3 files changed +31 -49
.changeset/bound-version-check-request.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Bound the background npm version check so registry outages cannot leave the request pending indefinitely.
ts/packages/core/src/utils/version.ts
+4 -10
@@ -19,15 +19,14 @@ export function isNewerVersion(version1: string, version2: string): boolean {
19 return false;
20 }
21
22 -/** Upper bound on the npm registry version check. Kept short: it is best-effort and unawaited. */
23 -const VERSION_CHECK_TIMEOUT_MS = 2000;
22 +const VERSION_CHECK_TIMEOUT_MS = 2_000;
23
24 /**
25 * Checks for the latest version of the Composio SDK from NPM.
26 * If a newer version is available, it logs a warning to the console.
27 *
29 - * Best-effort: never throws, and never keeps the process alive for more than
30 - * {@link VERSION_CHECK_TIMEOUT_MS}.
28 + * Best-effort: never throws. The npm registry request is aborted after
29 + * {@link VERSION_CHECK_TIMEOUT_MS} milliseconds.
30 */
31 export async function checkForLatestVersionFromNPM(currentVersion: string) {
32 try {
@@ -48,12 +47,7 @@ export async function checkForLatestVersionFromNPM(currentVersion: string) {
47 return;
48 }
49
51 - // Bounded and abortable: this check is a non-essential background nicety that
52 - // nobody awaits, so it must never extend process lifetime. An in-flight fetch
53 - // keeps its socket referenced on the event loop, so without a signal a slow or
54 - // black-holed registry (corporate proxy, egress firewall that drops rather than
55 - // rejects, npm incident) keeps short-lived scripts alive until undici's own
56 - // timeouts fire. The catch below already swallows the resulting TimeoutError.
50 + // Bound this best-effort request so a stalled registry cannot leave it pending indefinitely.
51 const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, {
52 signal: AbortSignal.timeout(VERSION_CHECK_TIMEOUT_MS),
53 });
ts/packages/core/test/utils/version.test.ts
+22 -39
@@ -3,57 +3,40 @@ import { checkForLatestVersionFromNPM } from '../../src/utils/version';
3
4 describe('checkForLatestVersionFromNPM', () => {
5 afterEach(() => {
6 + vi.restoreAllMocks();
7 vi.unstubAllGlobals();
8 });
9
9 - it('bounds the registry request with an AbortSignal so it cannot outlive the process', async () => {
10 - const fetchMock = vi.fn(async () => new Response(JSON.stringify({ version: '0.0.1' })));
10 + it('bounds the registry request with the configured timeout signal', async () => {
11 + const signal = new AbortController().signal;
12 + const timeoutSpy = vi.spyOn(AbortSignal, 'timeout').mockReturnValue(signal);
13 + const fetchMock = vi.fn<typeof fetch>(async () => Response.json({ version: '0.0.1' }));
14 vi.stubGlobal('fetch', fetchMock);
15
16 await checkForLatestVersionFromNPM('1.0.0');
17
15 - expect(fetchMock).toHaveBeenCalledOnce();
16 - const init = fetchMock.mock.calls[0]![1] as RequestInit | undefined;
17 - expect(init?.signal).toBeInstanceOf(AbortSignal);
18 + expect(timeoutSpy).toHaveBeenCalledWith(2_000);
19 + expect(fetchMock).toHaveBeenCalledWith('https://registry.npmjs.org/@composio/core/latest', {
20 + signal,
21 + });
22 });
23
20 - it('gives up instead of hanging when the registry never responds', async () => {
21 - // A registry that accepts the request and never answers. Without a timeout this
22 - // promise never settles, which is exactly what keeps a real process alive.
23 - vi.stubGlobal(
24 - 'fetch',
25 - vi.fn(
26 - (_url: string, init?: RequestInit) =>
27 - new Promise<Response>((_resolve, reject) => {
28 - init?.signal?.addEventListener('abort', () => reject(init.signal!.reason));
29 - })
30 - )
24 + it('swallows a timeout from a registry request that never responds', async () => {
25 + const timeoutController = new AbortController();
26 + vi.spyOn(AbortSignal, 'timeout').mockReturnValue(timeoutController.signal);
27 + const fetchMock = vi.fn<typeof fetch>(
28 + (_input, init) =>
29 + new Promise<Response>((_resolve, reject) => {
30 + init?.signal?.addEventListener('abort', () => reject(init.signal?.reason), {
31 + once: true,
32 + });
33 + })
34 );
32 -
33 - // Resolves (rather than hanging) only because the signal aborts it; the
34 - // function swallows the resulting TimeoutError.
35 - await expect(checkForLatestVersionFromNPM('1.0.0')).resolves.toBeUndefined();
36 - });
37 -
38 - it('never rejects when the registry errors', async () => {
39 - vi.stubGlobal(
40 - 'fetch',
41 - vi.fn(async () => {
42 - throw new Error('ENOTFOUND registry.npmjs.org');
43 - })
44 - );
45 -
46 - await expect(checkForLatestVersionFromNPM('1.0.0')).resolves.toBeUndefined();
47 - });
48 -
49 - it('skips the request entirely for non-semver and prerelease versions', async () => {
50 - const fetchMock = vi.fn(async () => new Response(JSON.stringify({ version: '9.9.9' })));
35 vi.stubGlobal('fetch', fetchMock);
36
53 - await checkForLatestVersionFromNPM('not-a-version');
54 - await checkForLatestVersionFromNPM('1.0.0-alpha.1');
55 - await checkForLatestVersionFromNPM('1.0.0-beta.3');
37 + const versionCheck = checkForLatestVersionFromNPM('1.0.0');
38 + timeoutController.abort(new DOMException('The operation timed out', 'TimeoutError'));
39
57 - expect(fetchMock).not.toHaveBeenCalled();
40 + await expect(versionCheck).resolves.toBeUndefined();
41 });
42 });