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:
Eric Traut authored and copyberry committed 2026-09-04 15:58:02 +00:00
1 parent b3f5e45cc1
commit a07158c784
11 files changed
+211 -38

No files matched your search

+73 -27
View File
@@ -769,13 +769,17 @@ impl AppServerSession {
#[cfg(test)]
pub(crate) async fn start_thread(&mut self, config: &Config) -> Result<AppServerStartedThread> {
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
}
pub(crate) async fn start_thread_with_session_start_source(
&mut self,
local_settings: &LocalSettings,
config: &Config,
session_start_source: Option<ThreadStartSource>,
remote_cwd_override: Option<&std::path::Path>,
@@ -802,8 +806,13 @@ impl AppServerSession {
if history_support == ThreadHistorySupport::LegacyOnly {
self.history_support = ThreadHistorySupport::LegacyOnly;
}
let mut started =
started_thread_from_start_response(response, config, self.thread_params_mode()).await?;
let mut started = started_thread_from_start_response(
response,
local_settings,
config,
self.thread_params_mode(),
)
.await?;
started.task_tools_available = task_tools_available;
if task_tools_available {
self.remember_task_tool_thread(started.session.thread_id);
@@ -958,8 +967,13 @@ impl AppServerSession {
"preserving the created fork after bounded history hydration failed"
);
}
let mut started =
started_thread_from_fork_response(response, &config, self.thread_params_mode()).await?;
let mut started = started_thread_from_fork_response(
response,
local_settings,
&config,
self.thread_params_mode(),
)
.await?;
started.session.fork_parent_title = fork_parent.and_then(|thread| thread.name);
if self.task_tools_available(thread_id) {
started.task_tools_available = true;
@@ -1621,6 +1635,7 @@ impl AppServerSession {
pub(crate) async fn start_thread_with_request_handle(
request_handle: AppServerRequestHandle,
local_settings: &LocalSettings,
config: Config,
thread_params_mode: ThreadParamsMode,
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)
})?;
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;
Ok(started)
}
@@ -2069,14 +2085,19 @@ fn thread_cwd_from_config(
async fn started_thread_from_start_response(
response: ThreadStartResponse,
local_settings: &LocalSettings,
config: &Config,
thread_params_mode: ThreadParamsMode,
) -> Result<AppServerStartedThread> {
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
let session =
thread_session_state_from_thread_start_response(&response, config, thread_params_mode)
.await
.map_err(color_eyre::eyre::Report::msg)?;
let session = thread_session_state_from_thread_start_response(
&response,
local_settings,
config,
thread_params_mode,
)
.await
.map_err(color_eyre::eyre::Report::msg)?;
Ok(AppServerStartedThread {
session,
turns: response.thread.turns,
@@ -2087,14 +2108,19 @@ async fn started_thread_from_start_response(
async fn started_thread_from_resume_response(
response: ThreadResumeResponse,
local_settings: &LocalSettings,
config: &Config,
thread_params_mode: ThreadParamsMode,
) -> Result<AppServerStartedThread> {
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
let session =
thread_session_state_from_thread_resume_response(&response, config, thread_params_mode)
.await
.map_err(color_eyre::eyre::Report::msg)?;
let session = thread_session_state_from_thread_resume_response(
&response,
local_settings,
config,
thread_params_mode,
)
.await
.map_err(color_eyre::eyre::Report::msg)?;
Ok(AppServerStartedThread {
session,
turns: response.thread.turns,
@@ -2105,14 +2131,19 @@ async fn started_thread_from_resume_response(
async fn started_thread_from_fork_response(
response: ThreadForkResponse,
local_settings: &LocalSettings,
config: &Config,
thread_params_mode: ThreadParamsMode,
) -> Result<AppServerStartedThread> {
let blocks_direct_input = thread_blocks_direct_input(&response.thread);
let session =
thread_session_state_from_thread_fork_response(&response, config, thread_params_mode)
.await
.map_err(color_eyre::eyre::Report::msg)?;
let session = thread_session_state_from_thread_fork_response(
&response,
local_settings,
config,
thread_params_mode,
)
.await
.map_err(color_eyre::eyre::Report::msg)?;
Ok(AppServerStartedThread {
session,
turns: response.thread.turns,
@@ -2123,6 +2154,7 @@ async fn started_thread_from_fork_response(
async fn thread_session_state_from_thread_start_response(
response: &ThreadStartResponse,
local_settings: &LocalSettings,
config: &Config,
thread_params_mode: ThreadParamsMode,
) -> Result<ThreadSessionState, String> {
@@ -2148,13 +2180,15 @@ async fn thread_session_state_from_thread_start_response(
response.runtime_workspace_roots.clone(),
response.instruction_source_path_uris(),
response.reasoning_effort.clone(),
config,
config.personality,
local_settings,
)
.await
}
async fn thread_session_state_from_thread_resume_response(
response: &ThreadResumeResponse,
local_settings: &LocalSettings,
config: &Config,
thread_params_mode: ThreadParamsMode,
) -> Result<ThreadSessionState, String> {
@@ -2189,13 +2223,15 @@ async fn thread_session_state_from_thread_resume_response(
response.runtime_workspace_roots.clone(),
response.instruction_source_path_uris(),
response.reasoning_effort.clone(),
config,
config.personality,
local_settings,
)
.await
}
async fn thread_session_state_from_thread_fork_response(
response: &ThreadForkResponse,
local_settings: &LocalSettings,
config: &Config,
thread_params_mode: ThreadParamsMode,
) -> Result<ThreadSessionState, String> {
@@ -2221,7 +2257,8 @@ async fn thread_session_state_from_thread_fork_response(
response.runtime_workspace_roots.clone(),
response.instruction_source_path_uris(),
response.reasoning_effort.clone(),
config,
config.personality,
local_settings,
)
.await
}
@@ -2271,7 +2308,8 @@ async fn thread_session_state_from_thread_response(
runtime_workspace_roots: Vec<AbsolutePathBuf>,
instruction_source_paths: Vec<PathUri>,
reasoning_effort: Option<codex_protocol::openai_models::ReasoningEffort>,
config: &Config,
personality: Option<codex_protocol::config_types::Personality>,
local_settings: &LocalSettings,
) -> Result<ThreadSessionState, String> {
let thread_id = ThreadId::from_string(thread_id)
.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)
.transpose()
.map_err(|err| format!("forked_from_id is invalid: {err}"))?;
let local_settings = LocalSettings::from(config);
let history_config = codex_message_history::HistoryConfig::new(
local_settings.codex_home,
local_settings.codex_home.clone(),
&local_settings.history,
);
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,
reasoning_effort,
collaboration_mode: None,
personality: config.personality,
personality,
message_history: Some(MessageHistoryMetadata {
log_id,
entry_count,
@@ -2333,6 +2370,10 @@ pub(crate) fn app_server_rate_limit_snapshots(
snapshots
}
#[cfg(test)]
#[path = "app_server_session/prompt_history_tests.rs"]
mod prompt_history_tests;
#[cfg(test)]
mod tests {
use super::*;
@@ -3780,6 +3821,7 @@ mod tests {
let started = started_thread_from_resume_response(
response.clone(),
&LocalSettings::from(&config),
&config,
ThreadParamsMode::Remote,
)
@@ -3810,6 +3852,7 @@ mod tests {
.expect("config should build");
let started = started_thread_from_resume_response(
response.clone(),
&LocalSettings::from(&embedded_config),
&embedded_config,
ThreadParamsMode::Embedded,
)
@@ -3821,6 +3864,7 @@ mod tests {
empty_roots_response.runtime_workspace_roots = Vec::new();
let started = started_thread_from_resume_response(
empty_roots_response,
&LocalSettings::from(&config),
&config,
ThreadParamsMode::Remote,
)
@@ -3907,7 +3951,8 @@ mod tests {
Vec::new(),
Vec::new(),
/*reasoning_effort*/ None,
&config,
config.personality,
&LocalSettings::from(&config),
)
.await
.expect("session should map");
@@ -3942,7 +3987,8 @@ mod tests {
Vec::new(),
Vec::new(),
/*reasoning_effort*/ None,
&config,
config.personality,
&LocalSettings::from(&config),
)
.await
.expect("session should map");