Land Phase 3 Epiphany thread state exposure
This commit is contained in:
parent
640e063350
commit
80bc702675
20 changed files with 681 additions and 200 deletions
|
|
@ -137,6 +137,7 @@ fn sample_thread_with_source(
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1461,6 +1461,7 @@ mod tests {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
},
|
||||
model: "gpt-5".to_string(),
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ use codex_protocol::protocol::AgentStatus as CoreAgentStatus;
|
|||
use codex_protocol::protocol::AskForApproval as CoreAskForApproval;
|
||||
use codex_protocol::protocol::CodexErrorInfo as CoreCodexErrorInfo;
|
||||
use codex_protocol::protocol::CreditsSnapshot as CoreCreditsSnapshot;
|
||||
use codex_protocol::protocol::EpiphanyThreadState as CoreEpiphanyThreadState;
|
||||
use codex_protocol::protocol::ExecCommandSource as CoreExecCommandSource;
|
||||
use codex_protocol::protocol::ExecCommandStatus as CoreExecCommandStatus;
|
||||
use codex_protocol::protocol::GranularApprovalConfig as CoreGranularApprovalConfig;
|
||||
|
|
@ -4431,6 +4432,11 @@ pub struct Thread {
|
|||
pub git_info: Option<GitInfo>,
|
||||
/// Optional user-facing thread title.
|
||||
pub name: Option<String>,
|
||||
/// Only populated on `thread/start`, `thread/resume`, `thread/fork`, `thread/read`,
|
||||
/// and notifications/responses that reuse those hydrated thread payloads.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(optional)]
|
||||
pub epiphany_state: Option<CoreEpiphanyThreadState>,
|
||||
/// Only populated on `thread/resume`, `thread/rollback`, `thread/fork`, and `thread/read`
|
||||
/// (when `includeTurns` is true) responses.
|
||||
/// For all other responses and notifications returning a Thread,
|
||||
|
|
|
|||
4
vendor/codex/codex-rs/app-server/README.md
vendored
4
vendor/codex/codex-rs/app-server/README.md
vendored
|
|
@ -136,6 +136,8 @@ Example with notification opt-out:
|
|||
|
||||
## API Overview
|
||||
|
||||
Hydrated thread responses such as `thread/start`, `thread/resume`, `thread/fork`, `thread/read`, and `thread/unarchive` may include `thread.epiphanyState` when the thread has persisted Epiphany state. When the thread is currently loaded, app-server prefers the live in-memory value; otherwise it reconstructs the latest surviving snapshot from rollout items using the same rollback/compaction semantics as core session replay.
|
||||
|
||||
- `thread/start` — create a new thread; emits `thread/started` (including the current `thread.status`) and auto-subscribes you to turn/item events for that thread. When the request includes a `cwd` and the resolved sandbox is `workspace-write` or full access, app-server also marks that project as trusted in the user `config.toml`. Pass `sessionStartSource: "clear"` when starting a replacement thread after clearing the current session so `SessionStart` hooks receive `source: "clear"` instead of the default `"startup"`. For permissions, prefer `permissionProfile`; the legacy `sandbox` shorthand is still accepted but cannot be combined with `permissionProfile`.
|
||||
- `thread/resume` — reopen an existing thread by id so subsequent `turn/start` calls append to it. Accepts the same permission override rules as `thread/start`.
|
||||
- `thread/fork` — fork an existing thread into a new thread id by copying the stored history; if the source thread is currently mid-turn, the fork records the same interruption marker as `turn/interrupt` instead of inheriting an unmarked partial turn suffix. The returned `thread.forkedFromId` points at the source thread when known. Accepts `ephemeral: true` for an in-memory temporary fork, emits `thread/started` (including the current `thread.status`), and auto-subscribes you to turn/item events for the new thread. Accepts the same permission override rules as `thread/start`.
|
||||
|
|
@ -377,6 +379,8 @@ Later, after the idle unload timeout:
|
|||
|
||||
Use `thread/read` to fetch a stored thread by id without resuming it. Pass `includeTurns` when you want the full rollout history loaded into `thread.turns`. The returned thread includes `agentNickname` and `agentRole` for AgentControl-spawned thread sub-agents when available.
|
||||
|
||||
When present, `thread.epiphanyState` is the latest surviving persisted `EpiphanyThreadState` snapshot for that thread.
|
||||
|
||||
```json
|
||||
{ "method": "thread/read", "id": 22, "params": { "threadId": "thr_123" } }
|
||||
{ "id": 22, "result": {
|
||||
|
|
|
|||
|
|
@ -244,6 +244,7 @@ use codex_core::find_archived_thread_path_by_id_str;
|
|||
use codex_core::find_thread_name_by_id;
|
||||
use codex_core::find_thread_names_by_ids;
|
||||
use codex_core::find_thread_path_by_id_str;
|
||||
use codex_core::latest_epiphany_state_from_rollout_items;
|
||||
use codex_core::path_utils;
|
||||
use codex_core::plugins::MarketplaceAddError;
|
||||
use codex_core::plugins::MarketplaceRemoveError;
|
||||
|
|
@ -315,6 +316,7 @@ use codex_protocol::protocol::ConversationAudioParams;
|
|||
use codex_protocol::protocol::ConversationStartParams;
|
||||
use codex_protocol::protocol::ConversationStartTransport;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::GitInfo as CoreGitInfo;
|
||||
use codex_protocol::protocol::InitialHistory;
|
||||
|
|
@ -2638,12 +2640,12 @@ impl CodexMessageProcessor {
|
|||
Ok(new_conv) => {
|
||||
let NewThread {
|
||||
thread_id,
|
||||
thread,
|
||||
thread: codex_thread,
|
||||
session_configured,
|
||||
..
|
||||
} = new_conv;
|
||||
if let Err(error) = Self::set_app_server_client_info(
|
||||
thread.as_ref(),
|
||||
codex_thread.as_ref(),
|
||||
app_server_client_name,
|
||||
app_server_client_version,
|
||||
)
|
||||
|
|
@ -2655,7 +2657,7 @@ impl CodexMessageProcessor {
|
|||
.await;
|
||||
return;
|
||||
}
|
||||
let config_snapshot = thread
|
||||
let config_snapshot = codex_thread
|
||||
.config_snapshot()
|
||||
.instrument(tracing::info_span!(
|
||||
"app_server.thread_start.config_snapshot",
|
||||
|
|
@ -2667,6 +2669,13 @@ impl CodexMessageProcessor {
|
|||
&config_snapshot,
|
||||
session_configured.rollout_path.clone(),
|
||||
);
|
||||
thread.epiphany_state = codex_thread
|
||||
.epiphany_state()
|
||||
.instrument(tracing::info_span!(
|
||||
"app_server.thread_start.epiphany_state",
|
||||
otel.name = "app_server.thread_start.epiphany_state",
|
||||
))
|
||||
.await;
|
||||
|
||||
// Auto-attach a thread listener when starting a thread.
|
||||
Self::log_listener_attach_result(
|
||||
|
|
@ -3542,6 +3551,17 @@ impl CodexMessageProcessor {
|
|||
/*has_in_progress_turn*/ false,
|
||||
);
|
||||
self.attach_thread_name(thread_id, &mut thread).await;
|
||||
if let Some(rollout_path) = thread.path.as_deref() {
|
||||
match load_epiphany_state_from_rollout_path(rollout_path).await {
|
||||
Ok(epiphany_state) => {
|
||||
thread.epiphany_state = epiphany_state;
|
||||
}
|
||||
Err(message) => {
|
||||
self.send_internal_error(request_id, message).await;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let thread_id = thread.id.clone();
|
||||
let response = ThreadUnarchiveResponse { thread };
|
||||
self.outgoing.send_response(request_id, response).await;
|
||||
|
|
@ -3993,6 +4013,9 @@ impl CodexMessageProcessor {
|
|||
)));
|
||||
};
|
||||
|
||||
self.apply_thread_read_epiphany_state(&mut thread, loaded_thread.as_ref())
|
||||
.await?;
|
||||
|
||||
let has_live_in_progress_turn = if let Some(loaded_thread) = loaded_thread.as_ref() {
|
||||
matches!(loaded_thread.agent_status().await, AgentStatus::Running)
|
||||
} else {
|
||||
|
|
@ -4084,6 +4107,27 @@ impl CodexMessageProcessor {
|
|||
Ok(Some(thread))
|
||||
}
|
||||
|
||||
async fn apply_thread_read_epiphany_state(
|
||||
&self,
|
||||
thread: &mut Thread,
|
||||
loaded_thread: Option<&Arc<CodexThread>>,
|
||||
) -> Result<(), ThreadReadViewError> {
|
||||
if let Some(loaded_thread) = loaded_thread {
|
||||
thread.epiphany_state = loaded_thread.epiphany_state().await;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let Some(rollout_path) = thread.path.as_deref() else {
|
||||
thread.epiphany_state = None;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
thread.epiphany_state = load_epiphany_state_from_rollout_path(rollout_path)
|
||||
.await
|
||||
.map_err(ThreadReadViewError::Internal)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn apply_thread_read_rollout_fields(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
|
|
@ -4852,7 +4896,7 @@ impl CodexMessageProcessor {
|
|||
async fn load_thread_from_resume_source_or_send_internal(
|
||||
&self,
|
||||
thread_id: ThreadId,
|
||||
thread: &CodexThread,
|
||||
live_thread: &CodexThread,
|
||||
thread_history: &InitialHistory,
|
||||
rollout_path: &Path,
|
||||
fallback_provider: &str,
|
||||
|
|
@ -4870,7 +4914,7 @@ impl CodexMessageProcessor {
|
|||
.await
|
||||
}
|
||||
InitialHistory::Forked(items) => {
|
||||
let config_snapshot = thread.config_snapshot().await;
|
||||
let config_snapshot = live_thread.config_snapshot().await;
|
||||
let mut thread = build_thread_from_snapshot(
|
||||
thread_id,
|
||||
&config_snapshot,
|
||||
|
|
@ -4894,6 +4938,7 @@ impl CodexMessageProcessor {
|
|||
)
|
||||
.await?;
|
||||
self.attach_thread_name(thread_id, &mut thread).await;
|
||||
thread.epiphany_state = live_thread.epiphany_state().await;
|
||||
Ok(thread)
|
||||
}
|
||||
|
||||
|
|
@ -5165,6 +5210,8 @@ impl CodexMessageProcessor {
|
|||
return;
|
||||
}
|
||||
|
||||
thread.epiphany_state = forked_thread.epiphany_state().await;
|
||||
|
||||
self.thread_watch_manager
|
||||
.upsert_thread_silently(thread.clone())
|
||||
.await;
|
||||
|
|
@ -7508,6 +7555,7 @@ impl CodexMessageProcessor {
|
|||
match read_summary_from_rollout(rollout_path.as_path(), fallback_provider).await {
|
||||
Ok(summary) => {
|
||||
let mut thread = summary_to_thread(summary, &self.config.cwd);
|
||||
thread.epiphany_state = review_thread.epiphany_state().await;
|
||||
self.thread_watch_manager
|
||||
.upsert_thread_silently(thread.clone())
|
||||
.await;
|
||||
|
|
@ -9359,6 +9407,7 @@ fn thread_from_stored_thread(
|
|||
source: source.into(),
|
||||
git_info,
|
||||
name: thread.name,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
};
|
||||
(thread, history)
|
||||
|
|
@ -9842,6 +9891,7 @@ fn build_thread_from_snapshot(
|
|||
source: config_snapshot.session_source.clone().into(),
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -9897,10 +9947,25 @@ pub(crate) fn summary_to_thread(
|
|||
source: source.into(),
|
||||
git_info,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_epiphany_state_from_rollout_path(
|
||||
rollout_path: &Path,
|
||||
) -> std::result::Result<Option<EpiphanyThreadState>, String> {
|
||||
let items = read_rollout_items_from_rollout(rollout_path)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
format!(
|
||||
"failed to load rollout `{}` for Epiphany state: {err}",
|
||||
rollout_path.display()
|
||||
)
|
||||
})?;
|
||||
Ok(latest_epiphany_state_from_rollout_items(&items))
|
||||
}
|
||||
|
||||
fn thread_backwards_cursor_for_sort_key(
|
||||
summary: &ConversationSummary,
|
||||
sort_key: StoreThreadSortKey,
|
||||
|
|
@ -10915,6 +10980,96 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn load_epiphany_state_from_rollout_path_reads_latest_snapshot() -> Result<()> {
|
||||
use codex_protocol::protocol::EpiphanyStateItem;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::EventMsg;
|
||||
use codex_protocol::protocol::RolloutItem;
|
||||
use codex_protocol::protocol::RolloutLine;
|
||||
use codex_protocol::protocol::SessionMetaLine;
|
||||
use codex_protocol::protocol::TurnCompleteEvent;
|
||||
use codex_protocol::protocol::TurnStartedEvent;
|
||||
use codex_protocol::protocol::UserMessageEvent;
|
||||
use std::fs;
|
||||
|
||||
let temp_dir = TempDir::new()?;
|
||||
let path = temp_dir.path().join("rollout.jsonl");
|
||||
|
||||
let conversation_id = ThreadId::from_string("bfd12a78-5900-467b-9bc5-d3d35df08191")?;
|
||||
let timestamp = "2025-09-05T16:53:11.850Z".to_string();
|
||||
let epiphany_state = EpiphanyThreadState {
|
||||
revision: 7,
|
||||
objective: Some("Expose thread state to clients".to_string()),
|
||||
active_subgoal_id: Some("phase-3".to_string()),
|
||||
last_updated_turn_id: Some("turn-2".to_string()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let rollout_lines = vec![
|
||||
RolloutLine {
|
||||
timestamp: timestamp.clone(),
|
||||
item: RolloutItem::SessionMeta(SessionMetaLine {
|
||||
meta: SessionMeta {
|
||||
id: conversation_id,
|
||||
timestamp: timestamp.clone(),
|
||||
model_provider: Some("test-provider".to_string()),
|
||||
..SessionMeta::default()
|
||||
},
|
||||
git: None,
|
||||
}),
|
||||
},
|
||||
RolloutLine {
|
||||
timestamp: timestamp.clone(),
|
||||
item: RolloutItem::EventMsg(EventMsg::TurnStarted(TurnStartedEvent {
|
||||
turn_id: "turn-2".to_string(),
|
||||
started_at: None,
|
||||
model_context_window: None,
|
||||
collaboration_mode_kind: Default::default(),
|
||||
})),
|
||||
},
|
||||
RolloutLine {
|
||||
timestamp: timestamp.clone(),
|
||||
item: RolloutItem::EventMsg(EventMsg::UserMessage(UserMessageEvent {
|
||||
message: "load the scene".to_string(),
|
||||
images: None,
|
||||
text_elements: Vec::new(),
|
||||
local_images: Vec::new(),
|
||||
})),
|
||||
},
|
||||
RolloutLine {
|
||||
timestamp: timestamp.clone(),
|
||||
item: RolloutItem::EpiphanyState(EpiphanyStateItem {
|
||||
turn_id: Some("turn-2".to_string()),
|
||||
state: epiphany_state.clone(),
|
||||
}),
|
||||
},
|
||||
RolloutLine {
|
||||
timestamp,
|
||||
item: 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,
|
||||
})),
|
||||
},
|
||||
];
|
||||
|
||||
let encoded = rollout_lines
|
||||
.iter()
|
||||
.map(serde_json::to_string)
|
||||
.collect::<std::result::Result<Vec<_>, _>>()?
|
||||
.join("\n");
|
||||
fs::write(&path, format!("{encoded}\n"))?;
|
||||
|
||||
let loaded = load_epiphany_state_from_rollout_path(path.as_path())
|
||||
.await
|
||||
.map_err(anyhow::Error::msg)?;
|
||||
assert_eq!(loaded, Some(epiphany_state));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn aborting_pending_request_clears_pending_state() -> Result<()> {
|
||||
let thread_id = ThreadId::from_string("bfd12a78-5900-467b-9bc5-d3d35df08191")?;
|
||||
|
|
|
|||
|
|
@ -902,6 +902,7 @@ mod tests {
|
|||
source,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use codex_protocol::models::ResponseInputItem;
|
|||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::EpiphanyThreadState;
|
||||
use codex_protocol::protocol::Event;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::SandboxPolicy;
|
||||
|
|
@ -315,6 +316,10 @@ impl CodexThread {
|
|||
self.codex.thread_config_snapshot().await
|
||||
}
|
||||
|
||||
pub async fn epiphany_state(&self) -> Option<EpiphanyThreadState> {
|
||||
self.codex.session.epiphany_state().await
|
||||
}
|
||||
|
||||
pub async fn read_mcp_resource(
|
||||
&self,
|
||||
server: &str,
|
||||
|
|
|
|||
318
vendor/codex/codex-rs/core/src/epiphany_rollout.rs
vendored
Normal file
318
vendor/codex/codex-rs/core/src/epiphany_rollout.rs
vendored
Normal file
|
|
@ -0,0 +1,318 @@
|
|||
use crate::context_manager::is_user_turn_boundary;
|
||||
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 {
|
||||
if active_segment.counts_as_user_turn {
|
||||
*pending_rollback_turns -= 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if epiphany_state.is_none() && active_segment.counts_as_user_turn {
|
||||
*epiphany_state = active_segment.epiphany_state;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn latest_epiphany_state_from_rollout_items(
|
||||
rollout_items: &[RolloutItem],
|
||||
) -> Option<EpiphanyThreadState> {
|
||||
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() {
|
||||
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
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codex_protocol::models::ContentItem;
|
||||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::protocol::CompactedItem;
|
||||
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 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),
|
||||
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),
|
||||
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),
|
||||
Some(state)
|
||||
);
|
||||
}
|
||||
}
|
||||
2
vendor/codex/codex-rs/core/src/lib.rs
vendored
2
vendor/codex/codex-rs/core/src/lib.rs
vendored
|
|
@ -17,9 +17,11 @@ pub(crate) mod session;
|
|||
pub use session::SteerInputError;
|
||||
mod codex_thread;
|
||||
mod compact_remote;
|
||||
mod epiphany_rollout;
|
||||
pub use codex_thread::CodexThread;
|
||||
pub use codex_thread::CodexThreadTurnContextOverrides;
|
||||
pub use codex_thread::ThreadConfigSnapshot;
|
||||
pub use epiphany_rollout::latest_epiphany_state_from_rollout_items;
|
||||
mod agent;
|
||||
mod codex_delegate;
|
||||
mod command_canonicalization;
|
||||
|
|
|
|||
2
vendor/codex/codex-rs/exec/src/lib_tests.rs
vendored
2
vendor/codex/codex-rs/exec/src/lib_tests.rs
vendored
|
|
@ -259,6 +259,7 @@ fn turn_items_for_thread_returns_matching_turn_items() {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: vec![
|
||||
codex_app_server_protocol::Turn {
|
||||
id: "turn-1".to_string(),
|
||||
|
|
@ -411,6 +412,7 @@ fn session_configured_from_thread_response_uses_review_policy_from_response() {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: Some("thread".to_string()),
|
||||
epiphany_state: None,
|
||||
turns: vec![],
|
||||
},
|
||||
model: "gpt-5.4".to_string(),
|
||||
|
|
|
|||
|
|
@ -1327,6 +1327,7 @@ mod tests {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: vec![Turn {
|
||||
id: "turn-1".to_string(),
|
||||
items: vec![ThreadItem::CommandExecution {
|
||||
|
|
@ -1503,6 +1504,7 @@ mod tests {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: Some("restore".to_string()),
|
||||
epiphany_state: None,
|
||||
turns: vec![
|
||||
Turn {
|
||||
id: "turn-complete".to_string(),
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ mod tests {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
vendor/codex/codex-rs/tui/src/app/tests.rs
vendored
4
vendor/codex/codex-rs/tui/src/app/tests.rs
vendored
|
|
@ -2728,6 +2728,7 @@ async fn inactive_thread_started_notification_initializes_replay_session() -> Re
|
|||
agent_role: Some("explorer".to_string()),
|
||||
git_info: None,
|
||||
name: Some("agent thread".to_string()),
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
},
|
||||
}),
|
||||
|
|
@ -2813,6 +2814,7 @@ async fn inactive_thread_started_notification_preserves_primary_model_when_path_
|
|||
agent_role: Some("explorer".to_string()),
|
||||
git_info: None,
|
||||
name: Some("agent thread".to_string()),
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
},
|
||||
}),
|
||||
|
|
@ -2871,6 +2873,7 @@ async fn thread_read_session_state_does_not_reuse_primary_permission_profile() {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: Some("read thread".to_string()),
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
};
|
||||
|
||||
|
|
@ -4633,6 +4636,7 @@ async fn thread_rollback_response_discards_queued_active_thread_events() {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1576,6 +1576,7 @@ mod tests {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: None,
|
||||
epiphany_state: None,
|
||||
turns: vec![Turn {
|
||||
id: "turn-1".to_string(),
|
||||
items: vec![
|
||||
|
|
|
|||
|
|
@ -2048,6 +2048,7 @@ mod tests {
|
|||
agent_role: None,
|
||||
git_info: None,
|
||||
name: Some(String::from("Named thread")),
|
||||
epiphany_state: None,
|
||||
turns: Vec::new(),
|
||||
};
|
||||
|
||||
|
|
|
|||
Reference in a new issue