Store heartbeat adaptive pacing as typed state
This commit is contained in:
parent
41712ee7fd
commit
bcdc2f2b4d
8 changed files with 103 additions and 55 deletions
|
|
@ -14,8 +14,21 @@ mod heartbeat_projection;
|
|||
mod heartbeat_roles;
|
||||
mod heartbeat_store;
|
||||
pub use heartbeat_documents::*;
|
||||
use heartbeat_pacing::adaptive_swarm_pacing;
|
||||
use heartbeat_pacing::effective_cooldown_multiplier;
|
||||
use heartbeat_pacing::mood_cooldown_multiplier;
|
||||
use heartbeat_pacing::personality_cooldown_multiplier;
|
||||
use heartbeat_pacing::running_turn_count;
|
||||
pub use heartbeat_projection::heartbeat_status_projection;
|
||||
use heartbeat_projection::history_event_json;
|
||||
use heartbeat_projection::pending_turn_json;
|
||||
use heartbeat_projection::schedule_participant_json;
|
||||
use heartbeat_projection::selection_policy_json;
|
||||
use heartbeat_roles::ROLE_ORDER;
|
||||
use heartbeat_roles::agent_id_for_role;
|
||||
pub use heartbeat_roles::default_heartbeat_state;
|
||||
use heartbeat_roles::default_participant;
|
||||
use heartbeat_roles::display_name_for_role;
|
||||
pub use heartbeat_roles::ghostlight_scene_heartbeat_state;
|
||||
pub use heartbeat_roles::initialize_ghostlight_scene_heartbeat_store;
|
||||
pub use heartbeat_roles::initialize_heartbeat_store;
|
||||
|
|
@ -26,19 +39,6 @@ pub use heartbeat_store::validate_heartbeat_cognition;
|
|||
pub use heartbeat_store::validate_heartbeat_state;
|
||||
pub use heartbeat_store::write_heartbeat_cognition_entry;
|
||||
pub use heartbeat_store::write_heartbeat_state_entry;
|
||||
use heartbeat_projection::history_event_json;
|
||||
use heartbeat_projection::pending_turn_json;
|
||||
use heartbeat_projection::schedule_participant_json;
|
||||
use heartbeat_projection::selection_policy_json;
|
||||
use heartbeat_pacing::adaptive_swarm_pacing;
|
||||
use heartbeat_pacing::effective_cooldown_multiplier;
|
||||
use heartbeat_pacing::mood_cooldown_multiplier;
|
||||
use heartbeat_pacing::personality_cooldown_multiplier;
|
||||
use heartbeat_pacing::running_turn_count;
|
||||
use heartbeat_roles::ROLE_ORDER;
|
||||
use heartbeat_roles::agent_id_for_role;
|
||||
use heartbeat_roles::default_participant;
|
||||
use heartbeat_roles::display_name_for_role;
|
||||
|
||||
pub(super) const HEARTBEAT_ARENA_MAINTENANCE: &str = "maintenance";
|
||||
pub(super) const HEARTBEAT_ARENA_SCENE: &str = "scene";
|
||||
|
|
@ -73,8 +73,12 @@ pub fn run_void_routine_store(
|
|||
apply_personality_timing_profiles(&mut state, &appraisal_profiles);
|
||||
let resonance = build_memory_resonance(&memory_records);
|
||||
let incubation = build_incubation(
|
||||
&previous_cognition.as_ref().and_then(|entry| entry.incubation.clone()),
|
||||
&previous_cognition.as_ref().and_then(|entry| entry.bridge.clone()),
|
||||
&previous_cognition
|
||||
.as_ref()
|
||||
.and_then(|entry| entry.incubation.clone()),
|
||||
&previous_cognition
|
||||
.as_ref()
|
||||
.and_then(|entry| entry.bridge.clone()),
|
||||
&previous_cognition
|
||||
.as_ref()
|
||||
.and_then(|entry| entry.candidate_interventions.clone()),
|
||||
|
|
@ -83,7 +87,9 @@ pub fn run_void_routine_store(
|
|||
);
|
||||
let thought_lanes = build_thought_lanes(&resonance, &incubation, &memory_records);
|
||||
let bridge = build_thought_bridge(
|
||||
&previous_cognition.as_ref().and_then(|entry| entry.bridge.clone()),
|
||||
&previous_cognition
|
||||
.as_ref()
|
||||
.and_then(|entry| entry.bridge.clone()),
|
||||
&thought_lanes,
|
||||
&resonance,
|
||||
&incubation,
|
||||
|
|
@ -231,19 +237,16 @@ pub fn pump_heartbeat_store(
|
|||
|
||||
let pacing = adaptive_swarm_pacing(&state, &options);
|
||||
state.target_heartbeat_rate = pacing.effective_heartbeat_rate;
|
||||
state.extra.insert(
|
||||
"adaptivePacing".to_string(),
|
||||
serde_json::json!({
|
||||
"schema_version": "epiphany.adaptive_heartbeat_pacing.v0",
|
||||
"contract": "Swarm pressure controls both heartbeat tempo and concurrency. Relaxed systems sleep slow; urgent systems fill more lanes without re-waking unfinished turns.",
|
||||
"pressure": pacing.pressure,
|
||||
"effectiveHeartbeatRate": pacing.effective_heartbeat_rate,
|
||||
"targetConcurrency": pacing.target_concurrency,
|
||||
"runningTurns": pacing.running_turns,
|
||||
"activeParticipants": pacing.active_participants,
|
||||
"signals": pacing.signals,
|
||||
}),
|
||||
);
|
||||
state.adaptive_pacing = Some(HeartbeatAdaptivePacing {
|
||||
schema_version: "epiphany.adaptive_heartbeat_pacing.v0".to_string(),
|
||||
contract: "Swarm pressure controls both heartbeat tempo and concurrency. Relaxed systems sleep slow; urgent systems fill more lanes without re-waking unfinished turns.".to_string(),
|
||||
pressure: pacing.pressure,
|
||||
effective_heartbeat_rate: pacing.effective_heartbeat_rate,
|
||||
target_concurrency: pacing.target_concurrency,
|
||||
running_turns: pacing.running_turns,
|
||||
active_participants: pacing.active_participants,
|
||||
signals: pacing.signals.clone(),
|
||||
});
|
||||
|
||||
let artifact_dir = artifact_dir.as_ref();
|
||||
fs::create_dir_all(artifact_dir)
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ pub struct EpiphanyHeartbeatStateEntry {
|
|||
pub participants: Vec<HeartbeatParticipant>,
|
||||
#[cultcache(key = 6)]
|
||||
pub history: Vec<HeartbeatHistoryEvent>,
|
||||
#[cultcache(key = 7, default)]
|
||||
pub adaptive_pacing: Option<HeartbeatAdaptivePacing>,
|
||||
#[cultcache(key = 15, default)]
|
||||
pub extra: BTreeMap<String, Value>,
|
||||
}
|
||||
|
|
@ -135,6 +137,34 @@ pub struct HeartbeatPacingPolicy {
|
|||
pub extra: BTreeMap<String, Value>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HeartbeatAdaptivePacing {
|
||||
#[serde(rename = "schema_version")]
|
||||
pub schema_version: String,
|
||||
pub contract: String,
|
||||
pub pressure: f64,
|
||||
pub effective_heartbeat_rate: f64,
|
||||
pub target_concurrency: usize,
|
||||
pub running_turns: usize,
|
||||
pub active_participants: usize,
|
||||
pub signals: HeartbeatAdaptivePacingSignals,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HeartbeatAdaptivePacingSignals {
|
||||
pub external_urgency: f64,
|
||||
pub max_anxiety: f64,
|
||||
pub average_anxiety: f64,
|
||||
pub max_urgency: f64,
|
||||
pub max_arousal: f64,
|
||||
pub max_thought_pressure: f64,
|
||||
pub max_reaction_intensity: f64,
|
||||
pub pending_pressure: f64,
|
||||
pub contract: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct HeartbeatParticipant {
|
||||
pub agent_id: String,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use super::EpiphanyHeartbeatStateEntry;
|
||||
use super::HeartbeatAdaptivePacingSignals;
|
||||
use super::HeartbeatParticipant;
|
||||
use super::HeartbeatPumpOptions;
|
||||
use super::round3;
|
||||
|
|
@ -12,7 +13,7 @@ pub(super) struct AdaptiveSwarmPacing {
|
|||
pub(super) target_concurrency: usize,
|
||||
pub(super) running_turns: usize,
|
||||
pub(super) active_participants: usize,
|
||||
pub(super) signals: Value,
|
||||
pub(super) signals: HeartbeatAdaptivePacingSignals,
|
||||
}
|
||||
|
||||
pub(super) fn adaptive_swarm_pacing(
|
||||
|
|
@ -74,17 +75,17 @@ pub(super) fn adaptive_swarm_pacing(
|
|||
target_concurrency,
|
||||
running_turns,
|
||||
active_participants,
|
||||
signals: serde_json::json!({
|
||||
"externalUrgency": round3(external_urgency),
|
||||
"maxAnxiety": round3(mood_signals.max_anxiety),
|
||||
"averageAnxiety": round3(mood_signals.average_anxiety),
|
||||
"maxUrgency": round3(mood_signals.max_urgency),
|
||||
"maxArousal": round3(mood_signals.max_arousal),
|
||||
"maxThoughtPressure": round3(mood_signals.max_thought_pressure),
|
||||
"maxReactionIntensity": round3(mood_signals.max_reaction_intensity),
|
||||
"pendingPressure": round3(pending_pressure),
|
||||
"contract": "Anxiety-like state raises tempo and concurrency; calm state lets the swarm sleep slow.",
|
||||
}),
|
||||
signals: HeartbeatAdaptivePacingSignals {
|
||||
external_urgency: round3(external_urgency),
|
||||
max_anxiety: round3(mood_signals.max_anxiety),
|
||||
average_anxiety: round3(mood_signals.average_anxiety),
|
||||
max_urgency: round3(mood_signals.max_urgency),
|
||||
max_arousal: round3(mood_signals.max_arousal),
|
||||
max_thought_pressure: round3(mood_signals.max_thought_pressure),
|
||||
max_reaction_intensity: round3(mood_signals.max_reaction_intensity),
|
||||
pending_pressure: round3(pending_pressure),
|
||||
contract: "Anxiety-like state raises tempo and concurrency; calm state lets the swarm sleep slow.".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -177,16 +178,14 @@ mod tests {
|
|||
#[test]
|
||||
fn running_turn_count_reads_only_running_pending_turns() {
|
||||
let mut state = default_heartbeat_state(1.0);
|
||||
state.participants[0].pending_turn =
|
||||
Some(crate::heartbeat_state::HeartbeatPendingTurn {
|
||||
status: "running".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
state.participants[1].pending_turn =
|
||||
Some(crate::heartbeat_state::HeartbeatPendingTurn {
|
||||
status: "completed".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
state.participants[0].pending_turn = Some(crate::heartbeat_state::HeartbeatPendingTurn {
|
||||
status: "running".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
state.participants[1].pending_turn = Some(crate::heartbeat_state::HeartbeatPendingTurn {
|
||||
status: "completed".to_string(),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
assert_eq!(running_turn_count(&state), 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,11 @@ pub fn heartbeat_status_projection(
|
|||
.rev()
|
||||
.map(history_event_json)
|
||||
.collect();
|
||||
let adaptive_pacing = state
|
||||
.adaptive_pacing
|
||||
.as_ref()
|
||||
.and_then(|pacing| serde_json::to_value(pacing).ok())
|
||||
.or_else(|| state.extra.get("adaptivePacing").cloned());
|
||||
Ok(serde_json::json!({
|
||||
"schema_version": HEARTBEAT_STATUS_SCHEMA_VERSION,
|
||||
"ok": true,
|
||||
|
|
@ -81,7 +86,7 @@ pub fn heartbeat_status_projection(
|
|||
"candidateInterventions": cognition.as_ref().and_then(|entry| entry.candidate_interventions.clone()),
|
||||
"appraisals": cognition.as_ref().and_then(|entry| entry.appraisals.clone()),
|
||||
"reactions": cognition.as_ref().and_then(|entry| entry.reactions.clone()),
|
||||
"adaptivePacing": state.extra.get("adaptivePacing"),
|
||||
"adaptivePacing": adaptive_pacing,
|
||||
"availableActions": ["init", "tick", "pump", "complete", "status", "routine"],
|
||||
}))
|
||||
}
|
||||
|
|
@ -94,7 +99,10 @@ fn latest_json_artifacts(artifact_dir: impl AsRef<Path>, limit: usize) -> Vec<Va
|
|||
let mut paths: Vec<_> = read_dir
|
||||
.filter_map(Result::ok)
|
||||
.map(|entry| entry.path())
|
||||
.filter(|path| path.extension().is_some_and(|extension| extension == "json"))
|
||||
.filter(|path| {
|
||||
path.extension()
|
||||
.is_some_and(|extension| extension == "json")
|
||||
})
|
||||
.filter_map(|path| {
|
||||
let modified = path.metadata().and_then(|meta| meta.modified()).ok()?;
|
||||
Some((path, modified))
|
||||
|
|
@ -121,7 +129,8 @@ fn latest_json_artifacts(artifact_dir: impl AsRef<Path>, limit: usize) -> Vec<Va
|
|||
}
|
||||
|
||||
fn artifact_summary(payload: &Value) -> Value {
|
||||
if payload.get("schema_version") == Some(&Value::String(VOID_ROUTINE_SCHEMA_VERSION.to_string()))
|
||||
if payload.get("schema_version")
|
||||
== Some(&Value::String(VOID_ROUTINE_SCHEMA_VERSION.to_string()))
|
||||
{
|
||||
return serde_json::json!({
|
||||
"runId": payload.get("runId"),
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ pub fn default_heartbeat_state(target_heartbeat_rate: f64) -> EpiphanyHeartbeatS
|
|||
.map(|role_id| default_participant(role_id))
|
||||
.collect(),
|
||||
history: Vec::new(),
|
||||
adaptive_pacing: None,
|
||||
extra: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -254,7 +255,9 @@ fn participant_constraints(role_id: &str) -> Vec<&'static str> {
|
|||
}
|
||||
"imagination" => "Synthesizes futures; must not adopt objectives.",
|
||||
"research" => "Scouts known work; must not turn research into procrastination.",
|
||||
"modeling" => "Grows source-grounded maps and checkpoints; must not edit implementation code.",
|
||||
"modeling" => {
|
||||
"Grows source-grounded maps and checkpoints; must not edit implementation code."
|
||||
}
|
||||
"implementation" => {
|
||||
"Touches source only with accepted guidance and verifier-readable evidence."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ remembers doctrine; the branch remembers the blade.
|
|||
- Vendored app-server no longer imports `epiphany_core` directly. Retrieval query normalization and raw route job-launch DTO construction are bridge-owned adapters; the remaining direct native render call is in Codex core's model-context prompt fragment host seam.
|
||||
- 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 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.
|
|
@ -43,6 +43,9 @@ objective:
|
|||
JSON-RPC notifications.
|
||||
Epiphany prompt-state boundary tags live in `epiphany-state-model` and are
|
||||
re-exported through `codex-protocol` for compatibility.
|
||||
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.
|
||||
|
||||
constraints:
|
||||
- No frontier-scale training tithe.
|
||||
|
|
|
|||
Reference in a new issue