mirror of
https://github.com/openai/codex.git
synced 2026-11-16 22:00:36 +00:00
Show read-only conversations when resume encounters an active writer (#43253)
## Why Resuming a conversation that is open in another app fails with an active-writer error. Allow users to inspect its transcript and retry after closing it in the other app. ## What changed - Fall back to a read-only history snapshot on active-writer conflicts during startup and session selection. - Replace the composer with an explanatory notice, `R` to retry, exit shortcuts, and the configured transcript shortcut. - Block input and freeze active command and MCP animations while viewing the snapshot. Preserve initial prompts and existing drafts for a successful retry. - Keep the subscription when retrying the same thread and preserve read-only state across thread switches and reconnects. ## Testing Add regression tests for conflict detection, history viewing, draft preservation, same-thread retry without unsubscribing, exit shortcuts, and notice and frozen-tool rendering. GitOrigin-RevId: fa864cc73143cad9139c22e33b7958569eec20cf
This commit is contained in:
@@ -9,8 +9,10 @@ use super::bootstrap_request_error;
|
||||
use super::is_history_pagination_unsupported;
|
||||
use super::started_thread_from_resume_response;
|
||||
use super::thread_resume_params_from_config;
|
||||
use super::thread_session_state_from_thread_response;
|
||||
use crate::legacy_core::config::Config;
|
||||
use codex_app_server_client::TypedRequestError;
|
||||
use codex_app_server_protocol::AskForApproval;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::ThreadHistoryMode;
|
||||
use codex_app_server_protocol::ThreadResumeResponse;
|
||||
@@ -19,6 +21,53 @@ use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use color_eyre::eyre::Result;
|
||||
|
||||
impl AppServerSession {
|
||||
/// Read a conflicting thread without taking its writer lease. This is a snapshot, not an
|
||||
/// attachment: the caller must not route turns through this session.
|
||||
pub(crate) async fn read_thread_for_viewing(
|
||||
&mut self,
|
||||
config: &Config,
|
||||
local_settings: &crate::local_settings::LocalSettings,
|
||||
thread_id: ThreadId,
|
||||
) -> Result<AppServerStartedThread> {
|
||||
let mut thread = self.thread_read(thread_id, /*include_turns*/ false).await?;
|
||||
self.hydrate_initial_thread_history(
|
||||
&mut thread,
|
||||
/*turn_cursor*/ None,
|
||||
/*item_cursor*/ None,
|
||||
Some(config),
|
||||
Some(local_settings),
|
||||
HistoryHydrationScope::Initial,
|
||||
)
|
||||
.await?;
|
||||
let session = thread_session_state_from_thread_response(
|
||||
&thread.id,
|
||||
thread.forked_from_id.clone(),
|
||||
thread.name.clone(),
|
||||
thread.path.clone(),
|
||||
thread.model.clone().unwrap_or_default(),
|
||||
thread.model_provider.clone(),
|
||||
config.service_tier.clone(),
|
||||
AskForApproval::from(config.permissions.approval_policy.value()),
|
||||
config.approvals_reviewer,
|
||||
config.permissions.permission_profile().clone(),
|
||||
config.permissions.active_permission_profile(),
|
||||
thread.cwd.clone(),
|
||||
config.workspace_roots.clone(),
|
||||
Vec::new(),
|
||||
thread.reasoning_effort,
|
||||
config.personality,
|
||||
local_settings,
|
||||
)
|
||||
.await
|
||||
.map_err(color_eyre::eyre::Report::msg)?;
|
||||
Ok(AppServerStartedThread {
|
||||
session,
|
||||
turns: thread.turns,
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn with_local_codex_home(mut self, codex_home: &AbsolutePathBuf) -> Self {
|
||||
self.task_tool_capabilities_dir = (!self.uses_embedded_app_server())
|
||||
.then(|| codex_home.join("tui-thread-reference-capabilities"));
|
||||
|
||||
@@ -19,6 +19,49 @@ async fn build_config(temp_dir: &TempDir) -> Config {
|
||||
.expect("config should build")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn viewing_thread_reads_history_without_resuming_it() -> Result<()> {
|
||||
let codex_home = tempfile::tempdir()?;
|
||||
let config = build_config(&codex_home).await;
|
||||
let thread_id = ThreadId::from_string(
|
||||
&create_fake_rollout(
|
||||
codex_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?;
|
||||
let next_request_id = app_server.next_request_id;
|
||||
let viewed = app_server
|
||||
.read_thread_for_viewing(
|
||||
&config,
|
||||
&crate::local_settings::LocalSettings::from(&config),
|
||||
thread_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
assert_eq!(viewed.session.thread_id, thread_id);
|
||||
assert!(!viewed.turns.is_empty());
|
||||
assert!(!viewed.blocks_direct_input);
|
||||
assert!(app_server.next_request_id > next_request_id);
|
||||
app_server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_active_writer_failures_offer_read_only_view() {
|
||||
let conflict = color_eyre::eyre::eyre!("thread already has an active writer (code -32600)");
|
||||
let unrelated = color_eyre::eyre::eyre!("thread not found (code -32600)");
|
||||
assert!(crate::app_server_session::is_active_writer_error(&conflict));
|
||||
assert!(!crate::app_server_session::is_active_writer_error(
|
||||
&unrelated
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn legacy_resume_preserves_history_mode_after_picker_server_replacement() -> Result<()> {
|
||||
let codex_home = tempfile::tempdir().expect("tempdir");
|
||||
|
||||
Reference in New Issue
Block a user