From ec5baaba2036ac6b21a4b8d43aa1bc90b2cc21cc Mon Sep 17 00:00:00 2001 From: Mgeeeek Date: Wed, 6 May 2026 01:48:42 +0530 Subject: [PATCH] fix(telemetry): preserve existing vector-store id in OSS init Stop overwriting a stable vector-store UUID with the shared SDK user_id. Existing OSS users were having their telemetry identity silently swapped on next init, orphaning every prior PostHog event tagged with the old id (the same regression class as the bug PR #5040 set out to fix). The shared SDK id is now adopted only when the vector store reports "anonymous" / "anonymous-supabase" (fresh-install signals). --- mem0-ts/src/oss/src/memory/index.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mem0-ts/src/oss/src/memory/index.ts b/mem0-ts/src/oss/src/memory/index.ts index e175e71ff..c66255adb 100644 --- a/mem0-ts/src/oss/src/memory/index.ts +++ b/mem0-ts/src/oss/src/memory/index.ts @@ -463,16 +463,21 @@ export class Memory { private async _getTelemetryId() { try { if ( - !this.telemetryId || this.telemetryId === "anonymous" || this.telemetryId === "anonymous-supabase" ) { - this.telemetryId = - (await getOrCreateMem0UserId()) || - (await this.vectorStore.getUserId()); - try { - await this.vectorStore.setUserId(this.telemetryId); - } catch {} + const existing = await this.vectorStore.getUserId(); + if (existing && !existing.startsWith("anonymous")) { + // Preserve a real vector-store UUID so prior PostHog events stay + // tied to this user's identity. Cross-surface stitching with + // CLI/Python OSS for these existing users is deferred. + this.telemetryId = existing; + } else { + this.telemetryId = (await getOrCreateMem0UserId()) || existing; + try { + await this.vectorStore.setUserId(this.telemetryId); + } catch {} + } } return this.telemetryId; } catch (error) {