mirror of
https://github.com/openai/codex.git
synced 2026-05-02 04:11:39 +03:00
Materialize rollout state on-demand for v2 thread APIs
### Change summary Defer rollout file creation until needed. * Add a core API to force rollout persistence for loaded non-ephemeral threads: * seeds initial context if needed * flushes rollout and returns persisted path Add concurrency guard to make lazy rollout initialization idempotent under concurrent calls. Add centralized app-server rollout-path resolver that: * uses in-memory thread state when loaded * forces persistence on demand for rollout-dependent calls * falls back to on-disk lookup for unloaded threads * maps ephemeral threads to invalid-request errors for rollout-dependent operations Route rollout-dependent endpoints through the resolver (v2 + shared legacy surfaces), including: * thread/archive * thread/resume (thread-id path) * thread/fork (thread-id path) * resumeConversation * forkConversation * thread summary by thread id * detached review parent-thread path resolution * feedback include_logs rollout resolution Remove stale cached rollout-path assumptions in rollback/detached-review flows by resolving via thread id when needed. No wire-schema changes; behavior-only change. v1 compatibility is not expanded in this PR. ### Tests updated/added * thread_start: assert rollout is absent immediately after thread/start; created after first completed turn. * thread_resume: resume by thread id succeeds for just-started thread via on-demand persistence; path-vs-thread-id precedence test updated. * thread_fork: fork by thread id succeeds for just-started thread. * thread_archive: archive succeeds for just-started thread and materializes before archive. * thread_unarchive: adjusted for deferred creation timing. * thread_rollback: rollback path no longer depends on stale cached rollout path. * Detached review targeted test verified for lazy path behavior. * Core tests for new persistence API
This commit is contained in:
@@ -9,7 +9,10 @@ use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::ThreadStartParams;
|
||||
use codex_app_server_protocol::ThreadStartResponse;
|
||||
use codex_app_server_protocol::ThreadStartedNotification;
|
||||
use codex_app_server_protocol::TurnStartParams;
|
||||
use codex_app_server_protocol::UserInput;
|
||||
use codex_core::config::set_project_trust_level;
|
||||
use codex_core::find_thread_path_by_id_str;
|
||||
use codex_protocol::config_types::TrustLevel;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use std::path::Path;
|
||||
@@ -59,6 +62,11 @@ async fn thread_start_creates_thread_and_emits_started() -> Result<()> {
|
||||
thread.created_at > 0,
|
||||
"created_at should be a positive UNIX timestamp"
|
||||
);
|
||||
let rollout_path = find_thread_path_by_id_str(codex_home.path(), &thread.id).await?;
|
||||
assert!(
|
||||
rollout_path.is_none(),
|
||||
"fresh threads should not create rollout files until first turn"
|
||||
);
|
||||
|
||||
// A corresponding thread/started notification should arrive.
|
||||
let notif: JSONRPCNotification = timeout(
|
||||
@@ -70,6 +78,33 @@ async fn thread_start_creates_thread_and_emits_started() -> Result<()> {
|
||||
serde_json::from_value(notif.params.expect("params must be present"))?;
|
||||
assert_eq!(started.thread, thread);
|
||||
|
||||
// First turn should create the rollout file lazily.
|
||||
let turn_id = mcp
|
||||
.send_turn_start_request(TurnStartParams {
|
||||
thread_id: thread.id.clone(),
|
||||
input: vec![UserInput::Text {
|
||||
text: "Hello".to_string(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
..Default::default()
|
||||
})
|
||||
.await?;
|
||||
let _: JSONRPCResponse = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_response_message(RequestId::Integer(turn_id)),
|
||||
)
|
||||
.await??;
|
||||
let _: JSONRPCNotification = timeout(
|
||||
DEFAULT_READ_TIMEOUT,
|
||||
mcp.read_stream_until_notification_message("turn/completed"),
|
||||
)
|
||||
.await??;
|
||||
let rollout_path = find_thread_path_by_id_str(codex_home.path(), &thread.id).await?;
|
||||
assert!(
|
||||
rollout_path.is_some(),
|
||||
"first completed turn should create rollout file"
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user