mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
Resume unsent TUI input after reconnecting (#49105)
## Why Reconnecting paused all recovered input, including queued messages that had never been sent. Those messages can resume automatically once any uncertain submissions are resolved. ## What changed - Track unsent and unconfirmed messages separately. Reconcile submitted prompts and steers using exact client message IDs from restored history, buffered events, and later receipts. - Remove confirmed submissions from the recovered queue and resume unsent input after replay. Keep uncertain submissions paused without resending them, and show a notice identifying the message whose delivery could not be confirmed. - Preserve pauses for unavailable conversations, pending compact/review requests, and existing input recovery failures. - Simplify reconnect status text and remove blanket disconnect/reconnect transcript notices. ## Testing Update reconnect integration tests and snapshots for automatic queue resumption. Add coverage for matching and unrelated receipts, missing history, late confirmations across navigation, pending compaction, and preservation of image-failure recovery pauses. GitOrigin-RevId: d0b9aa43c4019d472985d12bbce8ba9bbfb9253b
This commit is contained in:
@@ -389,6 +389,7 @@ async fn parent_owned_thread_preserves_queued_input_before_draining() {
|
||||
let queued_message = QueuedUserMessage {
|
||||
user_message: UserMessage::from("keep this queued prompt"),
|
||||
action: QueuedInputAction::Plain,
|
||||
delivery: MessageDelivery::Unsent,
|
||||
pending_pastes: vec![("[Image 1]".to_string(), "pasted contents".to_string())],
|
||||
source: UserMessageSource::Prompt,
|
||||
};
|
||||
@@ -1826,7 +1827,9 @@ async fn restore_thread_input_state_applies_running_state_policy() {
|
||||
queued_user_messages: VecDeque::from([UserMessage::from("already queued").into()]),
|
||||
queued_user_message_history_records: VecDeque::from([queued_history.clone()]),
|
||||
recovered_queue: false,
|
||||
reconnect_pending: false,
|
||||
user_turn_pending_start: true,
|
||||
pending_user_message_client_id: None,
|
||||
submit_pending_steers_after_interrupt: true,
|
||||
current_collaboration_mode: chat.current_collaboration_mode.clone(),
|
||||
active_collaboration_mask: chat.active_collaboration_mask.clone(),
|
||||
@@ -1867,7 +1870,8 @@ async fn restore_thread_input_state_applies_running_state_policy() {
|
||||
);
|
||||
assert!(!chat.has_queued_follow_up_messages());
|
||||
// Editing the last queued draft must not release the uncertain steer for replay.
|
||||
assert!(chat.capture_thread_input_state().unwrap().recovered_queue);
|
||||
assert_eq!(chat.input_queue.pending_steers.len(), 1);
|
||||
assert!(chat.input_queue.suppress_queue_autosend);
|
||||
chat.handle_restricted_key(
|
||||
KeyEvent::new(KeyCode::Up, KeyModifiers::ALT),
|
||||
RestrictedInputMode::Disconnected,
|
||||
@@ -2359,46 +2363,106 @@ async fn interrupt_prepends_queued_messages_before_existing_composer_text() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconnect_holds_only_recovered_input_until_manually_edited() {
|
||||
for (recovered, pending_start) in [
|
||||
(None, false),
|
||||
(Some("review this old input"), false),
|
||||
(Some("unacknowledged prompt"), true),
|
||||
] {
|
||||
async fn reconnect_resumes_unsent_input_and_reconciles_confirmed_submissions() {
|
||||
for pending_start in [false, true] {
|
||||
let (mut chat, _rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
if let Some(text) = recovered {
|
||||
if pending_start {
|
||||
chat.input_queue.user_turn_pending_start = true;
|
||||
chat.safety_buffering_prompt = Some(UserMessage::from(text));
|
||||
} else {
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from(text).into());
|
||||
}
|
||||
}
|
||||
chat.pause_for_disconnect();
|
||||
let input = chat.capture_thread_input_state();
|
||||
let (mut chat, _rx, mut ops) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.restore_reconnected_input(input);
|
||||
chat.set_queue_autosend_suppressed(/*suppressed*/ false);
|
||||
if let Some(text) = recovered {
|
||||
assert!(!chat.maybe_send_next_queued_input());
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Up, KeyModifiers::ALT));
|
||||
assert_eq!(chat.bottom_pane.composer_text(), text);
|
||||
assert_no_submit_op(&mut ops);
|
||||
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
|
||||
assert_matches!(next_submit_op(&mut ops), Op::UserTurn { .. });
|
||||
chat.input_queue.user_turn_pending_start = false;
|
||||
if !pending_start {
|
||||
handle_turn_started(&mut chat, "turn-1");
|
||||
}
|
||||
chat.submit_user_message("first message".into());
|
||||
let client_id = if pending_start {
|
||||
chat.input_queue
|
||||
.pending_user_message_client_id
|
||||
.clone()
|
||||
.unwrap()
|
||||
} else {
|
||||
chat.input_queue.pending_steers[0].client_id.clone()
|
||||
};
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from("new follow-up").into());
|
||||
assert!(chat.maybe_send_next_queued_input());
|
||||
assert_matches!(next_submit_op(&mut ops), Op::UserTurn { .. });
|
||||
.push_back(UserMessage::from("follow-up").into());
|
||||
chat.pause_for_disconnect();
|
||||
let mut input = chat.capture_thread_input_state();
|
||||
// Missing history and unrelated receipts never authorize resubmitting uncertain input.
|
||||
for ids in [
|
||||
vec![],
|
||||
vec!["different-submission".into()],
|
||||
vec![client_id.clone()],
|
||||
] {
|
||||
let confirmed = ids.contains(&client_id);
|
||||
input.as_mut().unwrap().reconnect_pending = true;
|
||||
let (mut restored, mut rx, mut ops) =
|
||||
make_chatwidget_manual(/*model_override*/ None).await;
|
||||
restored.thread_id = Some(ThreadId::new());
|
||||
if confirmed && pending_start {
|
||||
// A fresh steer submitted during recovery must remain uncertain after navigation.
|
||||
let steer = pending_steer("later steer");
|
||||
let later_id = steer.client_id.clone();
|
||||
input.as_mut().unwrap().pending_steers.push_back(steer);
|
||||
input.as_mut().unwrap().reconnect_pending = false;
|
||||
restored.restore_reconnected_input(input, &[]);
|
||||
for (text, id) in [("first message", &client_id), ("later steer", &later_id)] {
|
||||
assert_no_submit_op(&mut ops);
|
||||
restored.on_committed_user_message(
|
||||
&[UserInput::Text {
|
||||
text: text.into(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
Some(id),
|
||||
/*from_replay*/ false,
|
||||
"turn-1",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
restored.restore_reconnected_input(input, &ids);
|
||||
assert_eq!(restored.maybe_send_next_queued_input(), confirmed);
|
||||
}
|
||||
if confirmed {
|
||||
assert_matches!(next_submit_op(&mut ops), Op::UserTurn { items, .. }
|
||||
if items == vec![UserInput::Text {
|
||||
text: "follow-up".into(),
|
||||
text_elements: Vec::new(),
|
||||
}]);
|
||||
assert!(!restored.has_queued_follow_up_messages());
|
||||
} else {
|
||||
assert_eq!(
|
||||
restored.queued_user_message_texts(),
|
||||
vec!["first message", "follow-up"]
|
||||
);
|
||||
assert_no_submit_op(&mut ops);
|
||||
let notice = drain_insert_history(&mut rx)
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|line| line.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
insta::allow_duplicates! {
|
||||
assert_snapshot!(notice, @"• Couldn't confirm whether “first message” was sent. It hasn't been resent.");
|
||||
}
|
||||
}
|
||||
input = restored.capture_thread_input_state();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconnect_keeps_queue_paused_after_pending_compact() {
|
||||
let (mut chat, _rx, mut ops) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
chat.thread_id = Some(ThreadId::new());
|
||||
chat.prepare_local_op_submission(&AppCommand::Compact);
|
||||
chat.queue_user_message("follow-up".into());
|
||||
chat.pause_for_disconnect();
|
||||
let mut input = chat.capture_thread_input_state();
|
||||
input.as_mut().unwrap().reconnect_pending = true;
|
||||
chat.restore_reconnected_input(input, &[]);
|
||||
chat.set_queue_autosend_suppressed(/*suppressed*/ false);
|
||||
|
||||
assert!(!chat.maybe_send_next_queued_input());
|
||||
assert_eq!(chat.queued_user_message_texts(), vec!["follow-up"]);
|
||||
assert_no_submit_op(&mut ops);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn image_submission_is_portable_for_new_turns_and_steers() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
@@ -2522,6 +2586,9 @@ async fn image_preparation_failure_restores_full_input_without_submitting() {
|
||||
chat.input_queue
|
||||
.pending_steers
|
||||
.push_back(pending_steer("already sent"));
|
||||
chat.input_queue
|
||||
.queued_user_messages
|
||||
.push_back(UserMessage::from("follow-up").into());
|
||||
}
|
||||
let pending_steers = chat.input_queue.pending_steers.clone();
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
@@ -2596,6 +2663,26 @@ async fn image_preparation_failure_restores_full_input_without_submitting() {
|
||||
normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80))
|
||||
);
|
||||
}
|
||||
if running {
|
||||
// A transport recovery must preserve the pause for the failed image draft.
|
||||
chat.pause_for_disconnect();
|
||||
let mut input = chat.capture_thread_input_state();
|
||||
input.as_mut().unwrap().reconnect_pending = true;
|
||||
chat.restore_reconnected_input(input, &[pending_steers[0].client_id.clone()]);
|
||||
chat.on_committed_user_message(
|
||||
&[UserInput::Text {
|
||||
text: "already sent".into(),
|
||||
text_elements: Vec::new(),
|
||||
}],
|
||||
Some(&pending_steers[0].client_id),
|
||||
/*from_replay*/ false,
|
||||
"turn",
|
||||
);
|
||||
chat.input_queue.suppress_queue_autosend = false;
|
||||
handle_turn_completed(&mut chat, "turn", /*duration_ms*/ None);
|
||||
assert_eq!(chat.queued_user_message_texts(), vec!["follow-up"]);
|
||||
assert_no_submit_op(&mut op_rx);
|
||||
}
|
||||
pixels.save(&path).unwrap();
|
||||
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
while let Some(event) = rx.recv().await {
|
||||
|
||||
@@ -363,7 +363,7 @@ async fn reconnect_preserves_buffered_question_answer_source() {
|
||||
|
||||
let (mut restored, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
restored.thread_id = Some(ThreadId::new());
|
||||
restored.restore_reconnected_input(state);
|
||||
restored.restore_reconnected_input(state, &[]);
|
||||
assert_eq!(
|
||||
restored
|
||||
.input_queue
|
||||
@@ -801,7 +801,7 @@ async fn question_drafts_survive_navigation_and_snapshot_replay() {
|
||||
Some(ReplayKind::ThreadSnapshot),
|
||||
);
|
||||
assert_eq!(question_count(&chat), 1);
|
||||
chat.restore_reconnected_input(saved);
|
||||
chat.restore_reconnected_input(saved, &[]);
|
||||
assert!(render_bottom_popup(&chat, /*width*/ 80).contains("second draft"));
|
||||
chat.pause_unavailable_thread();
|
||||
chat.handle_question_key(KeyEvent::new(KeyCode::Char(']'), KeyModifiers::CONTROL));
|
||||
|
||||
@@ -390,7 +390,9 @@ async fn restore_thread_input_state_restores_pending_steers_without_downgrading_
|
||||
queued_user_messages,
|
||||
queued_user_message_history_records: VecDeque::new(),
|
||||
recovered_queue: false,
|
||||
reconnect_pending: false,
|
||||
user_turn_pending_start: false,
|
||||
pending_user_message_client_id: None,
|
||||
submit_pending_steers_after_interrupt: false,
|
||||
current_collaboration_mode: chat.current_collaboration_mode.clone(),
|
||||
active_collaboration_mask: chat.active_collaboration_mask.clone(),
|
||||
|
||||
Reference in New Issue
Block a user