Open tasks managed elsewhere as read-only history in the command center (#44969)

## Why

The command center previously refused to open tasks managed by another app server, preventing users from viewing their saved history.

## What changed

- Fall back to a frozen, read-only history snapshot when attaching fails because another server owns the task. Preserve drafts and skip buffered request replay and paused-goal prompts while viewing.
- Keep the snapshot when reopening the displayed task, and allow explicit retry to attach once the other server releases it.
- Allow pasting into the command center while a read-only conversation is displayed, while keeping the conversation composer protected.
- Box the TUI startup future to keep it out of the CLI caller's frame.

## Testing

Add coverage for read-only history, draft and selection preservation, retry before and after ownership release, and history-read failure without leaving the current conversation. Assert that opening a read-only task does not start a turn and that the TUI startup future remains below 64 KiB.

GitOrigin-RevId: f1bdb5b2d9182079de4e53346a56742a4a02a1c7
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-12 04:28:14 +00:00
1 parent 53ff712a48
commit 7efb0262d6
6 files changed
+304 -53

No files matched your search

@@ -1,5 +1,6 @@
use super::*;
use crate::app_event::TranscriptExportDestination;
use crate::bottom_pane::BottomPaneView;
use app_test_support::create_fake_paginated_rollout;
use app_test_support::create_fake_parented_rollout_with_source;
use app_test_support::create_fake_rollout;
@@ -149,6 +150,7 @@ pub(super) enum HistoryCapabilities {
LegacyOnlyUnsupportedVariant,
LegacyDynamicToolsAndHistory,
ForkHydrationFails,
ReadAfterResumeFails,
ThreadListFails,
ThreadStartFails,
ConfigReadUnsupported(i64),
@@ -358,6 +360,22 @@ pub(super) async fn start_recording_app_server_with_realtime_speech(
id: request_id,
result: serde_json::json!({}),
})
} else if history_capabilities == HistoryCapabilities::ReadAfterResumeFails
&& request.method == "thread/read"
&& request_sink
.lock()
.expect("request recorder lock")
.iter()
.any(|recorded| recorded.method == "thread/resume")
{
JSONRPCMessage::Error(JSONRPCError {
id: request_id,
error: JSONRPCErrorError {
code: -32603,
data: None,
message: "saved history unavailable".to_string(),
},
})
} else if let HistoryCapabilities::ConfigReadUnsupported(code) =
history_capabilities
&& request.method == "config/read"
@@ -4460,3 +4478,86 @@ async fn external_writer_escape_preserves_snapshot_and_explicit_quits() -> Resul
}
Ok(())
}
#[tokio::test]
async fn command_center_read_only_open_requests_and_failure_preservation() -> Result<()> {
for history_capabilities in [
HistoryCapabilities::Current,
HistoryCapabilities::ReadAfterResumeFails,
] {
let (mut app, _codex_home) = Box::pin(make_history_test_app()).await?;
std::fs::write(
app.config.codex_home.join("config.toml"),
"[tui]\nresume_cwd = \"current\"\n",
)?;
for cwd in [test_path_buf("/"), app.config.cwd.to_path_buf()] {
crate::legacy_core::config::set_project_trust_level(
app.config.codex_home.as_path(),
&cwd,
codex_protocol::config_types::TrustLevel::Trusted,
)
.map_err(std::io::Error::other)?;
}
let thread_id =
create_history_rollout(&app.config, ThreadHistoryMode::Legacy, "Locked task")?;
let mut owner = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
Box::pin(owner.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::PreserveExistingThread,
))
.await?;
let (mut server, requests, proxy) = start_recording_app_server_with_history(
&app.config,
history_capabilities,
/*blocked_thread_list*/ None,
/*failed_thread_name*/ None,
crate::app_server_session::ThreadParamsMode::Embedded,
LoaderOverrides::default(),
)
.await?;
app.app_server_target = AppServerTarget::LocalDaemon {
endpoint: crate::resolve_remote_addr("ws://127.0.0.1:4500")?,
};
let current = Box::pin(server.start_thread(&app.config)).await?;
let current_id = current.session.thread_id;
app.enqueue_primary_thread_session(current.session, current.turns)
.await?;
let thread = owner
.thread_read(thread_id, /*include_turns*/ false)
.await?;
let mut view = app.agents_overview_view(vec![thread], Some(thread_id));
view.handle_paste("Keep this draft".into());
app.chat_widget.show_bottom_pane_view(Box::new(view));
let before = render_bottom_popup(&app.chat_widget, /*width*/ 96);
requests.lock().unwrap().clear();
let mut tui = crate::tui::test_support::make_test_tui()?;
Box::pin(app.select_agents_overview_thread(&mut tui, &mut server, thread_id)).await?;
assert_eq!(recorded_params(&requests, "thread/resume").len(), 1);
assert!(recorded_params(&requests, "turn/start").is_empty());
if history_capabilities == HistoryCapabilities::ReadAfterResumeFails {
let error = render_bottom_popup(&app.chat_widget, /*width*/ 96);
assert!(
error.contains("Failed to view task open elsewhere"),
"{error}"
);
assert_eq!(app.current_displayed_thread_id(), Some(current_id));
assert!(recorded_params(&requests, "thread/unsubscribe").is_empty());
app.chat_widget.handle_key_event(KeyCode::Esc.into());
assert_eq!(render_bottom_popup(&app.chat_widget, /*width*/ 96), before);
} else {
assert_eq!(app.current_displayed_thread_id(), Some(thread_id));
assert!(app.chat_widget.is_external_writer_view());
assert_eq!(
app.thread_event_channels[&thread_id].attachment(),
ThreadEventAttachment::ExternalWriter
);
}
owner.shutdown().await?;
server.shutdown().await?;
proxy.await??;
}
Ok(())
}