wave: reporting helpers (node_reports, deferred_nodes, node_label, acts_since, act_line) move from the verse driver to the wave organ; ControllerRunner::through runs the decision lanes over a window port

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-03 11:36:54 +01:00
commit 2732d38c96
5 changed files with 214 additions and 187 deletions

View file

@ -3283,6 +3283,20 @@ impl ControllerRunner {
})
}
/// This runner's decision lanes over another inference port: the port of a
/// window whose ledger the calls reserve in. The mailbox, the work store and
/// the models are this runner's own, so a wave run through it resumes the
/// same controller-work rows.
pub fn through(&self, inference: Arc<dyn InferencePort>) -> Self {
Self {
mailbox: self.mailbox.clone(),
elaboration: self.elaboration.clone(),
inference,
work: Arc::clone(&self.work),
models: self.models.clone(),
}
}
/// The authoring lane, over the mailbox the decision lanes use, reading the
/// evidence the caller's timeline is bound to and calling the provider only
/// through `inference`: the port of the window the sweep spends in. A world

View file

@ -114,9 +114,9 @@ pub use aetheria::{
pub use cover::{AgencyGraph, Cell, Cover, CoverBudget, CoverBudgetError, TickIndex, derive_cover};
pub use hierarchy::{Hierarchy, Node, NodeAnchor, NodeId};
pub use wave::{
Deferral, Focus, FrozenCell, GestaltKnobs, GestaltKnobsError, NodeOutcome, NodeTurn, Refusal,
RefusalReason, UnattributedCall, Wave, WaveClock, WaveOutcome, WaveStop, plan_wave,
run_frozen_cells,
Deferral, DeferredNode, Focus, FrozenCell, GestaltKnobs, GestaltKnobsError, NodeOutcome, NodeReport,
NodeTurn, Refusal, RefusalReason, UnattributedCall, Wave, WaveClock, WaveOutcome, WaveStop,
act_line, acts_since, deferred_nodes, node_label, node_reports, plan_wave, run_frozen_cells,
};
pub use elaboration::{
ElaborationCheckpoint, ElaborationRunner, ElaboratorSession, SweepReport, EvidenceError, EvidenceQuery,
@ -168,7 +168,7 @@ pub use vault::{
pub use verse::{
CALL_RECORD_SCHEMA, CallRecordError, CallRecordStore, CreateVerseWorldIntent, Lane, LaneTokens,
NodeSpend, ProviderCallRecord, WaveSpend,
RUN_RECORD_SCHEMA, DeferredNode, NodeReport, RecordedKnobs, RecordingInferencePort, RunClaim,
RUN_RECORD_SCHEMA, RecordedKnobs, RecordingInferencePort, RunClaim,
ReplayInferencePort, RunField, RunId, RunOutcome, RunStart, RunStatus, TickCheckpoint,
TickReport, VerseGenesisError, VerseRunConfig, VerseRunError, VerseRunRecord, VerseRunStore,
call_run_id, run_manual,

View file

@ -14,7 +14,7 @@ pub use calls::{
WaveSpend,
};
pub use run::{
RUN_RECORD_SCHEMA, DeferredNode, NodeReport, RecordedKnobs, RunClaim, RunOutcome, RunStatus,
RUN_RECORD_SCHEMA, RecordedKnobs, RunClaim, RunOutcome, RunStatus,
TickCheckpoint, TickReport, VerseRunConfig, VerseRunError, VerseRunRecord, VerseRunStore,
call_run_id, run_manual,
};

View file

@ -25,12 +25,13 @@
use super::calls::{RecordingInferencePort, WaveSpend, canonical};
use crate::cover::TickIndex;
use crate::wave::{
Deferral, FrozenCell, Focus, GestaltKnobs, GestaltKnobsError, Refusal, RefusalReason, UnattributedCall,
WaveClock, WaveOutcome, WaveStop, plan_wave, run_frozen_cells,
Deferral, DeferredNode, FrozenCell, Focus, GestaltKnobs, GestaltKnobsError, NodeReport, Refusal,
RefusalReason, UnattributedCall, WaveClock, WaveOutcome, WaveStop, act_line, acts_since,
deferred_nodes, node_label, node_reports, plan_wave, run_frozen_cells,
};
use crate::{
AgencyGraph, CommandId, ControllerRunner, DecisionOpportunity, FictionalMinutes, Hierarchy, MailboxError,
NodeAnchor, NodeId, OperatorEvent, RenderPath, SubjectId, TickMinutes, WorldId, WorldMailbox,
NodeAnchor, NodeId, OperatorEvent, SubjectId, TickMinutes, WorldId, WorldMailbox,
WorldSnapshot,
};
use chrono::Utc;
@ -206,29 +207,6 @@ pub struct VerseRunConfig {
pub knobs: GestaltKnobs,
}
/// What one node's turn did in a tick, as the operator reads it.
#[derive(Clone, Debug)]
pub struct NodeReport {
/// The node's anchor's label; `-` when the world no longer names the
/// anchor, and for acts no frozen cell claims.
pub label: String,
/// Hierarchy distance from the focus when the wave was planned; none for
/// acts no frozen cell claims.
pub distance: Option<u8>,
/// The acts the node's members committed, from the operator log.
pub acts: Vec<OperatorEvent>,
pub refusals: Vec<Refusal>,
/// Tokens charged while the node's cells ran in this invocation.
pub spent: u64,
}
/// A node that took no turn, or not all of it, as the operator reads it.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeferredNode {
pub label: String,
pub reason: Deferral,
}
/// A tick as the operator reads it, including the one a run ended inside.
#[derive(Clone, Debug)]
pub struct TickReport {
@ -290,22 +268,7 @@ impl std::fmt::Display for TickReport {
None => writeln!(f, " node {}: {} tokens", node.label, node.spent)?,
}
for act in &node.acts {
let path = match act.render_path {
Some(RenderPath::ShipAction) => "ship_action",
Some(RenderPath::Conversation) => "conversation",
None => "-",
};
write!(f, " {} {} [{path}]", act.speaker_label, act.verb)?;
for role in &act.roles {
write!(f, " {}={}", role.role, role.target)?;
}
if let Some(speech) = &act.speech {
write!(f, " says {:?}", speech.as_str())?;
}
if let Some(display) = &act.display {
write!(f, " shows {:?}", display.as_str())?;
}
writeln!(f)?;
writeln!(f, " {}", act_line(act))?;
}
for refusal in &node.refusals {
let reason = match refusal.reason {
@ -890,7 +853,7 @@ where
.collect();
let report = TickReport {
nodes: node_reports(&tick.cells, &outcome, acts, &spend, &snapshot, &hierarchy),
deferred: deferred_nodes(&tick, &outcome, &snapshot, &hierarchy),
deferred: deferred_nodes(&tick.deferred, &tick.cells, &outcome, &snapshot, &hierarchy),
spend,
checkpoint,
labels,
@ -900,145 +863,6 @@ where
(open.map_or(TickEnd::Closed, TickEnd::Open), Some(report))
}
/// The tick's nodes in the order its frozen cells first name them, each with
/// the acts its members committed and the refusals its cells ended in. A node
/// the run never reached and that committed nothing is not listed. An act no
/// frozen cell claims is kept under a node labelled `-`, never dropped.
fn node_reports(
frozen: &[FrozenCell],
outcome: &WaveOutcome,
acts: Vec<OperatorEvent>,
spend: &WaveSpend,
snapshot: &WorldSnapshot,
hierarchy: &Hierarchy,
) -> Vec<NodeReport> {
let mut order: Vec<(NodeId, u8)> = Vec::new();
let mut home: BTreeMap<SubjectId, usize> = BTreeMap::new();
for cell in frozen {
let at = order
.iter()
.position(|(node, _)| *node == cell.node)
.unwrap_or_else(|| {
order.push((cell.node, cell.distance));
order.len() - 1
});
home.extend(cell.members.iter().map(|member| (*member, at)));
}
let mut reports: Vec<NodeReport> = order
.iter()
.map(|(node, distance)| {
let ran = outcome.nodes.iter().find(|ran| ran.node == *node);
NodeReport {
label: node_label(*node, snapshot, hierarchy),
distance: Some(*distance),
acts: Vec::new(),
refusals: ran.map(|ran| ran.refusals.clone()).unwrap_or_default(),
spent: spend
.nodes
.iter()
.find(|spent| spent.node == *node)
.map_or(0, |spent| spent.charged),
}
})
.collect();
let ran: Vec<bool> = order
.iter()
.map(|(node, _)| outcome.nodes.iter().any(|ran| ran.node == *node))
.collect();
let mut unclaimed = Vec::new();
for act in acts {
match home.get(&act.speaker) {
Some(&at) => reports[at].acts.push(act),
None => unclaimed.push(act),
}
}
let mut kept: Vec<NodeReport> = reports
.into_iter()
.zip(ran)
.filter(|(report, ran)| *ran || !report.acts.is_empty())
.map(|(report, _)| report)
.collect();
if !unclaimed.is_empty() {
kept.push(NodeReport {
label: "-".into(),
distance: None,
acts: unclaimed,
refusals: Vec::new(),
spent: 0,
});
}
kept
}
/// The nodes of the tick that took no turn: the plan's deferrals, frozen with
/// the tick, and, when the run stopped on its allowance, the nodes it never
/// reached and the one it stopped inside. A fault stop defers nothing.
fn deferred_nodes(
tick: &VerseTick,
outcome: &WaveOutcome,
snapshot: &WorldSnapshot,
hierarchy: &Hierarchy,
) -> Vec<DeferredNode> {
let mut deferred: Vec<(NodeId, Deferral)> = tick.deferred.clone();
if outcome.stop == Some(WaveStop::Budget) {
let entered: Vec<NodeId> = outcome.nodes.iter().map(|node| node.node).collect();
let stopped_in = entered.last().copied();
let mut seen: Vec<NodeId> = Vec::new();
for cell in &tick.cells {
if seen.contains(&cell.node) {
continue;
}
seen.push(cell.node);
if !entered.contains(&cell.node) || Some(cell.node) == stopped_in {
deferred.push((cell.node, Deferral::Allowance));
}
}
}
deferred
.into_iter()
.map(|(node, reason)| DeferredNode {
label: node_label(node, snapshot, hierarchy),
reason,
})
.collect()
}
/// What the operator calls a node: its anchor's label in the snapshot, `world`
/// for the root, `-` for an anchor the world no longer holds.
fn node_label(node: NodeId, snapshot: &WorldSnapshot, hierarchy: &Hierarchy) -> String {
let subject = |id: SubjectId| {
snapshot
.subjects
.iter()
.find(|subject| subject.id == id)
.map(|subject| subject.label.clone())
};
match hierarchy.nodes.get(&node).map(|node| node.anchor) {
Some(NodeAnchor::World) => Some("world".to_owned()),
Some(NodeAnchor::Institution(id) | NodeAnchor::Subject(id)) => subject(id),
Some(NodeAnchor::Place(entity)) => snapshot
.places
.iter()
.find(|place| place.id == entity)
.map(|place| place.label.clone()),
None => None,
}
.unwrap_or_else(|| "-".to_owned())
}
/// The acts a tick committed: the operator log's events past the tick's
/// opening revision. A log that cannot be read is `None`, never an empty tick.
fn acts_since(
log: Result<Vec<OperatorEvent>, MailboxError>,
since: u64,
) -> Option<Vec<OperatorEvent>> {
log.ok().map(|log| {
log.into_iter()
.filter(|event| event.revision > since)
.collect()
})
}
/// The tick document for `ordinal`: the open one a run left, or a new one
/// frozen from a wave planned now over the derived hierarchy with no focus. An
/// open tick the world has moved past is closed as the world's first. A

View file

@ -42,6 +42,8 @@ use super::{
SubmissionDisposition,
},
hierarchy::{Hierarchy, Node, NodeAnchor, NodeId},
verse::WaveSpend,
MailboxError, OperatorEvent, RenderPath, WorldSnapshot,
};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet, VecDeque};
@ -762,6 +764,193 @@ pub async fn run_frozen_cells(
WaveOutcome { nodes, stop }
}
// What a wave did, as a reader sees it.
/// What one node's turn did in a wave, as the operator or the table reads it.
#[derive(Clone, Debug)]
pub struct NodeReport {
/// The node's anchor's label; `-` when the world no longer names the
/// anchor, and for acts no frozen cell claims.
pub label: String,
/// Hierarchy distance from the focus when the wave was planned; none for
/// acts no frozen cell claims.
pub distance: Option<u8>,
/// The acts the node's members committed, from the operator log.
pub acts: Vec<OperatorEvent>,
pub refusals: Vec<Refusal>,
/// Tokens charged while the node's cells ran in this invocation.
pub spent: u64,
}
/// A node that took no turn, or not all of it, as the operator reads it.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeferredNode {
pub label: String,
pub reason: Deferral,
}
/// The tick's nodes in the order its frozen cells first name them, each with
/// the acts its members committed and the refusals its cells ended in. A node
/// the run never reached and that committed nothing is not listed. An act no
/// frozen cell claims is kept under a node labelled `-`, never dropped.
pub fn node_reports(
frozen: &[FrozenCell],
outcome: &WaveOutcome,
acts: Vec<OperatorEvent>,
spend: &WaveSpend,
snapshot: &WorldSnapshot,
hierarchy: &Hierarchy,
) -> Vec<NodeReport> {
let mut order: Vec<(NodeId, u8)> = Vec::new();
let mut home: BTreeMap<SubjectId, usize> = BTreeMap::new();
for cell in frozen {
let at = order
.iter()
.position(|(node, _)| *node == cell.node)
.unwrap_or_else(|| {
order.push((cell.node, cell.distance));
order.len() - 1
});
home.extend(cell.members.iter().map(|member| (*member, at)));
}
let mut reports: Vec<NodeReport> = order
.iter()
.map(|(node, distance)| {
let ran = outcome.nodes.iter().find(|ran| ran.node == *node);
NodeReport {
label: node_label(*node, snapshot, hierarchy),
distance: Some(*distance),
acts: Vec::new(),
refusals: ran.map(|ran| ran.refusals.clone()).unwrap_or_default(),
spent: spend
.nodes
.iter()
.find(|spent| spent.node == *node)
.map_or(0, |spent| spent.charged),
}
})
.collect();
let ran: Vec<bool> = order
.iter()
.map(|(node, _)| outcome.nodes.iter().any(|ran| ran.node == *node))
.collect();
let mut unclaimed = Vec::new();
for act in acts {
match home.get(&act.speaker) {
Some(&at) => reports[at].acts.push(act),
None => unclaimed.push(act),
}
}
let mut kept: Vec<NodeReport> = reports
.into_iter()
.zip(ran)
.filter(|(report, ran)| *ran || !report.acts.is_empty())
.map(|(report, _)| report)
.collect();
if !unclaimed.is_empty() {
kept.push(NodeReport {
label: "-".into(),
distance: None,
acts: unclaimed,
refusals: Vec::new(),
spent: 0,
});
}
kept
}
/// The nodes of a wave that took no turn, or not all of it: the plan's
/// deferrals, frozen with the wave, and, when the run stopped on its allowance,
/// the nodes it never reached and the one it stopped inside. A fault stop
/// defers nothing.
pub fn deferred_nodes(
planned: &[(NodeId, Deferral)],
frozen: &[FrozenCell],
outcome: &WaveOutcome,
snapshot: &WorldSnapshot,
hierarchy: &Hierarchy,
) -> Vec<DeferredNode> {
let mut deferred: Vec<(NodeId, Deferral)> = planned.to_vec();
if outcome.stop == Some(WaveStop::Budget) {
let entered: Vec<NodeId> = outcome.nodes.iter().map(|node| node.node).collect();
let stopped_in = entered.last().copied();
let mut seen: Vec<NodeId> = Vec::new();
for cell in frozen {
if seen.contains(&cell.node) {
continue;
}
seen.push(cell.node);
if !entered.contains(&cell.node) || Some(cell.node) == stopped_in {
deferred.push((cell.node, Deferral::Allowance));
}
}
}
deferred
.into_iter()
.map(|(node, reason)| DeferredNode {
label: node_label(node, snapshot, hierarchy),
reason,
})
.collect()
}
/// What the operator calls a node: its anchor's label in the snapshot, `world`
/// for the root, `-` for an anchor the world no longer holds.
pub fn node_label(node: NodeId, snapshot: &WorldSnapshot, hierarchy: &Hierarchy) -> String {
let subject = |id: SubjectId| {
snapshot
.subjects
.iter()
.find(|subject| subject.id == id)
.map(|subject| subject.label.clone())
};
match hierarchy.nodes.get(&node).map(|node| node.anchor) {
Some(NodeAnchor::World) => Some("world".to_owned()),
Some(NodeAnchor::Institution(id) | NodeAnchor::Subject(id)) => subject(id),
Some(NodeAnchor::Place(entity)) => snapshot
.places
.iter()
.find(|place| place.id == entity)
.map(|place| place.label.clone()),
None => None,
}
.unwrap_or_else(|| "-".to_owned())
}
/// The acts a tick committed: the operator log's events past the tick's
/// opening revision. A log that cannot be read is `None`, never an empty tick.
pub fn acts_since(
log: Result<Vec<OperatorEvent>, MailboxError>,
since: u64,
) -> Option<Vec<OperatorEvent>> {
log.ok().map(|log| {
log.into_iter()
.filter(|event| event.revision > since)
.collect()
})
}
/// One committed act as a line of prose for a reader: who, which verb, how it
/// renders, what its roles are bound to, what was said or shown.
pub fn act_line(act: &OperatorEvent) -> String {
let path = match act.render_path {
Some(RenderPath::ShipAction) => "ship_action",
Some(RenderPath::Conversation) => "conversation",
None => "-",
};
let mut line = format!("{} {} [{path}]", act.speaker_label, act.verb);
for role in &act.roles {
line.push_str(&format!(" {}={}", role.role, role.target));
}
if let Some(speech) = &act.speech {
line.push_str(&format!(" says {:?}", speech.as_str()));
}
if let Some(display) = &act.display {
line.push_str(&format!(" shows {:?}", display.as_str()));
}
line
}
#[cfg(test)]
mod tests {
use super::*;