Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(cli): honor disabled telemetry in identity link; make alias idempotent
Kshitij Jhunjhunwala64dc2488d249
diff --git a/ts/packages/cli/src/analytics/dispatch.ts b/ts/packages/cli/src/analytics/dispatch.tsindex 73fbeb310..2c2859e67 100644--- a/ts/packages/cli/src/analytics/dispatch.ts+++ b/ts/packages/cli/src/analytics/dispatch.ts@@ -574,21 +574,31 @@ export const emitPostHogAlias = (installId: string, apolloUserId: string) =>yield* enqueuePostHogEnvelope(envelope);}).pipe(Effect.catchAllCause(() => Effect.void));-// Called at login: persist the Apollo identity and alias the device into it.-// Non-fatal so login never fails on telemetry.+// Called at login: persist the Apollo identity and, on first association, alias+// the anonymous install into it. Non-fatal so login never fails on telemetry.export const linkApolloIdentityForAnalytics = (apolloUserId: string) =>Effect.gen(function* () {- if (typeof apolloUserId !== 'string' || apolloUserId.trim().length === 0) {+ const resolved = typeof apolloUserId === 'string' ? apolloUserId.trim() : '';+ if (resolved.length === 0) {return;}+ // Disabled telemetry writes nothing — not even the local identity file.const disabled = yield* analyticsDisabled;- const installId = yield* getOrCreateInstallId;- yield* persistApolloUserId(installId, apolloUserId);if (disabled) {+ yield* telemetryDebugLog('alias_skip', { reason: 'disabled' });return;}- yield* emitPostHogAlias(installId, apolloUserId);++ const existing = yield* readApolloUserId;+ const installId = yield* getOrCreateInstallId;+ yield* persistApolloUserId(installId, resolved);+ // Alias only the first time this install is tied to an Apollo user: a repeat+ // login is redundant, and PostHog rejects re-aliasing one install into a+ // second account, so skip once an id has already been persisted.+ if (existing === null) {+ yield* emitPostHogAlias(installId, resolved);+ }}).pipe(Effect.catchAllCause(() => Effect.void));export const trackCliCodactFailureEffect = (failure: CliCodactFailure) =>diff --git a/ts/packages/cli/test/src/analytics.dispatch.test.ts b/ts/packages/cli/test/src/analytics.dispatch.test.tsindex 4d78ce915..7bfaba64a 100644--- a/ts/packages/cli/test/src/analytics.dispatch.test.ts+++ b/ts/packages/cli/test/src/analytics.dispatch.test.ts@@ -392,6 +392,12 @@ describe('CLI analytics dispatch', () => {yield* linkApolloIdentityForAnalytics('apollo_user_disabled');expect(childProcessMocks.spawn).not.toHaveBeenCalled();++ // Disabled telemetry must not even create the local identity file.+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const exists = yield* fs.exists(path.join(home, '.composio', 'analytics.json'));+ expect(exists).toBe(false);}).pipe(Effect.provide(makePlatformLayer(home)));});@@ -489,6 +495,10 @@ describe('CLI analytics dispatch', () => {apollo_user_id: 'om_apollo_login',created_at: '2026-01-01T00:00:00.000Z',});++ // A repeat login with the same Apollo id does not re-emit the alias.+ yield* linkApolloIdentityForAnalytics('om_apollo_login');+ expect(childProcessMocks.spawn).toHaveBeenCalledTimes(1);}).pipe(Effect.provide(makePlatformLayer(home)));});