diff --git a/js/net/src/ietf/join.test.ts b/js/net/src/ietf/join.test.ts index 40da0f6e939..def2ff01ff9 100644 --- a/js/net/src/ietf/join.test.ts +++ b/js/net/src/ietf/join.test.ts @@ -1,6 +1,7 @@ import { expect, jest, onTestFinished, test } from "bun:test"; import { Elapsed, Instant, Milli, Nano, now, timeout } from "@moq/clock"; 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"; @@ -329,6 +330,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 748185dba30..351c4059667 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, unauthorized } from "../error.ts"; +import { + error, + ProtocolViolation, + SessionCode, + SessionError, + StreamCode, + Stream as StreamError, + unauthorized, +} from "../error.ts"; import { type Hop, HopSchema } from "../hop.ts"; import { hooks } from "../internal.ts"; import { createMockTransportPair, SessionBroadcast } from "../mock.ts"; @@ -2067,6 +2075,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 f38d06dd5b9..5e81c425442 100644 --- a/js/net/src/ietf/publisher.ts +++ b/js/net/src/ietf/publisher.ts @@ -1024,23 +1024,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 a7b0a8103a0..60b46de1242 100644 --- a/js/net/src/ietf/subscriber.ts +++ b/js/net/src/ietf/subscriber.ts @@ -986,6 +986,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 a5d1c4a376f..9bcf9e51893 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -220,7 +220,6 @@ lite-07; bitrate enforcement is not part of this release. - [Lint override and deprecation audit](/quest/m2/audit-lints.md) - repeat the suppression and deprecation audit after the release ships, starting with clippy on the macOS and Windows targets - [Tenant matrix on both runtimes](/quest/m2/tenant-matrix.md) - tenant, mount, HTTP, normalization, and revalidation boundaries are tested on Tokio and io_uring - [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/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 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 3a6a02e92e6..8299a70020d 100644 --- a/rs/moq-ffi/src/error.rs +++ b/rs/moq-ffi/src/error.rs @@ -692,6 +692,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 b5669f30158..a12748baf82 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 fe81f059c8a..7dc7a00f5db 100644 --- a/rs/moq-net/src/ietf/publisher.rs +++ b/rs/moq-net/src/ietf/publisher.rs @@ -736,6 +736,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(_) | Self::RenewalRefused(_) => (ietf::PublishDoneStatus::UpdateFailed, "update failed"), // Pausing ends no subscription, so nothing reports it. @@ -7365,6 +7370,33 @@ 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. + #[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)] { + 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(); + kio::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).