Skip to content

feat(macos-client): HostAdvert and ConnectOutcome seams - #78

Closed
KooshaPari wants to merge 2 commits into
vindeckyy:mainfrom
KooshaPari:feat/mac-client-seams
Closed

KooshaPari wants to merge 2 commits into
vindeckyy:mainfrom
KooshaPari:feat/mac-client-seams

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Two testable seams for the macOS client: HostAdvert (discovery TXT -> host policy, fail-closed) and ConnectOutcome (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. HostAdvert now fails closed rather than guessing a permissive default.

How

  • HostAdvert maps the discovery TXT record to a host policy; anything it cannot parse yields "do not use this host", not a permissive fallback.
  • ConnectOutcome is the admission matrix, so every connect result has a name and the UI no longer infers terminality from strings.
  • HostDiscovery and SessionModel were 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._udp on 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=0 over 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.


Devin Review

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)
Copilot AI balanced review requested due to automatic review settings November 16, 2026 13:18
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e0760a1-7f52-442b-bbf4-33389f8fef12
Commits

Reviewing files that changed from the base of the PR and between 93f083d and c14b845.

Files selected for processing: 9

  • clients/apple/Sources/SlipstreamClient/Session/SessionModel.swift
  • clients/apple/Sources/SlipstreamKit/Connection/ConnectOutcome.swift
  • clients/apple/Sources/SlipstreamKit/Connection/HostAdvert.swift
  • clients/apple/Sources/SlipstreamKit/Connection/HostDiscovery.swift
  • clients/apple/Tests/SlipstreamKitTests/ConnectOutcomeTests.swift
  • clients/apple/Tests/SlipstreamKitTests/HostAdvertTests.swift
  • crates/slipstream-host/src/main.rs
  • crates/ss-vdisplay/src/display/linux/kwin.rs
  • crates/ss-vdisplay/src/lib.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@KooshaPari
KooshaPari marked this pull request as draft November 16, 2026 13:19

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

/// 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() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
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() {

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@vindeckyy vindeckyy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two fmt diffs are failing CI. Applying these clears cargo fmt --all --check.

Comment on lines +380 to +381
ss_vdisplay::warm_socket();
gamestream::serve(mgmt_opts, native, gamestream)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} let Some(path) = diagnostic_socket_path(
}
let Some(path) = diagnostic_socket_path(

@vindeckyy vindeckyy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub mod kwin;
pub(crate) mod kwin;

Comment on lines +721 to +722
#[cfg(target_os = "linux")]
ss_vdisplay::warm_socket();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code. run_default_serve is Windows only, so the Linux-gated call inside it can never compile on any platform.

Suggested change
#[cfg(target_os = "linux")]
ss_vdisplay::warm_socket();

Comment on lines +1301 to +1307
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(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.pairingPolicy = HostPairingPolicy(rawValue: txt["pair"] ?? "") ?? .unspecified
let pairValue = txt["pair"]?.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
self.pairingPolicy = HostPairingPolicy(rawValue: pairValue) ?? .unspecified

@vindeckyy

Copy link
Copy Markdown
Owner

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.

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.

3 participants