Skip to content

Constrain connected loopback fixture buffers - #786

Open
MorganHo001 wants to merge 1 commit into
sysprog21:mainfrom
MorganHo001:fix-loopback-backpressure-fixtures
Open

MorganHo001 wants to merge 1 commit into
sysprog21:mainfrom
MorganHo001:fix-loopback-backpressure-fixtures

Conversation

@MorganHo001

@MorganHo001 MorganHo001 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Measurements on macOS 27.2.1 (26B131) recorded SO_SNDBUF as 1024 before connect, 65328 after connect and 1024 after reapplying its limit. In the reported macOS 26.6.2 runs, small-buffer read-backs did not keep startup writes stalled. The startup ordering tests need an explicit pending-flush checkpoint instead of inferring persistent backpressure from a 100 ms pause.

Constrain and read back the connected sender, test the helper against a deliberately oversized connected buffer, and retain the end-to-end bound test. For startup ordering, hold a sink-owned audio flush at an explicit checkpoint and use three ordinary 10 ms PCM frames. These cases no longer depend on small TCP buffers or TCP_NODELAY. Keep genuine TCP handoff and large-message write-failure tests. Production networking is unchanged; deadline, receive-time, cancellation and audio-order assertions remain intact.

Validation

  • RUST_TEST_THREADS=1 ./scripts/test.sh rust passes at 0034ed6d on macOS 27.2.1 arm64 and Ubuntu ARM64. The library suite records 2,129 passes and 19 ignored cases; the web suite records 229 passes and two ignored cases. cargo-deny was unavailable.
  • Ubuntu's full Rust run includes all three face-detector cases without skips.
  • The startup group passes 53 tests. Removing queued-audio ownership, cancelled-buffer clearing or original receive-time handling makes the corresponding regression fail, with one case executed in each probe.
  • The deadline cases now require exact wire sequences: [0, 3] after successful rescue, [0] after failed startup, and [] without audio. A controlled fault that loses frame 0 passes the old assertion but fails the new one; restoring the writer ordering passes. The fault is not included in the commit.
  • The full browser and portable lanes were not rerun for this Rust-fixture revision.

A macOS 26.6.2 rerun remains outstanding. The linked review threads retain the original socket readings and Apple references; the published XNU snapshot differs from the measured kernel, so its exact mechanism remains unverified.

Close #780

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as outdated.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

@jserv

jserv commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

#767 is open, redesigns the interview setup and device preparation pages, and also carries this branch's loopback fixture changes unchanged: the post-connect set_send_buffer_size in src/gemini/socket/loopback.rs, set_nodelay in tests/unit/gemini/live_startup.rs, the connected-sender test in tests/unit/gemini/socket_loopback.rs and the STARTUP_PRESSURE_FRAMES workload in tests/unit/livekit/startup_media.rs. Neither thread links the other, so both would land the same edits. Please read the #767 diff and reply with how the two relate: fold the fixture change into one, rebase one on the other, or keep both with a sentence on why.

jserv

This comment was marked as outdated.

@jserv

jserv commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@MorganHo001 The head now has the connected-sender helper with its direct test, set_recv_buffer_size(4096) on the accepted sockets, and a 256-frame workload. The three open threads are still unanswered, and each is blocked on evidence, not code:

  • loopback.rs: the sw_vers output and the SO_SNDBUF value before connect, right after connect, and after the post-connect call, read with send_buffer_size() on the same stream, plus the Apple or XNU material the description rests on.
  • live_startup.rs: repeated runs of the two named tests on one macOS build with and without set_nodelay(true), with the yielded counts.
  • startup_media.rs: whether the original 200 frames hold now that the accepted socket is bounded. If 256 is still needed, the receive-buffer reading that requires it and the before and after Linux CI wall time of each affected test.

Post these as replies on the threads. If a reading does not reproduce the behavior, delete that call instead of keeping it. Please also make the PR title match the commit subject (the title-and-description check fails on it), and answer the #767 notice with which of the two PRs keeps this fixture change.

@MorganHo001 MorganHo001 changed the title Stabilize loopback backpressure fixtures Constrain connected loopback fixture buffers Nov 20, 2026
@MorganHo001
MorganHo001 force-pushed the fix-loopback-backpressure-fixtures branch from 0c9161c to 8f678af Compare November 20, 2026 06:29
@jserv

jserv commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Issue #780 reports that four LiveKit startup and handoff tests fail on macOS arm64 because the loopback fixture's small socket buffers do not produce the backpressure they assert, and its follow-up actions ask to measure and then fix the fixture. This branch bounds the connected sender after connect, reads the accepted receive limit after the WebSocket handshake, and scopes TCP_NODELAY to the startup fixture, which are the changes those tests need, but the description does not link the issue. If this branch is the fix #780 asks for, add Close #780 to the description so the issue closes with it, and say in a reply if any of the four tests it lists is still not covered.

Comment thread tests/unit/livekit/startup_media.rs Resolved
Comment thread tests/unit/gemini/live_startup.rs Resolved
@MorganHo001

Copy link
Copy Markdown
Contributor Author

All four tests listed in #780 pass on macOS 27.2.1 arm64 at 8f678af1: the startup group passes 53 tests, and the isolated listening-note handoff test passes. The issue's macOS 26.6.2 environment was not rerun.

@MorganHo001
MorganHo001 force-pushed the fix-loopback-backpressure-fixtures branch from 8f678af to 17d2f21 Compare November 21, 2026 11:53
jserv

This comment was marked as resolved.

@MorganHo001
MorganHo001 force-pushed the fix-loopback-backpressure-fixtures branch from 17d2f21 to 625636e Compare November 21, 2026 15:57
jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

The measured macOS socket replaces the requested send buffer during
connect. A brief pause in small writes also fails to establish sustained
pressure across macOS versions, making the startup fixtures unstable.

Reapply and verify the connected sender limit. Hold a sink-owned startup
audio flush explicitly for cancellation and receive-time checks without
altering production writes. Keep the real large-message write-failure
case and the connected-buffer regressions. Remove fixture TCP_NODELAY;
the controlled flush no longer relies on packet timing.

Close sysprog21#780

Change-Id: I0ef6a814f871e26e266337613364539d0208330d
@MorganHo001
MorganHo001 force-pushed the fix-loopback-backpressure-fixtures branch from 625636e to 0034ed6 Compare November 22, 2026 23:25

@AchlysChang AchlysChang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both points from my earlier review are resolved at 0034ed6, verified on the macOS 26.6.2 host that reproduced #780: set_nodelay is removed, the delayed-write test now passes 10/10 (base 6/10), and all four #780 tests pass, with livekit::tests::startup at 53/53 over 5 runs.

@ColtenOuO ColtenOuO added the ready for maintainer review The pull request ready for maintainer review. label Nov 23, 2026
@github-actions github-actions Bot removed the ready for maintainer review The pull request ready for maintainer review. label Nov 23, 2026
Comment on lines +467 to +469
writing
.try_recv()
.expect("the sink owns the paused audio write");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The checkpoint is inferred from a 100 ms timer here: the frames go in at 80% of the 1 s limit, and the select! above returns at 90% whether or not the probe has consumed them. After a stall that long on a loaded runner both arms are ready, and select! polls its arms in random order, so the sleep arm can win before the probe has run. Then try_recv() finds entered unsent and panics with "the sink owns the paused audio write", or the blocked == 1 assertion below fails at 0, with the implementation correct. Awaiting the checkpoint removes the dependence: when backpressure is set, await writing under a generous safety timeout right after the frames are sent, and keep the 90% wait only for the deadline-sensitive part. The same try_recv() in startup_success_after_a_delayed_microphone_write_keeps_the_receive_time deserves a look for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Four LiveKit startup and handoff tests fail on macOS 26.6 arm64

4 participants