Mitigate sync settings UI race condtions - #9316
Merged
Merged
Conversation
Contributor
Author
This was referenced Jul 28, 2026
MiSikora
force-pushed
the
feature/msikora/simple-sync/race-conditions
branch
from
July 29, 2026 10:05
e325353 to
e6d6b41
Compare
This was referenced Jul 29, 2026
CDRussell
reviewed
Jul 30, 2026
| @Toggle.DefaultValue(DefaultFeatureValue.FALSE) | ||
| fun useSimplifiedSync(): Toggle | ||
|
|
||
| @Toggle.DefaultValue(DefaultFeatureValue.INTERNAL) |
Member
There was a problem hiding this comment.
what's the plan for enabling? Should it just default to TRUE now, and can use the remote config to disable it if there are problems in the wild?
Contributor
Author
There was a problem hiding this comment.
Yeah, you're right. I didn't think of handling it this way. Thanks!
CDRussell
approved these changes
Jul 30, 2026
Contributor
Author
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Task/Issue URL: https://app.asana.com/1/137249556945/project/1216103556496795/task/1216942050413056?focus=true
Tech Design URL (if applicable): https://app.asana.com/1/137249556945/project/1216103556496795/task/1216509582049467?focus=true
API Proposals URL(s) (if applicable): N/A
Description
I've been running into inconsistencies in the new simplified sync flow (V2). Editing a device, removing a device, or turning sync off happens on a separate screen, and coming back to the main sync settings screen also kicks off a device list refresh. That refresh raced with the updates made by the action itself, so the screen would show stale or wrong data until the next refresh sorted it out.
The root cause is that the screen's view state gets written from several coroutines at once (the sync state monitor, device fetches, and user actions), and the old read-then-write pattern let one update silently overwrite another. This PR makes those updates atomic instead, behind a feature flag.
SyncActivityViewModelnow goes through oneupdateViewStatehelper that takes a function transforming the current state.updateSyncActivityViewStateAtomicallyflag on, the helper usesMutableStateFlow.updateso nothing gets lost. With the flag off, it keeps the old read-then-write behavior.Steps to test this PR
Sync Settings regression
Device management
Turn off sync
Flag disabled
updateSyncActivityViewStateAtomicallyflag in the FF inventory.UI changes
N/A
Note
Medium Risk
Changes concurrency semantics for sync settings UI state across many code paths; rollout is gated by an internal feature flag with legacy behavior when off.
Overview
Addresses stale or wrong sync settings UI when device list refreshes race with edits, removals, or turn-off actions from other screens. Concurrent coroutines (sync state monitor, device fetches, user actions) could overwrite each other via read-then-write on
viewState.Changes: All
SyncActivityViewModelview-state writes go through a singleupdateViewStatehelper. WithupdateSyncActivityViewStateAtomicallyenabled (newSyncFeaturetoggle, default INTERNAL), updates useMutableStateFlow.update; when disabled, behavior stays the old assign-after-read path.Signed-in state is rebuilt via
updateSignedInState: repository reads (signed-in, this device, auto-restore) run first, then the lambda applies on the latest state—still falling back to signed-out if the connected device is missing. Tests wire the fake feature toggle with atomic updates on.Reviewed by Cursor Bugbot for commit e6d6b41. Bugbot is set up for automated code reviews on this repo. Configure here.