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

+1
View File
@@ -652,6 +652,7 @@ impl App {
);
match app_server
.start_thread_with_session_start_source(
&self.local_settings,
&config,
/*session_start_source*/ None,
remote_cwd.as_deref(),
+1
View File
@@ -483,6 +483,7 @@ impl App {
Ok(_) => {
app_server
.start_thread_with_session_start_source(
&self.local_settings,
&config, /*session_start_source*/ None,
/*remote_cwd_override*/ None,
)
@@ -857,6 +857,7 @@ impl App {
);
match app_server
.start_thread_with_session_start_source(
&self.local_settings,
&config,
session_start_source,
/*remote_cwd_override*/ None,
+8 -1
View File
@@ -22,6 +22,7 @@ async fn resolve_runtime_model_provider_base_url(provider: &ModelProviderInfo) -
fn spawn_startup_thread_start(
app_server: &AppServerSession,
local_settings: crate::local_settings::LocalSettings,
config: Config,
app_event_tx: AppEventSender,
) {
@@ -32,6 +33,7 @@ fn spawn_startup_thread_start(
tokio::spawn(async move {
let result = crate::app_server_session::start_thread_with_request_handle(
request_handle,
&local_settings,
config,
thread_params_mode,
remote_cwd_override,
@@ -288,7 +290,12 @@ impl App {
| SessionSelection::Exit
| SessionSelection::AgentsOverview => {
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.
let startup_tooltip_override = if start_in_agents_overview {
+23 -6
View File
@@ -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 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?;
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,
HistoryLookupResponse::Entry {
offset: 0,
log_id: 1,
entry: None,
log_id,
entry: Some("local prompt".to_string()),
}
);
let cursor = codex_message_history::HistoryBatchCursor::new(/*end_offset*/ 10);
app.lookup_message_history_batch(thread_id, cursor, /*log_id*/ 1)
let cursor = codex_message_history::HistoryBatchCursor::new(/*end_offset*/ 1);
app.lookup_message_history_batch(thread_id, cursor, log_id)
.await?;
let app_event = tokio::time::timeout(Duration::from_secs(1), app_event_rx.recv())
.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!(
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(())
@@ -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(
session.request_handle(),
&app.local_settings,
app.config.clone(),
ThreadParamsMode::Remote,
/*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));
let startup = crate::app_server_session::start_thread_with_request_handle(
app_server.request_handle(),
&app.local_settings,
app.config.clone(),
crate::app_server_session::ThreadParamsMode::Embedded,
/*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));
let startup = crate::app_server_session::start_thread_with_request_handle(
app_server.request_handle(),
&app.local_settings,
app.config.clone(),
crate::app_server_session::ThreadParamsMode::Embedded,
/*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));
let startup = crate::app_server_session::start_thread_with_request_handle(
app_server.request_handle(),
&app.local_settings,
app.config.clone(),
crate::app_server_session::ThreadParamsMode::Embedded,
/*remote_cwd_override*/ None,
+4 -1
View File
@@ -156,7 +156,10 @@ impl App {
} else {
app_server
.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
};