Skip to content

fix(sync): propagate device removal across LAN peers and disambiguate device names - #663

Open
Captain-Vikram wants to merge 1 commit into
Flow-Tube:mainfrom
Captain-Vikram:fix/issue-662-sync-device-removal-propagation
Open

Captain-Vikram wants to merge 1 commit into
Flow-Tube:mainfrom
Captain-Vikram:fix/issue-662-sync-device-removal-propagation

Conversation

@Captain-Vikram

Copy link
Copy Markdown
Contributor

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.rs verify that an evicted peer can now successfully complete the handshake under historical epoch validation and process EngineError::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

  1. LAN Handshake Abrupt Drop on Evicted Peer:
    When Device A removes Device B from a sync group, Device A creates an Op::Remove entry advancing the group epoch (e.g. from 0 to 1).
    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 against session.roster().members. Because Device B was removed at epoch 1, it was missing from the head roster, causing device_key to return Err(EngineError::Removed).
    Device A abruptly dropped the TCP connection before serving Request::Roster. As a result, Device B never received the Op::Remove entry, never learned that it had been removed, and remained indefinitely stuck in the "Linked" state.

  2. 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

  1. Historical Sender Validation in LAN Handshake (src-tauri/src/sync2/lan_link.rs):

    • Updated device_key to accept the peer's claimed epoch.
    • If the peer is not present in the current session.roster().members, it checks historical sender authorizations in session.senders().
    • If the peer was an authorized Role::Device during the claimed epoch (epoch >= sender.since && sender.until.is_none_or(|until| epoch <= until)), the handshake is permitted.
    • This allows the evicted peer to complete the handshake, fetch Request::Roster, ingest the Op::Remove entry into its HeldStore, and transition to EngineError::Removed (triggering forget_with_keys to cleanly leave the group).
    • Any writes (Request::Put) remain strictly guarded by Holder, ensuring removed peers cannot write beyond their removal boundary.
  2. Disambiguate Default Device Names (src-tauri/src/sync/identity.rs):

    • default_device_name() now inspects environment hostnames (COMPUTERNAME / HOSTNAME) and adds Dev tag in debug builds (cfg!(debug_assertions)).
    • Generates distinct names: e.g. Flow Desktop (MY-PC - Windows) or Flow Desktop (MY-PC - Windows, Dev), preventing naming collisions when testing or running multiple desktop installations.

Testing & Verification

  • New Integration Test: Added a_removed_device_learns_its_removal_over_lan_and_is_shut_out in src-tauri/tests/sync2_lan.rs:
    • Device A removes Device B (remove_devices).
    • Device B dials Device A over LAN under epoch 0.
    • Handshake succeeds, Device B receives and holds the new removal roster entry.
    • Device B attempts to open a session and correctly receives Err(EngineError::Removed).
    • Result: test a_removed_device_learns_its_removal_over_lan_and_is_shut_out ... ok.
  • Existing Suites:
    • cargo test --test sync_phase1 passes (17/17).
    • cargo check clean with 0 warnings / 0 errors.
    • cargo fmt and cargo clippy pass with code 0.
    • Frontend typecheck (pnpm build) clean.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Device removal is not synchronized across the group when multiple devices share the same name

1 participant