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).
This commit is contained in:
Mgeeeek
2026-05-06 01:48:42 +05:30
parent 12bb2588f0
commit ec5baaba20
+12 -7
View File
@@ -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) {