Repository navigation
fix(sync): propagate device removal across LAN peers and disambiguate device names - #663
Open
Captain-Vikram wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Closes #662
Overview
Resolves an issue where removing a device from a sync group leaves other connected devices or the removed device itself in an inconsistent/stale state on LAN, and prevents unintended cascading removals or UI confusion caused by identical default device names.
Important
Note to @A-EDev :
Please test this fix thoroughly with actual Android <-> Desktop hardware setups before merging. While the unit/integration tests in
sync2_lan.rsverify that an evicted peer can now successfully complete the handshake under historical epoch validation and processEngineError::Removed, I am not working on the Flow Android codebase and cannot directly verify whether the Android app's LAN server listener requires a matching historical epoch check or whether Android's device list UI keys device removal exclusively by ID. Cross-platform verification on your test bench would be greatly appreciated!Root Cause Analysis
LAN Handshake Abrupt Drop on Evicted Peer:
When Device A removes Device B from a sync group, Device A creates an
Op::Removeentry advancing the group epoch (e.g. from0to1).When Device B connects over LAN to sync, it dials with its current applied epoch (
0).In
src-tauri/src/sync2/lan_link.rs::hello_as_server, incoming connections were validated strictly againstsession.roster().members. Because Device B was removed at epoch1, it was missing from the head roster, causingdevice_keyto returnErr(EngineError::Removed).Device A abruptly dropped the TCP connection before serving
Request::Roster. As a result, Device B never received theOp::Removeentry, never learned that it had been removed, and remained indefinitely stuck in the "Linked" state.Default Device Name Collisions:
In
src-tauri/src/sync/identity.rs,default_device_name()produced identical names ("Flow Desktop (Windows)") for all desktop clients. When a user installed multiple desktop instances (e.g. a dev build and a release build) or had multiple PCs, they shared identical display names. During device removal,devices_added_by()cascades removals based on adding relationships, which could cause adjacent desktop installations to be unexpectedly removed when removing a device with an identical name.Key Changes
Historical Sender Validation in LAN Handshake (
src-tauri/src/sync2/lan_link.rs):device_keyto accept the peer's claimedepoch.session.roster().members, it checks historical sender authorizations insession.senders().Role::Deviceduring the claimedepoch(epoch >= sender.since && sender.until.is_none_or(|until| epoch <= until)), the handshake is permitted.Request::Roster, ingest theOp::Removeentry into itsHeldStore, and transition toEngineError::Removed(triggeringforget_with_keysto cleanly leave the group).Request::Put) remain strictly guarded byHolder, ensuring removed peers cannot write beyond their removal boundary.Disambiguate Default Device Names (
src-tauri/src/sync/identity.rs):default_device_name()now inspects environment hostnames (COMPUTERNAME/HOSTNAME) and addsDevtag in debug builds (cfg!(debug_assertions)).Flow Desktop (MY-PC - Windows)orFlow Desktop (MY-PC - Windows, Dev), preventing naming collisions when testing or running multiple desktop installations.Testing & Verification
a_removed_device_learns_its_removal_over_lan_and_is_shut_outinsrc-tauri/tests/sync2_lan.rs:remove_devices).Err(EngineError::Removed).test a_removed_device_learns_its_removal_over_lan_and_is_shut_out ... ok.cargo test --test sync_phase1passes (17/17).cargo checkclean with 0 warnings / 0 errors.cargo fmtandcargo clippypass with code 0.pnpm build) clean.