From 0ca51cf90a48713c712dc417a3334504332fe3e0 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Fri, 4 Sep 2026 19:11:57 +0200 Subject: [PATCH] Extract apply_operations as the one owner of operation application and conservation The seed/apply/accumulate/check_ledger sequence was inlined in the tail of admit_resolved, which made declaration admission the only lane able to prove custody conservation. Lift it verbatim into apply_operations, taking the operations and the evidence list; admit_resolved calls it after its declaration loops. No behaviour change. Co-Authored-By: Claude Fable 5.1 --- .../ghostlight-dungeon/src/world/journal.rs | 4 +-- crates/ghostlight-dungeon/src/world/mod.rs | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/ghostlight-dungeon/src/world/journal.rs b/crates/ghostlight-dungeon/src/world/journal.rs index 6a297b5..aab73ad 100644 --- a/crates/ghostlight-dungeon/src/world/journal.rs +++ b/crates/ghostlight-dungeon/src/world/journal.rs @@ -1384,9 +1384,7 @@ mod custody_tests { // An empty target set is the second representation of nothing, and there // is only supposed to be one. let mut emptied = kernel.state.clone(); - emptied - .dependencies - .insert(custody.holder, BTreeSet::new()); + emptied.dependencies.insert(custody.holder, BTreeSet::new()); assert!(matches!( verify_state_shape(&emptied), Err(JournalError::Corrupt(_)) diff --git a/crates/ghostlight-dungeon/src/world/mod.rs b/crates/ghostlight-dungeon/src/world/mod.rs index a8d1d8b..81b154a 100644 --- a/crates/ghostlight-dungeon/src/world/mod.rs +++ b/crates/ghostlight-dungeon/src/world/mod.rs @@ -1282,18 +1282,32 @@ fn admit_resolved(state: &mut WorldState, resolved: &ResolvedPatch) -> Result<() } } } - // A forged `PatchAdmitted` reaches this function without ever passing the - // resolver, so conservation is re-derived here over the committed - // partitions, against the same equation, with `before` read from state - // rather than from anything the effect asserts. + apply_operations(state, &resolved.operations, &resolved.evidence) +} + +/// The component writer for every lane: snapshot the before-totals for every +/// resource the operations name, apply each operation, accumulate the ledger +/// deltas, and prove conservation once. Declaration admission calls it after its +/// declaration loops; an exercised affordance's lowered effects call it +/// directly. One writer, one conservation statement. +/// +/// A forged effect reaches this function without ever passing the resolver, so +/// conservation is re-derived over the committed partitions, against the same +/// equation, with `before` read from state rather than from anything the effect +/// asserts. +fn apply_operations( + state: &mut WorldState, + operations: &[ResolvedOp], + evidence: &[EvidenceRef], +) -> Result<(), KernelError> { let mut deltas: BTreeMap = BTreeMap::new(); - for operation in &resolved.operations { + for operation in operations { for resource in operation_resources(operation) { deltas.entry(resource).or_default().before = resource_total(state, resource); } } - for operation in &resolved.operations { - apply_operation(state, operation, &resolved.evidence)?; + for operation in operations { + apply_operation(state, operation, evidence)?; match operation { ResolvedOp::Transform { from_resource,