mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
codex: address PR review feedback (#26754)
This commit is contained in:
@@ -1723,8 +1723,8 @@ impl App {
|
||||
self.handle_start_side(app_server, parent_thread_id, user_message)
|
||||
.await;
|
||||
}
|
||||
AppEvent::SideThreadPrepared(result) => {
|
||||
self.handle_side_thread_prepared(tui, app_server, result)
|
||||
AppEvent::SideThreadPrepared { request_id, result } => {
|
||||
self.handle_side_thread_prepared(tui, app_server, request_id, result)
|
||||
.await?;
|
||||
}
|
||||
AppEvent::OpenSkillsList => {
|
||||
|
||||
@@ -197,6 +197,7 @@ pub(super) struct SideThreadState {
|
||||
}
|
||||
|
||||
pub(super) struct PendingSideStart {
|
||||
pub(super) request_id: Uuid,
|
||||
pub(super) parent_thread_id: ThreadId,
|
||||
pub(super) user_message: Option<crate::chatwidget::UserMessage>,
|
||||
}
|
||||
@@ -501,6 +502,11 @@ impl App {
|
||||
self.restore_side_user_message(user_message);
|
||||
}
|
||||
|
||||
pub(super) fn take_pending_side_start(&mut self, request_id: Uuid) -> Option<PendingSideStart> {
|
||||
self.pending_side_start
|
||||
.take_if(|pending| pending.request_id == request_id)
|
||||
}
|
||||
|
||||
pub(super) fn install_side_thread_snapshot(
|
||||
store: &mut ThreadEventStore,
|
||||
mut session: ThreadSessionState,
|
||||
@@ -561,7 +567,9 @@ impl App {
|
||||
self.refresh_in_memory_config_from_disk_best_effort("starting a side conversation")
|
||||
.await;
|
||||
|
||||
let request_id = Uuid::new_v4();
|
||||
self.pending_side_start = Some(PendingSideStart {
|
||||
request_id,
|
||||
parent_thread_id,
|
||||
user_message,
|
||||
});
|
||||
@@ -583,7 +591,7 @@ impl App {
|
||||
)
|
||||
.await
|
||||
.map_err(|err| format!("{err:#}"));
|
||||
app_event_tx.send(AppEvent::SideThreadPrepared(result));
|
||||
app_event_tx.send(AppEvent::SideThreadPrepared { request_id, result });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -591,25 +599,27 @@ impl App {
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
request_id: Uuid,
|
||||
result: std::result::Result<AppServerStartedThread, String>,
|
||||
) -> Result<()> {
|
||||
let Some(PendingSideStart {
|
||||
parent_thread_id,
|
||||
mut user_message,
|
||||
}) = self.pending_side_start.take()
|
||||
..
|
||||
}) = self.take_pending_side_start(request_id)
|
||||
else {
|
||||
if let Ok(started) = result {
|
||||
// Esc and session teardown only cancel the UI transition; close a child that
|
||||
// finishes after its pending state has been abandoned.
|
||||
let thread_id = started.session.thread_id;
|
||||
// ThreadStarted may have created local state before this preparation was canceled.
|
||||
self.discard_thread_local_state(thread_id).await;
|
||||
let request_handle = app_server.request_handle();
|
||||
tokio::spawn(async move {
|
||||
if let Err(err) =
|
||||
super::side_server::unsubscribe_side_thread(request_handle, thread_id).await
|
||||
super::side_server::cleanup_side_thread(request_handle, thread_id).await
|
||||
{
|
||||
tracing::warn!(
|
||||
thread_id = %thread_id,
|
||||
"failed to unsubscribe abandoned side thread: {err}"
|
||||
"failed to clean up abandoned side thread: {err}"
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,8 @@ use codex_app_server_protocol::ThreadInjectItemsParams;
|
||||
use codex_app_server_protocol::ThreadInjectItemsResponse;
|
||||
use codex_app_server_protocol::ThreadUnsubscribeParams;
|
||||
use codex_app_server_protocol::ThreadUnsubscribeResponse;
|
||||
use codex_app_server_protocol::TurnInterruptParams;
|
||||
use codex_app_server_protocol::TurnInterruptResponse;
|
||||
|
||||
pub(super) async fn prepare_side_thread(
|
||||
request_handle: AppServerRequestHandle,
|
||||
@@ -38,7 +40,7 @@ pub(super) async fn prepare_side_thread(
|
||||
.await;
|
||||
if let Err(err) = inject_result {
|
||||
// The caller only receives fully prepared threads, so clean up this partial fork here.
|
||||
if let Err(cleanup_err) = unsubscribe_side_thread(request_handle, child_thread_id).await {
|
||||
if let Err(cleanup_err) = cleanup_side_thread(request_handle, child_thread_id).await {
|
||||
tracing::warn!(
|
||||
thread_id = %child_thread_id,
|
||||
"failed to clean up side thread after inject failure: {cleanup_err}"
|
||||
@@ -49,11 +51,21 @@ pub(super) async fn prepare_side_thread(
|
||||
Ok(started)
|
||||
}
|
||||
|
||||
pub(super) async fn unsubscribe_side_thread(
|
||||
pub(super) async fn cleanup_side_thread(
|
||||
request_handle: AppServerRequestHandle,
|
||||
thread_id: ThreadId,
|
||||
) -> Result<()> {
|
||||
request_handle
|
||||
let interrupt_result = request_handle
|
||||
.request_typed::<TurnInterruptResponse>(ClientRequest::TurnInterrupt {
|
||||
request_id: RequestId::String(format!("side-thread-interrupt-{}", Uuid::new_v4())),
|
||||
params: TurnInterruptParams {
|
||||
thread_id: thread_id.to_string(),
|
||||
turn_id: String::new(),
|
||||
},
|
||||
})
|
||||
.await
|
||||
.wrap_err("turn/interrupt failed while cleaning up TUI side thread");
|
||||
let unsubscribe_result = request_handle
|
||||
.request_typed::<ThreadUnsubscribeResponse>(ClientRequest::ThreadUnsubscribe {
|
||||
request_id: RequestId::String(format!("side-thread-unsubscribe-{}", Uuid::new_v4())),
|
||||
params: ThreadUnsubscribeParams {
|
||||
@@ -62,5 +74,7 @@ pub(super) async fn unsubscribe_side_thread(
|
||||
})
|
||||
.await
|
||||
.wrap_err("thread/unsubscribe failed in TUI")
|
||||
.map(drop)
|
||||
.map(drop);
|
||||
interrupt_result?;
|
||||
unsubscribe_result
|
||||
}
|
||||
|
||||
@@ -3386,6 +3386,7 @@ async fn side_thread_ignores_global_mcp_startup_notifications() {
|
||||
async fn cancelling_pending_side_start_restores_message() {
|
||||
let mut app = make_test_app().await;
|
||||
app.pending_side_start = Some(PendingSideStart {
|
||||
request_id: Uuid::new_v4(),
|
||||
parent_thread_id: ThreadId::new(),
|
||||
user_message: Some(crate::chatwidget::UserMessage::from("side question")),
|
||||
});
|
||||
@@ -3400,6 +3401,23 @@ async fn cancelling_pending_side_start_restores_message() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn side_completion_only_consumes_its_own_pending_start() {
|
||||
let mut app = make_test_app().await;
|
||||
let current_request_id = Uuid::new_v4();
|
||||
app.pending_side_start = Some(PendingSideStart {
|
||||
request_id: current_request_id,
|
||||
parent_thread_id: ThreadId::new(),
|
||||
user_message: None,
|
||||
});
|
||||
|
||||
assert!(app.take_pending_side_start(Uuid::new_v4()).is_none());
|
||||
assert_eq!(
|
||||
app.pending_side_start.as_ref().unwrap().request_id,
|
||||
current_request_id
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn side_discard_selection_keeps_current_side_thread() {
|
||||
let mut app = make_test_app().await;
|
||||
|
||||
@@ -48,6 +48,7 @@ use codex_protocol::models::ActivePermissionProfile;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcEvent;
|
||||
use codex_realtime_webrtc::RealtimeWebrtcSessionHandle;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::history_cell::HistoryCell;
|
||||
|
||||
@@ -147,7 +148,10 @@ pub(crate) enum AppEvent {
|
||||
user_message: Option<UserMessage>,
|
||||
},
|
||||
/// Finish preparing a transient side conversation off the TUI event loop.
|
||||
SideThreadPrepared(Result<AppServerStartedThread, String>),
|
||||
SideThreadPrepared {
|
||||
request_id: Uuid,
|
||||
result: Result<AppServerStartedThread, String>,
|
||||
},
|
||||
|
||||
/// Submit an op to the specified thread, regardless of current focus.
|
||||
SubmitThreadOp {
|
||||
|
||||
Reference in New Issue
Block a user