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): never reuse the aliased install_id as an anonymous identity
Kshitij Jhunjhunwalac22c7b325bdf
diff --git a/ts/packages/cli/src/analytics/dispatch.ts b/ts/packages/cli/src/analytics/dispatch.tsindex 56a59395a..d31cfc8ef 100644--- a/ts/packages/cli/src/analytics/dispatch.ts+++ b/ts/packages/cli/src/analytics/dispatch.ts@@ -262,14 +262,25 @@ const getDistinctId = (installId: string) =>Effect.gen(function* () {const state = yield* readAnalyticsState;const apolloUserId = state?.apollo_user_id;- if (typeof apolloUserId !== 'string' || apolloUserId.length === 0) {- return installId;+ const fingerprint = yield* getApiKeyFingerprint;++ if (+ typeof apolloUserId === 'string' &&+ apolloUserId.length > 0 &&+ fingerprint !== null &&+ fingerprint === state?.api_key_fingerprint+ ) {+ return apolloUserId;}- const fingerprint = yield* getApiKeyFingerprint;- return fingerprint !== null && fingerprint === state?.api_key_fingerprint- ? apolloUserId- : installId;+ // Once the install has been aliased, PostHog has permanently merged the bare+ // install_id into that Apollo person — reusing it here would attribute these+ // events to the previous user rather than to nobody. Fall back to an id that+ // was never merged: pseudonymous per credential, or per device when signed out.+ if (typeof state?.aliased_apollo_user_id !== 'string') {+ return installId;+ }+ return fingerprint !== null ? `user_${fingerprint}` : `anon_${installId}`;});const cwdHash = (cwd: string): string => djb2Hash(cwd).toString(36);diff --git a/ts/packages/cli/test/src/analytics.dispatch.test.ts b/ts/packages/cli/test/src/analytics.dispatch.test.tsindex 7ad259d17..e5d9d1004 100644--- a/ts/packages/cli/test/src/analytics.dispatch.test.ts+++ b/ts/packages/cli/test/src/analytics.dispatch.test.ts@@ -675,7 +675,10 @@ describe('CLI analytics dispatch', () => {const args = childProcessMocks.spawn.mock.calls[0]![1] as string[];const payload = decodeWorkerPayload<{ distinctId: string; installId: string }>(args[2]!);expect(payload.distinctId).not.toBe('om_user_a');- expect(payload.distinctId).toBe(payload.installId);+ // The install_id is already merged into user A's PostHog person, so+ // reusing it would still attribute to A. Must be a never-merged id.+ expect(payload.distinctId).not.toBe(payload.installId);+ expect(payload.distinctId.startsWith('user_')).toBe(true);}).pipe(Effect.provide(makePlatformLayer(home)));});@@ -704,6 +707,33 @@ describe('CLI analytics dispatch', () => {}).pipe(Effect.provide(makePlatformLayer(home)));});+ it.effect('does not reuse the aliased install_id after logout', () => {+ const home = tempy.temporaryDirectory();+ const scriptPath = `${home}/composio.ts`;+ enableTelemetry('uak_logged_in');+ process.argv[1] = scriptPath;++ return Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ yield* fs.writeFileString(scriptPath, '');++ yield* linkApolloIdentityForAnalytics('om_logged_in', 'uak_logged_in');+ yield* clearApolloIdentityForAnalytics;+ childProcessMocks.spawn.mockClear();++ // Signed out: no credential at all.+ vi.stubEnv('COMPOSIO_USER_API_KEY', '');+ yield* trackCliEventEffect({ name: 'producer_event' });++ const args = childProcessMocks.spawn.mock.calls[0]![1] as string[];+ const payload = decodeWorkerPayload<{ distinctId: string; installId: string }>(args[2]!);+ expect(payload.distinctId).not.toBe('om_logged_in');+ // Bare install_id now resolves to the logged-out user's person.+ expect(payload.distinctId).not.toBe(payload.installId);+ expect(payload.distinctId).toBe(`anon_${payload.installId}`);+ }).pipe(Effect.provide(makePlatformLayer(home)));+ });+it.effect('does not create the identity file when logging out with telemetry disabled', () => {const home = tempy.temporaryDirectory();enableTelemetry();