From 3e55aadb9c1d03f8da26f33836dd22c102b74a70 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 05:02:47 +0100 Subject: [PATCH] Make legacy Epiphany rollout payload opaque --- notes/fresh-workspace-handoff.md | 7 +++- notes/native-coordinator-liberation-map.md | 8 ++++ state/ledgers.msgpack | Bin 410599 -> 411072 bytes state/map.yaml | 2 +- .../epiphany_thread_host.rs | 2 +- .../legacy_epiphany_rollout.rs | 36 +++++++++++++----- .../session/rollout_reconstruction_tests.rs | 22 +++++++---- .../codex/codex-rs/core/src/session/tests.rs | 15 +++++++- vendor/codex/codex-rs/protocol/Cargo.toml | 2 +- .../codex/codex-rs/protocol/src/protocol.rs | 14 ++++--- 10 files changed, 81 insertions(+), 27 deletions(-) diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 6e3757a0..97f04ba3 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -1912,7 +1912,12 @@ slab is deleted: app-server-protocol, app-server, and core legacy tests import the native model directly; Codex protocol keeps only a private state-item import for historical rollout decoding. Next make that legacy payload opaque in Codex protocol and decode it only in the app-server quarantine, removing -`epiphany-state-model` from Codex protocol's production dependency graph. +`epiphany-state-model` from Codex protocol's production dependency graph. That +cut is complete: the rollout variant carries opaque JSON, app-server alone +performs typed validation, malformed payloads fail closed, and production +Codex protocol has no native-state dependency. Next delete its obsolete +native-state test fixture and dev-dependency, leaving only an opaque historical +envelope preservation test. ## Immediate Re-entry Instruction diff --git a/notes/native-coordinator-liberation-map.md b/notes/native-coordinator-liberation-map.md index e385eb8d..d9f7e426 100644 --- a/notes/native-coordinator-liberation-map.md +++ b/notes/native-coordinator-liberation-map.md @@ -312,3 +312,11 @@ app-server compatibility code, and legacy-focused core tests import `EpiphanyStateItem` import solely to decode the historical rollout variant; its two round-trip tests and app-server's two migration tests pass. A source guard forbids `pub use epiphany_state_model::*` from returning. + +The historical rollout payload is now opaque inside Codex protocol: +`RolloutItem::EpiphanyState(serde_json::Value)`. App-server's legacy quarantine +alone decodes that value into `EpiphanyStateItem`, returns a typed state only +after validation, and rejects malformed payloads. The old tagged JSON shape, +latest-surviving selection, and rollback semantics remain covered. Codex +protocol no longer has a production dependency on `epiphany-state-model`; a +source guard proves both the opaque variant and dependency boundary. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index d4f0ce505792a3a1d47dde2377879c5a87257a07..c5b7f1446fef8b36bcd24a43138a0c2d8b7fafbb 100644 GIT binary patch delta 516 zcmZ9JzfW5+5XX6;Wn)92Y$vhuAPrHG!c++chAtE_utZn;k{JAaj_numrVI=jI?{}l zy0aiLAU3A%{VVu4xR(S}bvRo-ef|C1kC$ol`A749Gh6R;TkY8z1S)c2~y2Z@i5v&P!#myMrK?NRm>5-R?PB$ruNUHC^XEaAL(4&}k@mOd3+< z~xo?sHVbUIJL__=~a^ABDPNnPzg zzqEGQq2fSLJIcH8Mye6?&YX=w4NVegDUyK{u9wjNW+Ow=<)XA=51r}PZbOXV_ items, InitialHistory::Resumed(resumed) => resumed.history, }; - Ok(latest_legacy_epiphany_state(&items)) + latest_legacy_epiphany_state(&items) } pub(super) async fn live_thread_epiphany_state( diff --git a/vendor/codex/codex-rs/app-server/src/codex_message_processor/legacy_epiphany_rollout.rs b/vendor/codex/codex-rs/app-server/src/codex_message_processor/legacy_epiphany_rollout.rs index 3000ffcd..290ec11a 100644 --- a/vendor/codex/codex-rs/app-server/src/codex_message_processor/legacy_epiphany_rollout.rs +++ b/vendor/codex/codex-rs/app-server/src/codex_message_processor/legacy_epiphany_rollout.rs @@ -28,7 +28,9 @@ fn is_out_of_band(segment: &LegacySegment) -> bool { segment.turn_id.is_none() && !segment.user_turn && segment.state.is_some() } -pub(super) fn latest_legacy_epiphany_state(items: &[RolloutItem]) -> Option { +pub(super) fn latest_legacy_epiphany_state( + items: &[RolloutItem], +) -> Result, String> { let mut state = None; let mut rollbacks = 0usize; let mut segment: Option = None; @@ -66,7 +68,11 @@ pub(super) fn latest_legacy_epiphany_state(items: &[RolloutItem]) -> Option { segment.get_or_insert_with(LegacySegment::default).user_turn = true; } - RolloutItem::EpiphanyState(item) => { + RolloutItem::EpiphanyState(payload) => { + let item: epiphany_state_model::EpiphanyStateItem = + serde_json::from_value(payload.clone()).map_err(|error| { + format!("invalid legacy Epiphany rollout payload: {error}") + })?; let segment = segment.get_or_insert_with(LegacySegment::default); if segment.turn_id.is_none() { segment.turn_id = item.turn_id.clone(); @@ -96,7 +102,7 @@ pub(super) fn latest_legacy_epiphany_state(items: &[RolloutItem]) -> Option RolloutItem { + RolloutItem::EpiphanyState( + serde_json::to_value(item).expect("serialize legacy Epiphany rollout payload"), + ) +} + fn user_message(text: &str) -> ResponseItem { ResponseItem::Message { id: None, @@ -138,7 +144,7 @@ async fn record_initial_history_resumed_accepts_legacy_epiphany_state_items() { }, )), RolloutItem::TurnContext(first_context_item), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(first_turn_id.clone()), state: first_epiphany, }), @@ -167,7 +173,7 @@ async fn record_initial_history_resumed_accepts_legacy_epiphany_state_items() { text_elements: Vec::new(), }, )), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(second_turn_id.clone()), state: second_epiphany.clone(), }), @@ -201,7 +207,7 @@ async fn record_initial_history_resumed_accepts_out_of_band_epiphany_state_befor session .record_initial_history(InitialHistory::Resumed(ResumedHistory { conversation_id: ThreadId::default(), - history: vec![RolloutItem::EpiphanyState(EpiphanyStateItem { + history: vec![legacy_epiphany_state(EpiphanyStateItem { turn_id: None, state: epiphany_state.clone(), })], @@ -239,7 +245,7 @@ async fn record_initial_history_resumed_accepts_out_of_band_epiphany_state_after text_elements: Vec::new(), }, )), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(turn_id.clone()), state: turn_state, }), @@ -252,7 +258,7 @@ async fn record_initial_history_resumed_accepts_out_of_band_epiphany_state_after time_to_first_token_ms: None, }, )), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: None, state: control_plane_state.clone(), }), @@ -476,7 +482,7 @@ async fn reconstruct_history_ignores_legacy_epiphany_items_during_rollback() { }, )), RolloutItem::TurnContext(first_context_item), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(first_turn_id.clone()), state: sample_epiphany_state("turn-1"), }), @@ -505,7 +511,7 @@ async fn reconstruct_history_ignores_legacy_epiphany_items_during_rollback() { text_elements: Vec::new(), }, )), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(rolled_back_turn_id.clone()), state: sample_epiphany_state("turn-2"), }), @@ -1293,7 +1299,7 @@ async fn reconstruct_history_ignores_legacy_epiphany_items_during_compaction() { }, )), RolloutItem::TurnContext(previous_context_item), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(previous_turn_id.clone()), state: epiphany_state.clone(), }), diff --git a/vendor/codex/codex-rs/core/src/session/tests.rs b/vendor/codex/codex-rs/core/src/session/tests.rs index ef3489e1..1b5110ea 100644 --- a/vendor/codex/codex-rs/core/src/session/tests.rs +++ b/vendor/codex/codex-rs/core/src/session/tests.rs @@ -147,6 +147,12 @@ use std::time::Duration as StdDuration; mod guardian_tests; +fn legacy_epiphany_state(item: EpiphanyStateItem) -> RolloutItem { + RolloutItem::EpiphanyState( + serde_json::to_value(item).expect("serialize legacy Epiphany rollout payload"), + ) +} + #[test] fn codex_session_has_no_epiphany_state_custody() { let session_state = include_str!("../state/session.rs"); @@ -154,6 +160,7 @@ fn codex_session_has_no_epiphany_state_custody() { let codex_thread = include_str!("../codex_thread.rs"); let core_lib = include_str!("../lib.rs"); let protocol = include_str!("../../../protocol/src/protocol.rs"); + let protocol_manifest = include_str!("../../../protocol/Cargo.toml"); assert!(!session_state.contains("epiphany_state")); assert!(!session.contains("set_epiphany_state")); @@ -162,6 +169,12 @@ fn codex_session_has_no_epiphany_state_custody() { assert!(!codex_thread.contains("pub async fn epiphany_")); assert!(!core_lib.contains("epiphany_rollout")); assert!(!protocol.contains("pub use epiphany_state_model::")); + assert!(protocol.contains("EpiphanyState(serde_json::Value)")); + let production_dependencies = protocol_manifest + .split("[dev-dependencies]") + .next() + .expect("protocol manifest should declare dependencies"); + assert!(!production_dependencies.contains("epiphany-state-model")); } fn sample_epiphany_state_for_prompt() -> EpiphanyThreadState { @@ -5350,7 +5363,7 @@ async fn build_initial_context_does_not_inject_resumed_epiphany_state() { text_elements: Vec::new(), })), RolloutItem::TurnContext(turn_context_item), - RolloutItem::EpiphanyState(EpiphanyStateItem { + legacy_epiphany_state(EpiphanyStateItem { turn_id: Some(turn_id), state: epiphany_state, }), diff --git a/vendor/codex/codex-rs/protocol/Cargo.toml b/vendor/codex/codex-rs/protocol/Cargo.toml index e058452b..d3ae68ea 100644 --- a/vendor/codex/codex-rs/protocol/Cargo.toml +++ b/vendor/codex/codex-rs/protocol/Cargo.toml @@ -22,7 +22,6 @@ codex-utils-image = { workspace = true } codex-utils-string = { workspace = true } codex-utils-template = { workspace = true } encoding_rs = { workspace = true } -epiphany-state-model = { path = "../../../../epiphany-state-model" } globset = { workspace = true } icu_decimal = { workspace = true } icu_locale_core = { workspace = true } @@ -52,6 +51,7 @@ seccompiler = { workspace = true } [dev-dependencies] anyhow = { workspace = true } +epiphany-state-model = { path = "../../../../epiphany-state-model" } http = { workspace = true } pretty_assertions = { workspace = true } tempfile = { workspace = true } diff --git a/vendor/codex/codex-rs/protocol/src/protocol.rs b/vendor/codex/codex-rs/protocol/src/protocol.rs index 1bbfaf6d..fc32638b 100644 --- a/vendor/codex/codex-rs/protocol/src/protocol.rs +++ b/vendor/codex/codex-rs/protocol/src/protocol.rs @@ -52,8 +52,6 @@ use crate::request_user_input::RequestUserInputResponse; use crate::user_input::UserInput; #[cfg(test)] use epiphany_state_model::*; -#[cfg(not(test))] -use epiphany_state_model::EpiphanyStateItem; use codex_utils_absolute_path::AbsolutePathBuf; use schemars::JsonSchema; use serde::Deserialize; @@ -2947,7 +2945,7 @@ pub enum RolloutItem { ResponseItem(ResponseItem), Compacted(CompactedItem), TurnContext(TurnContextItem), - EpiphanyState(EpiphanyStateItem), + EpiphanyState(serde_json::Value), EventMsg(EventMsg), } @@ -5284,8 +5282,14 @@ mod tests { turn_id: Some("turn-123".to_string()), state: sample_epiphany_thread_state(), }; - let value = serde_json::to_value(&original)?; - let reparsed: EpiphanyStateItem = serde_json::from_value(value)?; + let rollout_item = RolloutItem::EpiphanyState(serde_json::to_value(&original)?); + let value = serde_json::to_value(&rollout_item)?; + assert_eq!(value["type"], "epiphany_state"); + let reparsed: RolloutItem = serde_json::from_value(value)?; + let RolloutItem::EpiphanyState(payload) = reparsed else { + panic!("expected opaque legacy Epiphany rollout payload"); + }; + let reparsed: EpiphanyStateItem = serde_json::from_value(payload)?; assert_eq!(reparsed, original); Ok(()) }