Cross-device Flow coordination
Flow connects trusted OpenLogi agents so a user can move configured input devices between computers by crossing a screen edge. It combines peer discovery, authenticated sessions, user-confirmed pairing, shared device state, and a timed handoff with the agent runtime that watches the pointer and changes device hosts.
Flow system
The Flow system turns peer and device configuration into a shared model of which computer owns each device and which screen edge reaches each peer. The agent uses this model to publish state, arm valid edges, and select the devices that must move. (crates/…/orchestrator.rs• L1257-1281)
The system has four broad responsibilities:
- Find a peer by its configured identity and reachable address.
- Establish a secure session and pair unknown peers through a user check.
- Keep peer device and link state current.
- Turn a screen-edge crossing into one coordinated device handoff.
Peer discovery
Peer discovery supplies address hints for a peer key. It does not establish trust. The session layer can use mDNS results and manual addresses, while the transport accepts a connection only when its authenticated identity matches the configured public key. (crates/…/runtime.rs• L326-345, crates/…/discovery.rs• L554-625)
Flow advertises a DNS-SD service when available and filters discovered records by the supported protocol range. Manual host names and IP addresses remain a fallback when local multicast discovery is not available. Several sources can answer at the same time, and duplicate addresses are removed before dialing. Each source has a time limit, so one stalled lookup does not block other address hints. (crates/…/runtime.rs• L386-405, crates/…/discovery.rs• L69-127)
Pairing uses a separate DNS-SD service that appears only while a user has pairing open. The pairing service carries display information and a pairing endpoint address, while the normal Flow service remains the discovery path for configured peers. (crates/…/pairing.rs• L527-563, crates/…/pairing.rs• L1386-1393)
Secure session
The Flow session uses QUIC with mutual TLS and a persistent machine identity. Each connection exchanges a Hello message after TLS. The peers check the key binding, select a shared protocol version, and intersect known capabilities before application traffic starts. (crates/…/runtime.rs• L206-217, crates/…/runtime.rs• L374-384, crates/…/transport.rs• L289-394, crates/…/negotiation.rs• L53-89)
The transport separates traffic by purpose:
| Traffic | Session role |
|---|---|
| Hello and pairing | Control and request streams before trust |
| Handoff and peer information | Request/response streams and notifications after trust |
| Ping and Pong | QUIC datagrams for agent-level liveness |
| Clipboard or file data | Ordered bulk response streams when capabilities allow it |
An untrusted session can carry only link and pairing messages. A trusted session can carry the peer and handoff messages allowed by the negotiated protocol. (crates/…/transport.rs• L357-393, crates/…/transport.rs• L464-505)
The pairing endpoint is separate from the trusted Flow endpoint. It accepts an unknown machine only for the pairing ceremony. The normal endpoint uses configured peer keys. After the ceremony saves a peer key, the temporary connection closes and later Flow traffic uses the normal trusted path. (crates/…/pairing.rs• L1-14, crates/…/pairing.rs• L1132-1160, crates/…/runtime.rs• L212-217)
Pairing ceremony
Pairing changes a TLS-authenticated but unknown peer into a trusted peer. It binds a short code to both machine keys, both Hello messages, and fresh nonces for that connection. Users compare the code on both machines, then both sides confirm before the peer key is saved. (crates/…/pairing.rs• L215-227, crates/…/pairing.rs• L300-311)
The ceremony uses a commit-then-reveal exchange. This prevents either side from choosing its nonce after seeing the other side's nonce. The state belongs to one connection, so a retry starts a new ceremony. (crates/…/pairing.rs• L312-412, crates/…/pairing.rs• L506-548)
sequenceDiagram
participant A as Initiator
participant B as Responder
A->>B: PairStart commitment
B-->>A: PairPrompted nonce and deadline
A->>B: PairReveal nonce
B-->>A: PairRevealed
Note over A,B: Both display and compare the same code
A->>B: PairConfirm
B->>A: PairConfirm
Note over A,B: Both persist the peer key and promote the session
The agent exposes pairing as a user-controlled session. While it is open, the agent advertises and browses for pairing candidates, accepts one attempt, and publishes phases such as searching, showing a code, waiting for the peer, success, or failure to the GUI. Pairing state now uses an explicit stage model, which keeps connection setup, code display, confirmation, and short post-result flushing separate. (crates/…/pairing.rs• L281-310, crates/…/stage.rs• L14-53, crates/…/stage.rs• L146-183)
Both users must confirm before the agent saves the peer in its configuration. The save completes before the agent reports pairing success. The saved-peer signal then lets the wider agent reload the new pin and start the normal trusted Flow runtime. (crates/…/pairing.rs• L754-803, crates/…/pairing.rs• L1132-1160)
Session lifecycle
The session manager keeps one reconnecting worker for each configured peer. It can accept inbound connections or race outbound dials from all available address sources. If both machines dial at once, the public-key order selects one connection so both sides keep the same link. (crates/…/session.rs• L176-259, crates/…/session.rs• L452-537)
Each live link reports Connected, Degraded, or Lost. Ping/Pong traffic measures agent liveness above QUIC. Failed links retry with capped delay and peer-specific variation. When a link becomes trusted, the session sends a complete device inventory and coarse peer state. Later whole-state updates heal missed notifications and reconnects. (crates/…/session.rs• L40-71, crates/…/session.rs• L569-680)
Peer and device state
Trusted peers exchange level-triggered state rather than small changes. A device announcement describes the physical device identity, whether it is live on this host, and the Easy-Switch slot that reaches the announcing host. A peer can match the same physical device across receiver, Bluetooth, or other transport views by intersecting validated identifiers. (crates/…/flow.v1.proto• L275-356, crates/…/identity.rs• L134-150)
The agent keeps configured devices in its Flow view even when they are offline or not listed by the current inventory. This lets the receiving agent recognize a device that arrives after a host switch. Pointing devices are ordered before keyboards so the cursor becomes usable before linked input devices finish arriving. (crates/…/devices.rs• L76-125, crates/…/devices.rs• L148-179)
Agent Flow runtime
The agent runs Flow as a generation owned by FlowController. The controller starts it only when Flow is enabled and at least one peer is configured. A changed Flow configuration replaces the generation, while inventory updates reach the current generation. The OS hook sends only a non-blocking pointer-moved signal into the active generation. (crates/…/controller.rs• L59-74, crates/…/controller.rs• L189-223, crates/…/controller.rs• L42-50)
The runtime binds the Flow endpoint, starts discovery and reconnecting peer sessions, starts the pointer thread, and gives the actor the current device inventory. The actor owns mutable handoff state. Peer tasks read and write network streams without making the actor wait on network I/O. This keeps edge decisions and handoff state in one place while allowing links to reconnect independently. If the pointer probe cannot start, the generation can still receive handoffs from peers. (crates/…/runtime.rs• L176-279, crates/…/actor.rs• L73-137)
The runtime shares receiver access with the rest of the agent. A transfer takes exclusive access while it prepares and writes host changes, so Flow does not compete with capture or other receiver work during a host transition. (crates/…/sender.rs• L100-124, crates/…/sender.rs• L162-169, crates/…/hardware.rs• L234-251)
flowchart LR
C[Flow configuration] --> S[FlowController]
I[Device inventory] --> A[Flow actor]
H[OS pointer hook] --> P[Pointer thread]
P --> E[Edge crossing]
E --> A
S --> R[Flow runtime generation]
R --> D[Discovery and session manager]
D --> L[Trusted peer links]
L --> A
A --> W[Device host-switch writes]
A --> U[Cursor entry placement]
Edge crossing
The pointer thread uses one shared desktop coordinate space and the current display bounds to find exposed display edges. It samples after pointer motion settles and also wakes for a dwell deadline, so a cursor can cross by a fast move or by holding it at an edge. A configured modifier can gate the crossing. (crates/…/edge.rs• L1-11, crates/…/pointer.rs• L1-14, crates/…/pointer.rs• L223-250)
The actor arms only edges whose peers are connected. A crossing is ignored when another transfer is active, no device is available for that peer, or the peer link is not ready. A valid crossing becomes an entry point with a side, normalized position, and optional velocity for the receiving computer. (crates/…/actor.rs• L218-275, crates/…/handoff.rs• L423-440)
Handoff transaction
The handoff is a two-sided transaction. The sender prepares all needed host-switch writes before asking the receiver to arm. The receiver validates the device identities, accepts at most one pending transfer, and watches for device arrival for a bounded window. The sender changes hosts only after the receiver accepts. (crates/…/sender.rs• L100-159, crates/…/handoff.rs• L130-215)
sequenceDiagram
participant S as Sender agent
participant R as Receiver agent
S->>S: Prepare all device host switches
S->>R: HandoffRequest with identities and entry point
alt Receiver accepts
R-->>S: HandoffAccept with arrival window
S->>S: Write device host switches
R->>R: Observe device arrivals
R->>R: Place cursor when pointing device arrives
R-->>S: HandoffResult
else Receiver rejects or writes do not start
R-->>S: HandoffReject or S sends HandoffCancel
end
After acceptance, the sender starts writes early enough for the devices to arrive within the receiver's window. If no write starts, it cancels the transfer. If a write starts, it waits for the receiver's result because the device may have switched even when the write reports an error. The receiver reports complete, partial, timed out, or cancelled outcomes and remembers recent transfer IDs for replay. (crates/…/handoff.rs• L348-420, crates/…/sender.rs• L171-251)
The receiver places the cursor as soon as the first pointing device arrives. It maps the sender's normalized edge position onto an exposed edge on the receiver and keeps the cursor slightly inside the display to prevent an immediate reverse crossing. (crates/…/handoff.rs• L7-18, crates/…/pointer.rs• L342-423)
Agent state and input coordination
Flow reports peer links and pairing phases through the agent's shared observable state. The GUI can wait for a changed generation instead of polling separate Flow and inventory sources. (crates/…/observable.rs• L36-45, crates/…/observable.rs• L117-149, crates/…/observable.rs• L205-227)
The input runtime keeps hook callbacks non-blocking while Flow and other agent actions run in workers. Pointer motion wakes Flow, while button and key events use the same action lifecycle that handles cancellation and device changes. This lets Flow share the agent's input path without making the OS hook wait for network or device I/O. (crates/…/hook.rs• L648-739, crates/…/runtime.rs• L747-800)
The shared hardware access path resolves the current inventory channel only when a device operation is ready to run. Per-transport turns serialize agent-owned HID work, and the host I/O gate stops proactive writes during sleep, lock, or shutdown. These rules matter to Flow because a handoff must use a live route and must not race another receiver operation. (crates/…/hardware.rs• L102-159, crates/…/hardware.rs• L301-349, crates/…/hardware.rs• L1034-1053)
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the protocol schema, envelope frame rules, negotiation gates, and transport response mapping aligned when changing a Flow message.
- Keep the trusted Flow service and pairing service separate. Their service types, ports, advertised identity data, and protocol filters describe different connection purposes.
- Keep device identity encoding, configuration identity keys, and the cross-peer matching rule aligned when adding a device identifier.
- Keep the sender write deadline, receiver arrival window, cancellation rules, and replay behavior aligned when changing handoff timing.
- Keep whole-state revisions newer than state from an earlier process run so peers do not discard fresh state as stale.
- Keep peer key persistence, TLS trust, pairing transcript binding, and configuration pins aligned when changing identity storage.
- Keep pairing save notifications and Flow generation replacement aligned so a newly saved peer becomes a trusted session without using the temporary pairing endpoint.
- Keep edge layout, pointer entry mapping, peer names, and modifier rules aligned when changing screen-edge configuration.
- Keep exclusive receiver access, current-channel resolution, and the host I/O gate aligned with Flow host-switch writes.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The peer key in Hello differs from the TLS identity | The connection is rejected before trust | Verify the key binding during Hello negotiation |
| Protocol ranges do not overlap | The session cannot carry Flow traffic | Reject the Hello with the peer's supported range |
| A device identity is malformed or has no intersection | The receiver rejects the handoff as unknown | Validate all identifiers before matching |
| The receiver already has a pending transfer | The new request is rejected | Allow one armed incoming transfer and use transfer IDs for duplicates |
| No host-switch write starts before the write deadline | The receiver is disarmed and no device moves | Cancel the transfer rather than wait for a result |
| A host-switch write starts but fails or the link drops | The device may still move and the final result may be delayed | Keep the receiver armed until its deadline and report no result only after the sender gives up |
| A pointer probe is unavailable | Outgoing edge handoff is disabled for that generation | Continue receiving handoffs without enabling outgoing crossings |
| mDNS is unavailable | Automatic discovery does not find the peer | Use configured manual addresses |
| A second unknown machine tries to pair while one candidate is active | The new pairing connection is refused or reported as busy | Keep one pairing slot and release it only when the attempt ends or is promoted |
| A pairing attempt reaches both local confirmations but the peer key cannot be saved | The peer is not trusted and the temporary session ends as a save failure | Persist the peer before reporting the attempt as paired |
| Pairing discovery sees an incompatible or withdrawn advertisement | The machine is not shown as a usable pairing target | Filter by protocol overlap and update the candidate list on service changes |
| Receiver access remains busy or device I/O is suspended | The sender cannot prepare or write the host switches | Bound exclusive access and check the host I/O gate before each write |
| A Flow configuration change arrives during a handoff | The current generation stops while the transfer is active | Replace the generation and give the sender a short shutdown grace period |
Key files
| File | Why to read it |
|---|---|
| crates/…/lib.rs | Defines the Flow protocol crate and its generated message surface. |
| crates/…/discovery.rs | Explains normal and pairing address hints from mDNS and manual configuration. |
| crates/…/transport.rs | Shows how authenticated Flow connections bind streams, trust, and message families. |
| crates/…/session.rs | Coordinates reconnecting peer sessions and liveness state. |
| crates/…/pairing.rs | Defines the user-confirmed trust ceremony. |
| crates/…/controller.rs | Starts, replaces, and stops the agent's Flow generation. |
| crates/…/runtime.rs | Assembles discovery, sessions, pointer input, and the Flow actor. |
| crates/…/pairing.rs | Runs the user-controlled pairing service and saves new peer pins before normal Flow uses them. |
| crates/…/stage.rs | Defines the high-level phases and deadlines of one pairing attempt. |
| crates/…/actor.rs | Owns peer status, edge crossings, device state, and handoff decisions. |
| crates/…/devices.rs | Joins configured devices with inventory and defines peer matching and handoff order. |
| crates/…/sender.rs | Coordinates preparation, host-switch writes, cancellation, and result waits. |
| crates/…/handoff.rs | Defines receiver windows, sender deadlines, outcomes, and replay behavior. |
| crates/…/pointer.rs | Connects pointer motion, display edges, and cursor placement to Flow. |
| crates/…/observable.rs | Publishes Flow link and pairing state to the GUI through the agent snapshot. |
| crates/…/hardware.rs | Defines the shared device-I/O rules used by host switching and other agent actions. |
| crates/…/hook.rs | Connects OS input events and pointer motion to the agent action and Flow runtimes. |
| crates/…/runtime.rs | Provides the shared lifecycle for actions from OS hooks and device capture. |