mirror of
https://github.com/openai/codex.git
synced 2026-11-26 23:40:43 +00:00
Prevent accidental TUI interrupts after a steer is accepted (#63784)
## Why A pending steering message offers a shortcut to interrupt the running turn and send the message immediately. If Codex accepts the message before the terminal redraws, pressing the shortcut while that hint is still visible can interrupt the turn even though the message has already been accepted. ## What changed Track whether the interrupt-and-send hint appeared in the last terminal frame. If Codex has since accepted the last pending steer for the running turn, ignore one interrupt press and its key repeats and briefly show “Message received. Ignored one interrupt.” A fresh press can still interrupt the turn. If the hint was never drawn or a redraw has removed it, the first press interrupts as usual. ## Testing Add regression coverage in both TUI rendering modes for an interrupt before and after redraw, a hint that was never displayed, held-key repeats, and an image submission in progress. GitOrigin-RevId: 8be3bd51c623af44c108987fe0c2148eeb4515c7
This commit is contained in:
@@ -178,6 +178,33 @@ impl ChatWidget {
|
||||
.then_some((cycle, environment))
|
||||
}
|
||||
|
||||
pub(crate) fn interrupts_acknowledged_steer(&self, key: KeyEvent) -> bool {
|
||||
self.turn_lifecycle.steer_hint == SteerHint::Acknowledged
|
||||
&& self.bottom_pane.should_interrupt_running_task(key)
|
||||
}
|
||||
|
||||
fn ignore_late_interrupt(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
activation_key: Option<KeyBinding>,
|
||||
) -> bool {
|
||||
if !self.interrupts_acknowledged_steer(key_event) {
|
||||
return false;
|
||||
}
|
||||
self.turn_lifecycle.steer_hint = SteerHint::Hidden;
|
||||
let key = activation_key.unwrap_or_else(|| KeyBinding::from_event(key_event));
|
||||
self.suppress_current_view_key_until_release(
|
||||
key,
|
||||
Instant::now(),
|
||||
ActivationKeySuppression::ReportedRepeats,
|
||||
);
|
||||
self.bottom_pane.show_footer_flash(
|
||||
"Message received. Ignored one interrupt.".dim().into(),
|
||||
Duration::from_secs(3),
|
||||
);
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn handle_key_event_with_activation_key(
|
||||
&mut self,
|
||||
key_event: KeyEvent,
|
||||
@@ -256,6 +283,9 @@ impl ChatWidget {
|
||||
&& self.pending_image_submission.is_some()
|
||||
{
|
||||
if self.is_cancellable_work_active() {
|
||||
if self.ignore_late_interrupt(key_event, activation_key) {
|
||||
return KeyEventAction::None;
|
||||
}
|
||||
self.requeue_image_submission();
|
||||
self.input_queue.recovered_queue = true;
|
||||
if self.submit_op(AppCommand::interrupt()) {
|
||||
@@ -381,6 +411,9 @@ impl ChatWidget {
|
||||
}
|
||||
_ => {
|
||||
let had_modal_or_popup = !self.bottom_pane.no_modal_or_popup_active();
|
||||
if self.ignore_late_interrupt(key_event, activation_key) {
|
||||
return KeyEventAction::None;
|
||||
}
|
||||
let should_pause_active_goal =
|
||||
self.bottom_pane.should_interrupt_running_task(key_event);
|
||||
let input_result = self
|
||||
|
||||
@@ -446,6 +446,20 @@ impl ChatWidget {
|
||||
(!lines.is_empty()).then_some(lines)
|
||||
}
|
||||
|
||||
/// Discard offscreen renders. Only a successful terminal draw changes key routing.
|
||||
pub(crate) fn begin_steer_hint_draw(&self) {
|
||||
self.bottom_pane.take_painted_steer_hint();
|
||||
}
|
||||
|
||||
pub(crate) fn finish_steer_hint_draw(&mut self) {
|
||||
self.turn_lifecycle.steer_hint =
|
||||
if self.bottom_pane.take_painted_steer_hint() && self.no_modal_or_popup_active() {
|
||||
SteerHint::Pending
|
||||
} else {
|
||||
SteerHint::Hidden
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) fn note_rendered_width(&self, width: u16) {
|
||||
self.last_rendered_width.set(Some(width));
|
||||
}
|
||||
|
||||
@@ -6,12 +6,21 @@ use std::time::Instant;
|
||||
|
||||
use codex_utils_sleep_inhibitor::SleepInhibitor;
|
||||
|
||||
/// State of the interrupt-and-send hint in the last terminal frame.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub(super) enum SteerHint {
|
||||
Hidden,
|
||||
Pending,
|
||||
Acknowledged,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(super) struct TurnLifecycleState {
|
||||
pub(super) sleep_inhibitor: SleepInhibitor,
|
||||
/// Tracks whether codex-core currently considers an agent turn to be in progress.
|
||||
pub(super) agent_turn_running: bool,
|
||||
pub(super) last_turn_id: Option<String>,
|
||||
pub(super) steer_hint: SteerHint,
|
||||
/// A live or restored turn makes the parent available for side-chat creation.
|
||||
pub(super) has_turn_history: bool,
|
||||
/// Cloud confirmed admission to a turn whose live start we have yet to process.
|
||||
@@ -29,6 +38,7 @@ impl TurnLifecycleState {
|
||||
sleep_inhibitor: SleepInhibitor::new(prevent_idle_sleep),
|
||||
agent_turn_running: false,
|
||||
last_turn_id: None,
|
||||
steer_hint: SteerHint::Hidden,
|
||||
has_turn_history: false,
|
||||
admitted_turn_id: None,
|
||||
budget_limited_turn_ids: HashSet::new(),
|
||||
@@ -39,12 +49,14 @@ impl TurnLifecycleState {
|
||||
}
|
||||
|
||||
pub(super) fn start(&mut self, now: Instant) {
|
||||
self.steer_hint = SteerHint::Hidden;
|
||||
self.agent_turn_running = true;
|
||||
self.goal_status_active_turn_started_at = Some(now);
|
||||
self.sleep_inhibitor.set_turn_running(/*turn_running*/ true);
|
||||
}
|
||||
|
||||
pub(super) fn finish(&mut self) {
|
||||
self.steer_hint = SteerHint::Hidden;
|
||||
self.agent_turn_running = false;
|
||||
self.goal_status_active_turn_started_at = None;
|
||||
self.sleep_inhibitor
|
||||
@@ -56,6 +68,7 @@ impl TurnLifecycleState {
|
||||
}
|
||||
|
||||
pub(super) fn restore_running(&mut self, running: bool, now: Instant) {
|
||||
self.steer_hint = SteerHint::Hidden;
|
||||
self.agent_turn_running = running;
|
||||
self.goal_status_active_turn_started_at = running.then_some(now);
|
||||
self.sleep_inhibitor.set_turn_running(running);
|
||||
|
||||
Reference in New Issue
Block a user