Repository navigation
feat(macos-client): HostAdvert and ConnectOutcome seams - #78
KooshaPari wants to merge 2 commits into
Conversation
apply_session_env() rewrites the process environment on every session handshake
and, when detection yields ActiveKind::None, removes WAYLAND_DISPLAY outright
(session.rs:555, remove_var at session.rs:590-592). Every later connect_to_env()
in that process then fails with wayland-client's "Could not find wayland
compositor", while connections opened earlier keep working: the reported
"video dead, input alive" asymmetry.
Pin the socket once, from the environment the host was started with, before any
session can retarget it, and prefer the pin in both the probe and
connect_wayland_diagnostic paths, falling back to environment resolution when
the pinned socket is no longer usable (a compositor restart re-creates it).
This is the source of the kwin-pin.patch that the nixos host package applies via
overrideAttrs; it existed only as uncommitted local changes until now.
tx-agent: jcode
tx-validated: manual (deployed and exercised on nixos; ss-vdisplay is linux-only
so it cannot be checked locally from the Windows desk)
Splits the macOS client's admission and discovery policy out of the views so both are testable without a live host: - HostAdvert maps discovery TXT records to a host policy and fails closed on anything it cannot parse. - ConnectOutcome is the explicit admission matrix for connect attempts. Verified on the Mac: 205 tests pass, 20 of them new, and discovery over _slipstream._udp on 9777 is confirmed against the real nixos host. tx-agent: jcode tx-validated: test (205 passed on macOS, 20 new)
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
| /// Connect to the pinned KWin socket, falling back to wayland-client's own resolution when the pin | ||
| /// is absent or no longer usable (a compositor restart re-creates its socket). | ||
| fn connect_kwin() -> Result<Connection> { | ||
| if let Some(path) = pinned_socket() { |
There was a problem hiding this comment.
🟡 Inherited Wayland connection ignored
When WAYLAND_SOCKET and a reachable WAYLAND_DISPLAY coexist, connect_kwin ignores the supplied descriptor. Readiness checks and monitor mirroring fail if that descriptor targets KWin but the named socket targets another compositor.
Learn more
WAYLAND_SOCKET supplies an already-connected Wayland file descriptor and takes precedence over resolving WAYLAND_DISPLAY. The previous implementation delegated that choice to wayland-client. The new helper returns as soon as the pinned named socket opens, without consulting the descriptor. Both probe and run_existing use this helper. The separate connect_wayland_diagnostic still checks the descriptor first, so virtual-output creation and readiness now resolve connections differently.
Example: A launcher supplies a descriptor connected to KWin while WAYLAND_DISPLAY still names a reachable parent compositor without KDE screencast support. The readiness probe previously used KWin; now it queries the parent and reports that the required global is absent.
Recommended fix: Honor WAYLAND_SOCKET before attempting the pinned path. Add an isolated connection test with both a supplied descriptor and a reachable named socket, asserting that the named listener receives no connection.
| if let Some(path) = pinned_socket() { | |
| if std::env::var_os("WAYLAND_SOCKET").is_some() { | |
| return Ok(Connection::connect_to_env()?); | |
| } | |
| if let Some(path) = pinned_socket() { |
Was this helpful? React with 👍 or 👎 to provide feedback.
vindeckyy
left a comment
There was a problem hiding this comment.
Two fmt diffs are failing CI. Applying these clears cargo fmt --all --check.
| ss_vdisplay::warm_socket(); | ||
| gamestream::serve(mgmt_opts, native, gamestream) |
There was a problem hiding this comment.
| ss_vdisplay::warm_socket(); | |
| gamestream::serve(mgmt_opts, native, gamestream) | |
| ss_vdisplay::warm_socket(); | |
| gamestream::serve(mgmt_opts, native, gamestream) |
| return Ok(conn); | ||
| } | ||
| } | ||
| } let Some(path) = diagnostic_socket_path( |
There was a problem hiding this comment.
| } let Some(path) = diagnostic_socket_path( | |
| } | |
| let Some(path) = diagnostic_socket_path( |
vindeckyy
left a comment
There was a problem hiding this comment.
Two bigger things. First, the KWin socket pin is a host behavior change riding along in a PR titled and described as macOS-client seams. It should be split into its own PR, or at minimum described in the body. Second, CI has no macOS/Swift job, so the Swift half here is verified only by your local run. A macOS Swift test job would close that.
| #[cfg(target_os = "linux")] | ||
| #[path = "display/linux/kwin.rs"] | ||
| mod kwin; | ||
| pub mod kwin; |
There was a problem hiding this comment.
| pub mod kwin; | |
| pub(crate) mod kwin; |
| #[cfg(target_os = "linux")] | ||
| ss_vdisplay::warm_socket(); |
There was a problem hiding this comment.
This is dead code. run_default_serve is Windows only, so the Linux-gated call inside it can never compile on any platform.
| #[cfg(target_os = "linux")] | |
| ss_vdisplay::warm_socket(); |
| if let Some(path) = pinned_socket() { | ||
| if let Ok(stream) = std::os::unix::net::UnixStream::connect(&path) { | ||
| if let Ok(conn) = Connection::from_socket(stream) { | ||
| return Ok(conn); | ||
| } | ||
| } | ||
| } let Some(path) = diagnostic_socket_path( |
There was a problem hiding this comment.
Log the diagnostic fallback like connect_kwin does. This also includes the fmt fix for line 1307, so it supersedes the earlier fmt suggestion there.
| if let Some(path) = pinned_socket() { | |
| if let Ok(stream) = std::os::unix::net::UnixStream::connect(&path) { | |
| if let Ok(conn) = Connection::from_socket(stream) { | |
| return Ok(conn); | |
| } | |
| } | |
| } let Some(path) = diagnostic_socket_path( | |
| if let Some(path) = pinned_socket() { | |
| match std::os::unix::net::UnixStream::connect(&path) | |
| .ok() | |
| .and_then(|stream| Connection::from_socket(stream).ok()) | |
| { | |
| Some(conn) => return Ok(conn), | |
| None => tracing::warn!(path = %path.display(), | |
| "KWin Wayland: pinned socket unusable for diagnostics - falling back"), | |
| } | |
| } | |
| let Some(path) = diagnostic_socket_path( |
| let rawFP = txt["fp"]?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | ||
| self.fingerprintHex = rawFP.isEmpty ? nil : rawFP.lowercased() | ||
|
|
||
| self.pairingPolicy = HostPairingPolicy(rawValue: txt["pair"] ?? "") ?? .unspecified |
There was a problem hiding this comment.
| self.pairingPolicy = HostPairingPolicy(rawValue: txt["pair"] ?? "") ?? .unspecified | |
| let pairValue = txt["pair"]?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | |
| self.pairingPolicy = HostPairingPolicy(rawValue: pairValue) ?? .unspecified |
|
Closing this as superseded by #80. I could not push to your fork, so I rebased the macOS seams commit onto main after #79 and applied the review fixes here instead: the pair TXT trim with a test. The KWin pin that rode along in this PR is now in main via #79, so #80 is only the macOS seams. Your commit is the base and you are still the author. Thanks for the PR. |
What
Two testable seams for the macOS client:
HostAdvert(discovery TXT -> host policy, fail-closed) andConnectOutcome(the explicit admission matrix for connect attempts).Why
Both pieces of policy were previously buried in view code, so neither could be tested without a live host. That is why the client had broad UI coverage but nothing pinning down what it does with a malformed advert, or which admission states are terminal.
Making them explicit also fixed a real behaviour question: what should happen when a host's TXT record is unparseable.
HostAdvertnow fails closed rather than guessing a permissive default.How
HostAdvertmaps the discovery TXT record to a host policy; anything it cannot parse yields "do not use this host", not a permissive fallback.ConnectOutcomeis the admission matrix, so every connect result has a name and the UI no longer infers terminality from strings.HostDiscoveryandSessionModelwere rewired to consume both, which is the only reason the diff touches them.Evidence
Verified on the Mac: 205 tests pass, 20 of them new, and discovery over
_slipstream._udpon port 9777 is confirmed against the real host.Live acceptance on the same build against the nixos host delivered video at 89-106 fps with e2e p50 6-9.7 ms and
lost=0over a 51-second run.Follow-up (not in this PR)
The app still mints a fresh client identity on each launch, so every relaunch is parked as an unpaired device and needs re-approval. That is a separate defect with its own fix.