diff --git a/epiphany-state-model/src/lib.rs b/epiphany-state-model/src/lib.rs index 1126dbac..d80dd2dc 100644 --- a/epiphany-state-model/src/lib.rs +++ b/epiphany-state-model/src/lib.rs @@ -15,6 +15,26 @@ pub struct EpiphanyStateItem { pub state: EpiphanyThreadState, } +impl EpiphanyStateItem { + pub fn anchored_to_turn(turn_id: impl Into, state: EpiphanyThreadState) -> Self { + Self { + turn_id: Some(turn_id.into()), + state, + } + } + + pub fn for_optional_turn(turn_id: Option, state: EpiphanyThreadState) -> Self { + Self { turn_id, state } + } + + pub fn out_of_band(state: EpiphanyThreadState) -> Self { + Self { + turn_id: None, + state, + } + } +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, TS, Default)] pub struct EpiphanyThreadState { pub revision: u64, @@ -98,6 +118,41 @@ pub struct EpiphanyAcceptanceReceipt { pub summary: Option, } +#[cfg(test)] +mod tests { + use super::EpiphanyStateItem; + use super::EpiphanyThreadState; + + #[test] + fn state_item_constructors_name_snapshot_anchoring() { + let state = EpiphanyThreadState { + revision: 7, + ..Default::default() + }; + + let anchored = EpiphanyStateItem::anchored_to_turn("turn-7", state.clone()); + assert_eq!(anchored.turn_id.as_deref(), Some("turn-7")); + assert_eq!(anchored.state, state); + + let optional = EpiphanyStateItem::for_optional_turn( + Some("turn-8".to_string()), + EpiphanyThreadState { + revision: 8, + ..Default::default() + }, + ); + assert_eq!(optional.turn_id.as_deref(), Some("turn-8")); + assert_eq!(optional.state.revision, 8); + + let out_of_band = EpiphanyStateItem::out_of_band(EpiphanyThreadState { + revision: 9, + ..Default::default() + }); + assert!(out_of_band.turn_id.is_none()); + assert_eq!(out_of_band.state.revision, 9); + } +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, TS, Default)] pub struct EpiphanyRuntimeLink { pub id: String, diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index ff8a508d..92ae199b 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -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. +- Epiphany rollout snapshot anchoring now lives in typed `EpiphanyStateItem` constructors (`anchored_to_turn`, `for_optional_turn`, `out_of_band`) in `epiphany-state-model`. Codex core still physically writes rollout/session items, but live host code no longer hand-assembles the turn/out-of-band snapshot shape. - 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, mood timing, and pending-turn cooldown multipliers now live as typed fields instead of durable `participant.extra` / `pendingTurn.extra` JSON pockets. Scheduler pacing and status projection read the typed fields first and keep legacy extra fallbacks only as sealed compatibility scars. - Heartbeat cognition appraisals and reactions now live as typed CultCache fields instead of `Option` blobs. The mood-timing scheduler consumes typed appraisals directly; legacy cognition migration parses old appraisal/reaction JSON only when loading prior stores. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index f1eb771e..77285175 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index a74af597..ee141521 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -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. + Epiphany rollout snapshot anchoring lives on the typed state item + constructors in `epiphany-state-model`; Codex may physically persist + snapshots, but it should not hand-assemble their turn/out-of-band meaning. 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. diff --git a/vendor/codex/codex-rs/core/src/codex_thread.rs b/vendor/codex/codex-rs/core/src/codex_thread.rs index 33afc1e7..48791655 100644 --- a/vendor/codex/codex-rs/core/src/codex_thread.rs +++ b/vendor/codex/codex-rs/core/src/codex_thread.rs @@ -345,10 +345,9 @@ impl CodexThread { .await; self.codex .session - .persist_rollout_items(&[RolloutItem::EpiphanyState(EpiphanyStateItem { - turn_id: reference_turn_id, - state: state.clone(), - })]) + .persist_rollout_items(&[RolloutItem::EpiphanyState( + EpiphanyStateItem::for_optional_turn(reference_turn_id, state.clone()), + )]) .await; self.codex.session.flush_rollout().await?; Ok(state) diff --git a/vendor/codex/codex-rs/core/src/session/mod.rs b/vendor/codex/codex-rs/core/src/session/mod.rs index ad62f559..9cbbb404 100644 --- a/vendor/codex/codex-rs/core/src/session/mod.rs +++ b/vendor/codex/codex-rs/core/src/session/mod.rs @@ -2550,10 +2550,12 @@ impl Session { self.persist_rollout_items(&[RolloutItem::TurnContext(turn_context_item.clone())]) .await; if let Some(epiphany_state) = self.epiphany_state().await { - self.persist_rollout_items(&[RolloutItem::EpiphanyState(EpiphanyStateItem { - turn_id: turn_context_item.turn_id.clone(), - state: epiphany_state, - })]) + self.persist_rollout_items(&[RolloutItem::EpiphanyState( + EpiphanyStateItem::for_optional_turn( + turn_context_item.turn_id.clone(), + epiphany_state, + ), + )]) .await; }