Map: docs/persona-only-heartbeat-map.md (imagination/persona-only-heartbeat,
d861574), cut C2. Rulings: eureka-body:ruling:persona-only-heartbeat (she
reads the Mind and never writes it; no Self runs from the Persona).
Persona organ (persona.rs 3983 -> ~420 lines): deleted the live session
organ whole: TURN_INSTRUCTION, TURN_REMINDER, MESSAGES_HEADER, WORK_QUESTION,
ANSWER_MESSAGES, WAKE_ASK, WORK_TAIL; PersonaReply with intent, remember,
rule, settle, start_self_run, tempo vote and urgency, and reply_schema; the
doctrine and persona-JSON system prompt (read_doctrine, render_instructions,
campaigns); start_session, persona_args, PersonaInbox; act, decode_reply and
every admission (memories, rulings, settles, pulses, follow-ups, run closure);
start_self_run; the responsibilities, recent-runs and wear renderers;
render_input and render_tempo. carry reads the brakes and answers Dead or
NoOrgan; a start writes nothing and records no run. Kept per the map's keep
list for C3: Config (doctrine, image store and fetch fields cut with their
consumers), the brake read, the chat-addressing helpers, the tail renderer
and FileTrace; uncalled ones carry allow(dead_code) naming C3.
Night: sleep.rs is deleted. It was a Mind-writing session built on the
deleted prelude; C4 retargets its contract from history.
attachment.rs is deleted with the reply's save_attachment, its one caller.
chat_image's loader and recall.rs stay for C3 under allow(dead_code).
Heartbeat: no Mind writes. A wake is a plain unit start through the
Launcher (brake, then alive, then start); busy is the unit's own state.
Deleted the Self-run branch (claimable briefs), the self-ended wake, tempo
votes and declared urgency (standing_vote, pending_urgency, last_self_end)
and the run-based last_turn and last_sleep reads; HeartbeatState gains
last_turn_at and last_night_at (default slots, so a state written before
this cut still decodes). The beat is HEARTBEAT_BEAT_S, default 1800 s.
InstanceTrace.vote_beat_s stays as an always-none slot so heartbeat.cc's
older trace records still decode. HeartbeatView loses latest; the
timeline reads FileStore::latest.
tempo.rs: tally, fallback_beat and the PID controller and its sim are
deleted; pick and score stay, without self_permille.
Tests that pinned deleted behaviour are deleted with it; surviving ones are
kept, and two heartbeat tests pin the cut: a Mind with claimable briefs gets
a Persona wake and no Self run, and no poll admits anything to any mind.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.7 KiB
Rust
65 lines
2.7 KiB
Rust
//! Who takes the beat, pure: no clock, no mind, no I/O (ruling
|
|
//! `eureka-body:ruling:swarm-shares-log-bound`).
|
|
//!
|
|
//! The heartbeat owns when a beat falls and what it wakes; this module owns
|
|
//! only the decision of who takes it: `pick`, by `score`.
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
/// How many orders of magnitude a full urgency may multiply a Mind's wait by.
|
|
/// Interim, per `swarm-shares-log-bound`, until the swarm's governance sets it.
|
|
pub const LOG_BOUND_ORDERS: f64 = 1.0;
|
|
|
|
/// What the pick sees of one Mind.
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct Standing {
|
|
pub slug: String,
|
|
/// Her brake is released and she is not in a turn.
|
|
pub eligible: bool,
|
|
/// Seconds since the heartbeat last woke her for a turn; none when it never has.
|
|
pub waited_s: Option<u64>,
|
|
/// When the heartbeat last woke her for a turn, in unix milliseconds; none when never.
|
|
pub last_turn_ms: Option<i64>,
|
|
/// The urgency her subscriptions give her pending deliveries, in thousandths.
|
|
pub topic_permille: u16,
|
|
/// A member (not the operator) has a pending message that names or tags her.
|
|
pub addressed_by_member: bool,
|
|
}
|
|
|
|
/// The urgency in force for a Mind, in thousandths: the stronger of what her
|
|
/// topics say and a member addressing her (which is 1000).
|
|
pub fn urgency_permille(standing: &Standing) -> u16 {
|
|
let addressed = if standing.addressed_by_member { 1000 } else { 0 };
|
|
standing.topic_permille.max(addressed).min(1000)
|
|
}
|
|
|
|
/// `(waited / beat) x 10^(LOG_BOUND_ORDERS x urgency / 1000)`. A Mind that has
|
|
/// never had a turn has waited forever: infinite, so she is first, and the tie
|
|
/// rule orders the never-acted among themselves.
|
|
pub fn score(standing: &Standing, beat_s: u32) -> f64 {
|
|
let waited = standing
|
|
.waited_s
|
|
.map_or(f64::INFINITY, |waited| waited as f64);
|
|
let exponent = LOG_BOUND_ORDERS * f64::from(urgency_permille(standing)) / 1000.0;
|
|
waited / f64::from(beat_s.max(1)) * 10f64.powf(exponent)
|
|
}
|
|
|
|
/// The winner of a beat, as an index into `rows`: the highest score among the
|
|
/// eligible; a tie goes to the oldest last turn (never is oldest), then to the
|
|
/// lowest slug. None when nobody is eligible. A braked or busy Mind is never picked.
|
|
pub fn pick(rows: &[Standing], beat_s: u32) -> Option<usize> {
|
|
let order = |a: &(usize, &Standing), b: &(usize, &Standing)| -> Ordering {
|
|
score(b.1, beat_s)
|
|
.total_cmp(&score(a.1, beat_s))
|
|
.then_with(|| a.1.last_turn_ms.cmp(&b.1.last_turn_ms))
|
|
.then_with(|| a.1.slug.cmp(&b.1.slug))
|
|
};
|
|
rows.iter()
|
|
.enumerate()
|
|
.filter(|(_, row)| row.eligible)
|
|
.min_by(order)
|
|
.map(|(index, _)| index)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|