mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Keep interrupt guidance visible during TUI streaming (#64018)
## Why Streaming output hides the working status row and its interrupt shortcut. When a message without a phase finishes before the turn does, the status row can also stay hidden while Codex is still working. ## What changed Show the configured interrupt shortcut in the composer footer while output streams and the status row is hidden. With the default binding, the footer shows `esc twice to interrupt` in Vim insert mode. Keep the status row visible through whitespace-only output. Restore it after a message without a phase completes and the stream queues drain if the turn is still running. ## Testing Cover whitespace-only output, footer hints with a draft and in Vim modes, hint layout at narrow widths, and status restoration before turn completion. GitOrigin-RevId: 246180593baf2d6ead0e84634bf7bd8ee4ec3ea5
This commit is contained in:
@@ -369,6 +369,17 @@ impl ChatWidget {
|
||||
};
|
||||
options.rendered_selection = Some(&self.rendered_selection);
|
||||
options.image_previews = self.composer_images.as_ref();
|
||||
if self.turn_lifecycle.agent_turn_running
|
||||
&& !self.statusline_disconnected
|
||||
&& self.bottom_pane.status_widget().is_none()
|
||||
&& self.input_queue.pending_steers.is_empty()
|
||||
&& (self.stream_controller.is_some() || self.plan_stream_controller.is_some())
|
||||
{
|
||||
options.stream_interrupt_key = self
|
||||
.bottom_pane
|
||||
.keymap()
|
||||
.primary_hint(KeymapContext::Chat, "interrupt_turn");
|
||||
}
|
||||
options.warning_count = self.warning_display_state.count;
|
||||
options.textarea_right_reserve = right_reserve;
|
||||
options.separate_status_line = options.command_popup_placement
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "hook_status_frame(&chat, 60)"
|
||||
---
|
||||
" "
|
||||
"• Working (0s • esc to interrupt) "
|
||||
" "
|
||||
" "
|
||||
"› Ask Codex to do anything "
|
||||
" "
|
||||
" GPT-5.6-Sol default · /tmp/project "
|
||||
" ? for shortcuts "
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tui/src/chatwidget/tests/status_and_layout.rs
|
||||
expression: "hints.join(\"\\n\")"
|
||||
---
|
||||
" esc to interrupt "
|
||||
" tab to queue message · esc to interrupt "
|
||||
" tab to queue "
|
||||
" esc twice to interrupt Vim: Insert "
|
||||
" esc to interrupt Vim: Normal "
|
||||
@@ -195,12 +195,12 @@ impl ChatWidget {
|
||||
.unwrap_or(true)
|
||||
}
|
||||
|
||||
/// Restore the status indicator only after commentary completion is pending,
|
||||
/// Restore the status indicator only after message completion is pending,
|
||||
/// the turn is still running, and all stream queues have drained.
|
||||
///
|
||||
/// This gate prevents flicker while normal output is still actively
|
||||
/// streaming, but still restores a visible "working" affordance when a
|
||||
/// commentary block ends before the turn itself has completed.
|
||||
/// message ends before the turn itself has completed.
|
||||
pub(super) fn maybe_restore_status_indicator_after_stream_idle(&mut self) {
|
||||
if !self.status_state.pending_status_indicator_restore
|
||||
|| !self.bottom_pane.is_task_running()
|
||||
@@ -300,7 +300,13 @@ impl ChatWidget {
|
||||
message: &str,
|
||||
phase: Option<MessagePhase>,
|
||||
) {
|
||||
if self.stream_controller.is_none() && !message.is_empty() {
|
||||
if !message.trim().is_empty()
|
||||
&& self
|
||||
.stream_controller
|
||||
.as_ref()
|
||||
.is_none_or(|stream| !stream.has_text())
|
||||
{
|
||||
self.stream_controller = None;
|
||||
let displayed =
|
||||
parse_assistant_markdown(message, self.config.cwd.as_path()).visible_markdown;
|
||||
self.handle_streaming_delta(displayed);
|
||||
@@ -563,9 +569,7 @@ impl ChatWidget {
|
||||
|
||||
/// Handle completion of an `AgentMessage` turn item.
|
||||
///
|
||||
/// Commentary completion sets a deferred restore flag so the status row
|
||||
/// returns once stream queues are idle. Final-answer completion (or absent
|
||||
/// phase for legacy models) clears the flag to preserve historical behavior.
|
||||
/// An unphased message can finish while the turn still has work to do.
|
||||
pub(super) fn on_agent_message_item_completed(
|
||||
&mut self,
|
||||
item: AgentMessageItem,
|
||||
@@ -755,7 +759,9 @@ impl ChatWidget {
|
||||
}
|
||||
self.status_state.pending_status_indicator_restore = item.questions.is_some()
|
||||
|| match item.phase {
|
||||
// Models that don't support preambles only output AgentMessageItems on turn completion.
|
||||
None if self.turn_lifecycle.agent_turn_running && !self.statusline_disconnected => {
|
||||
true
|
||||
}
|
||||
Some(MessagePhase::FinalAnswer) | None => {
|
||||
!self.input_queue.pending_steers.is_empty()
|
||||
}
|
||||
@@ -784,7 +790,7 @@ impl ChatWidget {
|
||||
///
|
||||
/// `scope` selects paced, catch-up, or replay draining. While lines are actively streaming
|
||||
/// we hide the status row to avoid duplicate "in progress" affordances. We only re-show
|
||||
/// the row after commentary completion once stream queues are idle.
|
||||
/// the row after message completion once stream queues are idle.
|
||||
pub(crate) fn run_commit_tick_with_scope(&mut self, scope: CommitTickScope) {
|
||||
let now = Instant::now();
|
||||
let outcome = run_commit_tick(
|
||||
|
||||
@@ -2684,22 +2684,53 @@ fn assert_goal_paused_event(
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn idle_commit_ticks_do_not_restore_status_without_commentary_completion() {
|
||||
async fn unphased_stream_keeps_activity_visible_until_turn_completion() {
|
||||
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
handle_turn_started(&mut chat, "turn-1");
|
||||
|
||||
chat.on_task_started();
|
||||
assert_eq!(chat.bottom_pane.status_indicator_visible(), true);
|
||||
|
||||
chat.on_agent_message_delta("Final answer line\n".to_string());
|
||||
let whitespace = "\u{3000}\n";
|
||||
handle_agent_message_delta(&mut chat, whitespace);
|
||||
chat.on_commit_tick();
|
||||
drain_insert_history(&mut rx);
|
||||
assert!(drain_insert_history(&mut rx).is_empty());
|
||||
assert!(chat.bottom_pane.status_indicator_visible());
|
||||
complete_assistant_message(&mut chat, "msg-1", whitespace, /*phase*/ None);
|
||||
assert!(chat.bottom_pane.status_indicator_visible());
|
||||
|
||||
assert_eq!(chat.bottom_pane.status_indicator_visible(), false);
|
||||
assert_eq!(chat.bottom_pane.is_task_running(), true);
|
||||
|
||||
// A second idle tick should not toggle the row back on and cause jitter.
|
||||
chat.on_agent_message_delta("Checking the workbook.\n".to_string());
|
||||
chat.on_commit_tick();
|
||||
assert_eq!(chat.bottom_pane.status_indicator_visible(), false);
|
||||
chat.on_commit_tick();
|
||||
let footer = |chat: &ChatWidget, width| {
|
||||
hook_status_frame(chat, width)
|
||||
.lines()
|
||||
.last()
|
||||
.unwrap()
|
||||
.to_owned()
|
||||
};
|
||||
assert!(!chat.bottom_pane.status_indicator_visible());
|
||||
let mut hints = vec![footer(&chat, 60)];
|
||||
chat.apply_external_edit("Follow up".into());
|
||||
hints.push(footer(&chat, 60));
|
||||
hints.push(footer(&chat, 26));
|
||||
chat.apply_external_edit(String::new());
|
||||
chat.bottom_pane.set_vim_enabled(/*enabled*/ true);
|
||||
chat.handle_key_event(KeyCode::Insert.into());
|
||||
hints.push(footer(&chat, 60));
|
||||
chat.handle_key_event(KeyCode::Esc.into());
|
||||
hints.push(footer(&chat, 60));
|
||||
chat.bottom_pane.set_vim_enabled(/*enabled*/ false);
|
||||
assert_chatwidget_snapshot!("streaming_interrupt_hint", hints.join("\n"));
|
||||
complete_assistant_message(
|
||||
&mut chat,
|
||||
"msg-2",
|
||||
"Checking the workbook.",
|
||||
/*phase*/ None,
|
||||
);
|
||||
assert_chatwidget_snapshot!(
|
||||
"paused_unphased_message",
|
||||
hook_status_frame(&chat, /*width*/ 60)
|
||||
);
|
||||
handle_turn_completed(&mut chat, "turn-1", /*duration_ms*/ None);
|
||||
assert!(!chat.bottom_pane.status_indicator_visible());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user