From 1df6af6077f162c4aecd462cd30581a5d7f3d2ee Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 11:18:03 -0600 Subject: [PATCH 1/2] feat(id-worlds): public construction path for JournalAdminHistory (#13421) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JournalAdminHistory's fields were pub(crate) with no public constructor, so code outside id-worlds — benches, integration tests, downstream tooling — could not build a current-form checkpoint's admin history and had to fall back to the legacy inline form (admin_history: None). - Add JournalAdminHistory::new(events, complete) plus events(), is_complete() and into_events() accessors; fields stay crate-private so the window is only ever set whole. - Re-export the type publicly from world/mod.rs; the id facade re-exports world wholesale, so id::world::JournalAdminHistory is the facade path. - Add pkgs/id/tests/journal_admin_history.rs: an external-crate test that builds a current-form checkpoint through the facade only and round-trips it through the journal line format. - Drop the now-false limitation claim from the stress_join bench header (bench behaviour unchanged). --- pkgs/id/benches/world_bench.rs | 10 +-- pkgs/id/crates/id-worlds/src/world/journal.rs | 33 ++++++++ pkgs/id/crates/id-worlds/src/world/mod.rs | 4 +- pkgs/id/tests/journal_admin_history.rs | 79 +++++++++++++++++++ 4 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 pkgs/id/tests/journal_admin_history.rs diff --git a/pkgs/id/benches/world_bench.rs b/pkgs/id/benches/world_bench.rs index b738a780a6..aec4c954b1 100644 --- a/pkgs/id/benches/world_bench.rs +++ b/pkgs/id/benches/world_bench.rs @@ -2750,12 +2750,10 @@ fn ensure_stress_fixture(quick: bool) -> Result { /// retained window and the bench program's snapshot, then the /// committed tail past the checkpoint. The shape mirrors what /// `WorldCore::checkpoint_entries` writes on compaction, in the -/// legacy admin-history form (`admin_history: None`): the current -/// form's `JournalAdminHistory` has crate-private fields and no -/// public constructor, so a bench outside `id-worlds` cannot build -/// one — restore supports the legacy form explicitly, and the -/// retained window (the checkpoint's dominant term) is carried in -/// full. The retained window at these sizes serializes under the +/// legacy admin-history form (`admin_history: None`): restore +/// supports the legacy form explicitly, and the retained window +/// (the checkpoint's dominant term) is carried in full. The +/// retained window at these sizes serializes under the /// writer's own inline bound (`MAX_CHECKPOINT_PART_BYTES`), so the /// single inline entry is the form the writer itself would choose /// for a checkpoint of this size without the admin window. diff --git a/pkgs/id/crates/id-worlds/src/world/journal.rs b/pkgs/id/crates/id-worlds/src/world/journal.rs index 407480b9a4..a0b3cb0119 100644 --- a/pkgs/id/crates/id-worlds/src/world/journal.rs +++ b/pkgs/id/crates/id-worlds/src/world/journal.rs @@ -704,6 +704,39 @@ pub struct JournalAdminHistory { pub(crate) complete: bool, } +impl JournalAdminHistory { + /// Build an admin-history window for a checkpoint. + /// + /// This is the public construction path for code outside + /// `id-worlds` — benches, integration tests and downstream + /// tooling writing journal fixtures (#13421): the fields stay + /// crate-private so the window's contents are only ever set + /// whole, here or by the journal writer itself. `events` is the + /// ordered sequenced and host-originated window the checkpoint + /// carries; `complete` states whether that window reaches back + /// to the start of the world's history, the same claim the + /// writer records from its own admin-history state. + pub fn new(events: Vec, complete: bool) -> Self { + Self { events, complete } + } + + /// The ordered events this window carries. + pub fn events(&self) -> &[WorldEvent] { + &self.events + } + + /// Whether this window reaches back to the start of the + /// world's history. + pub fn is_complete(&self) -> bool { + self.complete + } + + /// Consume the window, returning its events. + pub fn into_events(self) -> Vec { + self.events + } +} + /// Version written in a new journal's [`JournalEntry::Created`] header. /// /// Journal upgrade/rollback contract (issue #227): a journal is created at diff --git a/pkgs/id/crates/id-worlds/src/world/mod.rs b/pkgs/id/crates/id-worlds/src/world/mod.rs index 84f7234129..dae62414f2 100644 --- a/pkgs/id/crates/id-worlds/src/world/mod.rs +++ b/pkgs/id/crates/id-worlds/src/world/mod.rs @@ -80,7 +80,6 @@ pub use hotness::{FiredSignal, HotnessBand, HotnessReport, HotnessSignal}; /// The F12.14 portal policy types (code#1068), re-exported so the /// handle/hub portal surface names the same types the kernel checks. pub use id_caps::portal::{PortalGrantState, PortalGrants, PortalRefusal}; -pub(crate) use journal::JournalAdminHistory; pub use journal::{ CoordinatorJournalEntry, JOURNAL_VERSION, JOURNAL_VERSION_BLOB, JOURNAL_VERSION_CHECKPOINT_PARTS, JOURNAL_VERSION_EXECUTION_PROFILE, @@ -88,7 +87,8 @@ pub use journal::{ JOURNAL_VERSION_OPEN_PRESENCE, JOURNAL_VERSION_PORTALS, JOURNAL_VERSION_PROGRAM_BUNDLE, JOURNAL_VERSION_REGION_HANDOFF, JOURNAL_VERSION_SCHEDULE_RECURRENCE, JOURNAL_VERSION_SIGNED_PLAY, JOURNAL_VERSION_WORLD_BUDGET, JOURNAL_VERSION_WRITE_LEASE, - JournalAckMode, JournalEntry, JournalSignedMove, JournalSnapshot, JournalSnapshotSource, + JournalAckMode, JournalAdminHistory, JournalEntry, JournalSignedMove, JournalSnapshot, + JournalSnapshotSource, MAX_JOURNAL_VERSION, TrustBasis, TrustDecision, WorldJournal, journal_version_required_by, }; pub use metrics::{ diff --git a/pkgs/id/tests/journal_admin_history.rs b/pkgs/id/tests/journal_admin_history.rs new file mode 100644 index 0000000000..6abda9469b --- /dev/null +++ b/pkgs/id/tests/journal_admin_history.rs @@ -0,0 +1,79 @@ +//! External-construction coverage for `JournalAdminHistory` (#13421). +//! +//! Benches, integration tests and downstream tooling live outside +//! `id-worlds`; before #13421 they could not build the current-form +//! checkpoint admin history at all, because the type's fields were +//! crate-private and it had no public constructor — the `stress_join` +//! bench fixtures could only write the legacy inline-checkpoint form +//! (`admin_history: None`). This test uses only the `id` facade's +//! public surface — the same surface a bench writes journal fixtures +//! through — to build a current-form checkpoint, serialize it in the +//! journal's line format, and read it back unchanged. +//! +//! Oracle: the public constructor and accessors round-trip the exact +//! events and completeness flag, and a `JournalEntry::Checkpoint` +//! carrying the built history survives the journal's on-disk line +//! format byte-for-value. + +#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] + +use id::world::{JournalAdminHistory, JournalEntry, WorldEvent, WorldEventKind}; + +fn chat(sequence: u64, text: &str) -> WorldEvent { + WorldEvent { + sequence, + participant_id: 7, + kind: WorldEventKind::Chat(text.to_owned()), + } +} + +#[test] +fn external_code_can_build_a_current_form_checkpoint_admin_history() { + let admin_events = vec![chat(1, "first"), chat(2, "second")]; + let history = JournalAdminHistory::new(admin_events.clone(), true); + assert_eq!(history.events(), admin_events.as_slice()); + assert!(history.is_complete()); + assert_eq!(history.clone().into_events(), admin_events); + + let entry = JournalEntry::Checkpoint { + sequence: 2, + module_hash: "fixture-program".to_owned(), + seed: 42, + provenance: None, + execution_profile: None, + caps_ceiling: None, + schedules: None, + kv: None, + blobs: None, + transfers: None, + lease: None, + snapshot: "2".to_owned(), + events: admin_events.clone(), + admin_history: Some(history), + open_presence: Some(Vec::new()), + }; + + // The journal's on-disk line format: one JSON value per entry. + let line = serde_json::to_string(&entry).unwrap(); + let decoded: JournalEntry = serde_json::from_str(&line).unwrap(); + assert_eq!(decoded, entry); + let JournalEntry::Checkpoint { + admin_history: Some(decoded_history), + .. + } = decoded + else { + panic!("checkpoint lost its admin history on the wire"); + }; + assert_eq!(decoded_history.events(), admin_events.as_slice()); + assert!(decoded_history.is_complete()); +} + +#[test] +fn incomplete_admin_history_round_trips_as_incomplete() { + let history = JournalAdminHistory::new(Vec::new(), false); + assert!(history.events().is_empty()); + assert!(!history.is_complete()); + let line = serde_json::to_string(&history).unwrap(); + let decoded: JournalAdminHistory = serde_json::from_str(&line).unwrap(); + assert_eq!(decoded, history); +} From 7435fe7d09a3cdea5b589965f5bb4f7aebd7993e Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 23 Nov 2026 11:30:54 -0600 Subject: [PATCH 2/2] style(id-worlds): make JournalAdminHistory::new / is_complete const fn Clippy (missing_const_for_fn) on the new accessors from the previous commit; SessionId::new in the same module is already const, so match it. --- pkgs/id/crates/id-worlds/src/world/journal.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/id/crates/id-worlds/src/world/journal.rs b/pkgs/id/crates/id-worlds/src/world/journal.rs index a0b3cb0119..522f637306 100644 --- a/pkgs/id/crates/id-worlds/src/world/journal.rs +++ b/pkgs/id/crates/id-worlds/src/world/journal.rs @@ -716,7 +716,7 @@ impl JournalAdminHistory { /// carries; `complete` states whether that window reaches back /// to the start of the world's history, the same claim the /// writer records from its own admin-history state. - pub fn new(events: Vec, complete: bool) -> Self { + pub const fn new(events: Vec, complete: bool) -> Self { Self { events, complete } } @@ -727,7 +727,7 @@ impl JournalAdminHistory { /// Whether this window reaches back to the start of the /// world's history. - pub fn is_complete(&self) -> bool { + pub const fn is_complete(&self) -> bool { self.complete }