From 8112234597f0f46b3d0fdc920b646a560d61aebc Mon Sep 17 00:00:00 2001 From: soul Date: Fri, 20 Nov 2026 13:29:44 +0100 Subject: [PATCH] aetherlight: the gate world grows dependencies, retirements, forums and checks to world scale A dependency per person (to the previous live person), two failing on the last place's grain, a forum per place, a Holds check on every routine, every tenth person from the 35th retired, and the clock moved one period so every routine is past due. The fixed-count pins on dependencies and redress go; the gate asserts the population at scale, so a walk of dependencies, retired pledges, holdings or forums fails it. PROVENANCE records the cut. Co-Authored-By: Claude Sonnet 5.5 --- native/aetherlight/PROVENANCE.md | 62 ++++++++++++- native/aetherlight/src/golden_tests.rs | 120 +++++++++++++++++++------ 2 files changed, 152 insertions(+), 30 deletions(-) diff --git a/native/aetherlight/PROVENANCE.md b/native/aetherlight/PROVENANCE.md index 63ab68646..be2799b84 100644 --- a/native/aetherlight/PROVENANCE.md +++ b/native/aetherlight/PROVENANCE.md @@ -462,9 +462,63 @@ session, the populated worlds and forty clockwork commits. `indexes_are_derived` rebuilds every index from its map after each commit, after reopen and after each failed apply; `a_corrupted_index_is_detected` damages each index both ways. -Reads that still scan, each with its owner: `derive_motion`'s dependencies loop and -`snapshot` (the host's whole-world projection, never on the commit path); the -resolver's reads of the whole world in `AdmitPatch` -(`aetherlight-resolver-reads-world`); `aetherlight-cross-partition-views`. The +Reads that still scan, each with its owner: `snapshot` (the host's whole-world +projection, never on the commit path); the resolver's reads of the whole world in +`AdmitPatch` (`aetherlight-resolver-reads-world`). The "Timing" paragraph of AL3b above is superseded: the gate it deferred is `read_work_is_equal_at_100_and_1600`. + +## Cut AL3d-2: cross-partition views + +Authority: cut `aetherlight-cross-partition-views` r1 of campaign +`aetheria-release`; rulings `cultnet-scale-is-not-negotiable`, +`aetherlight-narrative-state-owner`, `terminus-clockwork-world`, +`dialogue-is-world-action`. Base `609b3ba5e`. No digested byte moves: +`fixtures/golden.digests` is identical at every commit of the cut. + +Two questions the clock asks are joins, so no one partition's index answers them +(a `Docs` projection is a pure function of one document). Whether a dependency is +failing joins `dependencies` with `edges`, `holdings` and `positions`, and two of +its arms are anti-joins (a resource not held, a subject not placed); whether a due +commitment is live joins `commitments` with `subjects.retired`. `views.rs` owns +both as `Views { live_due, failing }`: `live_due` is the subjects with a +commitment due at each minute, retired subjects excluded, and `failing` is the +(dependent, target) pairs failing a live dependent. + +`Views` is derived state, a sibling of the `Docs` indexes and not a projection: a +field of `WorldState` outside `partitions()`, so not digested, not encoded and +never exported; its `PartialEq` is always true, so equality is the documents'. +Its one writer is `Views::fold`, called by `WorldState::finish` before the logs +close, from the `changes()` of the six partitions the views join. A subject whose +commitments or retirement changed loses its due points and regains them if it is +live; a subject whose dependencies, holdings or retirement changed has its +failing rows re-judged; a changed route or placement re-judges its dependents, +which the new `DependsOn` index on `dependencies` names. Rollback never touches +it, because the view never saw the transaction; genesis and every replayed +commit close through the same `finish`, so open rebuilds it by replay. + +`derive_motion` reads the views only with clean logs (`debug_assert` on the six +partitions; both callers satisfy it: `reduce`, and `apply_effect`'s +`TimeAdvanced` arm before its first write). `DueAt` is deleted, so the due +question has one owner, and `motion_of` no longer walks every dependency row or +visits retired subjects' past-due routines. Motion is byte-identical. The old +walks are `cfg(test)`: `derive_motion_by_scan` over every promisor and every +dependency, and `Views::rebuild`. A test that forges partitions and then calls +`derive_motion` must close its writes through `finish`; a forged state that never +finishes has a stale view by design, the same contract as a `Docs` index. + +Oracles: `views_are_derived` (the view is the rebuild after every walked commit, +reopen and failed apply, over a scenario world that closes and reopens a route, +empties and refills a holding, removes a depended-on subject's position, releases +a dependency and retires a subject holding past-due routines and a failing +dependency), `view_reads_equal_reference_scans`, `a_corrupted_view_is_detected` +and a debug refusal of a read with an open log. View reads are counted where they +are owned, like `Docs` reads, so the gate sees them. + +The gate world grows with them: a dependency per person (to the previous live +person, so each stays satisfied), two failing (persons 0 and 1 on the last +place's grain), a forum per place, every routine checking that its person holds +their place's grain, every tenth person from the 35th retired, and the clock +moved one period so every routine is past due. The fixed-count pins on +`dependencies` and `redress` are gone; `read_work_is_equal_at_100_and_1600` now +asserts the population at scale. diff --git a/native/aetherlight/src/golden_tests.rs b/native/aetherlight/src/golden_tests.rs index c72fc841e..a6182b5f0 100644 --- a/native/aetherlight/src/golden_tests.rs +++ b/native/aetherlight/src/golden_tests.rs @@ -261,15 +261,26 @@ fn incremental_digest_equals_full_recompute() { /// listeners. Every partition a read index serves is populated, because an /// empty one hides its scan: one route between consecutive places, one /// `Reach::Place` channel per place controlled by its first person, one -/// institution per place with a warden office held by that person, and two -/// Obligations past due from the first minute, so a tick presses two sources -/// at every size. +/// institution per place with a warden office held by that person and a forum +/// for the place's grievances, and two Obligations past due from the first +/// minute, so a tick presses two sources at every size. +/// +/// Dependencies, retirement and checks grow with the world too, because +/// a partition that stays small hides the walk of it. Every person binds to the +/// previous live person (a satisfied dependency), and persons 0 and 1 also to +/// the last place's grain, which they do not hold: two failing dependencies at +/// every size. Every tenth person from the 35th retires (never a controller or +/// incumbent, who are place * 10), and every routine checks that its person +/// holds their place's grain. The clock then moves one period, so every +/// routine is past due: the live ones roll once, a retired person's stays due +/// for good, and a one-minute tick from there rolls two routines at every size. fn clockwork_world(persons: usize) -> (WorldKernel, Vec, crate::AffordanceId) { use crate::patch::kernel_speak_grant; use crate::patch::{ AccessKind, AuthoredSource, AuthorityGrantRef, AuthorityTargetRef, ChannelDeclaration, - DependencyRef, EntityDeclaration, EvidenceRef, FactDeclaration, FactStandingRef, Quantity, - ReachRef, RouteDeclaration, SubjectDeclaration, + DependencyRef, EntityDeclaration, EvidenceRef, FactDeclaration, FactStandingRef, + GrievanceKindName, PreconditionRef, Quantity, ReachRef, RouteDeclaration, + SubjectDeclaration, }; use crate::tests::{LEVY_KIND, TITHE_RECEIPT, WARDEN_OFFICE, authority_kind, office}; use crate::Confidence; @@ -338,10 +349,15 @@ fn clockwork_world(persons: usize) -> (WorldKernel, Vec, crate delegated: BTreeSet::from([authority_kind(LEVY_KIND)]), }); offices.push(ComponentOp::InstallIncumbent { - institution: Ref::Draft(institution), + institution: Ref::Draft(institution.clone()), office: office(WARDEN_OFFICE), incumbent: draft_person(place * 10), }); + offices.push(ComponentOp::OpenForum { + grievance: GrievanceKindName(format!("grievance_{place}")), + forum: Ref::Draft(institution), + standing: AuthorityTargetRef::PlaceSubtree(draft_place(place)), + }); } for person in 0..persons { let place = person / 10; @@ -368,14 +384,26 @@ fn clockwork_world(persons: usize) -> (WorldKernel, Vec, crate import_key: None, })); } - // Two dependencies, a fixed count: `derive_motion` still walks every - // dependency row (follow-up aetherlight-cross-partition-views), so a - // dependency per person would grow a tick's reads with the world. - for person in 0..2 { - offices.push(ComponentOp::Bind { - subject: draft_person(person), - target: DependencyRef::Subject(draft_person(2)), - }); + let retires = |person: usize| person >= 35 && (person - 35) % 10 == 0; + for person in 0..persons { + if person > 0 { + // The previous person, or the one before when that one retires and + // so leaves the topology: the dependency stays satisfied. + let previous = if retires(person - 1) { person - 2 } else { person - 1 }; + offices.push(ComponentOp::Bind { + subject: draft_person(person), + target: DependencyRef::Subject(draft_person(previous)), + }); + } + if person < 2 { + offices.push(ComponentOp::Bind { + subject: draft_person(person), + target: DependencyRef::Resource(Ref::Draft(DraftHandle::new(format!( + "grain-{}", + places - 1 + )))), + }); + } } let (mut kernel, _) = WorldKernel::create( CreateWorld { @@ -395,6 +423,13 @@ fn clockwork_world(persons: usize) -> (WorldKernel, Vec, crate .map(|person| subject_by_label(&kernel.state, &format!("Person {person}"))) .collect(); let period = (persons / 2) as u64; + let grain_of_place: std::collections::BTreeMap = kernel + .state + .entities + .iter() + .filter(|(_, record)| record.kind == EntityKind::Resource) + .map(|(id, record)| (record.label.clone(), *id)) + .collect(); let mut routines: Vec = people .iter() .enumerate() @@ -404,7 +439,10 @@ fn clockwork_world(persons: usize) -> (WorldKernel, Vec, crate kind: CommitmentKind::Routine, due: FictionalMinutes(1 + index as u64 % period), period: Some(TickMinutes::new(period as u32).unwrap()), - checks: Vec::new(), + checks: vec![PreconditionRef::Holds { + resource: Ref::Existing(grain_of_place[&format!("Grain {}", index / 10)]), + at_least: Quantity(1), + }], statement: Statement::new("Keeps the hour.").unwrap(), }) .collect(); @@ -426,6 +464,21 @@ fn clockwork_world(persons: usize) -> (WorldKernel, Vec, crate kernel .submit(placing, &AuthenticatedCaller::verified_play()) .expect("the routines are placed"); + let retired: Vec = (0..persons) + .filter(|person| retires(*person)) + .map(|person| ComponentOp::Retire { subject: Ref::Existing(people[person]) }) + .collect(); + if !retired.is_empty() { + let envelope = clockwork_envelope(&kernel, operations(retired)); + kernel + .submit(envelope, &AuthenticatedCaller::verified_play()) + .expect("the retirements land"); + } + // One period on: every routine is past due, the live ones roll once. + let envelope = clockwork_envelope(&kernel, tick_body(period as u32)); + kernel + .submit(envelope, &AuthenticatedCaller::verified_play()) + .expect("the clock moves one period"); let speak_entry = *kernel .state .affordance_catalog @@ -904,17 +957,32 @@ fn read_work_is_equal_at_100_and_1600() { let state = &kernel.state; assert!(state.holdings.len() >= persons && state.knowledge.len() >= persons); assert!(state.facts.len() >= persons / 10 && state.channels.len() == persons / 10); - assert!(state.positions.len() >= persons && state.commitments.len() >= persons); + let retired: Vec<_> = + people.iter().copied().filter(|person| crate::is_retired(state, *person)).collect(); + assert!(retired.len() >= persons / 20, "{persons} persons: too few retired subjects"); + assert_eq!(state.positions.len() + retired.len(), persons, "a retired subject has no position"); + assert!(state.commitments.len() >= persons); + for person in &retired { + assert!( + state.commitments[person].values().any(|commitment| { + commitment.kind == CommitmentKind::Routine && commitment.due <= state.header.now + }), + "{persons} persons: a retired subject holds no past-due routine" + ); + } + for held in state.commitments.values() { + for commitment in held.values().filter(|c| c.kind == CommitmentKind::Routine) { + assert!( + matches!(commitment.checks.as_slice(), [crate::patch::BoundPrecondition::Holds { .. }]), + "{persons} persons: a routine without its Holds check" + ); + } + } assert!(state.edges.len() + 1 == persons / 10 && state.selection.len() == persons / 10); - // Not at scale, on purpose: `derive_motion` still walks every dependency - // row, so a dependency per person would grow a tick's reads. The owner - // is follow-up aetherlight-cross-partition-views; when it lands this - // count flips to world scale (`>= persons`) so a scan of the partition - // is seen. - assert_eq!(state.dependencies.len(), 2); - // The gate world opens no forum, so `redress` is empty here; the same - // follow-up owns populating it at scale beside dependencies. - assert_eq!(state.redress.len(), 0); + // A dependency per person and a forum per place, so a walk of either + // is seen; the clock reads only the two that fail. + assert!(state.dependencies.len() >= persons); + assert_eq!(state.redress.len(), persons / 10); let mut counts = Vec::new(); for _ in 0..3 { counts.push(submit_counting_rows(&mut kernel, tick_body(1))); @@ -1056,7 +1124,7 @@ fn walked_states() -> Vec<(String, crate::WorldState)> { tick_body(1) } else { CommandBody::Act { - actor: people[step], + actor: people[step % 30], invocation: speak(speak_entry, &format!("Speech {step}.")), } };