diff --git a/crates/buzz-db/src/runtime/tests.rs b/crates/buzz-db/src/runtime/tests.rs index 77c209eec3..82982890b8 100644 --- a/crates/buzz-db/src/runtime/tests.rs +++ b/crates/buzz-db/src/runtime/tests.rs @@ -3594,6 +3594,7 @@ async fn thread_window_statement_cancel_propagates_without_writer_rerun() { kinds: &[7], accessible: &accessible, cursor: None, + since: None, }; match session .thread_window_aux(&aux, &mut ScanBudget::default()) diff --git a/crates/buzz-db/src/runtime/tests/thread_window_postgres_tests.rs b/crates/buzz-db/src/runtime/tests/thread_window_postgres_tests.rs index ac31f6043f..1610a1195e 100644 --- a/crates/buzz-db/src/runtime/tests/thread_window_postgres_tests.rs +++ b/crates/buzz-db/src/runtime/tests/thread_window_postgres_tests.rs @@ -99,6 +99,7 @@ async fn thread_window_upper_fence_terminal_snapshot_and_fallback() { kinds: &[5, 40003], accessible: &[channel], cursor: None, + since: None, }; let mut budget = ScanBudget::default(); let stale = session diff --git a/crates/buzz-db/src/store/thread_window.rs b/crates/buzz-db/src/store/thread_window.rs index daf37f7e94..cd067f0c35 100644 --- a/crates/buzz-db/src/store/thread_window.rs +++ b/crates/buzz-db/src/store/thread_window.rs @@ -29,6 +29,9 @@ pub struct ThreadWindow { /// A supported conversation root exists in this channel, possibly as a /// tombstone. Only then may the bridge serve rows, auxiliary events or bounds. pub root_in_channel: bool, + /// The root's `created_at` when [`Self::root_in_channel`]. The root is + /// always an auxiliary target, so it anchors the auxiliary time bound. + pub root_created_at: Option>, } fn invalid(message: impl Into) -> DbError { @@ -87,17 +90,19 @@ async fn select_window( } // Retain tombstones: deleting a root must not make its readable replies // disappear. Never follow a root belonging to another channel/community. - let root_in_channel: bool = sqlx::query_scalar( - "SELECT EXISTS(SELECT 1 FROM events WHERE community_id = $1 AND channel_id = $2 AND id = $3 AND kind = ANY($4))") + let root_created_at: Option> = sqlx::query_scalar( + "SELECT MIN(created_at) FROM events WHERE community_id = $1 AND channel_id = $2 AND id = $3 AND kind = ANY($4)") .bind(community.as_uuid()).bind(request.channel).bind(&root) .bind(ROW_KINDS.map(|k| k as i32).to_vec()) .fetch_one(&mut *conn).await?; + let root_in_channel = root_created_at.is_some(); if !root_in_channel { return Ok(ThreadWindow { rows: vec![], has_more: false, next_cursor: None, root_in_channel, + root_created_at, }); } // Order metadata before event lookups. With stale statistics a root-wide @@ -176,6 +181,7 @@ async fn select_window( has_more, next_cursor, root_in_channel, + root_created_at, }) } @@ -288,6 +294,9 @@ pub struct AuxQuery<'a> { pub accessible: &'a [Uuid], /// Last raw auxiliary scan position, not last delivered event. pub cursor: Option, + /// Optional lower `created_at` bound, so the `#e` probes can prune older + /// `events` partitions. `None` scans the community's whole history. + pub since: Option>, } /// Fixed raw auxiliary page budget (the probe is one extra row). @@ -373,6 +382,9 @@ async fn select_aux( ) .push_bind(query.targets) .push("))"); + if let Some(since) = query.since { + q.push(" AND created_at >= ").push_bind(since); + } if let Some(cursor) = &query.cursor { let (ts, id) = cursor_key(cursor)?; q.push(" AND (created_at < ") diff --git a/crates/buzz-db/src/store/thread_window/postgres_tests.rs b/crates/buzz-db/src/store/thread_window/postgres_tests.rs index a2bda65123..5cc9613fe8 100644 --- a/crates/buzz-db/src/store/thread_window/postgres_tests.rs +++ b/crates/buzz-db/src/store/thread_window/postgres_tests.rs @@ -340,6 +340,7 @@ async fn thread_aux_tombstone_ids_and_raw_cursor_survive_damaged_payload() { kinds: &[40003], accessible: &accessible, cursor: None, + since: None, }; let mut session = ReadSession { inner: ReadSessionInner::Writer(db.pool.clone()), @@ -379,6 +380,7 @@ async fn thread_aux_query_budget_fails_on_65th_real_scan() { kinds: &[7], accessible: &[channel], cursor: None, + since: None, }; let mut session = ReadSession { inner: ReadSessionInner::Writer(db.pool.clone()), @@ -427,6 +429,7 @@ async fn thread_aux_byte_budget_stops_consumption_and_survives_retry() { kinds: &[40003], accessible: &[channel], cursor: None, + since: None, }; let mut session = ReadSession { inner: ReadSessionInner::Writer(db.pool.clone()), @@ -538,6 +541,7 @@ async fn thread_reply_byte_budget_stops_before_collecting_page() { kinds: &[7], accessible: &[channel], cursor: None, + since: None, }, &mut budget, ) diff --git a/crates/buzz-relay/src/api/bridge.rs b/crates/buzz-relay/src/api/bridge.rs index 39a2ab9718..aff105b70f 100644 --- a/crates/buzz-relay/src/api/bridge.rs +++ b/crates/buzz-relay/src/api/bridge.rs @@ -936,6 +936,34 @@ const AUX_PAGE_LIMIT: i64 = buzz_db::DEFAULT_MAX_PAGE_LIMIT; /// loop forever against a pathological write pattern. const AUX_MAX_PAGES: usize = 64; +/// How far before the oldest retained window row the aux hops still look. +/// Ingest rejects any event more than 900 s from the relay clock +/// (`MAX_TIMESTAMP_DRIFT_SECS` in `handlers/ingest.rs`), so an aux event can +/// predate its target by at most ~30 min; a day covers that with room for +/// data that reached the store another way. The bound lets the `#e` GIN +/// probes prune older `events` partitions instead of scanning the +/// community's whole history. +const WINDOW_AUX_SINCE_MARGIN_SECS: i64 = 24 * 60 * 60; + +/// Lower `created_at` bound for both window aux hops: the oldest aux target +/// (Unix seconds) minus [`WINDOW_AUX_SINCE_MARGIN_SECS`]. Every aux event, in +/// either hop, really happened after the row it chains back to, so its +/// timestamp is at most twice the ingest drift before that row's; the same +/// bound covers both hops. +/// `None` when there are no targets (no hops run). +fn window_aux_since( + target_created_at: impl IntoIterator, +) -> Option> { + let oldest = target_created_at.into_iter().min()?; + let since = oldest.saturating_sub(WINDOW_AUX_SINCE_MARGIN_SECS).max(0); + chrono::DateTime::from_timestamp(since, 0) +} + +/// Unix seconds of a stored event, for [`window_aux_since`]. +fn stored_event_secs(event: &buzz_core::StoredEvent) -> i64 { + i64::try_from(event.event.created_at.as_secs()).unwrap_or(i64::MAX) +} + fn build_aux_query( community: buzz_core::CommunityId, target_ids: Vec, @@ -1109,9 +1137,16 @@ async fn handle_channel_window_filter( let mut seen_aux: std::collections::HashSet = std::collections::HashSet::new(); let mut hop_ids = row_ids_hex.clone(); + let aux_since = window_aux_since( + window + .rows + .iter() + .map(|row| stored_event_secs(&row.stored_event)), + ); for hop_kinds in [&WINDOW_AUX_KINDS[..], &WINDOW_AUX_DELETE_KINDS[..]] { - let aux_query = + let mut aux_query = build_aux_query(tenant.community(), std::mem::take(&mut hop_ids), hop_kinds); + aux_query.since = aux_since; let aux_events = query_all_pages( aux_query, AUX_PAGE_LIMIT, @@ -5617,6 +5652,170 @@ pub(crate) mod postgres_tests { ); } + /// The channel-window aux closure reads both hops from one day before the + /// oldest retained row, not before the newest row or the wall clock. The + /// window holds a row from now and one from 40 days ago; aux on the old + /// row inside that bound still comes back, on the two-row page and on the + /// cursor page holding only the old row, and aux dated more than a day + /// before the old row is not read. Mutations: drop `aux_query.since`, or + /// widen the margin by more than a minute → the out-of-bound events return + /// → RED; anchor on the newest row (`.max()`) or on `Utc::now()` → the + /// in-bound events vanish → RED. + #[tokio::test] + #[ignore = "requires Postgres and Redis"] + async fn channel_window_aux_hops_read_from_a_day_before_the_oldest_row() { + use buzz_core::kind::{KIND_DELETION, KIND_REACTION}; + use buzz_db::channel::{ChannelType, ChannelVisibility}; + + let state = bridge_handler_test_state() + .await + .expect("local Postgres and Redis"); + let host = format!("window-aux-bound-{}.local", uuid::Uuid::new_v4().simple()); + let community = state + .db + .ensure_configured_community(&host) + .await + .expect("ensure community"); + let author = Keys::generate(); + let (channel, _) = state + .db + .create_channel_with_id( + community.id, + uuid::Uuid::new_v4(), + &format!("window-aux-bound-{}", uuid::Uuid::new_v4().simple()), + ChannelType::Stream, + ChannelVisibility::Open, + None, + author.public_key().to_bytes().as_slice(), + None, + ) + .await + .expect("create channel"); + let ch = channel.id.to_string(); + + // Ingest's ±900 s clock check and the store's channel-event floor + // both refuse backdated events, so the backdated aux events are + // stored channel-less, as a NIP-09 deletion may be; the aux hops are + // community-wide `#e` lookups and still find them. The old row must + // be in the channel, so it is written as historical data would be. + let now = chrono::Utc::now().timestamp() as u64; + let day = 86_400; + let build = |kind: u32, at: u64, target: Option<&nostr::EventId>| { + let mut builder = EventBuilder::new(Kind::Custom(kind as u16), "+") + .tag(Tag::parse(["h", ch.as_str()]).expect("h")); + if let Some(target) = target { + builder = builder.tag(Tag::parse(["e", &target.to_hex()]).expect("e")); + } + builder + .custom_created_at(nostr::Timestamp::from(at)) + .sign_with_keys(&author) + .expect("sign") + }; + let store = |kind: u32, at: u64, target: &nostr::EventId| { + let event = build(kind, at, Some(target)); + let state = state.clone(); + async move { + state + .db + .insert_event(community.id, &event, None) + .await + .expect("insert"); + event.id + } + }; + let new_row = build(9, now, None); + state + .db + .insert_event(community.id, &new_row, Some(channel.id)) + .await + .expect("insert new row"); + let old_at = now - 40 * day; + let old_row = build(9, old_at, None); + let pool = sqlx::PgPool::connect(&crate::test_support::database_url()) + .await + .expect("pool"); + sqlx::query( + "INSERT INTO events (community_id,id,pubkey,created_at,kind,tags,content,sig,received_at,channel_id) \ + VALUES ($1,$2,$3,to_timestamp($4),$5,$6,$7,$8,now(),$9)", + ) + .bind(community.id.as_uuid()) + .bind(old_row.id.to_bytes().to_vec()) + .bind(old_row.pubkey.to_bytes().to_vec()) + .bind(old_at as f64) + .bind(9_i32) + .bind(serde_json::to_value(&old_row.tags).expect("tags")) + .bind(&old_row.content) + .bind(old_row.sig.serialize().to_vec()) + .bind(channel.id) + .execute(&pool) + .await + .expect("insert old row"); + let reaction_in = store(KIND_REACTION, old_at - day + 60, &old_row.id).await; + let reaction_out = store(KIND_REACTION, old_at - day - 60, &old_row.id).await; + let delete_in = store(KIND_DELETION, old_at - day + 120, &reaction_in).await; + let delete_out = store(KIND_DELETION, old_at - day - 120, &reaction_in).await; + + let query = |filter: Value| { + let state = state.clone(); + let host = host.clone(); + let pubkey = author.public_key().to_hex(); + async move { + let body = serde_json::to_vec(&[filter]).expect("json"); + let (status, bytes) = post_query(state, &host, &pubkey, &body).await; + assert_eq!( + status, + StatusCode::OK, + "{}", + String::from_utf8_lossy(&bytes) + ); + serde_json::from_slice::>(&bytes).expect("event array") + } + }; + let assert_old_row_aux = |events: &[Value], page: &str| { + let has = |id: &nostr::EventId| { + events + .iter() + .any(|e| e["id"].as_str() == Some(id.to_hex().as_str())) + }; + assert!(has(&old_row.id), "{page}: old row: {events:?}"); + assert!( + has(&reaction_in), + "{page}: hop 1 inside the bound: {events:?}" + ); + assert!( + has(&delete_in), + "{page}: hop 2 inside the bound: {events:?}" + ); + assert!( + !has(&reaction_out), + "{page}: hop 1 past the bound: {events:?}" + ); + assert!( + !has(&delete_out), + "{page}: hop 2 past the bound: {events:?}" + ); + }; + + let filter = serde_json::json!({ + "kinds": [9], "#h": [&ch], "top_level": true, "include_aux": true, + }); + assert_old_row_aux(&query(filter.clone()).await, "two-row page"); + + let mut paged = filter; + paged["limit"] = serde_json::json!(1); + let first = query(paged.clone()).await; + let bounds: Value = first + .iter() + .find(|e| e["kind"] == 39006) + .and_then(|e| e["content"].as_str()) + .map(|content| serde_json::from_str(content).expect("bounds content")) + .expect("window bounds"); + assert_eq!(bounds["has_more"], true, "{first:?}"); + paged["until"] = bounds["next_cursor"]["created_at"].clone(); + paged["before_id"] = bounds["next_cursor"]["id"].clone(); + assert_old_row_aux(&query(paged).await, "cursor page"); + } + // ────────────────────────────────────────────────────────────────────────── // Log-capture helpers and attribution-invariant tests // diff --git a/crates/buzz-relay/src/api/bridge/thread_window.rs b/crates/buzz-relay/src/api/bridge/thread_window.rs index fc5989172b..c8a955d90e 100644 --- a/crates/buzz-relay/src/api/bridge/thread_window.rs +++ b/crates/buzz-relay/src/api/bridge/thread_window.rs @@ -203,6 +203,15 @@ async fn query( if request.include_aux { let row_count = events.len(); let original_targets = targets; + // The root is always a target and the rows are replies, so the root + // anchors the bound (see `window_aux_since`). + let aux_since = super::window_aux_since( + window + .root_created_at + .map(|at| at.timestamp()) + .into_iter() + .chain(window.rows.iter().map(super::stored_event_secs)), + ); // A writer retry at an older aux cursor alone would miss newer writer // edits. Restart both closure hops once after permanent degradation; // preserve the request ledger/deadline, never reset work allowances. @@ -219,6 +228,7 @@ async fn query( kinds, accessible, cursor: None, + since: aux_since, }; loop { let was_replica = session.is_replica(); diff --git a/crates/buzz-relay/src/api/bridge/thread_window/postgres_tests.rs b/crates/buzz-relay/src/api/bridge/thread_window/postgres_tests.rs index 7430d7d7a9..7cc5fbc8d7 100644 --- a/crates/buzz-relay/src/api/bridge/thread_window/postgres_tests.rs +++ b/crates/buzz-relay/src/api/bridge/thread_window/postgres_tests.rs @@ -96,17 +96,18 @@ impl Fixture { .bind(count).bind(content).execute(&self.pool).await.unwrap(); } async fn reply(&self, n: usize) -> Event { - let reply = event( - &self.keys, - self.channel, - 9, + self.reply_to( + &self.root, &format!("reply {n}"), - Some(&self.root), self.root.created_at.as_secs() + n as u64, - ); + ) + .await + } + async fn reply_to(&self, root: &Event, content: &str, at: u64) -> Event { + let reply = event(&self.keys, self.channel, 9, content, Some(root), at); let ts = chrono::DateTime::from_timestamp(reply.created_at.as_secs() as i64, 0).unwrap(); let root_ts = - chrono::DateTime::from_timestamp(self.root.created_at.as_secs() as i64, 0).unwrap(); + chrono::DateTime::from_timestamp(root.created_at.as_secs() as i64, 0).unwrap(); self.state .db .insert_event_with_thread_metadata( @@ -117,9 +118,9 @@ impl Fixture { event_id: &reply.id.to_bytes(), event_created_at: ts, channel_id: self.channel, - parent_event_id: Some(&self.root.id.to_bytes()), + parent_event_id: Some(&root.id.to_bytes()), parent_event_created_at: Some(root_ts), - root_event_id: Some(&self.root.id.to_bytes()), + root_event_id: Some(&root.id.to_bytes()), root_event_created_at: Some(root_ts), depth: 1, broadcast: false, @@ -129,6 +130,27 @@ impl Fixture { .unwrap(); reply } + /// Store `event` as historical data that reached the store another way + /// would be: ingest's clock check and the store's channel-event floor + /// refuse backdated events. + async fn insert_raw(&self, event: &Event) { + sqlx::query( + "INSERT INTO events (community_id,id,pubkey,created_at,kind,tags,content,sig,received_at,channel_id) \ + VALUES ($1,$2,$3,to_timestamp($4),$5,$6,$7,$8,now(),$9)", + ) + .bind(self.community.as_uuid()) + .bind(event.id.to_bytes().to_vec()) + .bind(event.pubkey.to_bytes().to_vec()) + .bind(event.created_at.as_secs() as f64) + .bind(event.kind.as_u16() as i32) + .bind(serde_json::to_value(&event.tags).unwrap()) + .bind(&event.content) + .bind(event.sig.serialize().to_vec()) + .bind(self.channel) + .execute(&self.pool) + .await + .unwrap(); + } async fn aux(&self, kind: u16, target: &Event, channel: Option) -> Event { let aux = event( &self.keys, @@ -639,3 +661,64 @@ async fn torn_deletions_still_cancel_live_targets_in_both_windows() { } } } + +/// Both thread aux hops read from one day before the root (always a target; +/// the rows are replies): a reaction and a delete-of-reaction inside that +/// bound come back, ones dated more than a day before it do not. The only +/// reply is two days newer than the root, so anchoring on the replies alone +/// drops the in-bound events. Mutation: drop `since: aux_since` → the +/// out-of-bound events return → RED; drop the root from the bound → the +/// in-bound events vanish → RED. +#[tokio::test] +#[ignore = "requires Postgres"] +async fn thread_window_aux_hops_read_from_a_day_before_the_root() { + let f = Fixture::new().await; + let day = 86_400; + let reply = f.reply(2 * day as usize).await; + let root_at = f.root.created_at.as_secs(); + let backdated = |kind: u16, target: &Event, at: u64| { + event(&f.keys, f.channel, kind, "aux", Some(target), at) + }; + let reaction_in = backdated(7, &f.root, root_at - day + 60); + let reaction_out = backdated(7, &reply, root_at - day - 60); + let delete_in = backdated(5, &reaction_in, root_at - day + 120); + let delete_out = backdated(5, &reaction_in, root_at - day - 120); + for aux in [&reaction_in, &reaction_out, &delete_in, &delete_out] { + f.insert_raw(aux).await; + } + let page = f.query(&f.filter()).await; + let all = ids(&page, None); + let has = |event: &Event| all.contains(&event.id.to_hex().as_str()); + assert!(has(&reply), "window row: {page}"); + assert!(has(&reaction_in), "hop 1 inside the bound: {page}"); + assert!(has(&delete_in), "hop 2 inside the bound: {page}"); + assert!(!has(&reaction_out), "hop 1 past the bound: {page}"); + assert!(!has(&delete_out), "hop 2 past the bound: {page}"); +} + +/// An ancient root anchors the thread aux bound at its own time, not at the +/// wall clock or its recent replies: a reaction from the root's own time and +/// the deletion of that reaction come back. Mutation: anchor on `Utc::now()`, +/// or drop the root from the bound → both vanish → RED. +#[tokio::test] +#[ignore = "requires Postgres"] +async fn thread_window_aux_bound_follows_an_ancient_root() { + let f = Fixture::new().await; + let now = f.root.created_at.as_secs(); + let root_at = now - 60 * 86_400; + let root = event(&f.keys, f.channel, 9, "ancient root", None, root_at); + f.insert_raw(&root).await; + let reply = f.reply_to(&root, "recent reply", now).await; + let reaction = event(&f.keys, f.channel, 7, "aux", Some(&root), root_at + 60); + let delete = event(&f.keys, f.channel, 5, "aux", Some(&reaction), root_at + 120); + f.insert_raw(&reaction).await; + f.insert_raw(&delete).await; + let mut filter = f.filter(); + filter["#e"] = json!([root.id.to_hex()]); + let page = f.query(&filter).await; + let all = ids(&page, None); + let has = |event: &Event| all.contains(&event.id.to_hex().as_str()); + assert!(has(&reply), "window row: {page}"); + assert!(has(&reaction), "hop 1 at the root's time: {page}"); + assert!(has(&delete), "hop 2 at the root's time: {page}"); +} diff --git a/docs/bridge-channel-window.md b/docs/bridge-channel-window.md index 1f2470866a..ded4bb449c 100644 --- a/docs/bridge-channel-window.md +++ b/docs/bridge-channel-window.md @@ -89,7 +89,11 @@ Clients **partition by kind before any cursor math**: deletions targeting those aux events (the transitive second hop, e.g. a delete-of-a-reaction). One round trip; no client `#e` fan-out. Each hop is drained server-side across the DB page clamp, so the closure is - complete rather than newest-1000. + complete rather than newest-1000. Both hops read only events dated at + most one day before the oldest retained row + (`WINDOW_AUX_SINCE_MARGIN_SECS`), so they can skip older `events` + partitions; ingest's ±15 min clock check keeps aux events within that + margin of their targets. 3. **Thread summaries** (`include_summaries`) — one relay-signed `kind:39005` per row that has replies. 4. **Window bounds** — exactly one relay-signed `kind:39006` per window diff --git a/docs/nips/NIP-CW.md b/docs/nips/NIP-CW.md index c5ad73ad66..0a1250959d 100644 --- a/docs/nips/NIP-CW.md +++ b/docs/nips/NIP-CW.md @@ -101,7 +101,7 @@ For a valid window filter on an accessible channel (§Channel-mode Access Scopin 1. **Select rows.** From the target channel, take events that are top-level (§Channel-mode Top-level Classification), not deleted, and matching `kinds` if present, in the total order `created_at DESC, id ASC` (`id` compared bytewise). With a cursor `(ts, id)`, retain only events where `created_at < ts OR (created_at = ts AND id > id)`. 2. **Probe exhaustion.** Evaluate the query with an internal budget of `limit + 1` rows *after all predicates*. If `limit + 1` rows match, `has_more = true` and the sentinel row is discarded — it MUST NOT appear on the wire, in overlays, or in the aux closure. Otherwise `has_more = false`. 3. **Derive the next cursor.** If `has_more`, `next_cursor` is the **scan position**: the composite cursor of the last retained candidate, captured *before* any serving-time reconstruction or filtering of individual events. Otherwise `next_cursor = null`. The invariant `next_cursor = null ⇔ has_more = false` MUST hold. Because it is a scan position, `next_cursor` MAY reference an event that does not appear in the response (e.g. one skipped by the relay as unreconstructable); it is authoritative regardless, and deriving it from delivered rows instead would stall pagination on every skipped event. -4. **Append the aux closure** (if `include_aux` and at least one row): two hops of events referencing the rows by `e` tag. Hop 1: reactions (`kind:7`), deletions (`kind:5`, `kind:9005`), and edits (Buzz `kind:40003`) whose `e` tag is a row id. Hop 2: deletions whose `e` tag is a hop-1 event id (a delete-of-a-reaction). Each event appears at most once; access-scoped events the requester cannot read are omitted. Relays MAY cap each hop (Buzz: 1000 events per hop). +4. **Append the aux closure** (if `include_aux` and at least one row): two hops of events referencing the rows by `e` tag. Hop 1: reactions (`kind:7`), deletions (`kind:5`, `kind:9005`), and edits (Buzz `kind:40003`) whose `e` tag is a row id. Hop 2: deletions whose `e` tag is a hop-1 event id (a delete-of-a-reaction). Each event appears at most once; access-scoped events the requester cannot read are omitted. Relays MAY cap each hop (Buzz: 1000 events per hop). Relays MAY also omit, from both hops, events whose `created_at` is more than a fixed margin before the oldest row's (Buzz: one day), so the lookups need not scan the channel's whole history; the margin MUST exceed twice the relay's accepted clock drift, since a target and its aux event may each be stamped up to that drift away from real time in opposite directions. 5. **Append thread summaries** (if `include_summaries`): one `kind:39005` per row that has at least one reply. Rows without replies get none. 6. **Append window bounds**: exactly one `kind:39006` per served window response, always — including empty and exhausted pages. @@ -299,6 +299,8 @@ For an authorized request the relay MUST: original signatures, deduplicate by event ID, and apply access control to every event. A target reference requires an `e` tag with the target ID in its second position; containing both strings elsewhere is insufficient. + As in channel mode, relays MAY omit auxiliary events dated more than a fixed + margin before the oldest target, which always includes the root. 5. Append one bounds event to each served page, including empty and exhausted pages. Refresh access for the **entire query batch** before releasing any events or bounds. If the reader's accessible-channel set changed while any