Lightweight coding agent that runs in your terminal
Rust
fix(tui): queue steer Enter while final answer is still streaming to prevent dead state (#12569)
Beehive Innovationsbe4203023d05
diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rsindex 7ba3a95054..2cde0cab14 100644--- a/codex-rs/tui/src/chatwidget.rs+++ b/codex-rs/tui/src/chatwidget.rs@@ -3274,7 +3274,14 @@ impl ChatWidget {.bottom_pane.take_recent_submission_mention_bindings(),};- if self.is_session_configured() && !self.is_plan_streaming_in_tui() {+ // Steer submissions during active final-answer streaming can race with turn+ // completion and strand the UI in a running state. Queue those inputs instead+ // of injecting immediately; `on_task_complete()` drains this FIFO via+ // `maybe_send_next_queued_input()`, so no typed prompt is dropped.+ let should_submit_now = self.is_session_configured()+ && !self.is_plan_streaming_in_tui()+ && self.stream_controller.is_none();+ if should_submit_now {// Submitted is only emitted when steer is enabled.// Reset any reasoning header only when we are actually submitting a turn.self.reasoning_buffer.clear();diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rsindex 1e0487eddf..4599377e91 100644--- a/codex-rs/tui/src/chatwidget/tests.rs+++ b/codex-rs/tui/src/chatwidget/tests.rs@@ -3402,6 +3402,105 @@ async fn steer_enter_queues_while_plan_stream_is_active() {assert_matches!(op_rx.try_recv(), Err(TryRecvError::Empty));}+#[tokio::test]+async fn steer_enter_queues_while_final_answer_stream_is_active() {+ let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(None).await;+ chat.thread_id = Some(ThreadId::new());+ chat.on_task_started();+ // Keep the assistant stream open (no commit tick/finalize) to model the repro window:+ // user presses Enter while the final answer is still streaming.+ chat.on_agent_message_delta("Final answer line\n".to_string());++ chat.bottom_pane.set_composer_text(+ "queued while streaming".to_string(),+ Vec::new(),+ Vec::new(),+ );+ chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));++ assert_eq!(chat.queued_user_messages.len(), 1);+ assert_eq!(+ chat.queued_user_messages.front().unwrap().text,+ "queued while streaming"+ );+ assert_no_submit_op(&mut op_rx);++ // Once final output ends, the queued input must be submitted automatically.+ chat.on_task_complete(None, false);++ assert!(chat.queued_user_messages.is_empty());+ match next_submit_op(&mut op_rx) {+ Op::UserTurn { .. } => {}+ other => panic!("expected Op::UserTurn after stream completion, got {other:?}"),+ }+}++#[tokio::test]+async fn steer_enter_during_final_stream_preserves_follow_up_prompts_in_order() {+ let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(None).await;+ chat.thread_id = Some(ThreadId::new());+ chat.on_task_started();+ // Simulate "dead mode" repro timing by keeping a final-answer stream active while the+ // user submits multiple follow-up prompts.+ chat.on_agent_message_delta("Final answer line\n".to_string());++ chat.bottom_pane+ .set_composer_text("first follow-up".to_string(), Vec::new(), Vec::new());+ chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));+ chat.bottom_pane+ .set_composer_text("second follow-up".to_string(), Vec::new(), Vec::new());+ chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));++ assert_eq!(chat.queued_user_messages.len(), 2);+ assert_eq!(+ chat.queued_user_messages.front().unwrap().text,+ "first follow-up"+ );+ assert_eq!(+ chat.queued_user_messages.back().unwrap().text,+ "second follow-up"+ );+ assert_no_submit_op(&mut op_rx);++ // Completion must recover by submitting the oldest queued prompt first.+ chat.on_task_complete(None, false);++ let first_items = match next_submit_op(&mut op_rx) {+ Op::UserTurn { items, .. } => items,+ other => panic!("expected Op::UserTurn, got {other:?}"),+ };+ assert_eq!(+ first_items,+ vec![UserInput::Text {+ text: "first follow-up".to_string(),+ text_elements: Vec::new(),+ }]+ );+ assert_eq!(chat.queued_user_messages.len(), 1);+ assert_eq!(+ chat.queued_user_messages.front().unwrap().text,+ "second follow-up"+ );++ // A subsequent turn lifecycle should continue draining remaining queued prompts, proving+ // the widget did not enter a permanently stuck state.+ chat.on_task_started();+ chat.on_task_complete(None, false);++ let second_items = match next_submit_op(&mut op_rx) {+ Op::UserTurn { items, .. } => items,+ other => panic!("expected Op::UserTurn, got {other:?}"),+ };+ assert_eq!(+ second_items,+ vec![UserInput::Text {+ text: "second follow-up".to_string(),+ text_elements: Vec::new(),+ }]+ );+ assert!(chat.queued_user_messages.is_empty());+}+#[tokio::test]async fn steer_enter_submits_when_plan_stream_is_not_active() {let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(None).await;