Skip to content

[LWDM] fix(lld): preserve userId during identities migration for returning users#18770

Open
gre-ledger wants to merge 2 commits into
developfrom
fix/desktop-userid-migration
Open

[LWDM] fix(lld): preserve userId during identities migration for returning users#18770
gre-ledger wants to merge 2 commits into
developfrom
fix/desktop-userid-migration

Conversation

@gre-ledger

@gre-ledger gre-ledger commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

✅ Checklist

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • Desktop analytics identity (Segment userId / Braze external_id) on app boot.
    • QA: upgrade path from a build that has app.identities with deviceIds but no userId (deviceId rollout) while app.user.id exists — verify Settings → Developer → userId still matches the legacy id after upgrade.

📝 Description

Since LLD 2.145.0, a migration bug can assign a new userId to existing users on upgrade, so returning users appear as new in Segment (and Braze, which shares the id).

Root cause: desktop initIdentities branched on the mere existence of app.identities. Records created by the earlier deviceId rollout (~2.140) contain deviceIds only — no userId — so the slice generated a fresh UUID and the legacy app.user.id was never read. The wrong id was then persisted, making it permanent.

Fix: when the persisted userId is unusable, recover the legacy id from app.user (then localStorage.userId) and merge it onto the persisted deviceIds/push state. A fresh id is only generated when no legacy id exists anywhere. This mirrors the precedence mobile already uses. datadogId is recovered the same way. shouldUsePersistedId is now exported from @ledgerhq/client-ids/store so the helper and the slice agree on what counts as a usable id.

Tests: the previous test that encoded the bug as intentional ("persisted takes precedence") is rewritten to assert the legacy id is recovered; a localStorage-fallback variant is added. Both new tests were confirmed to fail against the old code before the fix.

❓ Context

@live-github-bot live-github-bot Bot added desktop Has changes in LLD shared-lib Label added for automated tagging of PRs labels Jun 19, 2026
@live-github-bot live-github-bot Bot changed the title fix(lld): preserve userId during identities migration for returning users [LWDM] fix(lld): preserve userId during identities migration for returning users Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Web Tools Build Status

Build Status Deployment
Web Tools Build ✅ Deployed https://web-tools-oc5djo1j1-ledger-hq-prd.vercel.app
Native Storybook Build ⏭️ Skipped
React Storybook Build ⏭️ Skipped

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 7 projects in monorepo, 7 projects with changes.

📊 Quick Summary
Project Total Size Change
desktop-main 2.6 MB -
desktop-preloader 7.1 KB -
desktop-renderer 81.2 MB -
desktop-webviewDappPreloader 36.9 KB -
desktop-webviewPreloader 200.0 B -
desktop-workers 36.8 KB -
mobile 257.0 MB -
📋 Detailed Reports (Click to expand)

📁 desktop-main

Path: rsdoctor/desktop-main/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.6 MB - -
📄 JavaScript 2.4 MB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 135.3 KB - -

📁 desktop-preloader

Path: rsdoctor/desktop-preloader/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 7.1 KB - -
📄 JavaScript 5.3 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 1.8 KB - -

📁 desktop-renderer

Path: rsdoctor/desktop-renderer/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 81.2 MB - -
📄 JavaScript 28.9 MB - -
🎨 CSS 172.5 KB - -
🌐 HTML 1.8 KB - -
📁 Other Assets 52.2 MB - -

📁 desktop-webviewDappPreloader

Path: rsdoctor/desktop-webviewDappPreloader/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 36.9 KB - -
📄 JavaScript 36.9 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 desktop-webviewPreloader

Path: rsdoctor/desktop-webviewPreloader/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 200.0 B - -
📄 JavaScript 200.0 B - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 desktop-workers

Path: rsdoctor/desktop-workers/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 36.8 KB - -
📄 JavaScript 36.8 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 mobile

Path: rsdoctor/mobile/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 257.0 MB - -
📄 JavaScript 107.9 MB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 149.1 MB - -

Generated by Rsdoctor GitHub Action

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Ledger Live Desktop’s identities boot migration to prevent returning users from being assigned a fresh analytics userId when upgrading from a state where app.identities exists but only contains deviceIds (deviceId rollout), by recovering the legacy userId (and datadogId) from legacy storage before initializing the identities slice.

Changes:

  • Exported shouldUsePersistedId from @ledgerhq/client-ids/store so “usable id” logic is shared across consumers.
  • Updated desktop initIdentities to merge legacy userId/datadogId into persisted identities when the persisted ids are unusable.
  • Updated/added Jest tests to cover the regression and a localStorage fallback path; added a changeset for patch releases.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
libs/client-ids/src/store/slice.ts Exports the id-usability helper so desktop init logic can align with slice behavior.
apps/ledger-live-desktop/src/renderer/helpers/identities.ts Recovers legacy ids during boot when persisted ids are missing/unusable, while preserving persisted deviceIds/push state.
apps/ledger-live-desktop/src/renderer/helpers/identities.test.ts Reworks regression coverage to assert legacy id recovery; adds localStorage-only recovery test.
.changeset/identities-userid-migration-fix.md Declares patch bumps and documents the migration fix behavior.

Comment thread apps/ledger-live-desktop/src/renderer/helpers/identities.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread apps/ledger-live-desktop/src/renderer/helpers/identities.test.ts Outdated
…sers

When app.identities was created by the deviceId rollout (deviceIds only,
no userId), boot generated a new userId instead of recovering the legacy
app.user/localStorage id, making returning users appear as new in Segment
and Braze. Recover the legacy id when the persisted one is unusable; only
generate a fresh id when none exists. Mirrors the mobile precedence.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gre-ledger gre-ledger force-pushed the fix/desktop-userid-migration branch from 76fe619 to 7817aff Compare June 19, 2026 14:09
@gre-ledger gre-ledger marked this pull request as ready for review June 19, 2026 14:58
@gre-ledger gre-ledger requested a review from a team as a code owner June 19, 2026 14:58
Copilot AI review requested due to automatic review settings June 19, 2026 14:58
LucasWerey
LucasWerey previously approved these changes Jun 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread apps/ledger-live-desktop/src/renderer/helpers/identities.ts
Comment thread apps/ledger-live-desktop/src/renderer/helpers/identities.test.ts
In the persisted-identities branch, legacy ids were only consulted when the
persisted userId was unusable, so a returning user with a valid persisted
userId but missing/invalid datadogId always got a freshly generated one even
when app.user.datadogId existed. Consult readLegacyIds() when either id is
unusable and fill only the missing piece, matching the PR intent and mobile.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ E2E tests are required

Changes detected require e2e testing before merge (even before asking for any review).

🖥️ Desktop

-> Run Desktop E2E

  • Select "Run workflow"
  • Branch: fix/desktop-userid-migration
  • Device: nanoSP or stax

📱 Mobile

-> Run Mobile E2E

  • Select "Run workflow"
  • Branch: fix/desktop-userid-migration
  • Device: nanoX

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Has changes in LLD shared-lib Label added for automated tagging of PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants