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): log pusher subscription outcomes truthfully
- Log the full pusher:subscription_error payload (type, error, status) instead of a flattened String(data.error) so operators can tell auth failures from permission failures. - Log the subscription success message only when Pusher dispatches pusher:subscription_succeeded, not when subscribe() returns. - Extend regression coverage for both behaviors. Applies review findings #2 and #3 from the PR #4448 review.
jkomyno committed
Sep 15, 2026 at 15:19 UTC
334abd1e098538b3d8275a3b910066e690840640
3 files changed
+71
-38
.changeset/quiet-pumas-recover.md
+1
-1
@@ -3,4 +3,4 @@
3
'@composio/slim': patch
4
---
5
6
-Keep TypeScript realtime subscription errors inside the SDK logging boundary so an asynchronous Pusher subscription failure cannot escape as an uncaught exception.
6
+Keep TypeScript realtime subscription errors inside the SDK logging boundary so an asynchronous Pusher subscription failure cannot escape as an uncaught exception. The full subscription error payload is now logged, and the success message is logged only once Pusher confirms the subscription.
ts/packages/core/src/services/pusher/Pusher.ts
+6
-4
@@ -171,8 +171,12 @@ export class PusherService {
171
172
// add subscription error handling
173
channel.bind('pusher:subscription_error', (data: Record<string, unknown>) => {
174
- const error = data.error ? String(data.error) : 'Unknown subscription error';
175
- logger.error(`Trigger subscription error: ${error}`);
174
+ logger.error('Trigger subscription error:', data);
175
+ });
176
+
177
+ // log success only when Pusher itself confirms the subscription
178
+ channel.bind('pusher:subscription_succeeded', () => {
179
+ logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
180
});
181
182
// wrap the callback to handle errors
@@ -187,8 +191,6 @@ export class PusherService {
191
};
192
193
this.bindWithChunking(channel as PusherClient, 'trigger_to_client', safeCallback);
190
-
191
- logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
194
} catch (error) {
195
throw new ComposioFailedToSubscribeToPusherChannelError(
196
'Failed to subscribe to Pusher channel',
ts/packages/core/test/services/pusher.test.ts
+64
-33
@@ -3,34 +3,40 @@ import { PusherService } from '../../src/services/pusher/Pusher';
3
4
type EventHandler = (data: Record<string, unknown>) => void;
5
6
-const { bindings, mockChannel, mockPusherClient, mockGetCredentials, mockLoggerError } = vi.hoisted(
7
- () => {
8
- const eventBindings = new Map<string, EventHandler>();
9
- const channel = {
10
- bind: vi.fn((event: string, callback: EventHandler) => {
11
- eventBindings.set(event, callback);
12
- }),
13
- emit: (event: string, data: Record<string, unknown>) => {
14
- eventBindings.get(event)?.(data);
15
- },
16
- };
17
-
18
- return {
19
- bindings: eventBindings,
20
- mockChannel: channel,
21
- mockPusherClient: {
22
- subscribe: vi.fn().mockReturnValue(channel),
23
- unsubscribe: vi.fn().mockReturnValue(undefined),
24
- },
25
- mockGetCredentials: vi.fn().mockResolvedValue({
26
- projectId: 'project-id',
27
- pusherKey: 'pusher-key',
28
- pusherCluster: 'mt1',
29
- }),
30
- mockLoggerError: vi.fn(),
31
- };
32
- }
33
-);
6
+const {
7
+ bindings,
8
+ mockChannel,
9
+ mockPusherClient,
10
+ mockGetCredentials,
11
+ mockLoggerError,
12
+ mockLoggerInfo,
13
+} = vi.hoisted(() => {
14
+ const eventBindings = new Map<string, EventHandler>();
15
+ const channel = {
16
+ bind: vi.fn((event: string, callback: EventHandler) => {
17
+ eventBindings.set(event, callback);
18
+ }),
19
+ emit: (event: string, data: Record<string, unknown>) => {
20
+ eventBindings.get(event)?.(data);
21
+ },
22
+ };
23
+
24
+ return {
25
+ bindings: eventBindings,
26
+ mockChannel: channel,
27
+ mockPusherClient: {
28
+ subscribe: vi.fn().mockReturnValue(channel),
29
+ unsubscribe: vi.fn().mockReturnValue(undefined),
30
+ },
31
+ mockGetCredentials: vi.fn().mockResolvedValue({
32
+ projectId: 'project-id',
33
+ pusherKey: 'pusher-key',
34
+ pusherCluster: 'mt1',
35
+ }),
36
+ mockLoggerError: vi.fn(),
37
+ mockLoggerInfo: vi.fn(),
38
+ };
39
+});
40
41
vi.mock('pusher-js', () => ({
42
default: class FakePusher {
@@ -49,7 +55,7 @@ vi.mock('../../src/utils/logger', () => ({
55
default: {
56
debug: vi.fn(),
57
error: mockLoggerError,
52
- info: vi.fn(),
58
+ info: mockLoggerInfo,
59
warn: vi.fn(),
60
},
61
}));
@@ -60,6 +66,7 @@ describe('PusherService subscription errors', () => {
66
mockGetCredentials.mockClear();
67
mockPusherClient.subscribe.mockClear();
68
mockLoggerError.mockClear();
69
+ mockLoggerInfo.mockClear();
70
});
71
72
it('contains subscription errors emitted after subscribe resolves', async () => {
@@ -75,11 +82,35 @@ describe('PusherService subscription errors', () => {
82
});
83
84
expect(() => {
78
- mockChannel.emit('pusher:subscription_error', { error: 401 });
85
+ mockChannel.emit('pusher:subscription_error', {
86
+ type: 'AuthError',
87
+ error: 'Auth error: 401',
88
+ status: 401,
89
+ });
90
}).not.toThrow();
91
81
- expect(mockLoggerError).toHaveBeenCalledWith(
82
- expect.stringContaining('Trigger subscription error: 401')
83
- );
92
+ expect(mockLoggerError).toHaveBeenCalledWith('Trigger subscription error:', {
93
+ type: 'AuthError',
94
+ error: 'Auth error: 401',
95
+ status: 401,
96
+ });
97
+ expect(mockLoggerInfo).not.toHaveBeenCalled();
98
+ });
99
+
100
+ it('logs success only after pusher confirms the subscription', async () => {
101
+ const service = new PusherService({
102
+ baseURL: 'https://backend.composio.dev',
103
+ apiKey: 'api-key',
104
+ } as never);
105
+
106
+ await service.subscribe(vi.fn());
107
+
108
+ await new Promise<void>(resolve => {
109
+ setImmediate(resolve);
110
+ });
111
+
112
+ mockChannel.emit('pusher:subscription_succeeded', {});
113
+
114
+ expect(mockLoggerInfo).toHaveBeenCalledWith(expect.stringContaining('Subscribed to triggers'));
115
});
116
});