Update MOQT FETCH to draft-12.

Mostly, fields are just renamed, but the encoding of FETCH_OK End Location did change. Also changed some internal FETCH APIs to avoid an optional for end_object, instead just setting it to kMaxObjectId if the subscriber wants the whole group.

Also the interface between Joining Fetch processing and the Publisher was fatally broken. Joining Fetch must be forwarded upstream as-is, not with a priori knowledge of Largest Location.

PiperOrigin-RevId: 791399297
diff --git a/quiche/quic/moqt/moqt_framer.cc b/quiche/quic/moqt/moqt_framer.cc
index 6f0d6ab..d647785 100644
--- a/quiche/quic/moqt/moqt_framer.cc
+++ b/quiche/quic/moqt/moqt_framer.cc
@@ -642,10 +642,7 @@
   if (std::holds_alternative<StandaloneFetch>(message.fetch)) {
     const StandaloneFetch& standalone_fetch =
         std::get<StandaloneFetch>(message.fetch);
-    if (standalone_fetch.end_group < standalone_fetch.start_object.group ||
-        (standalone_fetch.end_group == standalone_fetch.start_object.group &&
-         standalone_fetch.end_object.has_value() &&
-         *standalone_fetch.end_object < standalone_fetch.start_object.object)) {
+    if (standalone_fetch.end_location < standalone_fetch.start_location) {
       QUICHE_BUG(MoqtFramer_invalid_fetch) << "Invalid FETCH object range";
       return quiche::QuicheBuffer();
     }
@@ -666,32 +663,31 @@
         WireDeliveryOrder(message.group_order),
         WireVarInt62(FetchType::kStandalone),
         WireFullTrackName(standalone_fetch.full_track_name),
-        WireVarInt62(standalone_fetch.start_object.group),
-        WireVarInt62(standalone_fetch.start_object.object),
-        WireVarInt62(standalone_fetch.end_group),
-        WireVarInt62(standalone_fetch.end_object.has_value()
-                         ? *standalone_fetch.end_object + 1
-                         : 0),
+        WireVarInt62(standalone_fetch.start_location.group),
+        WireVarInt62(standalone_fetch.start_location.object),
+        WireVarInt62(standalone_fetch.end_location.group),
+        WireVarInt62(standalone_fetch.end_location.object == kMaxObjectId
+                         ? 0
+                         : standalone_fetch.end_location.object + 1),
         WireKeyValuePairList(parameters));
   }
-  uint64_t subscribe_id;
-  uint64_t joining_start;
+  uint64_t request_id, joining_start;
   if (std::holds_alternative<JoiningFetchRelative>(message.fetch)) {
     const JoiningFetchRelative& joining_fetch =
         std::get<JoiningFetchRelative>(message.fetch);
-    subscribe_id = joining_fetch.joining_subscribe_id;
+    request_id = joining_fetch.joining_request_id;
     joining_start = joining_fetch.joining_start;
   } else {
     const JoiningFetchAbsolute& joining_fetch =
         std::get<JoiningFetchAbsolute>(message.fetch);
-    subscribe_id = joining_fetch.joining_subscribe_id;
+    request_id = joining_fetch.joining_request_id;
     joining_start = joining_fetch.joining_start;
   }
   return SerializeControlMessage(
       MoqtMessageType::kFetch, WireVarInt62(message.request_id),
       WireUint8(message.subscriber_priority),
       WireDeliveryOrder(message.group_order),
-      WireVarInt62(message.fetch.index() + 1), WireVarInt62(subscribe_id),
+      WireVarInt62(message.fetch.index() + 1), WireVarInt62(request_id),
       WireVarInt62(joining_start), WireKeyValuePairList(parameters));
 }
 
@@ -708,7 +704,9 @@
       MoqtMessageType::kFetchOk, WireVarInt62(message.request_id),
       WireDeliveryOrder(message.group_order), WireBoolean(message.end_of_track),
       WireVarInt62(message.end_location.group),
-      WireVarInt62(message.end_location.object),
+      WireVarInt62(message.end_location.object == kMaxObjectId
+                       ? 0
+                       : (message.end_location.object + 1)),
       WireKeyValuePairList(parameters));
 }
 
diff --git a/quiche/quic/moqt/moqt_framer_test.cc b/quiche/quic/moqt/moqt_framer_test.cc
index 4c715f3..3ee0fc1 100644
--- a/quiche/quic/moqt/moqt_framer_test.cc
+++ b/quiche/quic/moqt/moqt_framer_test.cc
@@ -530,15 +530,14 @@
 
 TEST_F(MoqtFramerSimpleTest, FetchEndBeforeStart) {
   MoqtFetch fetch = {
-      /*subscribe_id =*/1,
+      /*request_id=*/1,
       /*subscriber_priority=*/2,
       /*group_order=*/MoqtDeliveryOrder::kAscending,
       /*fetch=*/
       StandaloneFetch{
           FullTrackName("foo", "bar"),
-          /*start_object=*/Location{1, 2},
-          /*end_group=*/1,
-          /*end_object=*/1,
+          /*start_location=*/Location{1, 2},
+          /*end_location=*/Location{1, 1},
       },
       /*parameters=*/
       VersionSpecificParameters(AuthTokenType::kOutOfBand, "baz"),
@@ -547,13 +546,26 @@
   EXPECT_QUIC_BUG(buffer = framer_.SerializeFetch(fetch),
                   "Invalid FETCH object range");
   EXPECT_EQ(buffer.size(), 0);
-  std::get<StandaloneFetch>(fetch.fetch).end_group = 0;
-  std::get<StandaloneFetch>(fetch.fetch).end_object = std::nullopt;
+  std::get<StandaloneFetch>(fetch.fetch).end_location =
+      Location{0, kMaxObjectId};
   EXPECT_QUIC_BUG(buffer = framer_.SerializeFetch(fetch),
                   "Invalid FETCH object range");
   EXPECT_EQ(buffer.size(), 0);
 }
 
+TEST_F(MoqtFramerSimpleTest, FetchOkWholeGroup) {
+  MoqtFetchOk fetch_ok = {
+      /*request_id=*/1,
+      MoqtDeliveryOrder::kAscending,
+      /*end_of_track=*/false,
+      /*end_location=*/Location{4, kMaxObjectId},
+      VersionSpecificParameters(),
+  };
+  quiche::QuicheBuffer buffer = framer_.SerializeFetchOk(fetch_ok);
+  // Check that object ID is zero.
+  EXPECT_EQ(static_cast<uint8_t>(buffer.AsSpan()[7]), 0);
+}
+
 TEST_F(MoqtFramerSimpleTest, SubscribeUpdateEndGroupOnly) {
   MoqtSubscribeUpdate subscribe_update = {
       /*subscribe_id=*/3,
diff --git a/quiche/quic/moqt/moqt_live_relay_queue.h b/quiche/quic/moqt/moqt_live_relay_queue.h
index 60ef828..eb81b52 100644
--- a/quiche/quic/moqt/moqt_live_relay_queue.h
+++ b/quiche/quic/moqt/moqt_live_relay_queue.h
@@ -118,10 +118,19 @@
   MoqtDeliveryOrder GetDeliveryOrder() const override {
     return delivery_order_;
   }
-  std::unique_ptr<MoqtFetchTask> Fetch(Location /*start*/,
-                                       uint64_t /*end_group*/,
-                                       std::optional<uint64_t> /*end_object*/,
-                                       MoqtDeliveryOrder /*order*/) override {
+  std::unique_ptr<MoqtFetchTask> StandaloneFetch(
+      Location /*start*/, Location /*end*/,
+      MoqtDeliveryOrder /*order*/) override {
+    return std::make_unique<MoqtFailedFetch>(
+        absl::UnimplementedError("Fetch not implemented"));
+  }
+  std::unique_ptr<MoqtFetchTask> RelativeFetch(
+      uint64_t /*group_diff*/, MoqtDeliveryOrder /*order*/) override {
+    return std::make_unique<MoqtFailedFetch>(
+        absl::UnimplementedError("Fetch not implemented"));
+  }
+  std::unique_ptr<MoqtFetchTask> AbsoluteFetch(
+      uint64_t /*group*/, MoqtDeliveryOrder /*order*/) override {
     return std::make_unique<MoqtFailedFetch>(
         absl::UnimplementedError("Fetch not implemented"));
   }
diff --git a/quiche/quic/moqt/moqt_messages.cc b/quiche/quic/moqt/moqt_messages.cc
index 993fa2d..81f41a5 100644
--- a/quiche/quic/moqt/moqt_messages.cc
+++ b/quiche/quic/moqt/moqt_messages.cc
@@ -105,7 +105,7 @@
     case absl::StatusCode::kOutOfRange:
       return RequestErrorCode::kInvalidRange;
     case absl::StatusCode::kInvalidArgument:
-      return RequestErrorCode::kInvalidJoiningSubscribeId;
+      return RequestErrorCode::kInvalidJoiningRequestId;
     case absl::StatusCode::kUnauthenticated:
       return RequestErrorCode::kExpiredAuthToken;
     default:
@@ -132,7 +132,7 @@
     case RequestErrorCode::kNoObjects:
       // Equivalently, kRetryTrackAlias.
       return absl::StatusCode::kNotFound;
-    case RequestErrorCode::kInvalidJoiningSubscribeId:
+    case RequestErrorCode::kInvalidJoiningRequestId:
     case RequestErrorCode::kMalformedAuthToken:
       return absl::StatusCode::kInvalidArgument;
     case RequestErrorCode::kExpiredAuthToken:
diff --git a/quiche/quic/moqt/moqt_messages.h b/quiche/quic/moqt/moqt_messages.h
index d1979be..c5c2a79 100644
--- a/quiche/quic/moqt/moqt_messages.h
+++ b/quiche/quic/moqt/moqt_messages.h
@@ -30,6 +30,7 @@
 #include "quiche/common/platform/api/quiche_bug_tracker.h"
 #include "quiche/common/platform/api/quiche_export.h"
 #include "quiche/common/quiche_callbacks.h"
+#include "quiche/common/quiche_data_writer.h"
 #include "quiche/web_transport/web_transport.h"
 
 namespace moqt {
@@ -50,6 +51,7 @@
 inline constexpr uint64_t kMinNamespaceElements = 1;
 inline constexpr uint64_t kMaxNamespaceElements = 32;
 inline constexpr size_t kMaxFullTrackNameSize = 1024;
+inline constexpr uint64_t kMaxObjectId = quiche::kVarInt62MaxValue;
 
 enum AuthTokenType : uint64_t {
   kOutOfBand = 0x0,
@@ -332,13 +334,15 @@
   kUnauthorized = 0x1,
   kTimeout = 0x2,
   kNotSupported = 0x3,
-  kTrackDoesNotExist = 0x4,          // SUBSCRIBE_ERROR and FETCH_ERROR only.
-  kUninterested = 0x4,               // ANNOUNCE_ERROR and ANNOUNCE_CANCEL only.
-  kNamespacePrefixUnknown = 0x4,     // SUBSCRIBE_ANNOUNCES_ERROR only.
-  kInvalidRange = 0x5,               // SUBSCRIBE_ERROR and FETCH_ERROR only.
-  kNamespacePrefixOverlap = 0x5,     // SUBSCRIBE_ANNOUNCES_ERROR only.
-  kNoObjects = 0x6,                  // FETCH_ERROR only.
-  kInvalidJoiningSubscribeId = 0x7,  // FETCH_ERROR only.
+  kTrackDoesNotExist = 0x4,        // SUBSCRIBE_ERROR and FETCH_ERROR only.
+  kUninterested = 0x4,             // ANNOUNCE_ERROR and ANNOUNCE_CANCEL only.
+  kNamespacePrefixUnknown = 0x4,   // SUBSCRIBE_ANNOUNCES_ERROR only.
+  kInvalidRange = 0x5,             // SUBSCRIBE_ERROR and FETCH_ERROR only.
+  kNamespacePrefixOverlap = 0x5,   // SUBSCRIBE_ANNOUNCES_ERROR only.
+  kNoObjects = 0x6,                // FETCH_ERROR only.
+  kInvalidJoiningRequestId = 0x7,  // FETCH_ERROR only.
+  kUnknownStatusInRange = 0x8,     // FETCH_ERROR only.
+  kMalformedTrack = 0x9,
   kMalformedAuthToken = 0x10,
   kExpiredAuthToken = 0x12,
 };
@@ -462,7 +466,15 @@
   // https://moq-wg.github.io/moq-transport/draft-ietf-moq-transport.html#location-structure
   auto operator<=>(const Location&) const = default;
 
-  Location next() const { return Location(group, object + 1); }
+  Location Next() const {
+    if (object == kMaxObjectId) {
+      if (group == kMaxObjectId) {
+        return Location(0, 0);
+      }
+      return Location(group + 1, 0);
+    }
+    return Location(group, object + 1);
+  }
 
   template <typename H>
   friend H AbslHashValue(H h, const Location& m);
@@ -771,20 +783,18 @@
 
 struct StandaloneFetch {
   StandaloneFetch() = default;
-  StandaloneFetch(FullTrackName full_track_name, Location start_object,
-                  uint64_t end_group, std::optional<uint64_t> end_object)
+  StandaloneFetch(FullTrackName full_track_name, Location start_location,
+                  Location end_location)
       : full_track_name(full_track_name),
-        start_object(start_object),
-        end_group(end_group),
-        end_object(end_object) {}
+        start_location(start_location),
+        end_location(end_location) {}
   FullTrackName full_track_name;
-  Location start_object;  // subgroup is ignored
-  uint64_t end_group;
-  std::optional<uint64_t> end_object;
+  Location start_location;
+  Location end_location;
   bool operator==(const StandaloneFetch& other) const {
     return full_track_name == other.full_track_name &&
-           start_object == other.start_object && end_group == other.end_group &&
-           end_object == other.end_object;
+           start_location == other.start_location &&
+           end_location == other.end_location;
   }
   bool operator!=(const StandaloneFetch& other) const {
     return !(*this == other);
@@ -792,13 +802,12 @@
 };
 
 struct JoiningFetchRelative {
-  JoiningFetchRelative(uint64_t joining_subscribe_id, uint64_t joining_start)
-      : joining_subscribe_id(joining_subscribe_id),
-        joining_start(joining_start) {}
-  uint64_t joining_subscribe_id;
+  JoiningFetchRelative(uint64_t joining_request_id, uint64_t joining_start)
+      : joining_request_id(joining_request_id), joining_start(joining_start) {}
+  uint64_t joining_request_id;
   uint64_t joining_start;
   bool operator==(const JoiningFetchRelative& other) const {
-    return joining_subscribe_id == other.joining_subscribe_id &&
+    return joining_request_id == other.joining_request_id &&
            joining_start == other.joining_start;
   }
   bool operator!=(const JoiningFetchRelative& other) const {
@@ -807,13 +816,12 @@
 };
 
 struct JoiningFetchAbsolute {
-  JoiningFetchAbsolute(uint64_t joining_subscribe_id, uint64_t joining_start)
-      : joining_subscribe_id(joining_subscribe_id),
-        joining_start(joining_start) {}
-  uint64_t joining_subscribe_id;
+  JoiningFetchAbsolute(uint64_t joining_request_id, uint64_t joining_start)
+      : joining_request_id(joining_request_id), joining_start(joining_start) {}
+  uint64_t joining_request_id;
   uint64_t joining_start;
   bool operator==(const JoiningFetchAbsolute& other) const {
-    return joining_subscribe_id == other.joining_subscribe_id &&
+    return joining_request_id == other.joining_request_id &&
            joining_start == other.joining_start;
   }
   bool operator!=(const JoiningFetchAbsolute& other) const {
diff --git a/quiche/quic/moqt/moqt_outgoing_queue.cc b/quiche/quic/moqt/moqt_outgoing_queue.cc
index 324fa67..63e0140 100644
--- a/quiche/quic/moqt/moqt_outgoing_queue.cc
+++ b/quiche/quic/moqt/moqt_outgoing_queue.cc
@@ -6,7 +6,6 @@
 
 #include <algorithm>
 #include <cstdint>
-#include <limits>
 #include <memory>
 #include <optional>
 #include <utility>
@@ -26,6 +25,19 @@
 
 namespace moqt {
 
+namespace {
+void ObjectsInDescendingOrder(std::vector<Location>& objects) {
+  absl::c_reverse(objects);
+  for (auto it = objects.begin(); it != objects.end();) {
+    auto start_it = it;
+    while (it != objects.end() && it->group == start_it->group) {
+      ++it;
+    }
+    std::reverse(start_it, it);
+  }
+}
+}  // namespace
+
 void MoqtOutgoingQueue::AddObject(quiche::QuicheMemSlice payload, bool key) {
   if (queue_.empty() && !key) {
     QUICHE_BUG(MoqtOutgoingQueue_AddObject_first_object_not_key)
@@ -103,7 +115,7 @@
 std::vector<Location> MoqtOutgoingQueue::GetCachedObjectsInRange(
     Location start, Location end) const {
   std::vector<Location> sequences;
-  SubscribeWindow window(start, end.group, end.object);
+  SubscribeWindow window(start, end);
   for (const Group& group : queue_) {
     for (const CachedObject& object : group) {
       if (window.InWindow(object.metadata.location)) {
@@ -133,16 +145,13 @@
   return Location{current_group_id_, queue_.back().size() - 1};
 }
 
-std::unique_ptr<MoqtFetchTask> MoqtOutgoingQueue::Fetch(
-    Location start, uint64_t end_group, std::optional<uint64_t> end_object,
-    MoqtDeliveryOrder order) {
+std::unique_ptr<MoqtFetchTask> MoqtOutgoingQueue::StandaloneFetch(
+    Location start, Location end, MoqtDeliveryOrder order) {
   if (queue_.empty()) {
     return std::make_unique<MoqtFailedFetch>(
         absl::NotFoundError("No objects available on the track"));
   }
 
-  Location end = Location(
-      end_group, end_object.value_or(std::numeric_limits<uint64_t>::max()));
   Location first_available_object = Location(first_group_in_queue(), 0);
   Location last_available_object =
       Location(current_group_id_, queue_.back().size() - 1);
@@ -173,6 +182,48 @@
   return std::make_unique<FetchTask>(this, std::move(objects));
 }
 
+std::unique_ptr<MoqtFetchTask> MoqtOutgoingQueue::RelativeFetch(
+    uint64_t group_diff, MoqtDeliveryOrder order) {
+  if (queue_.empty()) {
+    return std::make_unique<MoqtFailedFetch>(
+        absl::NotFoundError("No objects available on the track"));
+  }
+
+  uint64_t start_group = (group_diff > first_group_in_queue())
+                             ? 0
+                             : current_group_id_ - group_diff;
+  start_group = std::max(start_group, first_group_in_queue());
+  Location start = Location(start_group, 0);
+  Location end = Location(current_group_id_, queue_.back().size() - 1);
+
+  std::vector<Location> objects = GetCachedObjectsInRange(start, end);
+  if (order == MoqtDeliveryOrder::kDescending) {
+    ObjectsInDescendingOrder(objects);
+  }
+  return std::make_unique<FetchTask>(this, std::move(objects));
+}
+
+std::unique_ptr<MoqtFetchTask> MoqtOutgoingQueue::AbsoluteFetch(
+    uint64_t group, MoqtDeliveryOrder order) {
+  if (queue_.empty()) {
+    return std::make_unique<MoqtFailedFetch>(
+        absl::NotFoundError("No objects available on the track"));
+  }
+
+  Location start(std::max(group, first_group_in_queue()), 0);
+  Location end = Location(current_group_id_, queue_.back().size() - 1);
+  if (start > end) {
+    return std::make_unique<MoqtFailedFetch>(
+        absl::NotFoundError("All of the requested objects are in the future"));
+  }
+
+  std::vector<Location> objects = GetCachedObjectsInRange(start, end);
+  if (order == MoqtDeliveryOrder::kDescending) {
+    ObjectsInDescendingOrder(objects);
+  }
+  return std::make_unique<FetchTask>(this, std::move(objects));
+}
+
 MoqtFetchTask::GetNextObjectResult MoqtOutgoingQueue::FetchTask::GetNextObject(
     PublishedObject& object) {
   MoqtFetchTask::GetNextObjectResult result;
diff --git a/quiche/quic/moqt/moqt_outgoing_queue.h b/quiche/quic/moqt/moqt_outgoing_queue.h
index c61b220..1034792 100644
--- a/quiche/quic/moqt/moqt_outgoing_queue.h
+++ b/quiche/quic/moqt/moqt_outgoing_queue.h
@@ -74,9 +74,12 @@
   MoqtDeliveryOrder GetDeliveryOrder() const override {
     return delivery_order_;
   }
-  std::unique_ptr<MoqtFetchTask> Fetch(Location start, uint64_t end_group,
-                                       std::optional<uint64_t> end_object,
-                                       MoqtDeliveryOrder order) override;
+  std::unique_ptr<MoqtFetchTask> StandaloneFetch(
+      Location start, Location end, MoqtDeliveryOrder order) override;
+  std::unique_ptr<MoqtFetchTask> RelativeFetch(
+      uint64_t group_diff, MoqtDeliveryOrder order) override;
+  std::unique_ptr<MoqtFetchTask> AbsoluteFetch(
+      uint64_t group, MoqtDeliveryOrder order) override;
 
   bool HasSubscribers() const { return !listeners_.empty(); }
   void SetDeliveryOrder(MoqtDeliveryOrder order) {
diff --git a/quiche/quic/moqt/moqt_outgoing_queue_test.cc b/quiche/quic/moqt/moqt_outgoing_queue_test.cc
index e45a9c1..841179c 100644
--- a/quiche/quic/moqt/moqt_outgoing_queue_test.cc
+++ b/quiche/quic/moqt/moqt_outgoing_queue_test.cc
@@ -293,11 +293,12 @@
   queue.GetObjectsFromPast(SubscribeWindow(Location(0, 0)));
 }
 
-TEST(MoqtOutgoingQueue, Fetch) {
+TEST(MoqtOutgoingQueue, StandaloneFetch) {
   TestMoqtOutgoingQueue queue;
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 2, 0,
-                                        MoqtDeliveryOrder::kAscending)),
-              StatusIs(absl::StatusCode::kNotFound));
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{2, 0},
+                                          MoqtDeliveryOrder::kAscending)),
+      StatusIs(absl::StatusCode::kNotFound));
 
   queue.AddObject(quiche::QuicheMemSlice::Copy("a"), true);
   queue.AddObject(quiche::QuicheMemSlice::Copy("b"), false);
@@ -305,44 +306,95 @@
   queue.AddObject(quiche::QuicheMemSlice::Copy("d"), false);
   queue.AddObject(quiche::QuicheMemSlice::Copy("e"), true);
 
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 2, 0,
-                                        MoqtDeliveryOrder::kAscending)),
-              IsOkAndHolds(ElementsAre("a", "b", "c", "d", "e")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 100}, 0, 1000,
-                                        MoqtDeliveryOrder::kAscending)),
-              IsOkAndHolds(IsEmpty()));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 2, 0,
-                                        MoqtDeliveryOrder::kDescending)),
-              IsOkAndHolds(ElementsAre("e", "c", "d", "a", "b")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 1, 0,
-                                        MoqtDeliveryOrder::kAscending)),
-              IsOkAndHolds(ElementsAre("a", "b", "c")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 1, 0,
-                                        MoqtDeliveryOrder::kAscending)),
-              IsOkAndHolds(ElementsAre("a", "b", "c")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{1, 0}, 5, std::nullopt,
-                                        MoqtDeliveryOrder::kAscending)),
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{2, 0},
+                                          MoqtDeliveryOrder::kAscending)),
+      IsOkAndHolds(ElementsAre("a", "b", "c", "d", "e")));
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 100}, Location{0, 1000},
+                                          MoqtDeliveryOrder::kAscending)),
+      IsOkAndHolds(IsEmpty()));
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{2, 0},
+                                          MoqtDeliveryOrder::kDescending)),
+      IsOkAndHolds(ElementsAre("e", "c", "d", "a", "b")));
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{1, 0},
+                                          MoqtDeliveryOrder::kAscending)),
+      IsOkAndHolds(ElementsAre("a", "b", "c")));
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{1, 0},
+                                          MoqtDeliveryOrder::kAscending)),
+      IsOkAndHolds(ElementsAre("a", "b", "c")));
+  EXPECT_THAT(FetchToVector(queue.StandaloneFetch(
+                  Location{1, 0}, Location{5, kMaxObjectId},
+                  MoqtDeliveryOrder::kAscending)),
               IsOkAndHolds(ElementsAre("c", "d", "e")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{3, 0}, 5, std::nullopt,
-                                        MoqtDeliveryOrder::kAscending)),
+  EXPECT_THAT(FetchToVector(queue.StandaloneFetch(
+                  Location{3, 0}, Location{5, kMaxObjectId},
+                  MoqtDeliveryOrder::kAscending)),
               StatusIs(absl::StatusCode::kNotFound));
 
   queue.AddObject(quiche::QuicheMemSlice::Copy("f"), true);
   queue.AddObject(quiche::QuicheMemSlice::Copy("g"), false);
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 0, 1,
-                                        MoqtDeliveryOrder::kAscending)),
-              StatusIs(absl::StatusCode::kNotFound));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 2, 0,
-                                        MoqtDeliveryOrder::kAscending)),
-              IsOkAndHolds(ElementsAre("c", "d", "e")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{1, 0}, 5, std::nullopt,
-                                        MoqtDeliveryOrder::kAscending)),
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{0, 1},
+                                          MoqtDeliveryOrder::kAscending)),
+      StatusIs(absl::StatusCode::kNotFound));
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{2, 0},
+                                          MoqtDeliveryOrder::kAscending)),
+      IsOkAndHolds(ElementsAre("c", "d", "e")));
+  EXPECT_THAT(FetchToVector(queue.StandaloneFetch(
+                  Location{1, 0}, Location{5, kMaxObjectId},
+                  MoqtDeliveryOrder::kAscending)),
               IsOkAndHolds(ElementsAre("c", "d", "e", "f", "g")));
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{3, 0}, 5, std::nullopt,
-                                        MoqtDeliveryOrder::kAscending)),
+  EXPECT_THAT(FetchToVector(queue.StandaloneFetch(
+                  Location{3, 0}, Location{5, kMaxObjectId},
+                  MoqtDeliveryOrder::kAscending)),
               IsOkAndHolds(ElementsAre("f", "g")));
 }
 
+TEST(MoqtOutgoingQueue, RelativeJoiningFetch) {
+  TestMoqtOutgoingQueue queue;
+  queue.AddObject(quiche::QuicheMemSlice::Copy("a"), true);  // 0, 0
+  queue.AddObject(quiche::QuicheMemSlice::Copy("b"), true);  // 1, 0
+  // Request before group zero.
+  EXPECT_THAT(
+      FetchToVector(queue.RelativeFetch(4, MoqtDeliveryOrder::kDescending)),
+      IsOkAndHolds(ElementsAre("b", "a")));
+  queue.AddObject(quiche::QuicheMemSlice::Copy("c"), true);   // 2, 0
+  queue.AddObject(quiche::QuicheMemSlice::Copy("d"), false);  // 2, 1
+  queue.AddObject(quiche::QuicheMemSlice::Copy("e"), true);   // 3, 0
+  queue.AddObject(quiche::QuicheMemSlice::Copy("f"), false);  // 3, 1
+  queue.AddObject(quiche::QuicheMemSlice::Copy("g"), true);   // 4, 0
+  queue.SetDeliveryOrder(MoqtDeliveryOrder::kDescending);
+  // Early groups are already destroyed.
+  EXPECT_THAT(
+      FetchToVector(queue.RelativeFetch(4, MoqtDeliveryOrder::kDescending)),
+      IsOkAndHolds(ElementsAre("g", "e", "f", "c", "d")));
+}
+
+TEST(MoqtOutgoingQueue, AbsoluteJoiningFetch) {
+  TestMoqtOutgoingQueue queue;
+  queue.AddObject(quiche::QuicheMemSlice::Copy("a"), true);  // 0, 0
+  queue.AddObject(quiche::QuicheMemSlice::Copy("b"), true);  // 1, 0
+  // Request too far in the future
+  EXPECT_THAT(
+      FetchToVector(queue.AbsoluteFetch(4, MoqtDeliveryOrder::kDescending)),
+      StatusIs(absl::StatusCode::kNotFound));
+  queue.AddObject(quiche::QuicheMemSlice::Copy("c"), true);   // 2, 0
+  queue.AddObject(quiche::QuicheMemSlice::Copy("d"), false);  // 2, 1
+  queue.AddObject(quiche::QuicheMemSlice::Copy("e"), true);   // 3, 0
+  queue.AddObject(quiche::QuicheMemSlice::Copy("f"), false);  // 3, 1
+  queue.AddObject(quiche::QuicheMemSlice::Copy("g"), true);   // 4, 0
+  queue.SetDeliveryOrder(MoqtDeliveryOrder::kDescending);
+  // Early groups are already destroyed.
+  EXPECT_THAT(
+      FetchToVector(queue.AbsoluteFetch(1, MoqtDeliveryOrder::kDescending)),
+      IsOkAndHolds(ElementsAre("g", "e", "f", "c", "d")));
+}
+
 TEST(MoqtOutgoingQueue, ObjectsGoneWhileFetching) {
   TestMoqtOutgoingQueue queue;
   queue.AddObject(quiche::QuicheMemSlice::Copy("a"), true);
@@ -351,11 +403,12 @@
   queue.AddObject(quiche::QuicheMemSlice::Copy("d"), true);
   queue.AddObject(quiche::QuicheMemSlice::Copy("e"), true);
 
-  EXPECT_THAT(FetchToVector(queue.Fetch(Location{0, 0}, 5, 0,
-                                        MoqtDeliveryOrder::kAscending)),
-              IsOkAndHolds(ElementsAre("c", "d", "e")));
-  std::unique_ptr<MoqtFetchTask> deferred_fetch =
-      queue.Fetch(Location{0, 0}, 5, 0, MoqtDeliveryOrder::kAscending);
+  EXPECT_THAT(
+      FetchToVector(queue.StandaloneFetch(Location{0, 0}, Location{5, 0},
+                                          MoqtDeliveryOrder::kAscending)),
+      IsOkAndHolds(ElementsAre("c", "d", "e")));
+  std::unique_ptr<MoqtFetchTask> deferred_fetch = queue.StandaloneFetch(
+      Location{0, 0}, Location{5, 0}, MoqtDeliveryOrder::kAscending);
 
   queue.AddObject(quiche::QuicheMemSlice::Copy("f"), true);
   queue.AddObject(quiche::QuicheMemSlice::Copy("g"), true);
@@ -380,8 +433,8 @@
   TestMoqtOutgoingQueue queue;
   queue.AddObject(quiche::QuicheMemSlice::Copy("a"), true);  // Create (0, 0)
   queue.AddObject(quiche::QuicheMemSlice::Copy("b"), true);  // Create (1, 0)
-  std::unique_ptr<MoqtFetchTask> fetch = queue.Fetch(
-      Location{0, 0}, 5, std::nullopt, MoqtDeliveryOrder::kAscending);
+  std::unique_ptr<MoqtFetchTask> fetch = queue.StandaloneFetch(
+      Location{0, 0}, Location{5, kMaxObjectId}, MoqtDeliveryOrder::kAscending);
   bool end_of_track = false;
   Location end_location;
   // end_of_track is false before Close() is called.
@@ -396,8 +449,8 @@
 
   queue.Close();  // Create (2, 0)
   EXPECT_EQ(queue.GetLargestLocation(), Location(2, 0));
-  fetch = queue.Fetch(Location{0, 0}, 1, std::nullopt,
-                      MoqtDeliveryOrder::kAscending);
+  fetch = queue.StandaloneFetch(Location{0, 0}, Location{1, kMaxObjectId},
+                                MoqtDeliveryOrder::kAscending);
   // end_of_track is false if the fetch does not include the last object.
   fetch->SetFetchResponseCallback(
       [&end_of_track,
@@ -408,8 +461,8 @@
   EXPECT_FALSE(end_of_track);
   EXPECT_EQ(end_location, Location(1, 1));
 
-  fetch = queue.Fetch(Location{0, 0}, 5, std::nullopt,
-                      MoqtDeliveryOrder::kAscending);
+  fetch = queue.StandaloneFetch(Location{0, 0}, Location{5, kMaxObjectId},
+                                MoqtDeliveryOrder::kAscending);
   // end_of_track is true if the fetch includes the last object.
   fetch->SetFetchResponseCallback(
       [&end_of_track,
diff --git a/quiche/quic/moqt/moqt_parser.cc b/quiche/quic/moqt/moqt_parser.cc
index 498ea14..fd7078a 100644
--- a/quiche/quic/moqt/moqt_parser.cc
+++ b/quiche/quic/moqt/moqt_parser.cc
@@ -774,44 +774,42 @@
   }
   switch (static_cast<FetchType>(type)) {
     case FetchType::kAbsoluteJoining: {
-      uint64_t joining_subscribe_id;
+      uint64_t joining_request_id;
       uint64_t joining_start;
-      if (!reader.ReadVarInt62(&joining_subscribe_id) ||
+      if (!reader.ReadVarInt62(&joining_request_id) ||
           !reader.ReadVarInt62(&joining_start)) {
         return 0;
       }
-      fetch.fetch = JoiningFetchAbsolute{joining_subscribe_id, joining_start};
+      fetch.fetch = JoiningFetchAbsolute{joining_request_id, joining_start};
       break;
     }
     case FetchType::kRelativeJoining: {
-      uint64_t joining_subscribe_id;
+      uint64_t joining_request_id;
       uint64_t joining_start;
-      if (!reader.ReadVarInt62(&joining_subscribe_id) ||
+      if (!reader.ReadVarInt62(&joining_request_id) ||
           !reader.ReadVarInt62(&joining_start)) {
         return 0;
       }
-      fetch.fetch = JoiningFetchRelative{joining_subscribe_id, joining_start};
+      fetch.fetch = JoiningFetchRelative{joining_request_id, joining_start};
       break;
     }
     case FetchType::kStandalone: {
       fetch.fetch = StandaloneFetch();
       StandaloneFetch& standalone_fetch =
           std::get<StandaloneFetch>(fetch.fetch);
-      uint64_t end_object;
       if (!ReadFullTrackName(reader, standalone_fetch.full_track_name) ||
-          !reader.ReadVarInt62(&standalone_fetch.start_object.group) ||
-          !reader.ReadVarInt62(&standalone_fetch.start_object.object) ||
-          !reader.ReadVarInt62(&standalone_fetch.end_group) ||
-          !reader.ReadVarInt62(&end_object)) {
+          !reader.ReadVarInt62(&standalone_fetch.start_location.group) ||
+          !reader.ReadVarInt62(&standalone_fetch.start_location.object) ||
+          !reader.ReadVarInt62(&standalone_fetch.end_location.group) ||
+          !reader.ReadVarInt62(&standalone_fetch.end_location.object)) {
         return 0;
       }
-      standalone_fetch.end_object =
-          end_object == 0 ? std::optional<uint64_t>() : (end_object - 1);
-      if (standalone_fetch.end_group < standalone_fetch.start_object.group ||
-          (standalone_fetch.end_group == standalone_fetch.start_object.group &&
-           standalone_fetch.end_object.has_value() &&
-           *standalone_fetch.end_object <
-               standalone_fetch.start_object.object)) {
+      if (standalone_fetch.end_location.object == 0) {
+        standalone_fetch.end_location.object = kMaxObjectId;
+      } else {
+        --standalone_fetch.end_location.object;
+      }
+      if (standalone_fetch.end_location < standalone_fetch.start_location) {
         ParseError("End object comes before start object in FETCH");
         return 0;
       }
@@ -861,6 +859,11 @@
     ParseError("FETCH_OK message contains invalid parameters");
     return 0;
   }
+  if (fetch_ok.end_location.object == 0) {
+    fetch_ok.end_location.object = kMaxObjectId;
+  } else {
+    --fetch_ok.end_location.object;
+  }
   fetch_ok.group_order = static_cast<MoqtDeliveryOrder>(group_order);
   fetch_ok.end_of_track = end_of_track == 1;
   if (!KeyValuePairListToVersionSpecificParameters(parameters,
diff --git a/quiche/quic/moqt/moqt_parser_test.cc b/quiche/quic/moqt/moqt_parser_test.cc
index eda9dbf..ae42a62 100644
--- a/quiche/quic/moqt/moqt_parser_test.cc
+++ b/quiche/quic/moqt/moqt_parser_test.cc
@@ -1357,6 +1357,23 @@
             "Invalid group order value in SUBSCRIBE_OK");
 }
 
+TEST_F(MoqtMessageSpecificTest, FetchWholeGroup) {
+  webtransport::test::InMemoryStream stream(/*stream_id=*/0);
+  MoqtControlParser parser(kRawQuic, &stream, visitor_);
+  FetchMessage fetch;
+  fetch.SetEndObject(5, std::nullopt);
+  stream.Receive(fetch.PacketSample(), false);
+  parser.ReadAndDispatchMessages();
+  EXPECT_EQ(visitor_.messages_received_, 1);
+  EXPECT_TRUE(visitor_.last_message_.has_value());
+  if (!visitor_.last_message_.has_value()) {
+    return;
+  }
+  MoqtFetch parse_result = std::get<MoqtFetch>(*visitor_.last_message_);
+  auto standalone = std::get<StandaloneFetch>(parse_result.fetch);
+  EXPECT_EQ(standalone.end_location, Location(5, kMaxObjectId));
+}
+
 TEST_F(MoqtMessageSpecificTest, FetchInvalidRange) {
   webtransport::test::InMemoryStream stream(/*stream_id=*/0);
   MoqtControlParser parser(kRawQuic, &stream, visitor_);
diff --git a/quiche/quic/moqt/moqt_publisher.h b/quiche/quic/moqt/moqt_publisher.h
index ec7c121..a3f2ebc 100644
--- a/quiche/quic/moqt/moqt_publisher.h
+++ b/quiche/quic/moqt/moqt_publisher.h
@@ -8,6 +8,7 @@
 #include <cstdint>
 #include <memory>
 #include <optional>
+#include <string>
 #include <variant>
 
 #include "absl/status/status.h"
@@ -82,8 +83,7 @@
 class MoqtFetchTask {
  public:
   using ObjectsAvailableCallback = quiche::MultiUseCallback<void()>;
-  // If the fields are not correct (e.g. end_of_track is less than start) it
-  // will result in QUICHE_BUG. The request_id field will be ignored.
+  // The request_id field will be ignored.
   using FetchResponseCallback = quiche::SingleUseCallback<void(
       std::variant<MoqtFetchOk, MoqtFetchError>)>;
 
@@ -178,9 +178,12 @@
   virtual MoqtDeliveryOrder GetDeliveryOrder() const = 0;
 
   // Performs a fetch for the specified range of objects.
-  virtual std::unique_ptr<MoqtFetchTask> Fetch(
-      Location start, uint64_t end_group, std::optional<uint64_t> end_object,
-      MoqtDeliveryOrder order) = 0;
+  virtual std::unique_ptr<MoqtFetchTask> StandaloneFetch(
+      Location start, Location end, MoqtDeliveryOrder order) = 0;
+  virtual std::unique_ptr<MoqtFetchTask> RelativeFetch(
+      uint64_t group_diff, MoqtDeliveryOrder order) = 0;
+  virtual std::unique_ptr<MoqtFetchTask> AbsoluteFetch(
+      uint64_t group, MoqtDeliveryOrder order) = 0;
 };
 
 // MoqtPublisher is an interface to a publisher that allows it to publish
diff --git a/quiche/quic/moqt/moqt_session.cc b/quiche/quic/moqt/moqt_session.cc
index b05d5ff..1157031 100644
--- a/quiche/quic/moqt/moqt_session.cc
+++ b/quiche/quic/moqt/moqt_session.cc
@@ -523,7 +523,10 @@
     return false;
   }
   MoqtFetch message;
-  message.fetch = StandaloneFetch(name, start, end_group, end_object);
+  Location end_location = end_object.has_value()
+                              ? Location(end_group, *end_object)
+                              : Location(end_group, kMaxObjectId);
+  message.fetch = StandaloneFetch(name, start, end_location);
   message.request_id = next_request_id_;
   next_request_id_ += 2;
   message.subscriber_priority = priority;
@@ -1107,7 +1110,7 @@
   subscribe->set_track_alias(message.track_alias);
   // TODO(martinduke): Handle expires field.
   if (message.largest_location.has_value()) {
-    subscribe->TruncateStart(message.largest_location->next());
+    subscribe->TruncateStart(message.largest_location->Next());
   }
   if (subscribe->visitor() != nullptr) {
     subscribe->visitor()->OnReply(track->full_track_name(),
@@ -1442,31 +1445,45 @@
                    "FETCH after GOAWAY");
     return;
   }
+  std::unique_ptr<MoqtFetchTask> fetch;
   FullTrackName track_name;
-  Location start_object;
-  uint64_t end_group;
-  std::optional<uint64_t> end_object;
   if (std::holds_alternative<StandaloneFetch>(message.fetch)) {
     const StandaloneFetch& standalone_fetch =
         std::get<StandaloneFetch>(message.fetch);
     track_name = standalone_fetch.full_track_name;
-    start_object = standalone_fetch.start_object;
-    end_group = standalone_fetch.end_group;
-    end_object = standalone_fetch.end_object;
+    absl::StatusOr<std::shared_ptr<MoqtTrackPublisher>> track_publisher =
+        session_->publisher_->GetTrack(track_name);
+    if (!track_publisher.ok()) {
+      QUIC_DLOG(INFO) << ENDPOINT << "FETCH for " << track_name
+                      << " rejected by the application: "
+                      << track_publisher.status();
+      SendFetchError(message.request_id, RequestErrorCode::kTrackDoesNotExist,
+                     track_publisher.status().message());
+    }
+    QUIC_DLOG(INFO) << ENDPOINT << "Received a StandaloneFETCH for "
+                    << track_name;
+    // The check for end_object < start_object is done in
+    // MoqtTrackPublisher::Fetch().
+    fetch = (*track_publisher)
+                ->StandaloneFetch(standalone_fetch.start_location,
+                                  standalone_fetch.end_location,
+                                  message.group_order.value_or(
+                                      (*track_publisher)->GetDeliveryOrder()));
   } else {
-    uint64_t joining_subscribe_id =
+    // Joining Fetch processing.
+    uint64_t joining_request_id =
         std::holds_alternative<JoiningFetchRelative>(message.fetch)
             ? std::get<struct JoiningFetchRelative>(message.fetch)
-                  .joining_subscribe_id
-            : std::get<JoiningFetchAbsolute>(message.fetch)
-                  .joining_subscribe_id;
-    auto it = session_->published_subscriptions_.find(joining_subscribe_id);
+                  .joining_request_id
+            : std::get<JoiningFetchAbsolute>(message.fetch).joining_request_id;
+    auto it = session_->published_subscriptions_.find(joining_request_id);
     if (it == session_->published_subscriptions_.end()) {
       QUIC_DLOG(INFO) << ENDPOINT << "Received a JOINING_FETCH for "
-                      << "subscribe_id " << joining_subscribe_id
+                      << "request_id " << joining_request_id
                       << " that does not exist";
-      SendFetchError(message.request_id, RequestErrorCode::kTrackDoesNotExist,
-                     "Joining Fetch for non-existent subscribe");
+      SendFetchError(message.request_id,
+                     RequestErrorCode::kInvalidJoiningRequestId,
+                     "Joining Fetch for non-existent request");
       return;
     }
     if (it->second->filter_type() != MoqtFilterType::kLatestObject) {
@@ -1474,50 +1491,33 @@
       // LatestObject and AbsoluteStart with object ID > 0, but accept
       // JoiningFetch for AbsoluteStart.
       QUIC_DLOG(INFO) << ENDPOINT << "Received a JOINING_FETCH for "
-                      << "subscribe_id " << joining_subscribe_id
+                      << "joining_request_id " << joining_request_id
                       << " that is not a LatestObject";
       session_->Error(MoqtError::kProtocolViolation,
                       "Joining Fetch for non-LatestObject subscribe");
       return;
     }
     track_name = it->second->publisher().GetTrackName();
-    Location fetch_end = it->second->GetWindowStart();
     if (std::holds_alternative<JoiningFetchRelative>(message.fetch)) {
       const JoiningFetchRelative& relative_fetch =
           std::get<JoiningFetchRelative>(message.fetch);
-      if (relative_fetch.joining_start > fetch_end.group) {
-        start_object = Location(0, 0);
-      } else {
-        start_object =
-            Location(fetch_end.group - relative_fetch.joining_start, 0);
-      }
+      QUIC_DLOG(INFO) << ENDPOINT << "Received a Relative Joining FETCH for "
+                      << track_name;
+      fetch = it->second->publisher().RelativeFetch(
+          relative_fetch.joining_start,
+          message.group_order.value_or(
+              it->second->publisher().GetDeliveryOrder()));
     } else {
       const JoiningFetchAbsolute& absolute_fetch =
           std::get<JoiningFetchAbsolute>(message.fetch);
-      start_object =
-          Location(fetch_end.group - absolute_fetch.joining_start, 0);
+      QUIC_DLOG(INFO) << ENDPOINT << "Received a Absolute Joining FETCH for "
+                      << track_name;
+      fetch = it->second->publisher().AbsoluteFetch(
+          absolute_fetch.joining_start,
+          message.group_order.value_or(
+              it->second->publisher().GetDeliveryOrder()));
     }
-    end_group = fetch_end.group;
-    end_object = fetch_end.object - 1;
   }
-  // The check for end_object < start_object is done in
-  // MoqtTrackPublisher::Fetch().
-  QUIC_DLOG(INFO) << ENDPOINT << "Received a FETCH for " << track_name;
-  absl::StatusOr<std::shared_ptr<MoqtTrackPublisher>> track_publisher =
-      session_->publisher_->GetTrack(track_name);
-  if (!track_publisher.ok()) {
-    QUIC_DLOG(INFO) << ENDPOINT << "FETCH for " << track_name
-                    << " rejected by the application: "
-                    << track_publisher.status();
-    SendFetchError(message.request_id, RequestErrorCode::kTrackDoesNotExist,
-                   track_publisher.status().message());
-    return;
-  }
-  std::unique_ptr<MoqtFetchTask> fetch =
-      (*track_publisher)
-          ->Fetch(start_object, end_group, end_object,
-                  message.group_order.value_or(
-                      (*track_publisher)->GetDeliveryOrder()));
   if (!fetch->GetStatus().ok()) {
     QUIC_DLOG(INFO) << ENDPOINT << "FETCH for " << track_name
                     << " could not initialize the task";
@@ -1537,8 +1537,7 @@
   }
   MoqtFetchTask* fetch_task = result.first->second->fetch_task();
   fetch_task->SetFetchResponseCallback(
-      [this, request_id = message.request_id, fetch_start = start_object,
-       fetch_end = Location(end_group, end_object.value_or(UINT64_MAX))](
+      [this, request_id = message.request_id](
           std::variant<MoqtFetchOk, MoqtFetchError> message) {
         if (!session_->incoming_fetches_.contains(request_id)) {
           return;  // FETCH was cancelled.
@@ -1546,15 +1545,6 @@
         if (std::holds_alternative<MoqtFetchOk>(message)) {
           MoqtFetchOk& fetch_ok = std::get<MoqtFetchOk>(message);
           fetch_ok.request_id = request_id;
-          if (fetch_ok.end_location < fetch_start ||
-              fetch_ok.end_location > fetch_end) {
-            // TODO(martinduke): Add end_of_track to fetch_ok and check it's
-            // larger than end_location.
-            QUIC_BUG(quic_bug_fetch_ok_status_error)
-                << "FETCH_OK end or end_of_track is invalid";
-            session_->Error(MoqtError::kInternalError, "FETCH_OK status error");
-            return;
-          }
           SendOrBufferMessage(session_->framer_.SerializeFetchOk(fetch_ok));
           return;
         }
@@ -1999,7 +1989,7 @@
     if (forward_) {
       switch (filter_type_) {
         case MoqtFilterType::kLatestObject:
-          window_ = SubscribeWindow(largest_location->next());
+          window_ = SubscribeWindow(largest_location->Next());
           break;
         case MoqtFilterType::kNextGroupStart:
           window_ = SubscribeWindow(Location(largest_location->group + 1, 0));
diff --git a/quiche/quic/moqt/moqt_session_test.cc b/quiche/quic/moqt/moqt_session_test.cc
index 75c89b0..790db2a 100644
--- a/quiche/quic/moqt/moqt_session_test.cc
+++ b/quiche/quic/moqt/moqt_session_test.cc
@@ -94,7 +94,7 @@
       /*group_order=*/std::nullopt,
       /*fetch=*/
       StandaloneFetch(kDefaultTrackName(), Location(0, 0),
-                      kDefaultPeerRequestId, std::nullopt),
+                      Location(1, kMaxObjectId)),
       /*parameters=*/VersionSpecificParameters(),
   };
   return fetch;
@@ -2371,7 +2371,8 @@
   // No callbacks are synchronous. MockFetchTask will store the callbacks.
   auto fetch_task_ptr = std::make_unique<MockFetchTask>();
   MockFetchTask* fetch_task = fetch_task_ptr.get();
-  EXPECT_CALL(*track, Fetch).WillOnce(Return(std::move(fetch_task_ptr)));
+  EXPECT_CALL(*track, StandaloneFetch)
+      .WillOnce(Return(std::move(fetch_task_ptr)));
   stream_input->OnFetchMessage(fetch);
 
   // Compose and send the FETCH_OK.
@@ -2408,7 +2409,8 @@
   auto fetch_task_ptr =
       std::make_unique<MockFetchTask>(expected_ok, std::nullopt, true);
   MockFetchTask* fetch_task = fetch_task_ptr.get();
-  EXPECT_CALL(*track, Fetch).WillOnce(Return(std::move(fetch_task_ptr)));
+  EXPECT_CALL(*track, StandaloneFetch)
+      .WillOnce(Return(std::move(fetch_task_ptr)));
   EXPECT_CALL(mock_stream_, Writev(SerializedControlMessage(expected_ok), _));
   webtransport::test::MockStream data_stream;
   std::unique_ptr<webtransport::StreamVisitor> stream_visitor;
@@ -2433,7 +2435,8 @@
   auto fetch_task_ptr =
       std::make_unique<MockFetchTask>(std::nullopt, std::nullopt, true);
   MockFetchTask* fetch_task = fetch_task_ptr.get();
-  EXPECT_CALL(*track, Fetch).WillOnce(Return(std::move(fetch_task_ptr)));
+  EXPECT_CALL(*track, StandaloneFetch)
+      .WillOnce(Return(std::move(fetch_task_ptr)));
   webtransport::test::MockStream data_stream;
   std::unique_ptr<webtransport::StreamVisitor> stream_visitor;
   ExpectStreamOpen(mock_session_, fetch_task, data_stream, stream_visitor);
@@ -2460,7 +2463,8 @@
   auto fetch_task_ptr =
       std::make_unique<MockFetchTask>(std::nullopt, std::nullopt, true);
   MockFetchTask* fetch_task = fetch_task_ptr.get();
-  EXPECT_CALL(*track, Fetch).WillOnce(Return(std::move(fetch_task_ptr)));
+  EXPECT_CALL(*track, StandaloneFetch)
+      .WillOnce(Return(std::move(fetch_task_ptr)));
   webtransport::test::MockStream data_stream;
   std::unique_ptr<webtransport::StreamVisitor> stream_visitor;
   ExpectStreamOpen(mock_session_, fetch_task, data_stream, stream_visitor);
@@ -2501,7 +2505,8 @@
 
   auto fetch_task_ptr = std::make_unique<MockFetchTask>();
   MockFetchTask* fetch_task = fetch_task_ptr.get();
-  EXPECT_CALL(*track, Fetch).WillOnce(Return(std::move(fetch_task_ptr)));
+  EXPECT_CALL(*track, StandaloneFetch)
+      .WillOnce(Return(std::move(fetch_task_ptr)));
   EXPECT_CALL(*fetch_task, GetStatus())
       .WillRepeatedly(Return(absl::Status(absl::StatusCode::kInternal, "foo")));
   EXPECT_CALL(mock_stream_,
@@ -2518,7 +2523,8 @@
   auto fetch_task_ptr =
       std::make_unique<MockFetchTask>(std::nullopt, std::nullopt, true);
   MockFetchTask* fetch_task = fetch_task_ptr.get();
-  EXPECT_CALL(*track, Fetch).WillOnce(Return(std::move(fetch_task_ptr)));
+  EXPECT_CALL(*track, StandaloneFetch)
+      .WillOnce(Return(std::move(fetch_task_ptr)));
 
   stream_input->OnFetchMessage(fetch);
   EXPECT_CALL(mock_session_, CanOpenNextOutgoingUnidirectionalStream())
@@ -2538,7 +2544,7 @@
   stream_visitor->OnCanWrite();
 }
 
-TEST_F(MoqtSessionTest, IncomingJoiningFetch) {
+TEST_F(MoqtSessionTest, IncomingRelativeJoiningFetch) {
   MoqtSubscribe subscribe = DefaultSubscribe();
   // Give it the latest object filter.
   subscribe.filter_type = MoqtFilterType::kLatestObject;
@@ -2558,24 +2564,51 @@
   EXPECT_FALSE(
       MoqtSessionPeer::InSubscriptionWindow(subscription, Location(4, 10)));
 
-  // Joining FETCH arrives. The resulting Fetch should begin at (2, 0).
   MoqtFetch fetch = DefaultFetch();
   fetch.request_id = 3;
   fetch.fetch = JoiningFetchRelative(1, 2);
-  EXPECT_CALL(*track, Fetch(Location(2, 0), 4, std::optional<uint64_t>(10), _))
+  EXPECT_CALL(*track, RelativeFetch(2, _))
       .WillOnce(Return(std::make_unique<MockFetchTask>()));
   stream_input->OnFetchMessage(fetch);
 }
 
-TEST_F(MoqtSessionTest, IncomingJoiningFetchBadSubscribeId) {
+TEST_F(MoqtSessionTest, IncomingAbsoluteJoiningFetch) {
+  MoqtSubscribe subscribe = DefaultSubscribe();
+  // Give it the latest object filter.
+  subscribe.filter_type = MoqtFilterType::kLatestObject;
+  subscribe.start = std::nullopt;
+  subscribe.end_group = std::nullopt;
+  std::unique_ptr<MoqtControlParserVisitor> stream_input =
+      MoqtSessionPeer::CreateControlStream(&session_, &mock_stream_);
+  MockTrackPublisher* track = CreateTrackPublisher();
+  SetLargestId(track, Location(4, 10));
+  ReceiveSubscribeSynchronousOk(track, subscribe, stream_input.get());
+
+  MoqtObjectListener* subscription =
+      MoqtSessionPeer::GetSubscription(&session_, subscribe.request_id);
+  ASSERT_NE(subscription, nullptr);
+  EXPECT_TRUE(
+      MoqtSessionPeer::InSubscriptionWindow(subscription, Location(4, 11)));
+  EXPECT_FALSE(
+      MoqtSessionPeer::InSubscriptionWindow(subscription, Location(4, 10)));
+
+  MoqtFetch fetch = DefaultFetch();
+  fetch.request_id = 3;
+  fetch.fetch = JoiningFetchAbsolute(1, 2);
+  EXPECT_CALL(*track, AbsoluteFetch(2, _))
+      .WillOnce(Return(std::make_unique<MockFetchTask>()));
+  stream_input->OnFetchMessage(fetch);
+}
+
+TEST_F(MoqtSessionTest, IncomingJoiningFetchBadRequestId) {
   std::unique_ptr<MoqtControlParserVisitor> stream_input =
       MoqtSessionPeer::CreateControlStream(&session_, &mock_stream_);
   MoqtFetch fetch = DefaultFetch();
   fetch.fetch = JoiningFetchRelative(1, 2);
   MoqtFetchError expected_error = {
       /*request_id=*/1,
-      /*error_code=*/RequestErrorCode::kTrackDoesNotExist,
-      /*reason_phrase=*/"Joining Fetch for non-existent subscribe",
+      /*error_code=*/RequestErrorCode::kInvalidJoiningRequestId,
+      /*reason_phrase=*/"Joining Fetch for non-existent request",
   };
   EXPECT_CALL(mock_stream_,
               Writev(SerializedControlMessage(expected_error), _));
diff --git a/quiche/quic/moqt/moqt_subscribe_windows.h b/quiche/quic/moqt/moqt_subscribe_windows.h
index 0348044..bbdcbee 100644
--- a/quiche/quic/moqt/moqt_subscribe_windows.h
+++ b/quiche/quic/moqt/moqt_subscribe_windows.h
@@ -31,10 +31,7 @@
       : start_(start),
         end_(Location(end_group.value_or(UINT64_MAX), UINT64_MAX)) {}
   // For FETCH with end object
-  SubscribeWindow(Location start, uint64_t end_group,
-                  std::optional<uint64_t> end_object)
-      : start_(start),
-        end_(Location(end_group, end_object.value_or(UINT64_MAX))) {}
+  SubscribeWindow(Location start, Location end) : start_(start), end_(end) {}
 
   bool InWindow(const Location& seq) const {
     return start_ <= seq && seq <= end_;
diff --git a/quiche/quic/moqt/moqt_subscribe_windows_test.cc b/quiche/quic/moqt/moqt_subscribe_windows_test.cc
index 952c48f..20cf483 100644
--- a/quiche/quic/moqt/moqt_subscribe_windows_test.cc
+++ b/quiche/quic/moqt/moqt_subscribe_windows_test.cc
@@ -48,7 +48,7 @@
 
 TEST_F(SubscribeWindowTest, UpdateStartEnd) {
   SubscribeWindow window(start_, end_);
-  EXPECT_TRUE(window.TruncateStart(start_.next()));
+  EXPECT_TRUE(window.TruncateStart(start_.Next()));
   EXPECT_TRUE(window.TruncateEnd(end_ - 1));
   EXPECT_FALSE(window.InWindow(start_));
   EXPECT_FALSE(window.InWindow(Location(end_, 0)));
diff --git a/quiche/quic/moqt/moqt_track.h b/quiche/quic/moqt/moqt_track.h
index d2bfc18..4ff4ab8 100644
--- a/quiche/quic/moqt/moqt_track.h
+++ b/quiche/quic/moqt/moqt_track.h
@@ -227,8 +227,7 @@
                 FetchResponseCallback callback)
       : RemoteTrack(
             standalone.full_track_name, fetch.request_id,
-            SubscribeWindow(standalone.start_object, standalone.end_group,
-                            standalone.end_object),
+            SubscribeWindow(standalone.start_location, standalone.end_location),
             fetch.subscriber_priority),
         ok_callback_(std::move(callback)) {}
   // Relative Joining Fetch constructor
diff --git a/quiche/quic/moqt/moqt_track_test.cc b/quiche/quic/moqt/moqt_track_test.cc
index d8fa4a2..58ca466 100644
--- a/quiche/quic/moqt/moqt_track_test.cc
+++ b/quiche/quic/moqt/moqt_track_test.cc
@@ -101,7 +101,8 @@
       /*subscriber_priority=*/128,
       /*group_order=*/std::nullopt,
       /*fetch=*/
-      StandaloneFetch(FullTrackName("foo", "bar"), Location(1, 1), 3, 100),
+      StandaloneFetch(FullTrackName("foo", "bar"), Location(1, 1),
+                      Location(3, 100)),
       VersionSpecificParameters(),
   };
   // The pointer held by the application.
diff --git a/quiche/quic/moqt/test_tools/moqt_session_peer.h b/quiche/quic/moqt/test_tools/moqt_session_peer.h
index 4064ed3..414e364 100644
--- a/quiche/quic/moqt/test_tools/moqt_session_peer.h
+++ b/quiche/quic/moqt/test_tools/moqt_session_peer.h
@@ -188,8 +188,8 @@
         0,
         128,
         std::nullopt,
-        StandaloneFetch(FullTrackName{"foo", "bar"}, Location{0, 0}, 4,
-                        std::nullopt),
+        StandaloneFetch(FullTrackName{"foo", "bar"}, Location{0, 0},
+                        Location{4, kMaxObjectId}),
         VersionSpecificParameters(),
     };
     std::unique_ptr<MoqtFetchTask> task;
diff --git a/quiche/quic/moqt/test_tools/moqt_test_message.h b/quiche/quic/moqt/test_tools/moqt_test_message.h
index b558c38..313000c 100644
--- a/quiche/quic/moqt/test_tools/moqt_test_message.h
+++ b/quiche/quic/moqt/test_tools/moqt_test_message.h
@@ -1465,8 +1465,9 @@
     // Avoid varint nonsense.
     QUICHE_CHECK(group < 64);
     QUICHE_CHECK(!object.has_value() || *object < 64);
-    std::get<StandaloneFetch>(fetch_.fetch).end_group = group;
-    std::get<StandaloneFetch>(fetch_.fetch).end_object = object;
+    std::get<StandaloneFetch>(fetch_.fetch).end_location.group = group;
+    std::get<StandaloneFetch>(fetch_.fetch).end_location.object =
+        object.has_value() ? *object : kMaxObjectId;
     raw_packet_[18] = group;
     raw_packet_[19] = object.has_value() ? (*object + 1) : 0;
     SetWireImage(raw_packet_, sizeof(raw_packet_));
@@ -1486,8 +1487,8 @@
       0x01,                          // type = kStandalone
       0x01, 0x03, 0x66, 0x6f, 0x6f,  // track_namespace = "foo"
       0x03, 0x62, 0x61, 0x72,        // track_name = "bar"
-      0x01, 0x02,                    // start_object = 1, 2
-      0x05, 0x07,                    // end_object = 5, 6
+      0x01, 0x02,                    // start_location = 1, 2
+      0x05, 0x07,                    // end_location = 5, 6
       0x01, 0x03, 0x05, 0x03, 0x00, 0x62, 0x61, 0x7a,  // parameters = "baz"
   };
 
@@ -1498,9 +1499,8 @@
       /*fetch =*/
       StandaloneFetch{
           FullTrackName("foo", "bar"),
-          /*start_object=*/Location{1, 2},
-          /*end_group=*/5,
-          /*end_object=*/6,
+          /*start_location=*/Location{1, 2},
+          /*end_location=*/Location{5, 6},
       },
       VersionSpecificParameters(AuthTokenType::kOutOfBand, "baz"),
   };
@@ -1558,7 +1558,7 @@
       0x02,        // priority = kHigh
       0x01,        // group_order = kAscending
       0x02,        // type = kRelativeJoining
-      0x02, 0x02,  // joining_subscribe_id = 2, 2 groups
+      0x02, 0x02,  // joining_request_id = 2, 2 groups
       0x01, 0x03, 0x05, 0x03, 0x00, 0x62, 0x61, 0x7a,  // parameters = "baz"
   };
 
@@ -1623,7 +1623,7 @@
       0x02,        // priority = kHigh
       0x01,        // group_order = kAscending
       0x03,        // type = kAbsoluteJoining
-      0x02, 0x02,  // joining_subscribe_id = 2, group_id = 2
+      0x02, 0x02,  // joining_request_id = 2, group_id = 2
       0x01, 0x03, 0x05, 0x03, 0x00, 0x62, 0x61, 0x7a,  // parameters = "baz"
   };
 
@@ -1678,7 +1678,7 @@
       0x01,                    // request_id = 1
       0x01,                    // group_order = kAscending
       0x00,                    // end_of_track = false
-      0x05, 0x04,              // end_location = 5, 4
+      0x05, 0x04,              // end_location = 5, 3
       0x01, 0x04, 0x67, 0x10,  // MaxCacheDuration = 10000
   };
 
@@ -1686,7 +1686,7 @@
       /*request_id =*/1,
       /*group_order=*/MoqtDeliveryOrder::kAscending,
       /*end_of_track=*/false,
-      /*end_location=*/Location{5, 4},
+      /*end_location=*/Location{5, 3},
       VersionSpecificParameters(quic::QuicTimeDelta::Infinite(),
                                 quic::QuicTimeDelta::FromMilliseconds(10000)),
   };
diff --git a/quiche/quic/moqt/tools/moqt_mock_visitor.h b/quiche/quic/moqt/tools/moqt_mock_visitor.h
index ab2943c..cc46881 100644
--- a/quiche/quic/moqt/tools/moqt_mock_visitor.h
+++ b/quiche/quic/moqt/tools/moqt_mock_visitor.h
@@ -76,9 +76,12 @@
               (const, override));
   MOCK_METHOD(MoqtPriority, GetPublisherPriority, (), (const, override));
   MOCK_METHOD(MoqtDeliveryOrder, GetDeliveryOrder, (), (const, override));
-  MOCK_METHOD(std::unique_ptr<MoqtFetchTask>, Fetch,
-              (Location, uint64_t, std::optional<uint64_t>, MoqtDeliveryOrder),
-              (override));
+  MOCK_METHOD(std::unique_ptr<MoqtFetchTask>, StandaloneFetch,
+              (Location, Location, MoqtDeliveryOrder), (override));
+  MOCK_METHOD(std::unique_ptr<MoqtFetchTask>, RelativeFetch,
+              (uint64_t, MoqtDeliveryOrder), (override));
+  MOCK_METHOD(std::unique_ptr<MoqtFetchTask>, AbsoluteFetch,
+              (uint64_t, MoqtDeliveryOrder), (override));
 
  private:
   FullTrackName track_name_;