@devries-cameron20 / composio-1 / commits / 64dc2488d
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): honor disabled telemetry in identity link; make alias idempotent

Review follow-ups on the direct-to-PostHog telemetry: - linkApolloIdentityForAnalytics now checks the disabled/opt-out state BEFORE touching disk, so a disabled (TELEMETRY_DISABLED/CI/etc.) login no longer creates ~/.composio/analytics.json with the install_id + Apollo id. Honors the disabled-means-no-op contract. - Emit the $create_alias only on the first association of an install with an Apollo user: a repeat login is redundant, and PostHog rejects re-aliasing one install into a second account. Gates on the persisted apollo_user_id. Tests: disabled path now asserts the identity file is absent; alias test asserts a repeat login does not re-spawn the alias worker. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Kshitij Jhunjhunwala committed Jul 23, 2026 at 12:25 UTC 64dc2488d2496831a4e772155321fe8ec82817d6
2 files changed +26 -6
ts/packages/cli/src/analytics/dispatch.ts
+16 -6
@@ -574,21 +574,31 @@ export const emitPostHogAlias = (installId: string, apolloUserId: string) =>
574 yield* enqueuePostHogEnvelope(envelope);
575 }).pipe(Effect.catchAllCause(() => Effect.void));
576
577 -// Called at login: persist the Apollo identity and alias the device into it.
578 -// Non-fatal so login never fails on telemetry.
577 +// Called at login: persist the Apollo identity and, on first association, alias
578 +// the anonymous install into it. Non-fatal so login never fails on telemetry.
579 export const linkApolloIdentityForAnalytics = (apolloUserId: string) =>
580 Effect.gen(function* () {
581 - if (typeof apolloUserId !== 'string' || apolloUserId.trim().length === 0) {
581 + const resolved = typeof apolloUserId === 'string' ? apolloUserId.trim() : '';
582 + if (resolved.length === 0) {
583 return;
584 }
585
586 + // Disabled telemetry writes nothing — not even the local identity file.
587 const disabled = yield* analyticsDisabled;
586 - const installId = yield* getOrCreateInstallId;
587 - yield* persistApolloUserId(installId, apolloUserId);
588 if (disabled) {
589 + yield* telemetryDebugLog('alias_skip', { reason: 'disabled' });
590 return;
591 }
591 - yield* emitPostHogAlias(installId, apolloUserId);
592 +
593 + const existing = yield* readApolloUserId;
594 + const installId = yield* getOrCreateInstallId;
595 + yield* persistApolloUserId(installId, resolved);
596 + // Alias only the first time this install is tied to an Apollo user: a repeat
597 + // login is redundant, and PostHog rejects re-aliasing one install into a
598 + // second account, so skip once an id has already been persisted.
599 + if (existing === null) {
600 + yield* emitPostHogAlias(installId, resolved);
601 + }
602 }).pipe(Effect.catchAllCause(() => Effect.void));
603
604 export const trackCliCodactFailureEffect = (failure: CliCodactFailure) =>
ts/packages/cli/test/src/analytics.dispatch.test.ts
+10
@@ -392,6 +392,12 @@ describe('CLI analytics dispatch', () => {
392 yield* linkApolloIdentityForAnalytics('apollo_user_disabled');
393
394 expect(childProcessMocks.spawn).not.toHaveBeenCalled();
395 +
396 + // Disabled telemetry must not even create the local identity file.
397 + const fs = yield* FileSystem.FileSystem;
398 + const path = yield* Path.Path;
399 + const exists = yield* fs.exists(path.join(home, '.composio', 'analytics.json'));
400 + expect(exists).toBe(false);
401 }).pipe(Effect.provide(makePlatformLayer(home)));
402 });
403
@@ -489,6 +495,10 @@ describe('CLI analytics dispatch', () => {
495 apollo_user_id: 'om_apollo_login',
496 created_at: '2026-01-01T00:00:00.000Z',
497 });
498 +
499 + // A repeat login with the same Apollo id does not re-emit the alias.
500 + yield* linkApolloIdentityForAnalytics('om_apollo_login');
501 + expect(childProcessMocks.spawn).toHaveBeenCalledTimes(1);
502 }).pipe(Effect.provide(makePlatformLayer(home)));
503 });
504