@devries-cameron20 / composio-1 / commits / 1221c1578
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): bound the npm version-check fetch with an AbortSignal timeout (#4027)

Fixes #4026 ## Problem The `Composio` constructor fires a background npm version check unless `disableVersionCheck` is set — and `disableVersionCheck` has no default, so this is on for every user: ```ts // ts/packages/core/src/composio.ts:399-402 if (!this.config.disableVersionCheck) { checkForLatestVersionFromNPM(version); } ``` That check performed a bare fetch with no timeout and no AbortSignal: ```ts // ts/packages/core/src/utils/version.ts:46 const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`); ``` An in-flight fetch keeps its socket referenced on the Node event loop. When registry.npmjs.org is slow, black-holed, or unreachable-but-accepting (corporate proxy, egress firewall that drops rather than rejects, captive network, npm incident), the process cannot exit — all the user's work is done and it just sits there. It's also called without await, so a caller has nowhere to attach a bound of their own. Reproducing with a local server that accepts the socket and never responds: the process was still alive at 90s and had to be killed. ## Fix ```diff - // @TODO: Check if fetch is available, if not use node-fetch - const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`); + const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`, { + signal: AbortSignal.timeout(VERSION_CHECK_TIMEOUT_MS), + }); ``` `VERSION_CHECK_TIMEOUT_MS = 2000`. The existing `catch (_error) { /* Ignore and do nothing */ }` already swallows the resulting `TimeoutError`, so failure stays silent — which is right for a best-effort nicety nobody awaits. A comment records why the signal is there so a later cleanup doesn't drop it. Also removed the stale `@TODO: Check if fetch is available, if not use node-fetch` on the line above: the code already calls global `fetch` unconditionally, and `toolchain-versions.json` pins the tested Node versions to 22/24/25, where both `fetch` and `AbortSignal.timeout` (Node 17.3+) are available. ## Results, and one honest caveat End-to-end with the issue's reproduction: 91s, exit 124 (killed) → exited on its own after 6.0s, exit 0. That 6.0s deserves explanation, because the timeout is 2s and I did not want to overclaim. Measured in isolation: ```text fetch rejected at 2.01s with TimeoutError <- the signal works as intended handler done at 2.01s process exited at 6.03s <- undici's default 4s keepAliveTimeout ``` So the SDK's wait is bounded at 2s, which is what this change controls. The trailing ~4s is Node's global undici agent releasing the pooled socket, outside this code's reach — I tested `connection: 'close'` to see if it could be shortened and got an identical 6.03s. Eliminating it would require a custom dispatcher, which isn't worth the complexity for a background version check. Net: unbounded becomes bounded, worst-case exit ~6s instead of never. ## Tests Added `ts/packages/core/test/utils/version.test.ts` with two focused regressions: - asserts `AbortSignal.timeout` receives `2_000` and its exact signal is passed to the registry request - proves that aborting a registry request that never responds is swallowed by the best-effort check The timeout path uses a controlled `AbortController`, so the test is deterministic and does not wait two seconds of wall-clock time. ## Verification | Check | Result | |---|---| | Focused version-check tests | 2 passed | | Full core suite | 1046 passed | | Core typecheck | exit 0 | | Core build | passed, including ATTW and publint | | Package lint | exit 0 with existing repository warnings | | Changeset validation | passed | ## Out of scope — follow-up worth filing `TelemetryService.sendMetric` / `sendErrorLog` (`services/telemetry/TelemetryService.ts:14,35`) have the identical unbounded-fetch shape. Black-holing `telemetry.composio.dev` still hangs the process indefinitely with this fix applied: ```text blackhole=[registry] -> exited after 6.0s blackhole=[telemetry] -> HUNG (killed at 45s) ``` I deliberately left it alone: telemetry has its own `registerExitHandlers`/`flush` machinery that intends to block on exit, so bounding it is a real design decision rather than a one-liner, and it's outside what this issue covers. Happy to open a separate issue for it. ## Notes - Changeset included (`@composio/core: patch`). - The Python SDK has no equivalent version check, so no parity change is needed.

Alberto Schiabel committed Aug 5, 2026 at 21:07 UTC 1221c15783654b4e21586ac8a3225df12745a977

No changes.