Repository navigation
fix(remote-connect): let Desktop own the shared device Relay socket, with CLI standby takeover - #3689
Merged
bobleer merged 3 commits intoNov 2, 2026
Conversation
… local hosts Every OpenBitFun host on a machine shares device_identity.json, and the Relay keeps only the newest machine-scoped socket per device_id. A Desktop and a CLI daemon that are both signed in therefore replaced each other's socket every few seconds. Add a host-local routing lease: an OS advisory file lock per Relay endpoint and priority tier, stored next to the identity file. A primary host connects whenever it holds its lock. A secondary host connects only while no primary holds the primary lock, and otherwise stands by in the new Standby state. The OS releases a lock when its process exits or is killed, so the standing-by host takes over within about a second. Lock IO failures fall back to the previous unarbitrated behavior. The Relay protocol is unchanged.
Desktop opens its account device socket as the primary host. CLI, TUI and the daemon open theirs as secondary hosts: they stand by while a Desktop on the same machine serves the device and reconnect once it exits.
A CLI login while a Desktop serves the shared device started routing in standby but still reported "Device routing connected". Carry a routing_standby fact on the login result and say that this host takes over when the other one exits.
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.
Summary
A Desktop and a CLI daemon signed in on the same machine no longer fight over the account device's Relay socket. Desktop takes priority. The CLI stands by while a Desktop serves the device, and reconnects by itself once the Desktop exits or is killed.
Type and Areas
Type: bug fix
Areas: Rust services (remote-connect), desktop/Tauri, CLI
Motivation / Impact
Every host on a machine shares
device_identity.json, so they all authenticate as the samedevice_id. The Relay keeps only the newest machine-scoped socket per device (DeviceManager::activate_pending_innerforce-closes the previous one). BothRelayClient::runloops reconnect within 0.5 to 5 seconds, so each host replaced the other's connection over and over. One daemon recorded about 110 disconnects in its first 5 minutes.The fix is host-local arbitration in
remote_connect::routing_lease. It uses OS advisory file locks (fs2, already aremote-connectdependency), one per Relay endpoint and priority tier, stored next to the identity file:ConnectionState::Standby, andconnect_authenticatedstill succeeds. A connected secondary yields as soon as the Relay replaces its socket: it checks the lease before every reconnect. It needs no polling while connected.A CLI or app-server login that starts in standby now says that another host serves the device, instead of "Device routing connected." (
AccountLoginResult::routing_standby).Mostly a developer scenario. No user-facing change for single-instance users.
Verification
cargo test -p openbitfun-services-integrations --features remote-connect --lib remote_connect::r: 33 passed. New tests:cargo test -p openbitfun-cli --bin openbitfun account::tests: 4 passed, including the new check that a standby login does not claim connected routingcargo check -p openbitfun-cli -p openbitfun-desktop -p openbitfun-app-server: no new warningspnpm run check:core-boundaries: passedRemote scenarios: this only changes how local hosts arbitrate their own account device socket. The Relay protocol, controllers, Peer Device Mode and Dispatch wire contracts are unchanged. Exercised with unit and run-loop tests against a local TCP listener. Not yet exercised against a live Relay with a real Desktop and daemon running together.
Reviewer Notes
device_kindon the Relay row comes from the most recent login. After a Desktop exits and the daemon takes over, the device may still be labeleddesktopuntil the CLI logs in again.RelayClient::new()stays unarbitrated for tests and existing callers. Product hosts useRelayClient::new_device_host(priority).Checklist