@devries-cameron20 / composio-1 / commits / a84d05fc9
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(cli): resolve pusher-js constructor across ESM/CJS interop shapes (#3926)

## Summary `composio listen` crashes with `TypeError: Object is not a constructor` immediately after realtime init in every compiled release binary that bundles pusher-js 8.5.0 (reproduced on darwin-arm64 0.2.33-beta.291–298 and 0.2.32-beta.289, and linux-x64 0.2.33-beta.298). Full diagnosis in #3918. **Root cause (corrected after independent verification):** pusher-js changed the shape of its CJS export between versions — 8.4.x exports the constructor itself (`module.exports = Pusher`), **8.5.0's Node bundle exports a namespace object** (`module.exports = { Pusher }`; its webpack bundle ends with `module.exports.Pusher = __webpack_exports__`), and 8.6.0 exports the constructor again. This is an undocumented upstream packaging regression — reported in [pusher/pusher-js#935](https://github.com/pusher/pusher-js/issues/935), fixed by [pusher/pusher-js#936](https://github.com/pusher/pusher-js/pull/936), first released in 8.6.0 (2026-07-23) whose release notes do not mention it. With 8.5.0 (what the crashing published binaries bundled), `pusherModule.default` is not callable under **either Node or Bun, from source or compiled** — the constructor is only reachable via the named `Pusher` export. The earlier "build-target-dependent Bun interop" theory in this PR's first revision and in #3918 is not correct: compiled interop probes built with bun 1.3.10 for darwin-arm64 and bun-linux-x64 embed byte-identical bundles, so the shape varies by pusher-js version, not by build target. "Works from source" reports came from non-frozen installs resolving `^8.5.0` to 8.6.0. Note: `next` now pins pusher-js 8.6.0 (#3955), which incidentally restores a callable `module.default` in new builds — and this branch has since been merged up with `next`, so it resolves 8.6.0 too. This PR makes that robustness deliberate instead of incidental: pusher-js has changed its export shape twice within two minor versions, and the new real-module regression test has now passed against both shapes (8.5.0 pre-merge, 8.6.0 post-merge). Fixes #3918 ## Changes - `ts/packages/cli/src/services/triggers-realtime.ts`: - `resolvePusherConstructor` probes the interop shapes in precedence order — `module.default.default` (defensive double-wrap), `module.default` (8.4.0/8.6.0 class export), the module object itself, then the named `Pusher` export on either level (`module.default.Pusher` is the 8.5.0 shape that crashed release binaries) — returning the first callable candidate via `Arr.findFirst` with `Predicate.hasProperty`/`Predicate.isFunction` narrowing (no `as` casts). - Resolution failure surfaces as the service's typed `TriggerRealtimeSubscriptionError` instead of an untyped `TypeError`. - `new Pusher(...)` itself is now wrapped in `Effect.try`, so a callable-but-non-constructable candidate would also land on the typed error channel instead of escaping as an untyped defect past the listen commands' `catchTag`. - `ts/packages/cli/test/src/services/triggers-realtime.test.ts`: regression tests pinning every interop shape, precedence (including `default.Pusher` isolated from the top-level `Pusher` fallback), the module-object fallback, the no-constructor failure case, and the **real installed pusher-js module** — so the next packaging drift fails the unit suite rather than only the compiled binary. - `ts/packages/cli/CHANGELOG.md`: Patch Changes entry under 0.3.0 (the CLI is Changesets-ignored, so notes go in the changelog directly), stating the verified root cause. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? - `pnpm exec vitest run test/src/services/triggers-realtime.test.ts` — 9 passed. - `pnpm --filter @composio/cli test` — full package suite green (includes `validate:skills` and `validate:boundaries`). - CLI package `pnpm typecheck` (src + test) and `prettier --check` clean. - Independent empirical verification with the release toolchain (bun 1.3.10, pinned in `mise.toml`): - pusher-js **8.5.0**: `module.default` is `{ Pusher }` (not callable) under Node 24, Bun from source, and `bun build --compile --production` binaries — the pre-fix `new (module.default)(...)` throws the exact #3918 `TypeError` in all three environments; the resolver picks the named `Pusher` export and constructs successfully. - pusher-js **8.4.0** and **8.6.0**: `module.default` is the constructor; the resolver picks it directly and constructs successfully. - darwin-arm64 vs cross-compiled bun-linux-x64 binaries embed hash-identical pusher bundles — the interop shape does not vary by build target, only by pusher-js version. - Compiled-binary before/after on darwin-arm64 and linux-x64 as described in the original report (crash reproduced from a pre-fix `next` binary; fixed binary subscribes, holds the full `--timeout` window, disables the temporary trigger on exit, exit 0); end-to-end Gmail trigger delivery verified twice. ## Screenshots (if applicable) N/A — no visible command-surface change (internal wiring fix). ## Remaining follow-up (out of scope for this PR) - Release CI (`build-cli-binaries.yml`) smoke-tests binaries with only `--version`/`--help`; a per-target step exercising the bundled `import('pusher-js')` + constructor resolution would catch the next interop drift before publishing (requested in #3918). - The listen commands append network/login remediation hints to every `TriggerRealtimeSubscriptionError`, which is misleading for packaging failures, and the probed module shape is not logged on failure; a `reason` discriminant on the error would make a future variant easier to diagnose. ## Checklist - [x] I have read the Code of Conduct and this PR adheres to it - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed (CLI `CHANGELOG.md`; no docs-site change — behavior matches what `composio listen` already documents) - [x] I added tests (`test/src/services/triggers-realtime.test.ts`) - [x] I added a changeset if this change affects published packages — not applicable: `@composio/cli` is excluded from Changesets by design; changelog entry added instead --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: jkomyno <alberto@composio.dev>

Bill committed Jul 28, 2026 at 07:06 UTC a84d05fc99f00c2d77d7f25ba6553805d7d28b92
3 files changed +145 -33
ts/packages/cli/CHANGELOG.md
+1
@@ -15,6 +15,7 @@
15
16 ### Patch Changes
17
18 +- Fix `composio listen` crashing with `TypeError: Object is not a constructor` in compiled release binaries (issue #3918). pusher-js 8.5.0 exports a namespace object (`module.exports = { Pusher }`) instead of the constructor (an undocumented upstream packaging regression, pusher/pusher-js#935, fixed in pusher-js 8.6.0), so the dynamic import's `.default` is not callable under Node or Bun; the realtime service now probes every observed interop shape (including the named `Pusher` export), constructs the client inside `Effect.try`, and fails with a typed error instead of crashing.
19 - Preserve the original CLI diagnostic when an adjacent source map is malformed or unusable instead of letting optional source-map enrichment abort error capture. Source-map enrichment is now best-effort end to end: a malformed, invalid, or unreadable `.map`, and a valid map pointing at an original source that was never shipped, all degrade to the raw stack location. `captureErrors` can no longer fail.
20 - Fix source-map resolution on Windows: original source paths are now resolved with the platform path separator instead of a hardcoded `/`, and the `node_modules` filter no longer mistakes directories such as `node_modules_local` for real dependency paths.
21 - Make `composio version --check` report `checkStatus: "unknown"` when GitHub cannot confirm the latest stable release, preserve the last successful cache on failed refreshes, and avoid racing the command with the startup update check.
ts/packages/cli/src/services/triggers-realtime.ts
+82 -33
@@ -1,4 +1,4 @@
1 -import { Data, Effect, Either, Option, Runtime, Schema } from 'effect';
1 +import { Array as Arr, Data, Effect, Either, Option, Predicate, Runtime, Schema } from 'effect';
2 import { JsonRecordSchema } from 'src/effects/json';
3 import {
4 ComposioClientSingleton,
@@ -29,6 +29,47 @@ export class TriggerRealtimeSubscriptionError extends Data.TaggedError(
29 const subscriptionError = (message: string) => (cause: unknown) =>
30 new TriggerRealtimeSubscriptionError({ message, cause });
31
32 +type PusherConstructor = (typeof import('pusher-js'))['default'];
33 +
34 +const isPusherConstructor = (value: unknown): value is PusherConstructor =>
35 + Predicate.isFunction(value);
36 +
37 +const propertyOf = (value: unknown, property: string): unknown =>
38 + Predicate.hasProperty(value, property) ? value[property] : undefined;
39 +
40 +/**
41 + * Resolves the Pusher constructor across ESM/CJS interop shapes. pusher-js
42 + * ships CJS and has changed its export shape across versions: 8.4.x and 8.6.0
43 + * export the constructor itself (`module.exports = Pusher`), while 8.5.0's
44 + * Node bundle exports a namespace object (`module.exports = { Pusher }`) — an
45 + * undocumented upstream packaging regression (pusher/pusher-js#935, fixed by
46 + * pusher/pusher-js#936, first released in 8.6.0). With 8.5.0,
47 + * `module.default` stops being callable under both Node and Bun — from source
48 + * and in compiled binaries alike (issue #3918). The probes cover, in order: a
49 + * defensively double-wrapped default (`module.default.default`), the direct
50 + * class export (`module.default`, 8.4.0/8.6.0), a raw CJS module that is
51 + * itself the constructor, and the named `Pusher` export on either level
52 + * (`module.default.Pusher` is the 8.5.0 shape that crashed compiled release
53 + * binaries; runtimes also hoist it to `module.Pusher`).
54 + *
55 + * Exported for tests.
56 + */
57 +export const resolvePusherConstructor = (
58 + pusherModule: unknown
59 +): Option.Option<PusherConstructor> => {
60 + const moduleDefault = propertyOf(pusherModule, 'default');
61 + return Arr.findFirst(
62 + [
63 + propertyOf(moduleDefault, 'default'),
64 + moduleDefault,
65 + pusherModule,
66 + propertyOf(moduleDefault, 'Pusher'),
67 + propertyOf(pusherModule, 'Pusher'),
68 + ],
69 + isPusherConstructor
70 + );
71 +};
72 +
73 /**
74 * Service for listening to trigger events over Composio CLI realtime channels.
75 * Uses:
@@ -64,38 +105,46 @@ export class TriggersRealtime extends Effect.Service<TriggersRealtime>()(
105 catch: subscriptionError('Failed to load the realtime client'),
106 });
107
67 - const Pusher = pusherModule.default;
68 -
69 - const pusher = new Pusher(creds.pusher_key, {
70 - cluster: creds.pusher_cluster,
71 - channelAuthorization: {
72 - customHandler: (authOptions, callback) => {
73 - const channel_name = authOptions.channelName;
74 - const socket_id = authOptions.socketId;
75 -
76 - const doAuth = async () => {
77 - const response = await Runtime.runPromise(runtime)(
78 - params.authRealtimeChannel({
79 - channel_name,
80 - socket_id,
81 - })
82 - );
83 - // Pusher private channels verify signatures without channel_data.
84 - // Some auth endpoints may still return channel_data, which can cause
85 - // "Invalid signature" if included in the verification input.
86 - const normalizedResponse = channel_name.startsWith('private-')
87 - ? { auth: response.auth }
88 - : response;
89 - return normalizedResponse;
90 - };
91 -
92 - void doAuth()
93 - .then(data => callback(null, data))
94 - .catch(cause =>
95 - callback(cause instanceof Error ? cause : new Error(String(cause)), null)
96 - );
97 - },
98 - },
108 + const Pusher = yield* resolvePusherConstructor(pusherModule).pipe(
109 + Effect.mapError(
110 + subscriptionError('Realtime client module does not expose a constructor')
111 + )
112 + );
113 +
114 + const pusher = yield* Effect.try({
115 + try: () =>
116 + new Pusher(creds.pusher_key, {
117 + cluster: creds.pusher_cluster,
118 + channelAuthorization: {
119 + customHandler: (authOptions, callback) => {
120 + const channel_name = authOptions.channelName;
121 + const socket_id = authOptions.socketId;
122 +
123 + const doAuth = async () => {
124 + const response = await Runtime.runPromise(runtime)(
125 + params.authRealtimeChannel({
126 + channel_name,
127 + socket_id,
128 + })
129 + );
130 + // Pusher private channels verify signatures without channel_data.
131 + // Some auth endpoints may still return channel_data, which can cause
132 + // "Invalid signature" if included in the verification input.
133 + const normalizedResponse = channel_name.startsWith('private-')
134 + ? { auth: response.auth }
135 + : response;
136 + return normalizedResponse;
137 + };
138 +
139 + void doAuth()
140 + .then(data => callback(null, data))
141 + .catch(cause =>
142 + callback(cause instanceof Error ? cause : new Error(String(cause)), null)
143 + );
144 + },
145 + },
146 + }),
147 + catch: subscriptionError('Failed to construct the realtime client'),
148 });
149
150 const channel = pusher.subscribe(channelName);
ts/packages/cli/test/src/services/triggers-realtime.test.ts new
+62
@@ -0,0 +1,62 @@
1 +import { describe, expect, it } from '@effect/vitest';
2 +import { Option } from 'effect';
3 +import { resolvePusherConstructor } from 'src/services/triggers-realtime';
4 +
5 +/**
6 + * Regression tests for issue #3918: `composio listen` crashed with
7 + * `TypeError: Object is not a constructor` in compiled release binaries
8 + * because pusher-js 8.5.0 exports a namespace object
9 + * (`module.exports = { Pusher }`), so the dynamic import's `.default` is not
10 + * the constructor.
11 + */
12 +describe('resolvePusherConstructor', () => {
13 + class FakePusher {}
14 +
15 + it('resolves the constructor from `module.default` (Node interop, running from source)', () => {
16 + expect(resolvePusherConstructor({ default: FakePusher })).toEqual(Option.some(FakePusher));
17 + });
18 +
19 + it('resolves the constructor from `module.default.default` (defensive double-wrapped interop)', () => {
20 + expect(resolvePusherConstructor({ default: { default: FakePusher } })).toEqual(
21 + Option.some(FakePusher)
22 + );
23 + });
24 +
25 + it('prefers the nested constructor when both interop levels are callable', () => {
26 + const outer = Object.assign(function outer() {}, { default: FakePusher });
27 + expect(resolvePusherConstructor({ default: outer })).toEqual(Option.some(FakePusher));
28 + });
29 +
30 + it('falls back to the module object itself when it is the constructor', () => {
31 + expect(resolvePusherConstructor(FakePusher)).toEqual(Option.some(FakePusher));
32 + });
33 +
34 + it('resolves a named `Pusher` export on the default namespace (pusher-js 8.5.0 shape, issue #3918)', () => {
35 + expect(
36 + resolvePusherConstructor({ default: { Pusher: FakePusher }, Pusher: FakePusher })
37 + ).toEqual(Option.some(FakePusher));
38 + });
39 +
40 + it('resolves a named `Pusher` export on the module itself', () => {
41 + expect(resolvePusherConstructor({ Pusher: FakePusher })).toEqual(Option.some(FakePusher));
42 + });
43 +
44 + it('resolves a `default.Pusher` namespace export without a top-level `Pusher` fallback', () => {
45 + expect(resolvePusherConstructor({ default: { Pusher: FakePusher } })).toEqual(
46 + Option.some(FakePusher)
47 + );
48 + });
49 +
50 + it('resolves the constructor from the real installed pusher-js module', async () => {
51 + const pusherModule = await import('pusher-js');
52 + const resolved = resolvePusherConstructor(pusherModule);
53 + expect(Option.isSome(resolved)).toBe(true);
54 + });
55 +
56 + it('returns none when no interop shape exposes a callable constructor', () => {
57 + expect(resolvePusherConstructor({ default: { default: 'not-a-function' } })).toEqual(
58 + Option.none()
59 + );
60 + expect(resolvePusherConstructor(undefined)).toEqual(Option.none());
61 + });
62 +});