Put lens weights in the world (plan step 15, L1 Cut 2)
Lens weights are world data (L1-Q2), replaced only by an owner command (L1-Q3), and required at creation with no library default (L1-Q6). Library: - WorldState.lens_weights, written by genesis through ResolvedPatch.lens_weights (Some on the genesis lane only) and carried on CreateWorld and CreateWorldIntent (required). - CommandBody::SetLensWeights and WorldEffect::LensWeightsReplaced: owner only, any phase; reduce decides and apply_effect re-decides owner and draw rule. A set that never draws is Mismatch::LensWeightsNeverDraw at genesis and in the command; verify_state_shape refuses a stored one. - WorldSnapshot.lens_weights. - State and commit schemas go to consumer.v5; v4 stores are refused. - resolve_patch takes the weights; the action lane passes None. Dungeon: - CreatePayload.lens_weights required; world_create.v4 in the descriptor and operation_schema; the eighth create binding and a lens weights control defaulted to uniform_lens_weights(), which is Dungeon policy. - The smoke harness states uniform weights. The stale-payload test now denies v3, a v4 payload without weights (as a payload error) and one without a brief; new tests deny an unknown lens and an all-zero set. Tests: genesis writes and replays weights; an all-zero genesis is refused and writes no file; only the owner replaces weights (non-owner, stranger, elaborator, clock, consumer, stale revision, all-zero, hand-built effects); weights enter state_digest and no scope digest; a history with a weight change replays to the same digest; forged weight rows fail replay; a v4 store and an all-zero state row are refused; external non-owner refusal and unknown-lens decode. This commit builds (Windows only). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
3cb6a74bb0
commit
d06fd7ec2e
10 changed files with 815 additions and 33 deletions
|
|
@ -14,8 +14,8 @@
|
|||
use super::clock::{FictionalMinutes, TickMinutes};
|
||||
use super::tool_schema;
|
||||
use super::{
|
||||
AffordanceId, CommandId, ControllerAssignment, ControllerId, EdgeId, EntityId, NewController,
|
||||
SubjectId, SubjectKind, SubjectState, WorldId,
|
||||
AffordanceId, CommandId, ControllerAssignment, ControllerId, EdgeId, EntityId, LensWeights,
|
||||
NewController, SubjectId, SubjectKind, SubjectState, WorldId,
|
||||
};
|
||||
use codex_connector::CodexToolDefinition;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -1552,6 +1552,9 @@ pub enum Mismatch {
|
|||
/// The permille weights sum over 1000: weights distribute the target and
|
||||
/// never raise it.
|
||||
ScaleWeightsExceedWhole,
|
||||
/// A lens weight set with no nonzero weight, at genesis or in
|
||||
/// `SetLensWeights`. A single zero weight is admitted and never draws.
|
||||
LensWeightsNeverDraw,
|
||||
/// A jurisdictional author wrote outside its jurisdiction. The owner is
|
||||
/// unconfined and never sees this.
|
||||
OutsideJurisdiction {
|
||||
|
|
@ -1901,6 +1904,9 @@ pub(super) struct ResolvedPatch {
|
|||
/// carries no intent, so the write-once rule is the command shape rather
|
||||
/// than a check.
|
||||
pub(super) scale_intent: Option<WorldScaleIntent>,
|
||||
/// `Some` on the genesis lane and nowhere else, as `scale_intent` is. After
|
||||
/// genesis the weights change only through `SetLensWeights`.
|
||||
pub(super) lens_weights: Option<LensWeights>,
|
||||
}
|
||||
|
||||
impl ResolvedPatch {
|
||||
|
|
@ -2943,6 +2949,7 @@ pub(super) fn resolve_patch(
|
|||
command_id: CommandId,
|
||||
patch: &WorldPatch,
|
||||
scale_intent: Option<&WorldScaleIntentRef>,
|
||||
lens_weights: Option<&LensWeights>,
|
||||
) -> Result<ResolvedPatch, Vec<Mismatch>> {
|
||||
let world_id = state.world_id;
|
||||
let admits_human = super::admits_human(state.revision, &state.subjects);
|
||||
|
|
@ -4614,6 +4621,12 @@ pub(super) fn resolve_patch(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(weights) = lens_weights
|
||||
&& !weights.draws()
|
||||
{
|
||||
mismatches.push(Mismatch::LensWeightsNeverDraw);
|
||||
}
|
||||
|
||||
if patch.declarations.is_empty() && patch.operations.is_empty() {
|
||||
mismatches.push(Mismatch::NoCanonicalChange);
|
||||
}
|
||||
|
|
@ -5283,6 +5296,7 @@ pub(super) fn resolve_patch(
|
|||
})
|
||||
.collect(),
|
||||
}),
|
||||
lens_weights: lens_weights.cloned(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -8441,8 +8455,8 @@ mod tests {
|
|||
assert_ne!(admitted, genesis_human);
|
||||
|
||||
let command_id = CommandId::new();
|
||||
let first = resolve_patch(&kernel.state, command_id, &patch, None).unwrap();
|
||||
let second = resolve_patch(&kernel.state, command_id, &patch, None).unwrap();
|
||||
let first = resolve_patch(&kernel.state, command_id, &patch, None, None).unwrap();
|
||||
let second = resolve_patch(&kernel.state, command_id, &patch, None, None).unwrap();
|
||||
assert_eq!(first, second);
|
||||
}
|
||||
|
||||
|
|
@ -8585,7 +8599,7 @@ mod tests {
|
|||
Some(Ref::Draft(DraftHandle::new("rhythm-road"))),
|
||||
),
|
||||
]);
|
||||
let resolved = resolve_patch(&kernel.state, CommandId::new(), &patch, None).unwrap();
|
||||
let resolved = resolve_patch(&kernel.state, CommandId::new(), &patch, None, None).unwrap();
|
||||
let honest = super::super::WorldEffect::PatchAdmitted {
|
||||
resolved: resolved.clone(),
|
||||
answers: None,
|
||||
|
|
@ -8788,6 +8802,7 @@ mod tests {
|
|||
for edge_id in [topology.span, topology.shutter, topology.toll] {
|
||||
let forged = super::super::WorldEffect::PatchAdmitted {
|
||||
resolved: ResolvedPatch {
|
||||
lens_weights: None,
|
||||
subjects: Vec::new(),
|
||||
entities: Vec::new(),
|
||||
routes: Vec::new(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue