Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .claude/board/STATUS_BOARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Plan `.claude/plans/xlog-knowledge-spine-v1.md` (charter, DOCS ONLY); harvest `x
| D-XLOG-KNOWLEDGE-0 | Charter: three IR routes kept separate, donor roles, gates G0..G8, STOP conditions | In PR (#2093), docs only |
| D-XLOG-KNOWLEDGE-G0 | xlog.md + fork source harvest, page/claim/source manifest; 2.80x Scallop claim marked CONFLICT | Partial: 12 pages read, `/llms.txt` 404; manifest not built |
| D-XLOG-KNOWLEDGE-G1 | Reproduce the coverage census at pinned SHAs; add Datafrog as an independent comparator; falsifiers | Shipped (#2095): census reproduced byte-identical (lance-graph `bdee050`, xlog `beac406` = tree of `656def9`). Datafrog arm (`datafrog_arm.rs`, AdaWorldAPI fork `edd7cfc`): agrees on 85/87 oracle-agrees rules, 2 not applicable (integer constant), 0 disagree; rungs unchanged. 4 disable runs red; broken join -> 68 disagreements in the census, 0 rung changes. Entry `2026-11-15-d-xlog-knowledge-g1-datafrog.md` |
| D-DIRSIM-DT64-LANES | dir-sim results through the DT64 lane socket at DR64 / DR256 / n x DR256 | In PR: `dt64::DirLanes` (feature `dt64`); axis from survivors (40,64 -> DR64; 65,200 -> DR256; 512 -> 2 x DR256; 1000 -> 4); cells read in place through `View` (overlay-correct, 0 alloc on the read path); old-version binding refused (`ForeignFrame`), foreign population refused (`NotUsers`); 4 of 5 disables red (frame-revision disable inert: the refusal is per store instance). Lanes: UPN + primary SMTP only |
| D-DIRSIM-LINEAR-RESTORE | `VersionStore::restore` continues the previous overlay along a linear history | In PR: replay+restore 1.19 ms at 1 024 re-reads (was 50 ms), 0.45 ms at 128; 64-step chain applies exactly 64 changes (old fold 2 080); branch re-folds from root; disable red. Closes the quadratic-replay open point of `2026-11-16-d-dirsim-delta-read-1.md` |
| D-DIRSIM-DELTA-READ-1 | Read what changed between observations from the stored deltas; history cost probe | In PR: `VersionStore::history` (34-47 ns, 0 alloc at 1..1024 re-reads); `view`/`diff` linear in lineage; replay quadratic (50 ms cold at 1024) - linear restore proposed. Entry `2026-11-16-d-dirsim-delta-read-1.md` |
| D-DIRSIM-REOBSERVE | dir-sim stores a re-read as its verified changes; plan intent from the nearest observation | In PR: `VersionStore::reobserve`; one membership change = 1 change, 125 B log batch vs 11 094 B for a second root; 3 disable runs red. Entry `2026-11-16-d-dirsim-reobserve.md` |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/identity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ jobs:
# view_actors and membership_path need the rbac feature; without
# this step they compile only locally.
run: cargo test --manifest-path crates/lance-graph-dir-sim/Cargo.toml --features rbac
- name: Run the simulator's DT64 lane tests (feature dt64)
# dt64_lanes needs the dt64 feature; without this step it compiles
# only locally.
run: cargo test --manifest-path crates/lance-graph-dir-sim/Cargo.toml --features dt64 --test dt64_lanes
- name: The tests pinning Exchange behaviour exist
run: |
cargo test -q --manifest-path crates/lance-graph-dir-sim/Cargo.toml -- --list \
Expand Down
4 changes: 4 additions & 0 deletions crates/lance-graph-dir-sim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ ogar-az = { git = "https://github.com/AdaWorldAPI/OGAR", branch = "main" }
# The actor source over a view (`actors`, feature `rbac`): the contract's
# zero-dep `ActorSource` socket.
lance-graph-contract = { path = "../lance-graph-contract", optional = true }
# The DT64 lane socket over a version (`dt64`, feature `dt64`): dir-sim as a
# LaneSource + SelectionSource, its query results as DR selections.
lance-graph-dt64 = { path = "../lance-graph-dt64", optional = true }
# Group-to-role grants are the authority's versioned policy
# (`ogar_rbac::GroupRolePolicy`); `GroupRoles::from_policy` reads one
# version of it. The directory supplies membership only.
Expand All @@ -53,6 +56,7 @@ lance-graph-contract = { path = "../lance-graph-contract" }

[features]
rbac = ["dep:lance-graph-contract", "dep:ogar-rbac"]
dt64 = ["dep:lance-graph-dt64", "dep:lance-graph-contract"]

# mask-risc names ndarray by its canonical git coordinate; point it at the
# sibling checkout so this workspace has one ndarray identity and needs no
Expand Down
216 changes: 216 additions & 0 deletions crates/lance-graph-dir-sim/src/dt64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
//! A version's users through the DT64 lane socket, and dir-sim results as DR
//! selections.
//!
//! ```text
//! VersionStore::view(v) ──► DirLanes (LaneSource + SelectionSource)
//! users_with_key / subtree / … ──► Kept ──select──► (sel, Axis)
//! Axis = DR64 | DR256 | n × DR256
//! BindStore::bind_lanes ──► LaneBinding::selected(field, sel)
//! ──► (UserLane, &[u32]) read lane.get(i) per i
//! ```
//!
//! **A cell is a virtual tuple.** A [`UserLane`] holds no column. Reading row
//! `i` asks the version's [`View`] for that user's attribute, so a base value,
//! an overridden value and a user the version created all read correctly, and
//! nothing is copied into a second object universe. `A[i]:B[i]` is two such
//! reads at one known `i`; there is no tuple, row object or join.
//!
//! **The DR axis follows the survivors.** A selection's axis is
//! `Axis::for_survivors(kept.len())`: up to 64 rows one DR64 tile, up to 256 one
//! DR256 tile, more `ceil(n / 256)` DR256 tiles (512 rows are two). The count is
//! a popcount of the result bitmap; choosing the axis decodes no row. The
//! selection's position list, the socket's form (`SelectionSource`), is built
//! once per selection, bounded by its survivors, never per field or per read.
//!
//! **One version, one frame store.** A [`DirLanes`] is built over one version
//! and owns the frame store its frames come from. A binding made over another
//! version's `DirLanes` is refused (`ForeignFrame`) before any lane is
//! borrowed, so a reader cannot read one version's selection against another
//! version's cells.
//!
//! `Scope` is a consistency check between reader, lanes and selections, as
//! everywhere in DT64; it is not authorization.

use lance_graph_contract::ontology::FieldRef;
use lance_graph_dt64::dr::{Axis, Frame, FrameRevisions, FrameStore, Scope};
use lance_graph_dt64::{CoordSpace, LaneAddr, LaneSource, SchemaRev, SelAddr, SelectionSource};
use ogar_dir_sim::{Attribute, VersionId};

use crate::{Kept, UserOrdinal, View};

/// Field 0 of the user lanes: the UPN value.
pub const F_UPN: u8 = 0;
/// Field 1 of the user lanes: the primary SMTP value.
pub const F_SMTP: u8 = 1;

/// The schema revision these lanes serve.
pub const LANE_REV: SchemaRev = SchemaRev(1);

/// One user attribute of one version, read cell by cell. It holds no values.
#[derive(Clone, Copy)]
pub struct UserLane<'a, 's> {
view: &'a View<'s>,
attr: Attribute,
}

impl UserLane<'_, '_> {
/// The attribute's value id for the user at `row`; `None` when the user
/// has no such value, or `row` is past the version's users.
pub fn get(&self, row: u32) -> Option<u32> {
let g = self.view.user_guid(UserOrdinal(u16::try_from(row).ok()?))?;
self.view.attr(&g, self.attr).map(|v| v.0)
}
}

/// Why a result was not admitted as a selection.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SelectRefusal {
/// The result was computed over another population size than this
/// version's users (a group result, or another version's users).
NotUsers {
/// Rows of the result.
rows: usize,
/// Users of this version.
users: usize,
},
/// More selections than a `u16` id addresses.
Full,
}

/// A selection the source holds.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Selected {
/// Its id for [`lance_graph_dt64::LaneBinding::selected`].
pub sel: u16,
/// The DR axis its survivors take.
pub axis: Axis,
}

/// A version's users as a DT64 lane and selection source.
pub struct DirLanes<'a, 's> {
view: &'a View<'s>,
version: VersionId,
class: u32,
scope: Scope,
frames: FrameStore,
selections: Vec<Vec<u32>>,
}

impl<'a, 's> DirLanes<'a, 's> {
/// The users of `view` (version `version`), bound as class `class` for
/// reader `scope`.
pub fn new(view: &'a View<'s>, version: VersionId, class: u32, scope: Scope) -> Self {
Self {
view,
version,
class,
scope,
frames: FrameStore::new(FrameRevisions {
source: version.0,
relation_map: 0,
coordinates: version.0,
}),
selections: Vec::new(),
}
}

/// The row order the lanes and selections are in: this version's user
/// ordinals.
pub fn space(&self) -> CoordSpace {
CoordSpace {
population: u64::from(self.class),
coordinates: self.version.0,
}
}

/// The DR axis the version's whole user population takes.
pub fn identity_axis(&self) -> Axis {
Axis::for_survivors(self.view.users_len())
}

/// Hold `kept` (a result over this version's users) as a selection.
///
/// # Errors
///
/// [`SelectRefusal`]: the result is over another population, or the
/// source holds `u16::MAX + 1` selections already.
pub fn select(&mut self, kept: &Kept) -> Result<Selected, SelectRefusal> {
let users = self.view.users_len();
if kept.universe() != users {
return Err(SelectRefusal::NotUsers {
rows: kept.universe(),
users,
});
}
let sel = u16::try_from(self.selections.len()).map_err(|_| SelectRefusal::Full)?;
let axis = Axis::for_survivors(kept.len());
// Rows are user ordinals, at most 65,536, so each fits a `u32`.
self.selections
.push(kept.rows().into_iter().map(|r| r as u32).collect());
Ok(Selected { sel, axis })
}
}

impl LaneSource for DirLanes<'_, '_> {
type Lane<'b>
= UserLane<'b, 'b>
where
Self: 'b;

fn lane_of(
&self,
class: u32,
rev: SchemaRev,
field: u8,
_basis: &FieldRef,
_frame: &Frame,
) -> Option<LaneAddr> {
if class != self.class || rev != LANE_REV || field > F_SMTP {
return None;
}
Some(LaneAddr {
space: self.space(),
lane: u16::from(field),
scope: self.scope,
})
}

fn borrow(&self, addr: &LaneAddr) -> Option<UserLane<'_, '_>> {
if addr.space != self.space() {
return None;
}
let attr = match addr.lane {
0 => Attribute::Upn,
1 => Attribute::PrimarySmtp,
_ => return None,
};
Some(UserLane {
view: self.view,
attr,
})
}

fn frames(&self) -> &FrameStore {
&self.frames
}
}

impl SelectionSource for DirLanes<'_, '_> {
fn selection_of(&self, sel: u16, _frame: &Frame) -> Option<SelAddr> {
self.selections.get(usize::from(sel))?;
Some(SelAddr {
space: self.space(),
sel,
scope: self.scope,
})
}

fn borrow_positions(&self, addr: &SelAddr) -> Option<&[u32]> {
if addr.space != self.space() {
return None;
}
self.selections
.get(usize::from(addr.sel))
.map(Vec::as_slice)
}
}
15 changes: 15 additions & 0 deletions crates/lance-graph-dir-sim/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ impl Kept {
materialize_rows(&self.bits, self.n_rows)
}

/// How many rows were kept: a popcount, no row is decoded.
pub fn len(&self) -> usize {
self.bits.iter().map(|w| w.count_ones() as usize).sum()
}

/// Whether no row was kept.
pub fn is_empty(&self) -> bool {
self.bits.iter().all(|w| *w == 0)
}

/// Rows of the relation the program ran over (kept or not).
pub fn universe(&self) -> usize {
self.n_rows
}

/// Add one row (a delta-sized correction, e.g. an overridden value).
pub(crate) fn set(&mut self, row: usize) {
debug_assert!(row < self.n_rows);
Expand Down
2 changes: 2 additions & 0 deletions crates/lance-graph-dir-sim/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub mod actors;
pub mod ad;
pub mod bind;
pub mod cloud;
#[cfg(feature = "dt64")]
pub mod dt64;
mod exec;
pub mod groups;
pub mod image;
Expand Down
Loading