From d08fb1b60dd94da1c45ad7f46a277bbf9a42db2d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 00:10:02 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m0/nightly/qmux-bench-peer.md Quest-Claim: d34ed5ad18c605fc From 5745f5a71ed7ad6e3f689e0fd9cef42af42ec816 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 00:17:16 -0800 Subject: [PATCH 2/3] fix(net): the qmux startup benchmark's fake peer accepts like a server The Bun server in js/net/bench/qmux.ts never sent QMux transport parameters, and the JS session's ready now waits for them, so Nightly's startup benchmark timed out. The server now accepts each upgraded socket with Session.accept, as a real server does, which sends them first. Also format-fix the bench file and replace findIndex with indexOf in the ring-buffer test, which biome rejects on main. Co-Authored-By: Claude Haiku 5.5 --- js/net/bench/qmux.ts | 50 +++++++++++++++++++++++--- js/watch/src/audio/ring-buffer.test.ts | 2 +- quest/m0/nightly/README.md | 1 - quest/m0/nightly/qmux-bench-peer.md | 23 ------------ 4 files changed, 47 insertions(+), 29 deletions(-) delete mode 100644 quest/m0/nightly/qmux-bench-peer.md diff --git a/js/net/bench/qmux.ts b/js/net/bench/qmux.ts index f9b08490b63..42f8de4065e 100644 --- a/js/net/bench/qmux.ts +++ b/js/net/bench/qmux.ts @@ -1,9 +1,17 @@ /** Compare eager and cold lazy fallback startup with real WebSocket negotiation. */ import { basename } from "node:path"; import { gzipSync } from "node:zlib"; -import { selectSubprotocol } from "@moq/qmux"; +import { Session, selectSubprotocol, type WebSocketStreamCloseEvent, type WebSocketStreamCloseInfo } from "@moq/qmux"; import { type Browser, chromium } from "playwright"; +/** Per-connection state from the upgrade; `open` attaches the frame feed. */ +interface Peer { + url: string; + protocol: string; + closed: PromiseWithResolvers; + incoming?: ReadableStreamDefaultController; +} + const build = await Bun.build({ entrypoints: [`${import.meta.dir}/qmux-eager.ts`, `${import.meta.dir}/qmux-lazy.ts`], target: "browser", @@ -16,14 +24,15 @@ const files = new Map( build.outputs.map(async (file) => [basename(file.path), gzipSync(await file.arrayBuffer())] as const), ), ); -const server = Bun.serve({ +const server = Bun.serve({ port: 0, fetch(request, server) { const path = new URL(request.url).pathname; if (path === "/qmux") { const protocol = selectSubprotocol(request.headers.get("Sec-WebSocket-Protocol"), {}); if (!protocol) return new Response("unsupported QMux protocol", { status: 400 }); - if (server.upgrade(request, { headers: { "Sec-WebSocket-Protocol": protocol } })) return; + const data: Peer = { url: request.url, protocol, closed: Promise.withResolvers() }; + if (server.upgrade(request, { data, headers: { "Sec-WebSocket-Protocol": protocol } })) return; return new Response("upgrade required", { status: 400 }); } const code = files.get(path.slice(1)); @@ -34,7 +43,40 @@ const server = Bun.serve({ headers: { "Content-Type": "text/html" }, }); }, - websocket: { message() {} }, + websocket: { + // Accept the upgraded socket like a real server, so Session sends its transport parameters first. + open(ws) { + const peer = ws.data; + Session.accept({ + url: peer.url, + opened: Promise.resolve({ + protocol: peer.protocol, + extensions: "", + readable: new ReadableStream({ + start: (controller) => { + peer.incoming = controller; + }, + }), + writable: new WritableStream({ + write: (bytes) => { + ws.send(bytes); + }, + }), + }), + closed: peer.closed.promise, + close: (info?: WebSocketStreamCloseInfo) => ws.close(info?.closeCode, info?.reason), + }); + }, + message(ws, message) { + if (typeof message === "string") throw new Error("QMux frames are binary"); + if (!ws.data.incoming) throw new Error("QMux frame before the socket opened"); + ws.data.incoming.enqueue(message); + }, + close(ws, code, reason) { + ws.data.incoming?.close(); + ws.data.closed.resolve({ closeCode: code, reason }); + }, + }, }); let browser: Browser | undefined; try { diff --git a/js/watch/src/audio/ring-buffer.test.ts b/js/watch/src/audio/ring-buffer.test.ts index 07ca8a3f2bc..6b4f951d6fb 100644 --- a/js/watch/src/audio/ring-buffer.test.ts +++ b/js/watch/src/audio/ring-buffer.test.ts @@ -1054,7 +1054,7 @@ describe("time stretch", () => { // The staged window plays out once, then the rest of the silence, then the utterance. const [output] = read(buffer, frames(100), 1); expect(output.length).toBe(frames(100)); - const silence = output.findIndex((sample) => sample === 0); + const silence = output.indexOf(0); expect(silence).toBe(staged); expect(output.slice(silence).every((sample) => sample === 0 || sample === 0.5)).toBe(true); expect(output.at(-1)).toBe(0.5); diff --git a/quest/m0/nightly/README.md b/quest/m0/nightly/README.md index 3a82a9d0589..2bfe1c3e8ae 100644 --- a/quest/m0/nightly/README.md +++ b/quest/m0/nightly/README.md @@ -51,7 +51,6 @@ near the paired threshold (re-check if one repeats), a one-off ## Required - [Nightly's macOS platform job passes](/quest/m0/nightly/macos.md) - `moq-audio`'s tests compile on macOS again and the websocket version test's timeout is fixed if it recurs -- [The qmux startup benchmark's fake peer sends transport parameters](/quest/m0/nightly/qmux-bench-peer.md) - Audio quality's WebSocket startup step stops timing out - [The moq-net session bench completes moq-transport-22 at 16 broadcasts](/quest/m0/nightly/session-bench-handshake.md) - the bench workload stops panicking on a handshake timeout - [Bisect the moq-audio bus and moq-mux parameter_sets regressions](/quest/m0/nightly/bench-regressions.md) - two real benchmark regressions are explained and fixed or accepted - [Moxygen conformance cells pass again](/quest/m0/nightly/moxygen-conformance.md) - the first-object signal and integer extensions survive, or moxygen's divergence is skipped with an upstream link diff --git a/quest/m0/nightly/qmux-bench-peer.md b/quest/m0/nightly/qmux-bench-peer.md deleted file mode 100644 index e77df5d870d..00000000000 --- a/quest/m0/nightly/qmux-bench-peer.md +++ /dev/null @@ -1,23 +0,0 @@ -# [XS] The qmux startup benchmark's fake peer sends transport parameters - -## Goal - -Nightly's Audio quality job passes its "WebSocket fallback startup benchmark" -step: `just js qmux-bench` completes instead of failing with -`error: evaluate: Error: handshake timeout`. - -## Plan - -Planned 2026-11-09 (maintainer, /quest-complete from the triage of Nightly -runs [42377867523](https://github.com/moq-dev/moq/actions/runs/42377867523) -and [42487375545](https://github.com/moq-dev/moq/actions/runs/42487375545)). -Failed both nights. - -The Bun server in `js/net/bench/qmux.ts` never sends QMux transport -parameters, and the JS session now waits for them before it opens. -[moq-dev/moq#8290](https://github.com/moq-dev/moq/pull/8290) fixes the same -fake-peer handshake in `js/qmux/bench/datagrams.ts`, but Nightly runs the -`js/net` copy. Make the fake peer send them the way the real server does, -ideally through the same helper as `datagrams.ts` so the two cannot drift. - -Public API: none. Wire: none. From 9caf21d0960a2186a09c305916c666638e8ea170 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 9 Nov 2026 09:48:16 -0800 Subject: [PATCH 3/3] fix(net): the qmux bench's fake peer logs session failures and closes on text frames Log the accepted session's close, so a server-side handshake timeout shows up in the bench output instead of a generic socket close. Close with 1003 on a text frame instead of throwing from the Bun handler; QMux is binary-only. Drop the ring-buffer lint change: biome reports useIndexOf as info on main and exits 0, so it does not block just check. Co-Authored-By: Claude Haiku 5.5 --- js/net/bench/qmux.ts | 10 ++++++++-- js/watch/src/audio/ring-buffer.test.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/js/net/bench/qmux.ts b/js/net/bench/qmux.ts index 42f8de4065e..2c1b92bdca5 100644 --- a/js/net/bench/qmux.ts +++ b/js/net/bench/qmux.ts @@ -47,7 +47,7 @@ const server = Bun.serve({ // Accept the upgraded socket like a real server, so Session sends its transport parameters first. open(ws) { const peer = ws.data; - Session.accept({ + const session = Session.accept({ url: peer.url, opened: Promise.resolve({ protocol: peer.protocol, @@ -66,9 +66,15 @@ const server = Bun.serve({ closed: peer.closed.promise, close: (info?: WebSocketStreamCloseInfo) => ws.close(info?.closeCode, info?.reason), }); + // The client only sees the socket close, so log the server-side cause, such as a handshake timeout. + session.closed.catch((err: unknown) => console.error("qmux fake peer:", err)); }, message(ws, message) { - if (typeof message === "string") throw new Error("QMux frames are binary"); + // QMux is binary-only. Close rather than throw, so the session ends with the close. + if (typeof message === "string") { + ws.close(1003, "QMux frames are binary"); + return; + } if (!ws.data.incoming) throw new Error("QMux frame before the socket opened"); ws.data.incoming.enqueue(message); }, diff --git a/js/watch/src/audio/ring-buffer.test.ts b/js/watch/src/audio/ring-buffer.test.ts index 6b4f951d6fb..07ca8a3f2bc 100644 --- a/js/watch/src/audio/ring-buffer.test.ts +++ b/js/watch/src/audio/ring-buffer.test.ts @@ -1054,7 +1054,7 @@ describe("time stretch", () => { // The staged window plays out once, then the rest of the silence, then the utterance. const [output] = read(buffer, frames(100), 1); expect(output.length).toBe(frames(100)); - const silence = output.indexOf(0); + const silence = output.findIndex((sample) => sample === 0); expect(silence).toBe(staged); expect(output.slice(silence).every((sample) => sample === 0 || sample === 0.5)).toBe(true); expect(output.at(-1)).toBe(0.5);