Skip to content

[WOOMOB-2734] Fix duplicated device registration API calls on login - #16354

Merged
irfano merged 7 commits into
trunkfrom
issue/WOOMOB-2734-dedupe-device-registration
Aug 15, 2026
Merged

[WOOMOB-2734] Fix duplicated device registration API calls on login#16354
irfano merged 7 commits into
trunkfrom
issue/WOOMOB-2734-dedupe-device-registration

Conversation

@samiuelson

@samiuelson samiuelson commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes WOOMOB-2734

Problem:
RegisterDevice serializes runs with an internal mutex and skips WPCom registration when a device id is already stored, but the class was unscoped in Hilt, so every injection point got its own instance with its own mutex, and concurrent triggers raced past the "already registered" check (the device id is only persisted after a successful response) and each fired its own call. This PR scopes RegisterDevice as a @Singleton so that concurrent calls now queue, and follow-up runs no-op against the persisted state.

The same check also races within a single run: per-site Woo push registration falls back to WPCom registration when it fails, so several stores failing at once each fired an identical call before the first response persisted the device id. The fallback is now dropped from RegisterDevice runs, which already register WPCom once at the end of the run.

Test Steps

  1. Log out, then log in with a WP.com account that has multiple Woo stores available and select a store.
  2. Watch network traffic during the whole login flow: exactly one POST .../devices/new/ should fire, and subsequent registration runs should log "Skipping WP.com push registration".
  3. Background and foreground the app a few times - no further devices/new calls.
  4. Sanity-check re-registration still works: clear app data (or reinstall), log in again - a single registration call fires.

Images/gif

N/A

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@samiuelson samiuelson added type: bug A confirmed bug. feature: notifications Related to notifications or notifs. labels Aug 3, 2026
@samiuelson samiuelson added this to the 25.4 milestone Aug 3, 2026
@wpmobilebot

wpmobilebot commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

App Icon📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App NameWooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Build Number778
Version25.4-rc-1
Application IDcom.woocommerce.android.prealpha
Commit2b5a593
Installation URL0tqkusb9psmho
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot wpmobilebot modified the milestones: 25.4, 25.5 Aug 7, 2026
@wpmobilebot

Copy link
Copy Markdown
Collaborator

Version 25.4 has now entered code-freeze, so the milestone of this PR has been updated to 25.5.

@irfano

irfano commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@samiuelson, do you plan to open this PR this week? I’m asking because this is the last remaining task from the PN project.

…n fix

The fallback fan-out is a separate duplicate-registration cause with its own reproduction (several sites failing Woo registration at once, racing the same isWpComPushRegistered check). Keeping it here would mix two independent fixes in one review, so it moves to its own change along with the test that pins it.

What remains is the singleton scoping: the orchestration mutex and the in-flight job are instance state, so they only serialise concurrent triggers while the whole app shares one RegisterDevice.
@samiuelson
samiuelson force-pushed the issue/WOOMOB-2734-dedupe-device-registration branch from 333b4a4 to 34b9205 Compare August 12, 2026 12:00
@samiuelson
samiuelson marked this pull request as ready for review August 12, 2026 12:06
@samiuelson
samiuelson requested a review from irfano August 12, 2026 12:06

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

AI Code Review - No issues found. The changes look good.

The @Singleton annotation is the right fix: RegisterDevice serialises push registrations through instance-level state (orchestrationMutex and activeJob), so a shared single instance is required for the dedup to hold across the multiple injection sites (login ViewModels, AppInitializer, FCMMessageService, workers). All constructor dependencies are app-scoped singletons/unscoped, so there is no Hilt scope violation. The added tests cover both the runtime serialisation and the singleton-scoping contract.


Automatic review · claude-opus-4-8 · Workflow run

How to reply to a finding

Reply on this review (or inline at the line the finding refers to) with one of:

  • @claude addressed - I made the change. Bot verifies against the next diff before marking resolved.
  • @claude rejected: <reason> - Will not fix; reason gets quoted on the next review.
  • @claude not-applicable - Finding does not apply (wrong file, already covered elsewhere, etc.).

The bot honours these on the next review pass.

@samiuelson

Copy link
Copy Markdown
Contributor Author

@samiuelson, do you plan to open this PR this week? I’m asking because this is the last remaining task from the PN project.

Hi @irfano 👋 I wasn't able to repro this issue manually on device, only in unit test. If you're able to reproduce the bug and validate this PR fixes it it would be great. Otherwise, feel free to take over this issue because I don't want to block you.

@irfano irfano 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.

I was able to reproduce this on trunk: logging in with a multi-store account while watching traffic gives 5 identical devices/new calls. Your branch drops it to 4, so the singleton fix works, and the remaining duplicates all come from the per-site WPCom fallback you split out in 7177ce2. Since that turned out to be the main source of the duplicates, I restored it here by reverting that commit and updated the description. With both changes in, login fires exactly one call.

@irfano
irfano enabled auto-merge August 14, 2026 14:24
@irfano
irfano merged commit 13b2ae8 into trunk Aug 15, 2026
16 checks passed
@irfano
irfano deleted the issue/WOOMOB-2734-dedupe-device-registration branch August 15, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: notifications Related to notifications or notifs. type: bug A confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants