Quarantine legacy Epiphany rollout parsing
This commit is contained in:
parent
86c6e0b450
commit
d53ad941b5
10 changed files with 186 additions and 421 deletions
|
|
@ -1898,7 +1898,12 @@ That audit removed Codex session custody entirely: `SessionState`, `Session`, an
|
|||
reconstruction ignores legacy Epiphany items. The app-server reads unified
|
||||
CultCache first and invokes the legacy rollout parser directly only when native
|
||||
state is absent. Next move that parser out of `codex-core` into the compatibility
|
||||
boundary if the protocol seam permits it.
|
||||
boundary if the protocol seam permits it. That transplant is complete:
|
||||
app-server's `legacy_epiphany_rollout` quarantine module owns historical parsing
|
||||
and its latest-surviving/rollback tests; `codex-core` has no parser module or
|
||||
export and treats the legacy rollout variant as inert. Next remove the two
|
||||
Epiphany-named `CodexThread` convenience methods by deriving compatibility paths
|
||||
and reference context at the app-server boundary.
|
||||
|
||||
## Immediate Re-entry Instruction
|
||||
|
||||
|
|
|
|||
|
|
@ -292,3 +292,10 @@ reconstruction ignores historical Epiphany items. The app-server compatibility
|
|||
host reads unified CultCache first and, only when it is empty, invokes the
|
||||
legacy rollout reader directly at the boundary. A source guard rejects renewed
|
||||
session custody.
|
||||
|
||||
The historical rollout parser has now moved out of `codex-core` as well. It
|
||||
lives in app-server's explicitly quarantined `legacy_epiphany_rollout` module,
|
||||
where two migration tests prove latest-surviving selection and rollback
|
||||
rejection. `codex-core` no longer declares or exports an Epiphany rollout
|
||||
parser. The legacy `RolloutItem` variant remains readable so old files do not
|
||||
become undecodable, but normal core reconstruction treats it as inert cargo.
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -659,4 +659,4 @@ current_status:
|
|||
- Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass.
|
||||
- `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure.
|
||||
last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. Gjallar readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync.
|
||||
next_action: Move the remaining historical Epiphany rollout parser out of `codex-core` and into the compatibility bridge/app-server boundary if its protocol dependencies permit. Codex session state and normal rollout reconstruction now carry no Epiphany custody; unified CultCache is authoritative and the boundary-only legacy reader may seed an empty store.
|
||||
next_action: Remove the remaining Epiphany-named convenience methods from `codex-core::CodexThread`. App-server can derive the runtime-spine path from the generic config snapshot and should use a generic reference-context accessor; only inert legacy `RolloutItem::EpiphanyState` decoding should remain in core/protocol compatibility code.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ mod epiphany_mutation_routes;
|
|||
mod epiphany_read_routes;
|
||||
mod epiphany_thread_host;
|
||||
mod listener_lifecycle;
|
||||
mod legacy_epiphany_rollout;
|
||||
mod mcp_routes;
|
||||
mod realtime_routes;
|
||||
mod review_routes;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use std::path::Path;
|
||||
|
||||
use super::legacy_epiphany_rollout::latest_legacy_epiphany_state;
|
||||
use codex_core::CodexThread;
|
||||
use codex_core::RolloutRecorder;
|
||||
use codex_core::latest_epiphany_state_from_rollout_items;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::InitialHistory;
|
||||
use codex_protocol::protocol::TokenUsageInfo;
|
||||
|
|
@ -70,7 +70,7 @@ pub(super) async fn load_epiphany_state_from_rollout_path(
|
|||
InitialHistory::Forked(items) => items,
|
||||
InitialHistory::Resumed(resumed) => resumed.history,
|
||||
};
|
||||
Ok(latest_epiphany_state_from_rollout_items(&items))
|
||||
Ok(latest_legacy_epiphany_state(&items))
|
||||
}
|
||||
|
||||
pub(super) async fn live_thread_epiphany_state(
|
||||
|
|
|
|||
167
vendor/codex/codex-rs/app-server/src/codex_message_processor/legacy_epiphany_rollout.rs
vendored
Normal file
167
vendor/codex/codex-rs/app-server/src/codex_message_processor/legacy_epiphany_rollout.rs
vendored
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
|
||||
#[derive(Default)]
|
||||
struct LegacySegment {
|
||||
turn_id: Option<String>,
|
||||
user_turn: bool,
|
||||
state: Option<EpiphanyThreadState>,
|
||||
}
|
||||
|
||||
fn compatible(active: Option<&str>, item: Option<&str>) -> bool {
|
||||
active.is_none_or(|active| item.is_none_or(|item| item == active))
|
||||
}
|
||||
|
||||
fn finish(segment: LegacySegment, state: &mut Option<EpiphanyThreadState>, rollbacks: &mut usize) {
|
||||
if *rollbacks > 0 && segment.user_turn {
|
||||
*rollbacks -= 1;
|
||||
} else if state.is_none()
|
||||
&& (segment.user_turn || (segment.turn_id.is_none() && segment.state.is_some()))
|
||||
{
|
||||
*state = segment.state;
|
||||
}
|
||||
}
|
||||
|
||||
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<EpiphanyThreadState> {
|
||||
let mut state = None;
|
||||
let mut rollbacks = 0usize;
|
||||
let mut segment: Option<LegacySegment> = None;
|
||||
|
||||
for item in items.iter().rev() {
|
||||
if segment.as_ref().is_some_and(is_out_of_band)
|
||||
&& let Some(segment) = segment.take()
|
||||
{
|
||||
finish(segment, &mut state, &mut rollbacks);
|
||||
}
|
||||
if state.is_some() {
|
||||
break;
|
||||
}
|
||||
|
||||
match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(event)) => {
|
||||
rollbacks = rollbacks
|
||||
.saturating_add(usize::try_from(event.num_turns).unwrap_or(usize::MAX));
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
let segment = segment.get_or_insert_with(LegacySegment::default);
|
||||
segment.turn_id.get_or_insert_with(|| event.turn_id.clone());
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => {
|
||||
if let Some(turn_id) = &event.turn_id {
|
||||
segment
|
||||
.get_or_insert_with(LegacySegment::default)
|
||||
.turn_id
|
||||
.get_or_insert_with(|| turn_id.clone());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_)) => {
|
||||
segment.get_or_insert_with(LegacySegment::default).user_turn = true;
|
||||
}
|
||||
RolloutItem::ResponseItem(ResponseItem::Message { role, .. }) if role == "user" => {
|
||||
segment.get_or_insert_with(LegacySegment::default).user_turn = true;
|
||||
}
|
||||
RolloutItem::EpiphanyState(item) => {
|
||||
let segment = segment.get_or_insert_with(LegacySegment::default);
|
||||
if segment.turn_id.is_none() {
|
||||
segment.turn_id = item.turn_id.clone();
|
||||
}
|
||||
if compatible(segment.turn_id.as_deref(), item.turn_id.as_deref())
|
||||
&& segment.state.is_none()
|
||||
{
|
||||
segment.state = Some(item.state.clone());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => {
|
||||
if segment.as_ref().is_some_and(|segment| {
|
||||
compatible(segment.turn_id.as_deref(), Some(event.turn_id.as_str()))
|
||||
}) && let Some(segment) = segment.take()
|
||||
{
|
||||
finish(segment, &mut state, &mut rollbacks);
|
||||
}
|
||||
}
|
||||
RolloutItem::ResponseItem(_)
|
||||
| RolloutItem::EventMsg(_)
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::TurnContext(_)
|
||||
| RolloutItem::SessionMeta(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(segment) = segment {
|
||||
finish(segment, &mut state, &mut rollbacks);
|
||||
}
|
||||
state
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codex_protocol::config_types::ModeKind;
|
||||
use codex_protocol::protocol::EpiphanyStateItem;
|
||||
use codex_protocol::protocol::ThreadRolledBackEvent;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
|
||||
fn state(id: &str) -> EpiphanyThreadState {
|
||||
EpiphanyThreadState {
|
||||
revision: 1,
|
||||
last_updated_turn_id: Some(id.to_string()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn turn(id: &str, state: EpiphanyThreadState) -> Vec<RolloutItem> {
|
||||
vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: id.to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: ModeKind::Default,
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: id.to_string(),
|
||||
images: None,
|
||||
local_images: Vec::new(),
|
||||
text_elements: Vec::new(),
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some(id.to_string()),
|
||||
state,
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: id.to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returns_latest_surviving_legacy_state() {
|
||||
let first = state("one");
|
||||
let second = state("two");
|
||||
let mut items = turn("one", first);
|
||||
items.extend(turn("two", second.clone()));
|
||||
assert_eq!(latest_legacy_epiphany_state(&items), Some(second));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skips_rolled_back_legacy_state() {
|
||||
let first = state("one");
|
||||
let mut items = turn("one", first.clone());
|
||||
items.extend(turn("two", state("two")));
|
||||
items.push(RolloutItem::EventMsg(EventMsg::ThreadRolledBack(
|
||||
ThreadRolledBackEvent { num_turns: 1 },
|
||||
)));
|
||||
assert_eq!(latest_legacy_epiphany_state(&items), Some(first));
|
||||
}
|
||||
}
|
||||
415
vendor/codex/codex-rs/core/src/epiphany_rollout.rs
vendored
415
vendor/codex/codex-rs/core/src/epiphany_rollout.rs
vendored
|
|
@ -1,415 +0,0 @@
|
|||
use crate::context_manager;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct ActiveEpiphanyReplaySegment {
|
||||
turn_id: Option<String>,
|
||||
counts_as_user_turn: bool,
|
||||
epiphany_state: Option<EpiphanyThreadState>,
|
||||
}
|
||||
|
||||
fn turn_ids_are_compatible(active_turn_id: Option<&str>, item_turn_id: Option<&str>) -> bool {
|
||||
active_turn_id
|
||||
.is_none_or(|turn_id| item_turn_id.is_none_or(|item_turn_id| item_turn_id == turn_id))
|
||||
}
|
||||
|
||||
fn finalize_active_segment(
|
||||
active_segment: ActiveEpiphanyReplaySegment,
|
||||
epiphany_state: &mut Option<EpiphanyThreadState>,
|
||||
pending_rollback_turns: &mut usize,
|
||||
) {
|
||||
if *pending_rollback_turns > 0 && active_segment.counts_as_user_turn {
|
||||
*pending_rollback_turns -= 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if epiphany_state.is_none()
|
||||
&& (active_segment.counts_as_user_turn
|
||||
|| (active_segment.turn_id.is_none() && active_segment.epiphany_state.is_some()))
|
||||
{
|
||||
*epiphany_state = active_segment.epiphany_state;
|
||||
}
|
||||
}
|
||||
|
||||
fn is_out_of_band_epiphany_segment(active_segment: &ActiveEpiphanyReplaySegment) -> bool {
|
||||
active_segment.turn_id.is_none()
|
||||
&& !active_segment.counts_as_user_turn
|
||||
&& active_segment.epiphany_state.is_some()
|
||||
}
|
||||
|
||||
pub fn latest_epiphany_state_from_rollout_items<F>(
|
||||
rollout_items: &[RolloutItem],
|
||||
is_user_turn_boundary: F,
|
||||
) -> Option<EpiphanyThreadState>
|
||||
where
|
||||
F: Fn(&ResponseItem) -> bool,
|
||||
{
|
||||
let mut epiphany_state = None;
|
||||
let mut pending_rollback_turns = 0usize;
|
||||
let mut active_segment: Option<ActiveEpiphanyReplaySegment> = None;
|
||||
|
||||
for item in rollout_items.iter().rev() {
|
||||
if active_segment
|
||||
.as_ref()
|
||||
.is_some_and(is_out_of_band_epiphany_segment)
|
||||
&& let Some(active_segment) = active_segment.take()
|
||||
{
|
||||
finalize_active_segment(
|
||||
active_segment,
|
||||
&mut epiphany_state,
|
||||
&mut pending_rollback_turns,
|
||||
);
|
||||
}
|
||||
if epiphany_state.is_some() {
|
||||
break;
|
||||
}
|
||||
|
||||
match item {
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(rollback)) => {
|
||||
pending_rollback_turns = pending_rollback_turns
|
||||
.saturating_add(usize::try_from(rollback.num_turns).unwrap_or(usize::MAX));
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(event)) => {
|
||||
let active_segment =
|
||||
active_segment.get_or_insert_with(ActiveEpiphanyReplaySegment::default);
|
||||
if active_segment.turn_id.is_none() {
|
||||
active_segment.turn_id = Some(event.turn_id.clone());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnAborted(event)) => {
|
||||
if let Some(active_segment) = active_segment.as_mut() {
|
||||
if active_segment.turn_id.is_none()
|
||||
&& let Some(turn_id) = &event.turn_id
|
||||
{
|
||||
active_segment.turn_id = Some(turn_id.clone());
|
||||
}
|
||||
} else if let Some(turn_id) = &event.turn_id {
|
||||
active_segment = Some(ActiveEpiphanyReplaySegment {
|
||||
turn_id: Some(turn_id.clone()),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(_)) => {
|
||||
let active_segment =
|
||||
active_segment.get_or_insert_with(ActiveEpiphanyReplaySegment::default);
|
||||
active_segment.counts_as_user_turn = true;
|
||||
}
|
||||
RolloutItem::ResponseItem(response_item) => {
|
||||
let active_segment =
|
||||
active_segment.get_or_insert_with(ActiveEpiphanyReplaySegment::default);
|
||||
active_segment.counts_as_user_turn |= is_user_turn_boundary(response_item);
|
||||
}
|
||||
RolloutItem::EpiphanyState(item) => {
|
||||
let active_segment =
|
||||
active_segment.get_or_insert_with(ActiveEpiphanyReplaySegment::default);
|
||||
if active_segment.turn_id.is_none() {
|
||||
active_segment.turn_id = item.turn_id.clone();
|
||||
}
|
||||
if turn_ids_are_compatible(
|
||||
active_segment.turn_id.as_deref(),
|
||||
item.turn_id.as_deref(),
|
||||
) && active_segment.epiphany_state.is_none()
|
||||
{
|
||||
active_segment.epiphany_state = Some(item.state.clone());
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(event)) => {
|
||||
if active_segment.as_ref().is_some_and(|active_segment| {
|
||||
turn_ids_are_compatible(
|
||||
active_segment.turn_id.as_deref(),
|
||||
Some(event.turn_id.as_str()),
|
||||
)
|
||||
}) && let Some(active_segment) = active_segment.take()
|
||||
{
|
||||
finalize_active_segment(
|
||||
active_segment,
|
||||
&mut epiphany_state,
|
||||
&mut pending_rollback_turns,
|
||||
);
|
||||
}
|
||||
}
|
||||
RolloutItem::EventMsg(_)
|
||||
| RolloutItem::Compacted(_)
|
||||
| RolloutItem::TurnContext(_)
|
||||
| RolloutItem::SessionMeta(_) => {}
|
||||
}
|
||||
|
||||
if epiphany_state.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(active_segment) = active_segment.take() {
|
||||
finalize_active_segment(
|
||||
active_segment,
|
||||
&mut epiphany_state,
|
||||
&mut pending_rollback_turns,
|
||||
);
|
||||
}
|
||||
|
||||
epiphany_state
|
||||
}
|
||||
|
||||
pub fn latest_epiphany_state_from_codex_rollout_items(
|
||||
rollout_items: &[RolloutItem],
|
||||
) -> Option<EpiphanyThreadState> {
|
||||
latest_epiphany_state_from_rollout_items(rollout_items, context_manager::is_user_turn_boundary)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::latest_epiphany_state_from_rollout_items;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::CompactedItem;
|
||||
use codex_protocol::protocol::EpiphanyStateItem;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
use codex_protocol::protocol::ThreadRolledBackEvent;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
|
||||
fn simple_is_user_turn_boundary(item: &ResponseItem) -> bool {
|
||||
matches!(
|
||||
item,
|
||||
ResponseItem::Message { role, .. } if role == "user"
|
||||
)
|
||||
}
|
||||
|
||||
fn user_response_message(text: &str) -> ResponseItem {
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: text.to_string(),
|
||||
}],
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn sample_epiphany_state(turn_id: &str) -> EpiphanyThreadState {
|
||||
EpiphanyThreadState {
|
||||
revision: 1,
|
||||
objective: Some(format!("Objective for {turn_id}")),
|
||||
active_subgoal_id: Some(format!("subgoal-{turn_id}")),
|
||||
last_updated_turn_id: Some(turn_id.to_string()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latest_epiphany_state_from_rollout_items_returns_latest_surviving_snapshot() {
|
||||
let first = sample_epiphany_state("turn-1");
|
||||
let second = sample_epiphany_state("turn-2");
|
||||
let rollout_items = vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-1".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: "first".to_string(),
|
||||
images: None,
|
||||
text_elements: Vec::new(),
|
||||
local_images: Vec::new(),
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-1".to_string()),
|
||||
state: first,
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: "turn-1".to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-2".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
RolloutItem::ResponseItem(user_response_message("second")),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-2".to_string()),
|
||||
state: second.clone(),
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: "turn-2".to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
latest_epiphany_state_from_rollout_items(&rollout_items, simple_is_user_turn_boundary),
|
||||
Some(second)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latest_epiphany_state_from_rollout_items_skips_rolled_back_turns() {
|
||||
let first = sample_epiphany_state("turn-1");
|
||||
let second = sample_epiphany_state("turn-2");
|
||||
let rollout_items = vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-1".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: "first".to_string(),
|
||||
images: None,
|
||||
text_elements: Vec::new(),
|
||||
local_images: Vec::new(),
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-1".to_string()),
|
||||
state: first.clone(),
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: "turn-1".to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-2".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: "second".to_string(),
|
||||
images: None,
|
||||
text_elements: Vec::new(),
|
||||
local_images: Vec::new(),
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-2".to_string()),
|
||||
state: second,
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: "turn-2".to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::ThreadRolledBack(ThreadRolledBackEvent {
|
||||
num_turns: 1,
|
||||
})),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
latest_epiphany_state_from_rollout_items(&rollout_items, simple_is_user_turn_boundary),
|
||||
Some(first)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latest_epiphany_state_from_rollout_items_survives_compaction() {
|
||||
let state = sample_epiphany_state("turn-before-compaction");
|
||||
let rollout_items = vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-before-compaction".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: "before compaction".to_string(),
|
||||
images: None,
|
||||
text_elements: Vec::new(),
|
||||
local_images: Vec::new(),
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-before-compaction".to_string()),
|
||||
state: state.clone(),
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: "turn-before-compaction".to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
RolloutItem::Compacted(CompactedItem {
|
||||
message: "compact".to_string(),
|
||||
replacement_history: None,
|
||||
}),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
latest_epiphany_state_from_rollout_items(&rollout_items, simple_is_user_turn_boundary),
|
||||
Some(state)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latest_epiphany_state_from_rollout_items_accepts_out_of_band_snapshot() {
|
||||
let state = sample_epiphany_state("control-plane-update");
|
||||
let rollout_items = vec![RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: None,
|
||||
state: state.clone(),
|
||||
})];
|
||||
|
||||
assert_eq!(
|
||||
latest_epiphany_state_from_rollout_items(&rollout_items, simple_is_user_turn_boundary),
|
||||
Some(state)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latest_epiphany_state_from_rollout_items_accepts_out_of_band_snapshot_after_turn() {
|
||||
let turn_state = sample_epiphany_state("turn-before-control-plane-update");
|
||||
let control_plane_state = sample_epiphany_state("control-plane-update");
|
||||
let rollout_items = vec![
|
||||
RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-before-control-plane-update".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: "before control-plane update".to_string(),
|
||||
images: None,
|
||||
text_elements: Vec::new(),
|
||||
local_images: Vec::new(),
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-before-control-plane-update".to_string()),
|
||||
state: turn_state,
|
||||
}),
|
||||
RolloutItem::EventMsg(EventMsg::TurnComplete(TurnCompleteEvent {
|
||||
turn_id: "turn-before-control-plane-update".to_string(),
|
||||
last_agent_message: None,
|
||||
completed_at: None,
|
||||
duration_ms: None,
|
||||
time_to_first_token_ms: None,
|
||||
})),
|
||||
RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: None,
|
||||
state: control_plane_state.clone(),
|
||||
}),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
latest_epiphany_state_from_rollout_items(&rollout_items, simple_is_user_turn_boundary),
|
||||
Some(control_plane_state)
|
||||
);
|
||||
}
|
||||
}
|
||||
2
vendor/codex/codex-rs/core/src/lib.rs
vendored
2
vendor/codex/codex-rs/core/src/lib.rs
vendored
|
|
@ -19,8 +19,6 @@ mod compact_remote;
|
|||
pub use codex_thread::CodexThread;
|
||||
pub use codex_thread::CodexThreadTurnContextOverrides;
|
||||
pub use codex_thread::ThreadConfigSnapshot;
|
||||
mod epiphany_rollout;
|
||||
pub use epiphany_rollout::latest_epiphany_state_from_codex_rollout_items as latest_epiphany_state_from_rollout_items;
|
||||
mod agent;
|
||||
|
||||
mod codex_delegate;
|
||||
|
|
|
|||
|
|
@ -152,11 +152,13 @@ fn codex_session_has_no_epiphany_state_custody() {
|
|||
let session_state = include_str!("../state/session.rs");
|
||||
let session = include_str!("mod.rs");
|
||||
let codex_thread = include_str!("../codex_thread.rs");
|
||||
let core_lib = include_str!("../lib.rs");
|
||||
|
||||
assert!(!session_state.contains("epiphany_state"));
|
||||
assert!(!session.contains("set_epiphany_state"));
|
||||
assert!(!session.contains("async fn epiphany_state"));
|
||||
assert!(!codex_thread.contains("async fn epiphany_state"));
|
||||
assert!(!core_lib.contains("epiphany_rollout"));
|
||||
}
|
||||
|
||||
fn sample_epiphany_state_for_prompt() -> EpiphanyThreadState {
|
||||
|
|
|
|||
Reference in a new issue