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 @@ -9,6 +9,7 @@ Plan `.claude/plans/xlog-knowledge-spine-v1.md` (charter, DOCS ONLY); harvest `x
| 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-LICENSE-DR64 | Licences from ogar-az (OGAR #380) as DR64 planes over a dir-sim version: <=64 (sku, via, state) codes per tenant, read plane, exact capacity | In PR: `license::LicensePlanes`; 6 tests, 3 disable runs red (not-read->read, no 65th-code cap, no code dedupe). Next: DT64 `LaneSource` binding over the planes. DR512 reserved for users per OU per group (operator) |
| 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-LICENSE-DT64-1 | Licence-state planes (#2105) through the DT64 lane + selection sockets (#2106): codes bound by predicate IRI, StatePlane as a membership mask, evidence and coverage kept with the planes | In PR: Gate 0 corrections to #2105 (content-ordered codes, owned evidence, nextLink coverage); `dt64::LicenseLanes`; 512-user projection oracle-equal, warm read 0 allocs; depends on #2105 + #2106 |
| 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
2 changes: 1 addition & 1 deletion .github/workflows/identity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- 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
run: cargo test --manifest-path crates/lance-graph-dir-sim/Cargo.toml --features dt64 --test dt64_lanes --test license_dt64
- name: The tests pinning Exchange behaviour exist
run: |
cargo test -q --manifest-path crates/lance-graph-dir-sim/Cargo.toml -- --list \
Expand Down
317 changes: 304 additions & 13 deletions crates/lance-graph-dir-sim/src/dt64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,29 @@
//!
//! `Scope` is a consistency check between reader, lanes and selections, as
//! everywhere in DT64; it is not authorization.
//!
//! **Licence-state codes through the same socket** (D-DIRSIM-LICENSE-DT64-1).
//! [`LicenseLanes`] serves a version's [`LicensePlanes`] in the row order of
//! that version's [`DirLanes`]: one lane per licence-state code (at most 64),
//! over the version's user ordinals (any number of DR tiles). The code axis
//! and the user axis are two axes; nothing builds a user × code × group
//! table. A lane is a membership plane ([`StatePlane`]), not a value lane:
//! read a row with [`StatePlane::contains`], or hand its words to a mask-RISC
//! program as a mask. A field resolves to a code by the code's identity (its
//! `predicate_iri`), never by position, so a code that moved is a refused
//! binding, not a re-pointed one. The assignment paths behind a bit stay with
//! the planes' owner ([`LicensePlanes::explain`]); the borrowed plane carries
//! none.

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 lance_graph_contract::class_view::{ClassId, ClassView};
use lance_graph_contract::ontology::DisplayTemplate;

use crate::license::{Coverage, LicensePlanes};
use crate::{Kept, UserOrdinal, View};

/// Field 0 of the user lanes: the UPN value.
Expand Down Expand Up @@ -75,6 +92,27 @@ pub enum SelectRefusal {
},
/// More selections than a `u16` id addresses.
Full,
/// No licence-state code at that index.
NoSuchCode(usize),
}

/// Hold `kept` as one more position list of `selections`.
fn hold(
selections: &mut Vec<Vec<u32>>,
kept: &Kept,
users: usize,
) -> Result<Selected, SelectRefusal> {
if kept.universe() != users {
return Err(SelectRefusal::NotUsers {
rows: kept.universe(),
users,
});
}
let sel = u16::try_from(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`.
selections.push(kept.rows().into_iter().map(|r| r as u32).collect());
Ok(Selected { sel, axis })
}

/// A selection the source holds.
Expand Down Expand Up @@ -135,19 +173,17 @@ impl<'a, 's> DirLanes<'a, 's> {
/// [`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 })
hold(&mut self.selections, kept, self.view.users_len())
}

/// The version the lanes are over.
pub fn version(&self) -> VersionId {
self.version
}

/// The version's user slots (deleted users included).
pub fn users_len(&self) -> usize {
self.view.users_len()
}
}

Expand Down Expand Up @@ -214,3 +250,258 @@ impl SelectionSource for DirLanes<'_, '_> {
.map(Vec::as_slice)
}
}

// ---- Licence-state codes (D-DIRSIM-LICENSE-DT64-1) ---------------------------

/// The schema revision the licence-state lanes serve.
pub const LICENSE_REV: SchemaRev = SchemaRev(1);

/// The field basis of a licence-state class: one field per code of a
/// [`LicensePlanes`], in its code order, each named by the code's identity.
///
/// A store binds the class over this basis once and never re-binds it
/// (D5): when a later observation changes the codes, its basis differs, and
/// a binding made over the old one is refused rather than re-pointed.
pub struct LicenseBasis {
class: ClassId,
fields: Vec<FieldRef>,
}

impl LicenseBasis {
/// The basis of `planes`' codes for the view class of `class`. Built once
/// per binding, cold.
pub fn of(planes: &LicensePlanes, class: u32) -> Self {
let fields = (0..planes.states().len())
.filter_map(|c| planes.predicate_iri(c))
.map(|iri| FieldRef::new(iri, iri))
.collect();
Self {
class: lance_graph_dt64::view_class(class),
fields,
}
}

/// Fields in the basis: the number of codes.
pub fn len(&self) -> usize {
self.fields.len()
}

/// Whether the basis has no field.
pub fn is_empty(&self) -> bool {
self.fields.is_empty()
}
}

impl ClassView for LicenseBasis {
fn fields(&self, class: ClassId) -> &[FieldRef] {
if class == self.class {
&self.fields
} else {
&[]
}
}
fn template(&self, _class: ClassId) -> DisplayTemplate {
DisplayTemplate::Detail
}
fn dolce_category_id(&self, _class: ClassId) -> u8 {
0
}
}

/// One licence-state code's plane over a version's user ordinals, borrowed
/// from the planes' owner. A membership mask, one bit per user: never index
/// it as a value lane.
#[derive(Clone, Copy, Debug)]
pub struct StatePlane<'a> {
words: &'a [u64],
n_rows: usize,
}

impl<'a> StatePlane<'a> {
/// Whether user `row` holds the code (and its licences were read). A row
/// past the version's users holds nothing.
pub fn contains(&self, row: u32) -> bool {
let r = row as usize;
r < self.n_rows && (self.words[r / 64] >> (r % 64)) & 1 == 1
}

/// The plane's words, for a mask-RISC program's masks.
pub fn words(&self) -> &'a [u64] {
self.words
}

/// Rows the plane covers: the version's user slots.
pub fn n_rows(&self) -> usize {
self.n_rows
}
}

/// Why licence planes were not served.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LicenseSourceRefusal {
/// The planes are over another version than the directory lanes.
OtherVersion {
/// The planes' version.
planes: VersionId,
/// The directory lanes' version.
lanes: VersionId,
},
/// The planes cover another number of user slots.
OtherPopulation {
/// The planes' user slots.
planes: usize,
/// The directory lanes' user slots.
users: usize,
},
/// The licence pages are not one whole collection, so the planes cannot
/// stand for the version's licences.
Incomplete(Coverage),
}

/// A version's licence planes as a DT64 lane and selection source, in the
/// row order of that version's [`DirLanes`].
pub struct LicenseLanes<'p> {
planes: &'p LicensePlanes,
class: u32,
space: CoordSpace,
scope: Scope,
frames: FrameStore,
selections: Vec<Vec<u32>>,
}

impl<'p> LicenseLanes<'p> {
/// Serve `planes` as class `class` for reader `scope`, in `dir`'s row
/// order.
///
/// # Errors
///
/// [`LicenseSourceRefusal`]: the planes are over another version or
/// population than `dir`, or their pages are not one whole collection.
pub fn over(
dir: &DirLanes<'_, '_>,
planes: &'p LicensePlanes,
class: u32,
scope: Scope,
) -> Result<Self, LicenseSourceRefusal> {
if planes.version() != dir.version() {
return Err(LicenseSourceRefusal::OtherVersion {
planes: planes.version(),
lanes: dir.version(),
});
}
if planes.users_len() != dir.users_len() {
return Err(LicenseSourceRefusal::OtherPopulation {
planes: planes.users_len(),
users: dir.users_len(),
});
}
match planes.coverage() {
Coverage::Complete => {}
other => return Err(LicenseSourceRefusal::Incomplete(other)),
}
let version = planes.version().0;
Ok(Self {
planes,
class,
space: dir.space(),
scope,
frames: FrameStore::new(FrameRevisions {
source: version,
relation_map: 0,
coordinates: version,
}),
selections: Vec::new(),
})
}

/// The row order: the directory lanes' user ordinals.
pub fn space(&self) -> CoordSpace {
self.space
}

/// Hold the users with licence-state code `code` as a selection.
///
/// # Errors
///
/// [`SelectRefusal::NoSuchCode`], or the source is full.
pub fn select_state(&mut self, code: usize) -> Result<Selected, SelectRefusal> {
let kept = self
.planes
.with_state(code)
.ok_or(SelectRefusal::NoSuchCode(code))?;
hold(&mut self.selections, &kept, self.planes.users_len())
}

/// Hold `kept` (a result over this version's users) as a selection.
///
/// # Errors
///
/// [`SelectRefusal`] as for [`DirLanes::select`].
pub fn select(&mut self, kept: &Kept) -> Result<Selected, SelectRefusal> {
hold(&mut self.selections, kept, self.planes.users_len())
}
}

impl LaneSource for LicenseLanes<'_> {
type Lane<'b>
= StatePlane<'b>
where
Self: 'b;

/// The code whose identity is `basis.predicate_iri`. The field position
/// is not read: two bases can order their fields differently.
fn lane_of(
&self,
class: u32,
rev: SchemaRev,
_field: u8,
basis: &FieldRef,
_frame: &Frame,
) -> Option<LaneAddr> {
if class != self.class || rev != LICENSE_REV {
return None;
}
let code = self.planes.code_of(basis.predicate_iri.as_str())?;
Some(LaneAddr {
space: self.space,
lane: u16::try_from(code).ok()?,
scope: self.scope,
})
}

fn borrow(&self, addr: &LaneAddr) -> Option<StatePlane<'_>> {
if addr.space != self.space {
return None;
}
Some(StatePlane {
words: self.planes.plane(usize::from(addr.lane))?,
n_rows: self.planes.users_len(),
})
}

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

impl SelectionSource for LicenseLanes<'_> {
/// Only under this source's current frame.
fn selection_of(&self, sel: u16, frame: &Frame) -> Option<SelAddr> {
self.frames.check(frame).ok()?;
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)
}
}
22 changes: 22 additions & 0 deletions crates/lance-graph-dir-sim/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ impl Kept {
self.n_rows
}

/// The rows both results kept, as one bitmap AND; `None` when the two
/// were computed over relations of different sizes.
///
/// A `Kept` carries its relation's size, not its identity: the caller
/// vouches that both results are over the same version's rows (as
/// [`crate::dt64::DirLanes::select`] does). The DT64 sockets then check
/// the coordinate space when the result is read.
pub fn and(&self, other: &Kept) -> Option<Kept> {
if self.n_rows != other.n_rows {
return None;
}
Some(Kept {
bits: self
.bits
.iter()
.zip(&other.bits)
.map(|(a, b)| a & b)
.collect(),
n_rows: 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
Loading