mirror of
https://github.com/openai/codex.git
synced 2026-11-19 23:05:23 +00:00
Keep TUI prompt history tied to local settings (#42791)
## Why Prompt history is client-owned state, but app-server thread lifecycle responses derived its metadata from the active server configuration. When server and local settings differ, the TUI can advertise metadata for the wrong history log. ## What changed - Pass `LocalSettings` through thread start, resume, and fork response handling. - Build message-history metadata from the local Codex home and history preferences while continuing to use the thread configuration for server-owned session fields. ## Testing - Cover local history metadata across embedded and remote start, resume, and fork flows with deliberately different server settings. - Verify single-entry and batched history lookups return entries from the local prompt history. GitOrigin-RevId: 8b47230a4e9f2d342b8d79fd575d474c9062b05e
This commit is contained in:
1 parent
b3f5e45cc1
commit
a07158c784
11 files changed
+211
-38
No files matched your search
@@ -652,6 +652,7 @@ impl App {
|
|||||||
);
|
);
|
||||||
match app_server
|
match app_server
|
||||||
.start_thread_with_session_start_source(
|
.start_thread_with_session_start_source(
|
||||||
|
&self.local_settings,
|
||||||
&config,
|
&config,
|
||||||
/*session_start_source*/ None,
|
/*session_start_source*/ None,
|
||||||
remote_cwd.as_deref(),
|
remote_cwd.as_deref(),
|
||||||
|
|||||||
@@ -483,6 +483,7 @@ impl App {
|
|||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
app_server
|
app_server
|
||||||
.start_thread_with_session_start_source(
|
.start_thread_with_session_start_source(
|
||||||
|
&self.local_settings,
|
||||||
&config, /*session_start_source*/ None,
|
&config, /*session_start_source*/ None,
|
||||||
/*remote_cwd_override*/ None,
|
/*remote_cwd_override*/ None,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -857,6 +857,7 @@ impl App {
|
|||||||
);
|
);
|
||||||
match app_server
|
match app_server
|
||||||
.start_thread_with_session_start_source(
|
.start_thread_with_session_start_source(
|
||||||
|
&self.local_settings,
|
||||||
&config,
|
&config,
|
||||||
session_start_source,
|
session_start_source,
|
||||||
/*remote_cwd_override*/ None,
|
/*remote_cwd_override*/ None,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ async fn resolve_runtime_model_provider_base_url(provider: &ModelProviderInfo) -
|
|||||||
|
|
||||||
fn spawn_startup_thread_start(
|
fn spawn_startup_thread_start(
|
||||||
app_server: &AppServerSession,
|
app_server: &AppServerSession,
|
||||||
|
local_settings: crate::local_settings::LocalSettings,
|
||||||
config: Config,
|
config: Config,
|
||||||
app_event_tx: AppEventSender,
|
app_event_tx: AppEventSender,
|
||||||
) {
|
) {
|
||||||
@@ -32,6 +33,7 @@ fn spawn_startup_thread_start(
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let result = crate::app_server_session::start_thread_with_request_handle(
|
let result = crate::app_server_session::start_thread_with_request_handle(
|
||||||
request_handle,
|
request_handle,
|
||||||
|
&local_settings,
|
||||||
config,
|
config,
|
||||||
thread_params_mode,
|
thread_params_mode,
|
||||||
remote_cwd_override,
|
remote_cwd_override,
|
||||||
@@ -288,7 +290,12 @@ impl App {
|
|||||||
| SessionSelection::Exit
|
| SessionSelection::Exit
|
||||||
| SessionSelection::AgentsOverview => {
|
| SessionSelection::AgentsOverview => {
|
||||||
if !start_in_agents_overview {
|
if !start_in_agents_overview {
|
||||||
spawn_startup_thread_start(&app_server, config.clone(), app_event_tx.clone());
|
spawn_startup_thread_start(
|
||||||
|
&app_server,
|
||||||
|
local_settings.clone(),
|
||||||
|
config.clone(),
|
||||||
|
app_event_tx.clone(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Count a startup tooltip once the initial chat widget can render it.
|
// Count a startup tooltip once the initial chat widget can render it.
|
||||||
let startup_tooltip_override = if start_in_agents_overview {
|
let startup_tooltip_override = if start_in_agents_overview {
|
||||||
|
|||||||
@@ -702,7 +702,16 @@ async fn history_lookup_response_is_routed_to_requesting_thread() -> Result<()>
|
|||||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||||
let thread_id = ThreadId::new();
|
let thread_id = ThreadId::new();
|
||||||
|
|
||||||
app.lookup_message_history_entry(thread_id, /*offset*/ 0, /*log_id*/ 1)
|
let local_home = tempfile::tempdir()?;
|
||||||
|
app.local_settings.codex_home = AbsolutePathBuf::from_absolute_path(local_home.path())?;
|
||||||
|
let history_config = codex_message_history::HistoryConfig::new(
|
||||||
|
app.local_settings.codex_home.clone(),
|
||||||
|
&app.local_settings.history,
|
||||||
|
);
|
||||||
|
codex_message_history::append_entry("local prompt", thread_id, &history_config).await?;
|
||||||
|
let (log_id, _) = codex_message_history::history_metadata(&history_config).await;
|
||||||
|
|
||||||
|
app.lookup_message_history_entry(thread_id, /*offset*/ 0, log_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let app_event = tokio::time::timeout(Duration::from_secs(1), app_event_rx.recv())
|
let app_event = tokio::time::timeout(Duration::from_secs(1), app_event_rx.recv())
|
||||||
@@ -722,13 +731,13 @@ async fn history_lookup_response_is_routed_to_requesting_thread() -> Result<()>
|
|||||||
event,
|
event,
|
||||||
HistoryLookupResponse::Entry {
|
HistoryLookupResponse::Entry {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
log_id: 1,
|
log_id,
|
||||||
entry: None,
|
entry: Some("local prompt".to_string()),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let cursor = codex_message_history::HistoryBatchCursor::new(/*end_offset*/ 10);
|
let cursor = codex_message_history::HistoryBatchCursor::new(/*end_offset*/ 1);
|
||||||
app.lookup_message_history_batch(thread_id, cursor, /*log_id*/ 1)
|
app.lookup_message_history_batch(thread_id, cursor, log_id)
|
||||||
.await?;
|
.await?;
|
||||||
let app_event = tokio::time::timeout(Duration::from_secs(1), app_event_rx.recv())
|
let app_event = tokio::time::timeout(Duration::from_secs(1), app_event_rx.recv())
|
||||||
.await
|
.await
|
||||||
@@ -744,7 +753,15 @@ async fn history_lookup_response_is_routed_to_requesting_thread() -> Result<()>
|
|||||||
assert_eq!(routed_thread_id, thread_id);
|
assert_eq!(routed_thread_id, thread_id);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
event,
|
event,
|
||||||
HistoryLookupResponse::BatchError { cursor, log_id: 1 }
|
HistoryLookupResponse::Batch {
|
||||||
|
cursor,
|
||||||
|
log_id,
|
||||||
|
entries: vec![HistoryBatchEntryResponse {
|
||||||
|
offset: 0,
|
||||||
|
entry: Some("local prompt".to_string()),
|
||||||
|
}],
|
||||||
|
next_older_cursor: None,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ async fn lost_initial_thread_reply_keeps_startup_draft_offline() -> Result<()> {
|
|||||||
);
|
);
|
||||||
let result = crate::app_server_session::start_thread_with_request_handle(
|
let result = crate::app_server_session::start_thread_with_request_handle(
|
||||||
session.request_handle(),
|
session.request_handle(),
|
||||||
|
&app.local_settings,
|
||||||
app.config.clone(),
|
app.config.clone(),
|
||||||
ThreadParamsMode::Remote,
|
ThreadParamsMode::Remote,
|
||||||
/*remote_cwd_override*/ None,
|
/*remote_cwd_override*/ None,
|
||||||
|
|||||||
@@ -532,6 +532,7 @@ async fn external_transport_registers_dynamic_tools_and_finds_task_mentions() ->
|
|||||||
assert!(app_server.task_tools_available(started.session.thread_id));
|
assert!(app_server.task_tools_available(started.session.thread_id));
|
||||||
let startup = crate::app_server_session::start_thread_with_request_handle(
|
let startup = crate::app_server_session::start_thread_with_request_handle(
|
||||||
app_server.request_handle(),
|
app_server.request_handle(),
|
||||||
|
&app.local_settings,
|
||||||
app.config.clone(),
|
app.config.clone(),
|
||||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||||
/*remote_cwd_override*/ None,
|
/*remote_cwd_override*/ None,
|
||||||
@@ -690,6 +691,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
|
|||||||
assert!(app_server.task_tools_available(thread_id));
|
assert!(app_server.task_tools_available(thread_id));
|
||||||
let startup = crate::app_server_session::start_thread_with_request_handle(
|
let startup = crate::app_server_session::start_thread_with_request_handle(
|
||||||
app_server.request_handle(),
|
app_server.request_handle(),
|
||||||
|
&app.local_settings,
|
||||||
app.config.clone(),
|
app.config.clone(),
|
||||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||||
/*remote_cwd_override*/ None,
|
/*remote_cwd_override*/ None,
|
||||||
@@ -1050,6 +1052,7 @@ async fn older_external_server_starts_without_unsupported_dynamic_tools_or_histo
|
|||||||
assert!(!app_server.task_tools_available(started.session.thread_id));
|
assert!(!app_server.task_tools_available(started.session.thread_id));
|
||||||
let startup = crate::app_server_session::start_thread_with_request_handle(
|
let startup = crate::app_server_session::start_thread_with_request_handle(
|
||||||
app_server.request_handle(),
|
app_server.request_handle(),
|
||||||
|
&app.local_settings,
|
||||||
app.config.clone(),
|
app.config.clone(),
|
||||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||||
/*remote_cwd_override*/ None,
|
/*remote_cwd_override*/ None,
|
||||||
|
|||||||
@@ -156,7 +156,10 @@ impl App {
|
|||||||
} else {
|
} else {
|
||||||
app_server
|
app_server
|
||||||
.start_thread_with_session_start_source(
|
.start_thread_with_session_start_source(
|
||||||
&config, /*session_start_source*/ None, /*remote_cwd_override*/ None,
|
&local_settings,
|
||||||
|
&config,
|
||||||
|
/*session_start_source*/ None,
|
||||||
|
/*remote_cwd_override*/ None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -769,13 +769,17 @@ impl AppServerSession {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) async fn start_thread(&mut self, config: &Config) -> Result<AppServerStartedThread> {
|
pub(crate) async fn start_thread(&mut self, config: &Config) -> Result<AppServerStartedThread> {
|
||||||
self.start_thread_with_session_start_source(
|
self.start_thread_with_session_start_source(
|
||||||
config, /*session_start_source*/ None, /*remote_cwd_override*/ None,
|
&LocalSettings::from(config),
|
||||||
|
config,
|
||||||
|
/*session_start_source*/ None,
|
||||||
|
/*remote_cwd_override*/ None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn start_thread_with_session_start_source(
|
pub(crate) async fn start_thread_with_session_start_source(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
session_start_source: Option<ThreadStartSource>,
|
session_start_source: Option<ThreadStartSource>,
|
||||||
remote_cwd_override: Option<&std::path::Path>,
|
remote_cwd_override: Option<&std::path::Path>,
|
||||||
@@ -802,8 +806,13 @@ impl AppServerSession {
|
|||||||
if history_support == ThreadHistorySupport::LegacyOnly {
|
if history_support == ThreadHistorySupport::LegacyOnly {
|
||||||
self.history_support = ThreadHistorySupport::LegacyOnly;
|
self.history_support = ThreadHistorySupport::LegacyOnly;
|
||||||
}
|
}
|
||||||
let mut started =
|
let mut started = started_thread_from_start_response(
|
||||||
started_thread_from_start_response(response, config, self.thread_params_mode()).await?;
|
response,
|
||||||
|
local_settings,
|
||||||
|
config,
|
||||||
|
self.thread_params_mode(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
started.task_tools_available = task_tools_available;
|
started.task_tools_available = task_tools_available;
|
||||||
if task_tools_available {
|
if task_tools_available {
|
||||||
self.remember_task_tool_thread(started.session.thread_id);
|
self.remember_task_tool_thread(started.session.thread_id);
|
||||||
@@ -958,8 +967,13 @@ impl AppServerSession {
|
|||||||
"preserving the created fork after bounded history hydration failed"
|
"preserving the created fork after bounded history hydration failed"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let mut started =
|
let mut started = started_thread_from_fork_response(
|
||||||
started_thread_from_fork_response(response, &config, self.thread_params_mode()).await?;
|
response,
|
||||||
|
local_settings,
|
||||||
|
&config,
|
||||||
|
self.thread_params_mode(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
started.session.fork_parent_title = fork_parent.and_then(|thread| thread.name);
|
started.session.fork_parent_title = fork_parent.and_then(|thread| thread.name);
|
||||||
if self.task_tools_available(thread_id) {
|
if self.task_tools_available(thread_id) {
|
||||||
started.task_tools_available = true;
|
started.task_tools_available = true;
|
||||||
@@ -1621,6 +1635,7 @@ impl AppServerSession {
|
|||||||
|
|
||||||
pub(crate) async fn start_thread_with_request_handle(
|
pub(crate) async fn start_thread_with_request_handle(
|
||||||
request_handle: AppServerRequestHandle,
|
request_handle: AppServerRequestHandle,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: Config,
|
config: Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
remote_cwd_override: Option<PathBuf>,
|
remote_cwd_override: Option<PathBuf>,
|
||||||
@@ -1641,7 +1656,8 @@ pub(crate) async fn start_thread_with_request_handle(
|
|||||||
bootstrap_request_error("thread/start failed during TUI bootstrap", err)
|
bootstrap_request_error("thread/start failed during TUI bootstrap", err)
|
||||||
})?;
|
})?;
|
||||||
let mut started =
|
let mut started =
|
||||||
started_thread_from_start_response(response, &config, thread_params_mode).await?;
|
started_thread_from_start_response(response, local_settings, &config, thread_params_mode)
|
||||||
|
.await?;
|
||||||
started.task_tools_available = task_tools_available;
|
started.task_tools_available = task_tools_available;
|
||||||
Ok(started)
|
Ok(started)
|
||||||
}
|
}
|
||||||
@@ -2069,14 +2085,19 @@ fn thread_cwd_from_config(
|
|||||||
|
|
||||||
async fn started_thread_from_start_response(
|
async fn started_thread_from_start_response(
|
||||||
response: ThreadStartResponse,
|
response: ThreadStartResponse,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
) -> Result<AppServerStartedThread> {
|
) -> Result<AppServerStartedThread> {
|
||||||
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
|
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
|
||||||
let session =
|
let session = thread_session_state_from_thread_start_response(
|
||||||
thread_session_state_from_thread_start_response(&response, config, thread_params_mode)
|
&response,
|
||||||
.await
|
local_settings,
|
||||||
.map_err(color_eyre::eyre::Report::msg)?;
|
config,
|
||||||
|
thread_params_mode,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(color_eyre::eyre::Report::msg)?;
|
||||||
Ok(AppServerStartedThread {
|
Ok(AppServerStartedThread {
|
||||||
session,
|
session,
|
||||||
turns: response.thread.turns,
|
turns: response.thread.turns,
|
||||||
@@ -2087,14 +2108,19 @@ async fn started_thread_from_start_response(
|
|||||||
|
|
||||||
async fn started_thread_from_resume_response(
|
async fn started_thread_from_resume_response(
|
||||||
response: ThreadResumeResponse,
|
response: ThreadResumeResponse,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
) -> Result<AppServerStartedThread> {
|
) -> Result<AppServerStartedThread> {
|
||||||
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
|
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
|
||||||
let session =
|
let session = thread_session_state_from_thread_resume_response(
|
||||||
thread_session_state_from_thread_resume_response(&response, config, thread_params_mode)
|
&response,
|
||||||
.await
|
local_settings,
|
||||||
.map_err(color_eyre::eyre::Report::msg)?;
|
config,
|
||||||
|
thread_params_mode,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(color_eyre::eyre::Report::msg)?;
|
||||||
Ok(AppServerStartedThread {
|
Ok(AppServerStartedThread {
|
||||||
session,
|
session,
|
||||||
turns: response.thread.turns,
|
turns: response.thread.turns,
|
||||||
@@ -2105,14 +2131,19 @@ async fn started_thread_from_resume_response(
|
|||||||
|
|
||||||
async fn started_thread_from_fork_response(
|
async fn started_thread_from_fork_response(
|
||||||
response: ThreadForkResponse,
|
response: ThreadForkResponse,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
) -> Result<AppServerStartedThread> {
|
) -> Result<AppServerStartedThread> {
|
||||||
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
|
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
|
||||||
let session =
|
let session = thread_session_state_from_thread_fork_response(
|
||||||
thread_session_state_from_thread_fork_response(&response, config, thread_params_mode)
|
&response,
|
||||||
.await
|
local_settings,
|
||||||
.map_err(color_eyre::eyre::Report::msg)?;
|
config,
|
||||||
|
thread_params_mode,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(color_eyre::eyre::Report::msg)?;
|
||||||
Ok(AppServerStartedThread {
|
Ok(AppServerStartedThread {
|
||||||
session,
|
session,
|
||||||
turns: response.thread.turns,
|
turns: response.thread.turns,
|
||||||
@@ -2123,6 +2154,7 @@ async fn started_thread_from_fork_response(
|
|||||||
|
|
||||||
async fn thread_session_state_from_thread_start_response(
|
async fn thread_session_state_from_thread_start_response(
|
||||||
response: &ThreadStartResponse,
|
response: &ThreadStartResponse,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
) -> Result<ThreadSessionState, String> {
|
) -> Result<ThreadSessionState, String> {
|
||||||
@@ -2148,13 +2180,15 @@ async fn thread_session_state_from_thread_start_response(
|
|||||||
response.runtime_workspace_roots.clone(),
|
response.runtime_workspace_roots.clone(),
|
||||||
response.instruction_source_path_uris(),
|
response.instruction_source_path_uris(),
|
||||||
response.reasoning_effort.clone(),
|
response.reasoning_effort.clone(),
|
||||||
config,
|
config.personality,
|
||||||
|
local_settings,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn thread_session_state_from_thread_resume_response(
|
async fn thread_session_state_from_thread_resume_response(
|
||||||
response: &ThreadResumeResponse,
|
response: &ThreadResumeResponse,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
) -> Result<ThreadSessionState, String> {
|
) -> Result<ThreadSessionState, String> {
|
||||||
@@ -2189,13 +2223,15 @@ async fn thread_session_state_from_thread_resume_response(
|
|||||||
response.runtime_workspace_roots.clone(),
|
response.runtime_workspace_roots.clone(),
|
||||||
response.instruction_source_path_uris(),
|
response.instruction_source_path_uris(),
|
||||||
response.reasoning_effort.clone(),
|
response.reasoning_effort.clone(),
|
||||||
config,
|
config.personality,
|
||||||
|
local_settings,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn thread_session_state_from_thread_fork_response(
|
async fn thread_session_state_from_thread_fork_response(
|
||||||
response: &ThreadForkResponse,
|
response: &ThreadForkResponse,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
thread_params_mode: ThreadParamsMode,
|
thread_params_mode: ThreadParamsMode,
|
||||||
) -> Result<ThreadSessionState, String> {
|
) -> Result<ThreadSessionState, String> {
|
||||||
@@ -2221,7 +2257,8 @@ async fn thread_session_state_from_thread_fork_response(
|
|||||||
response.runtime_workspace_roots.clone(),
|
response.runtime_workspace_roots.clone(),
|
||||||
response.instruction_source_path_uris(),
|
response.instruction_source_path_uris(),
|
||||||
response.reasoning_effort.clone(),
|
response.reasoning_effort.clone(),
|
||||||
config,
|
config.personality,
|
||||||
|
local_settings,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
@@ -2271,7 +2308,8 @@ async fn thread_session_state_from_thread_response(
|
|||||||
runtime_workspace_roots: Vec<AbsolutePathBuf>,
|
runtime_workspace_roots: Vec<AbsolutePathBuf>,
|
||||||
instruction_source_paths: Vec<PathUri>,
|
instruction_source_paths: Vec<PathUri>,
|
||||||
reasoning_effort: Option<codex_protocol::openai_models::ReasoningEffort>,
|
reasoning_effort: Option<codex_protocol::openai_models::ReasoningEffort>,
|
||||||
config: &Config,
|
personality: Option<codex_protocol::config_types::Personality>,
|
||||||
|
local_settings: &LocalSettings,
|
||||||
) -> Result<ThreadSessionState, String> {
|
) -> Result<ThreadSessionState, String> {
|
||||||
let thread_id = ThreadId::from_string(thread_id)
|
let thread_id = ThreadId::from_string(thread_id)
|
||||||
.map_err(|err| format!("thread id `{thread_id}` is invalid: {err}"))?;
|
.map_err(|err| format!("thread id `{thread_id}` is invalid: {err}"))?;
|
||||||
@@ -2280,9 +2318,8 @@ async fn thread_session_state_from_thread_response(
|
|||||||
.map(ThreadId::from_string)
|
.map(ThreadId::from_string)
|
||||||
.transpose()
|
.transpose()
|
||||||
.map_err(|err| format!("forked_from_id is invalid: {err}"))?;
|
.map_err(|err| format!("forked_from_id is invalid: {err}"))?;
|
||||||
let local_settings = LocalSettings::from(config);
|
|
||||||
let history_config = codex_message_history::HistoryConfig::new(
|
let history_config = codex_message_history::HistoryConfig::new(
|
||||||
local_settings.codex_home,
|
local_settings.codex_home.clone(),
|
||||||
&local_settings.history,
|
&local_settings.history,
|
||||||
);
|
);
|
||||||
let (log_id, entry_count) = codex_message_history::history_metadata(&history_config).await;
|
let (log_id, entry_count) = codex_message_history::history_metadata(&history_config).await;
|
||||||
@@ -2303,7 +2340,7 @@ async fn thread_session_state_from_thread_response(
|
|||||||
instruction_source_paths,
|
instruction_source_paths,
|
||||||
reasoning_effort,
|
reasoning_effort,
|
||||||
collaboration_mode: None,
|
collaboration_mode: None,
|
||||||
personality: config.personality,
|
personality,
|
||||||
message_history: Some(MessageHistoryMetadata {
|
message_history: Some(MessageHistoryMetadata {
|
||||||
log_id,
|
log_id,
|
||||||
entry_count,
|
entry_count,
|
||||||
@@ -2333,6 +2370,10 @@ pub(crate) fn app_server_rate_limit_snapshots(
|
|||||||
snapshots
|
snapshots
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "app_server_session/prompt_history_tests.rs"]
|
||||||
|
mod prompt_history_tests;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -3780,6 +3821,7 @@ mod tests {
|
|||||||
|
|
||||||
let started = started_thread_from_resume_response(
|
let started = started_thread_from_resume_response(
|
||||||
response.clone(),
|
response.clone(),
|
||||||
|
&LocalSettings::from(&config),
|
||||||
&config,
|
&config,
|
||||||
ThreadParamsMode::Remote,
|
ThreadParamsMode::Remote,
|
||||||
)
|
)
|
||||||
@@ -3810,6 +3852,7 @@ mod tests {
|
|||||||
.expect("config should build");
|
.expect("config should build");
|
||||||
let started = started_thread_from_resume_response(
|
let started = started_thread_from_resume_response(
|
||||||
response.clone(),
|
response.clone(),
|
||||||
|
&LocalSettings::from(&embedded_config),
|
||||||
&embedded_config,
|
&embedded_config,
|
||||||
ThreadParamsMode::Embedded,
|
ThreadParamsMode::Embedded,
|
||||||
)
|
)
|
||||||
@@ -3821,6 +3864,7 @@ mod tests {
|
|||||||
empty_roots_response.runtime_workspace_roots = Vec::new();
|
empty_roots_response.runtime_workspace_roots = Vec::new();
|
||||||
let started = started_thread_from_resume_response(
|
let started = started_thread_from_resume_response(
|
||||||
empty_roots_response,
|
empty_roots_response,
|
||||||
|
&LocalSettings::from(&config),
|
||||||
&config,
|
&config,
|
||||||
ThreadParamsMode::Remote,
|
ThreadParamsMode::Remote,
|
||||||
)
|
)
|
||||||
@@ -3907,7 +3951,8 @@ mod tests {
|
|||||||
Vec::new(),
|
Vec::new(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
/*reasoning_effort*/ None,
|
/*reasoning_effort*/ None,
|
||||||
&config,
|
config.personality,
|
||||||
|
&LocalSettings::from(&config),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("session should map");
|
.expect("session should map");
|
||||||
@@ -3942,7 +3987,8 @@ mod tests {
|
|||||||
Vec::new(),
|
Vec::new(),
|
||||||
Vec::new(),
|
Vec::new(),
|
||||||
/*reasoning_effort*/ None,
|
/*reasoning_effort*/ None,
|
||||||
&config,
|
config.personality,
|
||||||
|
&LocalSettings::from(&config),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("session should map");
|
.expect("session should map");
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
//! Local prompt history stays independent of server settings across thread lifecycle requests.
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::legacy_core::config::ConfigBuilder;
|
||||||
|
use app_test_support::create_fake_rollout;
|
||||||
|
use codex_config::types::HistoryPersistence;
|
||||||
|
use codex_message_history::HistoryConfig;
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn lifecycle_metadata_uses_local_prompt_history() -> Result<()> {
|
||||||
|
let local_home = tempfile::tempdir()?;
|
||||||
|
let local_config = ConfigBuilder::default()
|
||||||
|
.codex_home(local_home.path().to_path_buf())
|
||||||
|
.build()
|
||||||
|
.await?;
|
||||||
|
let local_settings = LocalSettings::from(&local_config);
|
||||||
|
let history_config =
|
||||||
|
HistoryConfig::new(local_settings.codex_home.clone(), &local_settings.history);
|
||||||
|
codex_message_history::append_entry("local prompt", ThreadId::new(), &history_config).await?;
|
||||||
|
let (log_id, entry_count) = codex_message_history::history_metadata(&history_config).await;
|
||||||
|
let expected = Some(MessageHistoryMetadata {
|
||||||
|
log_id,
|
||||||
|
entry_count,
|
||||||
|
});
|
||||||
|
assert_eq!(entry_count, 1);
|
||||||
|
|
||||||
|
for mode in [ThreadParamsMode::Embedded, ThreadParamsMode::Remote] {
|
||||||
|
let server_home = tempfile::tempdir()?;
|
||||||
|
let mut config = ConfigBuilder::default()
|
||||||
|
.codex_home(server_home.path().to_path_buf())
|
||||||
|
.build()
|
||||||
|
.await?;
|
||||||
|
config.history.persistence = HistoryPersistence::None;
|
||||||
|
config.history.max_bytes = Some(1);
|
||||||
|
let thread_id = ThreadId::from_string(
|
||||||
|
&create_fake_rollout(
|
||||||
|
server_home.path(),
|
||||||
|
"2025-01-05T12-00-00",
|
||||||
|
"2025-01-05T12:00:00Z",
|
||||||
|
"Saved user message",
|
||||||
|
Some(config.model_provider_id.as_str()),
|
||||||
|
/*git_info*/ None,
|
||||||
|
)
|
||||||
|
.expect("create source rollout"),
|
||||||
|
)?;
|
||||||
|
let mut app_server = crate::start_embedded_app_server_for_picker(&config).await?;
|
||||||
|
app_server.thread_params_mode = mode;
|
||||||
|
|
||||||
|
let started = app_server
|
||||||
|
.start_thread_with_session_start_source(
|
||||||
|
&local_settings,
|
||||||
|
&config,
|
||||||
|
/*session_start_source*/ None,
|
||||||
|
/*remote_cwd_override*/ None,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(started.session.message_history, expected);
|
||||||
|
let startup = start_thread_with_request_handle(
|
||||||
|
app_server.request_handle(),
|
||||||
|
&local_settings,
|
||||||
|
config.clone(),
|
||||||
|
mode,
|
||||||
|
/*remote_cwd_override*/ None,
|
||||||
|
app_server.thread_tool_transport(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(startup.session.message_history, expected);
|
||||||
|
let resumed = app_server
|
||||||
|
.resume_thread(
|
||||||
|
&local_settings,
|
||||||
|
config.clone(),
|
||||||
|
thread_id,
|
||||||
|
ResumeModelSettings::RestoreFromThread,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(resumed.session.message_history, expected);
|
||||||
|
assert_eq!(resumed.session.thread_id, thread_id);
|
||||||
|
assert!(!resumed.turns.is_empty());
|
||||||
|
let forked = app_server
|
||||||
|
.fork_thread(&local_settings, config, thread_id)
|
||||||
|
.await?;
|
||||||
|
assert_eq!(forked.session.message_history, expected);
|
||||||
|
assert_eq!(forked.session.forked_from_id, Some(thread_id));
|
||||||
|
assert!(!forked.turns.is_empty());
|
||||||
|
app_server.shutdown().await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -146,9 +146,13 @@ impl AppServerSession {
|
|||||||
let fork_parent_title = self
|
let fork_parent_title = self
|
||||||
.fork_parent_title_from_app_server(response.thread.forked_from_id.as_deref())
|
.fork_parent_title_from_app_server(response.thread.forked_from_id.as_deref())
|
||||||
.await;
|
.await;
|
||||||
let mut started =
|
let mut started = started_thread_from_resume_response(
|
||||||
started_thread_from_resume_response(response, &config, self.thread_params_mode())
|
response,
|
||||||
.await?;
|
local_settings,
|
||||||
|
&config,
|
||||||
|
self.thread_params_mode(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
started.session.fork_parent_title = fork_parent_title;
|
started.session.fork_parent_title = fork_parent_title;
|
||||||
if self.task_tools_available(thread_id) {
|
if self.task_tools_available(thread_id) {
|
||||||
self.remember_task_tool_thread(thread_id);
|
self.remember_task_tool_thread(thread_id);
|
||||||
|
|||||||
Reference in new issue
Block a user