+ enum lttng_live_iterator_status adjust_status;
+ bt_message *adjusted_message;
+
+ /*
+ * The timestamp of the current message is before the last message sent
+ * by this component. We CANNOT send it as is.
+ *
+ * The only expected scenario in which that could happen is the
+ * following, everything else is a bug in this component, relay deamon,
+ * or CTF parser.
+ *
+ * Expected scenario: The CTF message iterator emitted discarded
+ * packets and discarded events with synthesized beginning and end
+ * timestamps from the bounds of the last known packet and the newly
+ * decoded packet header. The CTF message iterator is not aware of
+ * stream inactivity beacons. Hence, we have to adjust the beginning
+ * timestamp of those types of messages if a stream signalled its
+ * inactivity up until _after_ the last known packet's beginning
+ * timestamp.
+ *
+ * Otherwise, the monotonicity guarantee of message timestamps would
+ * not be preserved.
+ *
+ * In short, the only scenario in which it's okay and fixable to
+ * received a late message is when:
+ * 1. the late message is a discarded packets or discarded events
+ * message,
+ * 2. this stream produced an inactivity message downstream, and
+ * 3. the timestamp of the late message is within the inactivity
+ * timespan we sent downstream through the inactivity message.
+ */
+
+ BT_COMP_LOGD("Handling late message on live stream iterator: "
+ "stream-name=\"%s\", viewer-stream-id=%" PRIu64,
+ stream_iter->name->str, stream_iter->viewer_stream_id);
+
+ if (!stream_iter->last_inactivity_ts.is_set) {
+ BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Invalid live stream state: "
+ "have a late message when no inactivity message "
+ "was ever sent for that stream.");
+ stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
+ goto end;
+ }
+
+ if (!is_discarded_packet_or_event_message(late_msg)) {
+ BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Invalid live stream state: "
+ "have a late message that is not a packet discarded or "
+ "event discarded message: late-msg-type=%s",
+ bt_common_message_type_string(bt_message_get_type(late_msg)));
+ stream_iter_status = LTTNG_LIVE_ITERATOR_STATUS_ERROR;
+ goto end;
+ }