Store heartbeat participant timing as typed state

This commit is contained in:
Meta Vens 2026-05-18 07:44:20 +01:00
commit bc285c71d4
8 changed files with 117 additions and 48 deletions

View file

@ -1142,24 +1142,17 @@ fn apply_personality_timing_profiles(
continue;
};
let timing = personality_timing_for_profile(profile);
participant.extra.insert(
"personalityCooldownMultiplier".to_string(),
serde_json::json!(timing.cooldown_multiplier),
);
participant.extra.insert(
"personalityTiming".to_string(),
serde_json::json!({
"schema_version": "epiphany.personality_timing.v0",
"source": "state/agents.msgpack",
"cooldownMultiplier": timing.cooldown_multiplier,
"workDrive": timing.work_drive,
"handsiness": timing.handsiness,
"caution": timing.caution,
"ruminationBias": timing.rumination_bias,
"basis": timing.basis,
"contract": "Cooldown is personality-shaped. Lower multipliers recover faster; higher multipliers yield the floor to other lanes."
}),
);
participant.personality_timing = Some(HeartbeatPersonalityTiming {
schema_version: "epiphany.personality_timing.v0".to_string(),
source: "state/agents.msgpack".to_string(),
cooldown_multiplier: timing.cooldown_multiplier,
work_drive: timing.work_drive,
handsiness: timing.handsiness,
caution: timing.caution,
rumination_bias: timing.rumination_bias,
basis: timing.basis,
contract: "Cooldown is personality-shaped. Lower multipliers recover faster; higher multipliers yield the floor to other lanes.".to_string(),
});
}
}
@ -1326,25 +1319,21 @@ fn apply_mood_timing_from_appraisals(state: &mut EpiphanyHeartbeatStateEntry, ap
.clamp(0.0, 1.0);
let multiplier =
(1.10 - urgency * 0.24 - anxiety * 0.38 - reaction_intensity * 0.12).clamp(0.55, 1.25);
participant.extra.insert(
"moodCooldownMultiplier".to_string(),
serde_json::json!(round3(multiplier)),
);
participant.extra.insert(
"moodTiming".to_string(),
serde_json::json!({
"schema_version": "epiphany.mood_timing.v0",
"source": appraisal.get("appraisalId"),
"cooldownMultiplier": round3(multiplier),
"anxiety": round3(anxiety),
"urgency": round3(urgency),
"arousal": round3(arousal),
"thoughtPressure": round3(thought_pressure),
"guardedness": round3(guardedness),
"reactionIntensity": round3(reaction_intensity),
"contract": "Mood bends personality timing. Anxiety and urgency lower cooldown so the lane that needs the floor most gets it sooner."
}),
);
participant.mood_timing = Some(HeartbeatMoodTiming {
schema_version: "epiphany.mood_timing.v0".to_string(),
source: appraisal
.get("appraisalId")
.and_then(Value::as_str)
.map(str::to_string),
cooldown_multiplier: round3(multiplier),
anxiety: round3(anxiety),
urgency: round3(urgency),
arousal: round3(arousal),
thought_pressure: round3(thought_pressure),
guardedness: round3(guardedness),
reaction_intensity: round3(reaction_intensity),
contract: "Mood bends personality timing. Anxiety and urgency lower cooldown so the lane that needs the floor most gets it sooner.".to_string(),
});
}
}

View file

@ -174,6 +174,8 @@ pub struct HeartbeatParticipant {
pub arena: String,
#[serde(default)]
pub participant_kind: String,
#[serde(rename = "sceneId", default)]
pub scene_id: Option<String>,
pub initiative_speed: f64,
pub next_ready_at: f64,
pub reaction_bias: f64,
@ -185,10 +187,46 @@ pub struct HeartbeatParticipant {
pub last_woke_at: Option<String>,
pub last_finished_at: Option<String>,
pub pending_turn: Option<HeartbeatPendingTurn>,
#[serde(rename = "personalityTiming", default)]
pub personality_timing: Option<HeartbeatPersonalityTiming>,
#[serde(rename = "moodTiming", default)]
pub mood_timing: Option<HeartbeatMoodTiming>,
#[serde(flatten)]
pub extra: BTreeMap<String, Value>,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HeartbeatPersonalityTiming {
#[serde(rename = "schema_version")]
pub schema_version: String,
pub source: String,
pub cooldown_multiplier: f64,
pub work_drive: f64,
pub handsiness: f64,
pub caution: f64,
pub rumination_bias: f64,
pub basis: Vec<String>,
pub contract: String,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct HeartbeatMoodTiming {
#[serde(rename = "schema_version")]
pub schema_version: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
pub cooldown_multiplier: f64,
pub anxiety: f64,
pub urgency: f64,
pub arousal: f64,
pub thought_pressure: f64,
pub guardedness: f64,
pub reaction_intensity: f64,
pub contract: String,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct HeartbeatPendingTurn {
pub status: String,

View file

@ -104,6 +104,17 @@ fn swarm_mood_signals(state: &EpiphanyHeartbeatStateEntry) -> SwarmMoodSignals {
let mut anxiety_total = 0.0;
let mut anxiety_count = 0_usize;
for participant in &state.participants {
if let Some(mood) = participant.mood_timing.as_ref() {
signals.max_anxiety = signals.max_anxiety.max(mood.anxiety);
signals.max_urgency = signals.max_urgency.max(mood.urgency);
signals.max_arousal = signals.max_arousal.max(mood.arousal);
signals.max_thought_pressure = signals.max_thought_pressure.max(mood.thought_pressure);
signals.max_reaction_intensity =
signals.max_reaction_intensity.max(mood.reaction_intensity);
anxiety_total += mood.anxiety;
anxiety_count += 1;
continue;
}
let Some(mood) = participant.extra.get("moodTiming") else {
continue;
};
@ -148,18 +159,30 @@ fn number_at(value: &Value, pointer: &str) -> f64 {
pub(super) fn personality_cooldown_multiplier(participant: &HeartbeatParticipant) -> f64 {
participant
.extra
.get("personalityCooldownMultiplier")
.and_then(Value::as_f64)
.personality_timing
.as_ref()
.map(|timing| timing.cooldown_multiplier)
.or_else(|| {
participant
.extra
.get("personalityCooldownMultiplier")
.and_then(Value::as_f64)
})
.unwrap_or(1.0)
.clamp(0.25, 3.0)
}
pub(super) fn mood_cooldown_multiplier(participant: &HeartbeatParticipant) -> f64 {
participant
.extra
.get("moodCooldownMultiplier")
.and_then(Value::as_f64)
.mood_timing
.as_ref()
.map(|timing| timing.cooldown_multiplier)
.or_else(|| {
participant
.extra
.get("moodCooldownMultiplier")
.and_then(Value::as_f64)
})
.unwrap_or(1.0)
.clamp(0.25, 3.0)
}

View file

@ -203,18 +203,29 @@ fn heartbeat_cognition_status_json(cognition: &super::EpiphanyHeartbeatCognition
}
fn participant_status_json(participant: &HeartbeatParticipant) -> Value {
let personality_timing = participant
.personality_timing
.as_ref()
.and_then(|timing| serde_json::to_value(timing).ok())
.or_else(|| participant.extra.get("personalityTiming").cloned());
let mood_timing = participant
.mood_timing
.as_ref()
.and_then(|timing| serde_json::to_value(timing).ok())
.or_else(|| participant.extra.get("moodTiming").cloned());
serde_json::json!({
"agentId": participant.agent_id,
"roleId": participant.role_id,
"displayName": participant.display_name,
"arena": participant_arena(participant),
"participantKind": participant_kind(participant),
"sceneId": participant.scene_id.as_deref().or_else(|| participant.extra.get("sceneId").and_then(Value::as_str)),
"initiativeSpeed": participant.initiative_speed,
"personalityCooldownMultiplier": personality_cooldown_multiplier(participant),
"moodCooldownMultiplier": mood_cooldown_multiplier(participant),
"effectiveCooldownMultiplier": effective_cooldown_multiplier(participant),
"personalityTiming": participant.extra.get("personalityTiming"),
"moodTiming": participant.extra.get("moodTiming"),
"personalityTiming": personality_timing,
"moodTiming": mood_timing,
"nextReadyAt": participant.next_ready_at,
"reactionBias": participant.reaction_bias,
"interruptThreshold": participant.interrupt_threshold,

View file

@ -113,6 +113,7 @@ pub(super) fn default_participant(role_id: &str) -> HeartbeatParticipant {
display_name: display_name_for_role(role_id).to_string(),
arena: HEARTBEAT_ARENA_MAINTENANCE.to_string(),
participant_kind: PARTICIPANT_KIND_AGENT.to_string(),
scene_id: None,
initiative_speed: initiative_speed_for_role(role_id),
next_ready_at: 0.0,
reaction_bias: reaction_bias_for_role(role_id),
@ -127,6 +128,8 @@ pub(super) fn default_participant(role_id: &str) -> HeartbeatParticipant {
last_woke_at: None,
last_finished_at: None,
pending_turn: None,
personality_timing: None,
mood_timing: None,
extra: BTreeMap::new(),
}
}
@ -136,14 +139,13 @@ fn ghostlight_scene_participant(
seed: GhostlightSceneParticipantSeed,
) -> HeartbeatParticipant {
let role_id = ghostlight_role_id(seed.agent_id.as_str());
let mut extra = BTreeMap::new();
extra.insert("sceneId".to_string(), serde_json::json!(scene_id));
HeartbeatParticipant {
agent_id: seed.agent_id,
role_id,
display_name: seed.display_name,
arena: HEARTBEAT_ARENA_SCENE.to_string(),
participant_kind: PARTICIPANT_KIND_CHARACTER.to_string(),
scene_id: Some(scene_id.to_string()),
initiative_speed: seed.initiative_speed,
next_ready_at: 0.0,
reaction_bias: seed.reaction_bias,
@ -155,7 +157,9 @@ fn ghostlight_scene_participant(
last_woke_at: None,
last_finished_at: None,
pending_turn: None,
extra,
personality_timing: None,
mood_timing: None,
extra: BTreeMap::new(),
}
}

View file

@ -66,6 +66,7 @@ remembers doctrine; the branch remembers the blade.
- Coordinator automation input assembly and pre-compaction intervention text rendering now belong to `epiphany-codex-bridge`; vendored app-server keeps only host actions: submit Codex compaction, launch through bridge, steer active turns, and emit JSON-RPC notifications.
- Epiphany prompt-state boundary tags now live in `epiphany-state-model` and are re-exported through `codex-protocol`; Codex compatibility may wrap the prompt fragment, but it no longer owns those marker constants.
- Heartbeat adaptive pacing now lives as typed CultCache state on `EpiphanyHeartbeatStateEntry` instead of being written into `state.extra["adaptivePacing"]` as JSON. Status projection still emits JSON and reads the old extra pocket as a legacy fallback.
- Heartbeat participant scene id, personality timing, and mood timing now live as typed participant fields instead of durable `participant.extra` JSON pockets. Scheduler pacing and status projection read the typed fields first and keep legacy extra fallbacks only as sealed compatibility scars.
- Heartbeat durable document/schema types now live in `epiphany-core/src/heartbeat_state/heartbeat_documents.rs`, role/default construction lives in `epiphany-core/src/heartbeat_state/heartbeat_roles.rs`, persistence/validation lives in `epiphany-core/src/heartbeat_state/heartbeat_store.rs`, and status/artifact JSON projection lives in `epiphany-core/src/heartbeat_state/heartbeat_projection.rs`. The root `heartbeat_state.rs` keeps scheduling and Void cognition orchestration for the next cuts. Focused heartbeat tests and `epiphany-core` check pass after the splits.
- Heartbeat role/default and store seams now have module-local unit tests: fixed lane catalog, Ghostlight scene role projection, and typed state/cognition CultCache round-trip. Keep future heartbeat cuts aligned to those seam tests instead of growing root integration-only coverage.
- Heartbeat adaptive pacing now lives in `epiphany-core/src/heartbeat_state/heartbeat_pacing.rs`, including running-turn count and effective cooldown multipliers. It has a module-local unit test for pending-turn counting; root scheduling calls the pacing seam instead of owning pressure/concurrency math directly.

Binary file not shown.

View file

@ -46,6 +46,9 @@ objective:
Heartbeat adaptive pacing is now a typed CultCache field on
`EpiphanyHeartbeatStateEntry`; JSON projection remains only for status and
artifact output, with legacy `extra["adaptivePacing"]` as read fallback.
Heartbeat participant scene id, personality timing, and mood timing are
typed participant fields with legacy `extra` read fallbacks; scheduler
pacing no longer depends on those values as durable JSON pockets.
constraints:
- No frontier-scale training tithe.