Skip to content

fix(host): stop the wire capture-grid drifting ahead at non-native refresh - #77

Merged
vindeckyy merged 1 commit into
vindeckyy:mainfrom
KooshaPari:fix/wire-grid-drift
Nov 16, 2026
Merged

vindeckyy merged 1 commit into
vindeckyy:mainfrom
KooshaPari:fix/wire-grid-drift

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Stop the host's wire capture timestamp from drifting into the future when a client asks for a refresh rate that differs from the compositor's actual rate.

Why

The host does not put the real capture stamp on the wire. It puts a steady-grid point, wire_grid_ns, advanced by one requested interval per submission, and re-seeds it only when it falls more than 2 * interval behind submit_ns. There is no correction when it runs ahead.

Frame-driven pacing iterates at the source arrival rate ("arrivals are the clock"), so a client asking for 60 Hz against a 144 Hz compositor advances the grid ~2.4x faster than wall clock and walks it into the future without bound. The behind-only guard can never observe a future grid, because submit_ns.saturating_sub(g) saturates to 0.

Measured on the live nixos host, 1080p requested 60 on a 144 Hz desktop:

session result
first 60 Hz attempt 0 frames, no 0xCF timing datagrams at all
second 60 Hz attempt 771 frames but only 8 timing samples, latency p95 = p99 = max = 454 ms
back to 144 Hz 1606 frames, 1605 timing samples, p50 8.5 ms

Three consecutive 144 Hz sessions were unaffected (1559 / 1598 / 1694 frames), which is why this never showed up in normal use.

This also explains a long-standing reporting oddity: the probe's xfer stage is a residual (host_us - (queue + encode + pace)), and host_us is measured against the grid while queue_us is measured against the real frame.pts_ns. The two agree only while the grid has not drifted, so a flat ~5.3 ms "xfer" at 144 Hz is an accounting gap, and at 60 Hz the same expression saturates to 0.

How

  • Extracted the grid policy into a pure WireGrid state machine.
  • Added a symmetric ahead re-seed, so the grid is corrected when it leads real capture as well as when it lags.
  • Added a min(grid, submit_ns) clamp on emit.
  • The 144-on-144 path is unchanged; that is asserted by a test, not argued.

Tests

Three new unit tests: native-rate identity, 60-on-144 drift, and the reverse mismatch.

cargo test -p slipstream-host --bins (the package has no lib target): 377 tests, 371 passed, 6 failed. All three new grid tests pass. The 6 failures are pre-existing platform-mismatch tests that assert Linux behaviour while running on Windows - library::art (x2), mgmt::compositors_lists_all_backends_with_flags, ops::store::sources::published_index_signature_verifies, session::gamelease::a_launch_always_gets_a_reference_instant_to_adopt_against, protocol::slipstream1::c_abi_connection_roundtrip - none in the touched code. cargo check -p slipstream-host exits 0.

Notes

Until this lands, the practical mitigation is to pin sessions to the desktop's real mode. Do not request 60 Hz against a 144 Hz desktop.


Devin Review

…fresh

The host does not put the real capture stamp on the wire. It puts a steady-grid
point, wire_grid_ns, advanced by one requested `interval` per submission. The
grid was re-seeded only when it fell more than 2 * interval BEHIND submit_ns;
there was no correction when it ran AHEAD.

Frame-driven pacing iterates at the SOURCE arrival rate, not the requested rate
("arrivals are the clock"), so a client asking for 60 Hz against a 144 Hz
compositor advanced the grid ~2.4x faster than wall clock and walked it into the
future without bound, where the behind-only guard can never observe it
(saturating_sub yields 0).

Measured on the live nixos host, 1080p requested 60 on a 144 Hz desktop:
  H1 first 60 Hz attempt: 0 frames, no 0xCF timing datagrams at all
  H2 second 60 Hz attempt: 771 frames but only 8 timing samples, latency
     p95 = p99 = max = 454 ms
  H3 back to 144 Hz: 1606 frames, 1605 timing samples, p50 8.5 ms
Consecutive 144 Hz sessions were unaffected (1559/1598/1694 frames).

Fix: extract the grid policy into a pure WireGrid with a symmetric ahead-reseed
and a min(grid, submit_ns) emit clamp. The 144-on-144 path is byte-identical;
that is asserted by a test rather than argued.

Tests: three unit tests added (native identity, 60-on-144 drift, reverse
mismatch). The crate cannot link on this Windows desk because the vendored
libopus CMake build fails, so the in-crate tests did not execute here; they were
executed out of tree with rustc, 4/4 pass, and the pre-fix grid was measured
drifting ~1.94 s ahead over 200 frames.

tx-agent:     jcode
tx-validated: none in-crate (audiopus_sys CMake failure on Windows); out-of-tree
              rustc harness 4/4 pass; rustfmt clean
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: 214e2961-40f6-4477-853e-ec0a285dba67
Commits

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

Files selected for processing: 1

  • crates/slipstream-host/src/protocol/slipstream1/stream.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: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@vindeckyy
vindeckyy marked this pull request as ready for review November 16, 2026 16:06
@vindeckyy
vindeckyy merged commit 3068fc6 into vindeckyy:main Nov 16, 2026
15 checks passed

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

Three nits from my review. The code is solid, these are all cosmetic. Since this is already merged they need applying by hand, not one click.

if let Some(g) = self.next_ns {
if g.saturating_sub(submit_ns) > interval_ns.saturating_mul(2) {
self.next_ns = Some(if plausible {
frame_pts_ns.min(submit_ns)

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
frame_pts_ns.min(submit_ns)
frame_pts_ns

/// This is the 60 Hz-requested-on-a-144 Hz-compositor case: the loop follows the *source* arrival
/// rate (frame-driven pacing) but advances the grid by the *requested* interval, so a slower
/// request on a faster source outruns wall clock by (requested/actual)x and would otherwise drift
/// into the future without bound - which the behind-only guard can never see.

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
/// into the future without bound - which the behind-only guard can never see.
/// into the future without bound - which the behind-only guard can never see.

repeat: bool,
interval_ns: u64,
) -> u64 {
let fresh = !repeat && plausible;

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 fresh = !repeat && plausible;
debug_assert!(interval_ns > 0, "a zero interval would trip both stall guards every submission");
let fresh = !repeat && plausible;

vindeckyy added a commit that referenced this pull request Nov 16, 2026
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