From 3ff1d3f7f80adc89e6978062358ea13f8c65813f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 07:39:12 -0700 Subject: [PATCH 1/5] chore(quest): claim quest/m2/malformed-track-status.md Quest-Claim: ff3fa3d1c2467b82 From 3cce09f61b768bcce1799b7c5e854b5bf9ecb54a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 07:52:09 -0700 Subject: [PATCH 2/5] fix(net): say MALFORMED_TRACK downstream when a relay aborts a malformed track A relay that aborts a track as malformed, such as a timed object without a Timestamp, ended each downstream subscription with PUBLISH_DONE INTERNAL_ERROR, which bindings reported as Internal. Drafts 18 and 22 both register PUBLISH_DONE MALFORMED_TRACK (0x12), the same value as the stream reset code, so Rust and JS publishers now send it and subscribers read it back as the stream's MalformedTrack code, which moq-ffi and moq-c already name. Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/join.test.ts | 15 +++++++++++++ js/net/src/ietf/publish.ts | 2 ++ js/net/src/ietf/publisher.test.ts | 4 +++- js/net/src/ietf/publisher.ts | 18 ++++++++++------ js/net/src/ietf/subscriber.ts | 7 ++++++ quest/m2/README.md | 1 - quest/m2/malformed-track-status.md | 27 ------------------------ rs/moq-c/src/error.rs | 14 ++++++++++++ rs/moq-ffi/src/error.rs | 15 +++++++++++++ rs/moq-net/src/ietf/publish.rs | 17 ++++++++++++++- rs/moq-net/src/ietf/publisher.rs | 34 ++++++++++++++++++++++++++++++ 11 files changed, 118 insertions(+), 36 deletions(-) delete mode 100644 quest/m2/malformed-track-status.md diff --git a/js/net/src/ietf/join.test.ts b/js/net/src/ietf/join.test.ts index 075412d14f8..8877c98d9dc 100644 --- a/js/net/src/ietf/join.test.ts +++ b/js/net/src/ietf/join.test.ts @@ -1,5 +1,6 @@ import { expect, jest, onTestFinished, test } from "bun:test"; import * as Connection from "../connection/index.ts"; +import { StreamCode } from "../error.ts"; import { GRACE } from "../ledger.ts"; import { createMockTransportPair, textFrame } from "../mock.ts"; import { Producer as OriginProducer } from "../origin.ts"; @@ -332,6 +333,20 @@ test("SUBSCRIPTION_ENDED cancels a head nothing claimed", async () => { await expect(frames(group)).rejects.toThrow(); }); +test("MALFORMED_TRACK fails the track as malformed, not as a relay bug", async () => { + const { consumer, fetching, peer } = await join(); + await accept(fetching); + + await peer.writer.u53(PublishDone.id); + const done = new PublishDone({ + statusCode: PublishDoneStatus.MALFORMED_TRACK, + streamCount: 0n, + reasonPhrase: "malformed track", + }); + await done.encode(peer.writer, VERSION); + expect(await consumer.closed).toMatchObject({ code: StreamCode.MalformedTrack }); +}); + test("a whole group that precedes the head wins the sequence", async () => { const { subscriber, consumer, fetching, fetch } = await join(); if (!fetch) throw new Error("no fetch"); diff --git a/js/net/src/ietf/publish.ts b/js/net/src/ietf/publish.ts index a89a33968e1..1196aa22431 100644 --- a/js/net/src/ietf/publish.ts +++ b/js/net/src/ietf/publish.ts @@ -127,6 +127,8 @@ export const PublishDoneStatus = { /** Unassigned in draft-22. */ SUBSCRIPTION_ENDED: 0x3, UPDATE_FAILED: 0x8, + /** A relay found the track malformed, so it ended every subscription to it. */ + MALFORMED_TRACK: 0x12, } as const; /** diff --git a/js/net/src/ietf/publisher.test.ts b/js/net/src/ietf/publisher.test.ts index 3b5524fbe42..95ae86dc6f3 100644 --- a/js/net/src/ietf/publisher.test.ts +++ b/js/net/src/ietf/publisher.test.ts @@ -4,7 +4,7 @@ import { Signal } from "@moq/signals"; import type { Credential, Grant } from "../auth.ts"; import { Producer as BroadcastProducer } from "../broadcast.ts"; import * as Epoch from "../epoch.ts"; -import { error, ProtocolViolation, SessionCode, SessionError, StreamCode, unauthorized } from "../error.ts"; +import { error, ProtocolViolation, SessionCode, SessionError, StreamCode, Stream as StreamError, unauthorized } from "../error.ts"; import { MAX_GROUP_FRAMES } from "../group.ts"; import { type Hop, HopSchema } from "../hop.ts"; import { hooks } from "../internal.ts"; @@ -2276,6 +2276,8 @@ test("subscription completion sends PUBLISH_DONE on every supported draft", asyn [new Error("failed"), 0x0], [unauthorized("test"), 0x1], [new SessionError(SessionCode.Expired), 0x1], + // So does a malformed upstream: MALFORMED_TRACK, so the subscriber can tell it from a bug here. + [new StreamError(StreamCode.MalformedTrack), 0x12], ] as const) { const pair = createMockTransportPair(ALPN.DRAFT_18); const session = new NativeSession(pair.server, version, true); diff --git a/js/net/src/ietf/publisher.ts b/js/net/src/ietf/publisher.ts index fe8eaa09b9a..3a087d7ad82 100644 --- a/js/net/src/ietf/publisher.ts +++ b/js/net/src/ietf/publisher.ts @@ -1103,23 +1103,29 @@ export class Publisher { // PUBLISH_DONE is required for every supported draft. The peer may have already // closed its side to unsubscribe, in which case there is nowhere to send it. const updateFailed = publishError instanceof UpdateFailed; + // A malformed upstream, such as a moq-lite MALFORMED_TRACK reset, is passed on as one. + const malformed = publishError instanceof StreamError && publishError.code === StreamCode.MalformedTrack; try { const done = new PublishDone({ statusCode: unauthorized ? PublishDoneStatus.UNAUTHORIZED : updateFailed ? PublishDoneStatus.UPDATE_FAILED - : publishError - ? PublishDoneStatus.INTERNAL_ERROR - : PublishDoneStatus.TRACK_ENDED, + : malformed + ? PublishDoneStatus.MALFORMED_TRACK + : publishError + ? PublishDoneStatus.INTERNAL_ERROR + : PublishDoneStatus.TRACK_ENDED, streamCount: BigInt(streams.opened), reasonPhrase: unauthorized ? "not granted" : updateFailed ? "update failed" - : publishError - ? "internal error" - : "track ended", + : malformed + ? "malformed track" + : publishError + ? "internal error" + : "track ended", }); await Message.write(request.writer, PublishDone.id, done, version); } catch { diff --git a/js/net/src/ietf/subscriber.ts b/js/net/src/ietf/subscriber.ts index 02e467391d2..e47c7a26304 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -1039,6 +1039,13 @@ export class Subscriber { const done = await PublishDone.decode(framed.reader, version); // A revocation reads the same as one from a moq-lite peer. if (done.statusCode === PublishDoneStatus.UNAUTHORIZED) throw unauthorized(broadcast); + // The peer's code, as a moq-lite MALFORMED_TRACK reset reads, so a consumer can tell a + // malformed upstream apart from a relay bug. + if (done.statusCode === PublishDoneStatus.MALFORMED_TRACK) { + throw new StreamError(StreamCode.MalformedTrack, { + message: `publish done: malformed track reason=${done.reasonPhrase}`, + }); + } if (!publishDoneClean(done.statusCode, version)) { throw new Error(`publish done: status=0x${done.statusCode.toString(16)} reason=${done.reasonPhrase}`); } diff --git a/quest/m2/README.md b/quest/m2/README.md index 4f4f2452b0a..3d377787c3d 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -260,7 +260,6 @@ lite-07; bitrate enforcement is not part of this release. - [Tenant matrix on both runtimes](/quest/m2/tenant-matrix.md) - tenant, mount, HTTP, normalization, and revalidation boundaries are tested on Tokio and io_uring - [One typed SETUP parse](/quest/m2/setup-parse-once.md) - one function replaces three SETUP parameter parses - [Archive reads against a real store](/quest/m2/archive-store-bench.md) - LIST/GET counts and latency over track count -- [A malformed track says so downstream](/quest/m2/malformed-track-status.md) - subscribers and bindings see a malformed track, not INTERNAL_ERROR - [Branch checks lint examples](/quest/m2/lint-examples.md) - `just check` runs clippy on the selected crates' examples - [Drop kio's epoch fence](/quest/m2/crossbeam-pin-fence.md) - waiting on crossbeam#1352, then the `Read::drop` fence goes - [A cancelled miss stops waiting](/quest/m2/fill-wait-cancel-test.md) - a test proves a relay miss waiting on its own fill ends when no reader wants it diff --git a/quest/m2/malformed-track-status.md b/quest/m2/malformed-track-status.md deleted file mode 100644 index 40e65a96fd9..00000000000 --- a/quest/m2/malformed-track-status.md +++ /dev/null @@ -1,27 +0,0 @@ -# [S] A malformed track says so downstream - -## Goal - -When a relay aborts a track as malformed, such as a timed object without a -timestamp, every downstream subscriber learns that the track was malformed: -a specific status on moq-transport and lite, a distinct error in moq-net and -JS, and a distinct `MoqError` in the bindings. Today it ends as -`INTERNAL_ERROR` (0x0), which the bindings report as `MoqError.Internal`. - -## Plan - -Found 2026-10-28 while fixing [moq-dev/moq#7135](https://github.com/moq-dev/moq/pull/7135): -the relay aborted a JS publisher's track as malformed and every viewer saw -`Internal`, which hid the cause. - -Decided 2026-10-28 (maintainer): m2, a diagnostics improvement rather than a -correctness bug. - -- Check draft 22 (and 18) for an existing status or error code that fits a - malformed track before adding one. If none exists, decide whether lite-07 - and our IETF profile need a new code, and record the decision. -- Carry it through moq-net's error type, js/net, moq-ffi, moq-c and the - wrappers, so an app can tell a malformed upstream apart from a relay bug. - -Public API: likely a new error variant in each binding. Wire: possibly a new -status code. diff --git a/rs/moq-c/src/error.rs b/rs/moq-c/src/error.rs index 1ce0953575c..067e5229226 100644 --- a/rs/moq-c/src/error.rs +++ b/rs/moq-c/src/error.rs @@ -585,4 +585,18 @@ mod tests { super::moq_protocol_kind::MOQ_PROTOCOL_KIND_TOO_MANY_REQUESTS as u32 ); } + + /// A relay that found its upstream malformed says so, apart from a relay bug's INTERNAL_ERROR. + #[test] + fn received_malformed_track_keeps_its_kind() { + let error = super::Error::Moq(moq_net::StreamError::MalformedTrack.into()) + .protocol() + .expect("a stream code"); + assert_eq!(error.scope, super::moq_error_scope::MOQ_ERROR_SCOPE_STREAM as u32); + assert_eq!(error.code, 0x12); + assert_eq!( + error.kind, + super::moq_protocol_kind::MOQ_PROTOCOL_KIND_MALFORMED_TRACK as u32 + ); + } } diff --git a/rs/moq-ffi/src/error.rs b/rs/moq-ffi/src/error.rs index e6128d24710..bd4fb6c89ef 100644 --- a/rs/moq-ffi/src/error.rs +++ b/rs/moq-ffi/src/error.rs @@ -694,6 +694,21 @@ mod tests { } } + /// A relay that found its upstream malformed says so, and a binding can tell that + /// apart from a relay bug's INTERNAL_ERROR. + #[test] + fn stream_malformed_track_keeps_its_kind() { + let err = MoqError::from(moq_net::Error::from(moq_net::StreamError::MalformedTrack)); + match err { + MoqError::Protocol { details: protocol } => { + assert_eq!(protocol.scope, MoqErrorScope::Stream); + assert_eq!(protocol.code, 0x12); + assert_eq!(protocol.kind, MoqProtocolKind::MalformedTrack); + } + other => panic!("expected Protocol, got {other}"), + } + } + #[test] fn stream_app_code_is_verbatim() { let err = MoqError::from(moq_net::Error::from(moq_net::StreamError::App(7))); diff --git a/rs/moq-net/src/ietf/publish.rs b/rs/moq-net/src/ietf/publish.rs index c63e29efb13..47456a277da 100644 --- a/rs/moq-net/src/ietf/publish.rs +++ b/rs/moq-net/src/ietf/publish.rs @@ -129,6 +129,8 @@ pub(crate) enum PublishDoneStatus { TrackEnded, /// A requested subscription update could not be applied. UpdateFailed, + /// A relay found the track malformed, so it ended every subscription to it. + MalformedTrack, } impl PublishDoneStatus { @@ -140,6 +142,7 @@ impl PublishDoneStatus { Self::Unauthorized => 0x1, Self::TrackEnded => 0x2, Self::UpdateFailed => 0x8, + Self::MalformedTrack => 0x12, } } } @@ -169,6 +172,10 @@ impl PublishDone<'_> { match self.status_code { code if code == PublishDoneStatus::TrackEnded.code() => Ok(()), code if code == PublishDoneStatus::Unauthorized.code() => Err(crate::Error::Unauthorized), + // The peer's code, as a moq-lite MALFORMED_TRACK reset reads, so bindings name it. + code if code == PublishDoneStatus::MalformedTrack.code() => { + Err(crate::Error::Stream(crate::StreamError::MalformedTrack)) + } // SUBSCRIPTION_ENDED: the subscription reached the end its filter asked for. // Draft-22 removed it and left 0x3 unassigned. 0x3 if matches!(version, Version::Draft18) => Ok(()), @@ -475,10 +482,11 @@ mod tests { #[test] fn test_publish_done_registered_statuses_all_versions() { - for version in [Version::Draft18] { + for version in [Version::Draft18, Version::Draft22] { for (status, expected) in [ (PublishDoneStatus::InternalError, 0x0), (PublishDoneStatus::TrackEnded, 0x2), + (PublishDoneStatus::MalformedTrack, 0x12), ] { assert_eq!(status.code(), expected); @@ -517,6 +525,13 @@ mod tests { matches!(done(0x0).end(version), Err(crate::Error::Remote(0x0))), "{version:?}" ); + assert!( + matches!( + done(0x12).end(version), + Err(crate::Error::Stream(crate::StreamError::MalformedTrack)) + ), + "{version:?}" + ); } // SUBSCRIPTION_ENDED is clean until draft-22 unassigned it. diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index e1e2dcd18b6..988b9741092 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -691,6 +691,11 @@ impl Served { Self::Track(Err(Error::Expired | Error::Session(crate::SessionError::Expired))) => { (ietf::PublishDoneStatus::Unauthorized, "token expired") } + // The code its group streams reset with, so a relay passes a malformed upstream on + // rather than hiding it behind INTERNAL_ERROR. + Self::Track(Err(err)) if crate::StreamError::from(err) == crate::StreamError::MalformedTrack => { + (ietf::PublishDoneStatus::MalformedTrack, "malformed track") + } Self::Track(Err(_)) => (ietf::PublishDoneStatus::InternalError, "internal error"), Self::UpdateFailed(_) => (ietf::PublishDoneStatus::UpdateFailed, "update failed"), // Pausing ends no subscription, so nothing reports it. @@ -7342,6 +7347,35 @@ mod serve_tests { drop(group); } + /// A track aborted as malformed, as a relay does over an upstream's unstamped object on a + /// timed track, ends each subscription with PUBLISH_DONE(MALFORMED_TRACK), on either draft. + /// A moq-lite or JS upstream's MALFORMED_TRACK reset says the same. + #[moq_clock::test] + async fn publish_done_after_a_malformed_track_says_so() { + for version in [Version::Draft18, Version::Draft22] { + for err in [Error::MalformedTrack, Error::Stream(crate::StreamError::MalformedTrack)] { + let h = serve(version); + let stream = Stream::open(&mut crate::driver::Transport::new(h.session.clone()), version) + .await + .unwrap(); + let msg = subscribe(Filter::NextObject, None); + let mut serve = std::pin::pin!(h.publisher.clone().run_subscribe_stream(stream, msg)); + serve_until(serve.as_mut(), "SUBSCRIBE_OK was sent", || !h.log.trail().is_empty()).await; + + h.track.abort(err.clone()).unwrap(); + moq_clock::timeout(std::time::Duration::from_secs(10), serve) + .await + .expect("the malformed track ends the subscription") + .ok(); + + let (status, _) = Wire::read(&h.log, version) + .publish_done + .expect("PUBLISH_DONE was sent"); + assert_eq!(status, 0x12, "{version:?} {err:?}"); + } + } + } + /// A subscription that runs to the track's end counts every data stream it opened, /// the fill and the END_OF_TRACK marker included, and closes each one before /// PUBLISH_DONE(TRACK_ENDED). From 9eca8862e784b4b52fd3ecbb025a516d845ca727 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 08:38:21 -0700 Subject: [PATCH 3/5] style: format the malformed-track tests Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/publisher.test.ts | 10 +++++++++- rs/moq-net/src/ietf/publisher.rs | 4 +--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/js/net/src/ietf/publisher.test.ts b/js/net/src/ietf/publisher.test.ts index 95ae86dc6f3..60b1aac49fb 100644 --- a/js/net/src/ietf/publisher.test.ts +++ b/js/net/src/ietf/publisher.test.ts @@ -4,7 +4,15 @@ import { Signal } from "@moq/signals"; import type { Credential, Grant } from "../auth.ts"; import { Producer as BroadcastProducer } from "../broadcast.ts"; import * as Epoch from "../epoch.ts"; -import { error, ProtocolViolation, SessionCode, SessionError, StreamCode, Stream as StreamError, unauthorized } from "../error.ts"; +import { + error, + ProtocolViolation, + SessionCode, + SessionError, + StreamCode, + Stream as StreamError, + unauthorized, +} from "../error.ts"; import { MAX_GROUP_FRAMES } from "../group.ts"; import { type Hop, HopSchema } from "../hop.ts"; import { hooks } from "../internal.ts"; diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index 988b9741092..0c4790ceea9 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -7368,9 +7368,7 @@ mod serve_tests { .expect("the malformed track ends the subscription") .ok(); - let (status, _) = Wire::read(&h.log, version) - .publish_done - .expect("PUBLISH_DONE was sent"); + let (status, _) = Wire::read(&h.log, version).publish_done.expect("PUBLISH_DONE was sent"); assert_eq!(status, 0x12, "{version:?} {err:?}"); } } From 9a0c499995cdb4655fe218010cc41aeaad3077da Mon Sep 17 00:00:00 2001 From: quest fixer Date: Sat, 31 Oct 2026 15:45:47 -0700 Subject: [PATCH 4/5] docs(quest): drop completed malformed-track prerequisite --- quest/m2/publish-done-codes.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/quest/m2/publish-done-codes.md b/quest/m2/publish-done-codes.md index 78efe9abe11..270574e4d1c 100644 --- a/quest/m2/publish-done-codes.md +++ b/quest/m2/publish-done-codes.md @@ -11,7 +11,3 @@ Follow-up of [moq-dev/moq#7396](https://github.com/moq-dev/moq/pull/7396), which Decided 2026-10-30 (maintainer, follow-up planning after the /quest-afk run). Reuse #7396's path: the publisher picks the PUBLISH_DONE code from the same error-to-code mapping that resets the track's streams, and the subscriber reads it back as the peer's stream code. Cover drafts 18 and 22, both bindings, and JS, each test failing without its fix. Public API: none. Wire: existing registered codes only. - -## Required - -- [A malformed track says so downstream](/quest/m2/malformed-track-status.md) - its PR, #7396, adds the PUBLISH_DONE code path this extends From 6d787ddad6585bce806d48e743389d05e6dfe2d9 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 03:08:14 -0800 Subject: [PATCH 5/5] test(net): use kio's clock in the MALFORMED_TRACK relay test main moved moq-clock into kio (#7027); the test still named moq_clock. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/ietf/publisher.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rs/moq-net/src/ietf/publisher.rs b/rs/moq-net/src/ietf/publisher.rs index e6790fc7071..0796fc8e474 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -7477,7 +7477,7 @@ mod serve_tests { /// A track aborted as malformed, as a relay does over an upstream's unstamped object on a /// timed track, ends each subscription with PUBLISH_DONE(MALFORMED_TRACK), on either draft. /// A moq-lite or JS upstream's MALFORMED_TRACK reset says the same. - #[moq_clock::test] + #[kio::test] async fn publish_done_after_a_malformed_track_says_so() { for version in [Version::Draft18, Version::Draft22] { for err in [Error::MalformedTrack, Error::Stream(crate::StreamError::MalformedTrack)] { @@ -7490,7 +7490,7 @@ mod serve_tests { serve_until(serve.as_mut(), "SUBSCRIBE_OK was sent", || !h.log.trail().is_empty()).await; h.track.abort(err.clone()).unwrap(); - moq_clock::timeout(std::time::Duration::from_secs(10), serve) + kio::clock::timeout(std::time::Duration::from_secs(10), serve) .await .expect("the malformed track ends the subscription") .ok();