mirror of
https://github.com/openai/codex.git
synced 2026-11-22 07:13:50 +00:00
Dismiss stale app-server requests after remote resolution (#15134)
Dismiss stale TUI app-server approvals after remote resolution When an approval, user-input prompt, or elicitation request is resolved by another client, the TUI now dismisses the matching local UI instead of leaving stale prompts behind and emitting a misleading local cancellation. This change teaches pending app-server request tracking to map `serverRequest/resolved` notifications back to the concrete request type and stable request key, then propagates that resolved request into TUI prompt state. Approval, request-user-input, and MCP elicitation overlays now drop the resolved current or queued request quietly, advance to the next queued request when present, and avoid emitting abort/cancel events for stale UI. The latest update also retires matching prompts while they are still deferred behind active streaming and suppresses buffered active-thread requests whose app-server request id has already been resolved before drain. `ChatWidget` removes a resolved request from both the deferred interrupt queue and the materialized bottom-pane stack, while active-thread request handling verifies the app-server request is still pending before showing a prompt. Lifecycle events such as exec begin/end remain queued so approved work can still render normally. Tests cover resolved-request mapping, overlay dismissal behavior, deferred prompt pruning for same-turn user input, exec approval IDs, lifecycle-event retention, and the buffered active-thread ordering regression. Validation: - `just fmt` - `git diff --check` - `cargo test -p codex-tui resolved_buffered_approval_does_not_become_actionable_after_drain` - `cargo test -p codex-tui enqueue_primary_thread_session_replays_buffered_approval_after_attach` - `cargo test -p codex-tui chatwidget::interrupts` - `just fix -p codex-tui` --------- Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
1 parent
ba36415a30
commit
bc969b6516
12 files changed
+1164
-56
No files matched your search
@@ -15,6 +15,7 @@
|
||||
//! hint. The pane schedules redraws so those hints can expire even when the UI is otherwise idle.
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::app::app_server_requests::ResolvedAppServerRequest;
|
||||
use crate::app_event::ConnectorsSnapshot;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::bottom_pane::pending_input_preview::PendingInputPreview;
|
||||
@@ -379,6 +380,18 @@ impl BottomPane {
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
fn pop_active_view(&mut self) {
|
||||
if self.view_stack.pop().is_some() {
|
||||
self.on_view_stack_depth_decreased();
|
||||
}
|
||||
}
|
||||
|
||||
fn on_view_stack_depth_decreased(&mut self) {
|
||||
if self.view_stack.is_empty() {
|
||||
self.on_active_view_complete();
|
||||
}
|
||||
}
|
||||
|
||||
/// Forward a key event to the active view or the composer.
|
||||
pub fn handle_key_event(&mut self, key_event: KeyEvent) -> InputResult {
|
||||
// If a modal/view is active, handle it here; otherwise forward to composer.
|
||||
@@ -408,16 +421,14 @@ impl BottomPane {
|
||||
};
|
||||
|
||||
if ctrl_c_completed {
|
||||
self.view_stack.pop();
|
||||
self.on_active_view_complete();
|
||||
self.pop_active_view();
|
||||
if let Some(next_view) = self.view_stack.last()
|
||||
&& next_view.is_in_paste_burst()
|
||||
{
|
||||
self.request_redraw_in(ChatComposer::recommended_paste_flush_delay());
|
||||
}
|
||||
} else if view_complete {
|
||||
self.view_stack.clear();
|
||||
self.on_active_view_complete();
|
||||
self.pop_active_view();
|
||||
} else if view_in_paste_burst {
|
||||
self.request_redraw_in(ChatComposer::recommended_paste_flush_delay());
|
||||
}
|
||||
@@ -469,10 +480,10 @@ impl BottomPane {
|
||||
pub(crate) fn on_ctrl_c(&mut self) -> CancellationEvent {
|
||||
if let Some(view) = self.view_stack.last_mut() {
|
||||
let event = view.on_ctrl_c();
|
||||
let view_complete = view.is_complete();
|
||||
if matches!(event, CancellationEvent::Handled) {
|
||||
if view.is_complete() {
|
||||
self.view_stack.pop();
|
||||
self.on_active_view_complete();
|
||||
if view_complete {
|
||||
self.pop_active_view();
|
||||
}
|
||||
self.show_quit_shortcut_hint(key_hint::ctrl(KeyCode::Char('c')));
|
||||
self.request_redraw();
|
||||
@@ -493,17 +504,14 @@ impl BottomPane {
|
||||
}
|
||||
|
||||
pub fn handle_paste(&mut self, pasted: String) {
|
||||
if !self.view_stack.is_empty() {
|
||||
let (needs_redraw, view_complete) = {
|
||||
let last_index = self.view_stack.len() - 1;
|
||||
let view = &mut self.view_stack[last_index];
|
||||
(view.handle_paste(pasted), view.is_complete())
|
||||
};
|
||||
if let Some(view) = self.view_stack.last_mut() {
|
||||
let needs_redraw = view.handle_paste(pasted);
|
||||
let view_complete = view.is_complete();
|
||||
if view_complete {
|
||||
self.view_stack.clear();
|
||||
self.on_active_view_complete();
|
||||
}
|
||||
if needs_redraw {
|
||||
if needs_redraw || view_complete {
|
||||
self.request_redraw();
|
||||
}
|
||||
} else {
|
||||
@@ -1032,6 +1040,37 @@ impl BottomPane {
|
||||
self.push_view(Box::new(modal));
|
||||
}
|
||||
|
||||
pub(crate) fn dismiss_app_server_request(
|
||||
&mut self,
|
||||
request: &ResolvedAppServerRequest,
|
||||
) -> bool {
|
||||
if self.view_stack.is_empty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let mut changed = false;
|
||||
let mut completed_indices = Vec::new();
|
||||
for index in (0..self.view_stack.len()).rev() {
|
||||
let view = &mut self.view_stack[index];
|
||||
if !view.dismiss_app_server_request(request) {
|
||||
continue;
|
||||
}
|
||||
changed = true;
|
||||
if view.is_complete() {
|
||||
completed_indices.push(index);
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
return false;
|
||||
}
|
||||
for index in completed_indices {
|
||||
self.view_stack.remove(index);
|
||||
}
|
||||
self.on_view_stack_depth_decreased();
|
||||
self.request_redraw();
|
||||
true
|
||||
}
|
||||
|
||||
fn on_active_view_complete(&mut self) {
|
||||
self.resume_status_timer_after_modal();
|
||||
self.set_composer_input_enabled(/*enabled*/ true, /*placeholder*/ None);
|
||||
@@ -1241,6 +1280,7 @@ impl Renderable for BottomPane {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::app::app_server_requests::ResolvedAppServerRequest;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::status_indicator_widget::STATUS_DETAILS_DEFAULT_MAX_LINES;
|
||||
use crate::status_indicator_widget::StatusDetailsCapitalization;
|
||||
@@ -1248,9 +1288,12 @@ mod tests {
|
||||
use crate::test_support::test_path_buf;
|
||||
use codex_protocol::protocol::Op;
|
||||
use codex_protocol::protocol::SkillScope;
|
||||
use crossterm::event::KeyCode;
|
||||
use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyEventKind;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use insta::assert_snapshot;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use std::cell::Cell;
|
||||
@@ -1275,6 +1318,19 @@ mod tests {
|
||||
snapshot_buffer(&buf)
|
||||
}
|
||||
|
||||
fn test_pane(app_event_tx: AppEventSender) -> BottomPane {
|
||||
BottomPane::new(BottomPaneParams {
|
||||
app_event_tx,
|
||||
frame_requester: FrameRequester::test_dummy(),
|
||||
has_input_focus: true,
|
||||
enhanced_keys_supported: false,
|
||||
placeholder_text: "Ask Codex to do anything".to_string(),
|
||||
disable_paste_burst: false,
|
||||
animations_enabled: true,
|
||||
skills: Some(Vec::new()),
|
||||
})
|
||||
}
|
||||
|
||||
fn exec_request() -> ApprovalRequest {
|
||||
ApprovalRequest::Exec {
|
||||
thread_id: codex_protocol::ThreadId::new(),
|
||||
@@ -1291,6 +1347,73 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct DismissibleView {
|
||||
id: Option<&'static str>,
|
||||
dismiss_exec_id: Option<&'static str>,
|
||||
complete: bool,
|
||||
}
|
||||
|
||||
impl Renderable for DismissibleView {
|
||||
fn render(&self, _area: Rect, _buf: &mut Buffer) {}
|
||||
|
||||
fn desired_height(&self, _width: u16) -> u16 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl BottomPaneView for DismissibleView {
|
||||
fn is_complete(&self) -> bool {
|
||||
self.complete
|
||||
}
|
||||
|
||||
fn view_id(&self) -> Option<&'static str> {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn dismiss_app_server_request(&mut self, request: &ResolvedAppServerRequest) -> bool {
|
||||
let ResolvedAppServerRequest::ExecApproval { id } = request else {
|
||||
return false;
|
||||
};
|
||||
if self.dismiss_exec_id != Some(id.as_str()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.complete = true;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct CompletingView {
|
||||
id: Option<&'static str>,
|
||||
complete: bool,
|
||||
}
|
||||
|
||||
impl Renderable for CompletingView {
|
||||
fn render(&self, _area: Rect, _buf: &mut Buffer) {}
|
||||
|
||||
fn desired_height(&self, _width: u16) -> u16 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl BottomPaneView for CompletingView {
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
if key_event.code == KeyCode::Enter {
|
||||
self.complete = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn is_complete(&self) -> bool {
|
||||
self.complete
|
||||
}
|
||||
|
||||
fn view_id(&self) -> Option<&'static str> {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ctrl_c_on_modal_consumes_without_showing_quit_hint() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
@@ -1373,6 +1496,89 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dismiss_app_server_request_removes_matching_buried_view() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let mut pane = test_pane(tx);
|
||||
|
||||
pane.push_view(Box::new(DismissibleView {
|
||||
id: Some("buried"),
|
||||
dismiss_exec_id: Some("request-1"),
|
||||
complete: false,
|
||||
}));
|
||||
pane.push_view(Box::new(DismissibleView {
|
||||
id: Some("top"),
|
||||
dismiss_exec_id: None,
|
||||
complete: false,
|
||||
}));
|
||||
|
||||
assert!(
|
||||
pane.dismiss_app_server_request(&ResolvedAppServerRequest::ExecApproval {
|
||||
id: "request-1".to_string(),
|
||||
})
|
||||
);
|
||||
assert_eq!(pane.view_stack.len(), 1);
|
||||
assert_eq!(
|
||||
pane.view_stack.last().and_then(|view| view.view_id()),
|
||||
Some("top")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dismiss_app_server_request_returns_false_when_no_view_matches() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let mut pane = test_pane(tx);
|
||||
|
||||
pane.push_view(Box::new(DismissibleView {
|
||||
id: Some("first"),
|
||||
dismiss_exec_id: Some("other-request"),
|
||||
complete: false,
|
||||
}));
|
||||
pane.push_view(Box::new(DismissibleView {
|
||||
id: Some("second"),
|
||||
dismiss_exec_id: None,
|
||||
complete: false,
|
||||
}));
|
||||
|
||||
assert!(
|
||||
!pane.dismiss_app_server_request(&ResolvedAppServerRequest::ExecApproval {
|
||||
id: "request-1".to_string(),
|
||||
})
|
||||
);
|
||||
assert_eq!(pane.view_stack.len(), 2);
|
||||
assert_eq!(
|
||||
pane.view_stack.last().and_then(|view| view.view_id()),
|
||||
Some("second")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn completing_top_view_preserves_underlying_view() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
let tx = AppEventSender::new(tx_raw);
|
||||
let mut pane = test_pane(tx);
|
||||
|
||||
pane.push_view(Box::new(DismissibleView {
|
||||
id: Some("underlying"),
|
||||
dismiss_exec_id: None,
|
||||
complete: false,
|
||||
}));
|
||||
pane.push_view(Box::new(CompletingView {
|
||||
id: Some("top"),
|
||||
complete: false,
|
||||
}));
|
||||
|
||||
pane.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
|
||||
assert_eq!(pane.view_stack.len(), 1);
|
||||
assert_eq!(
|
||||
pane.view_stack.last().and_then(|view| view.view_id()),
|
||||
Some("underlying")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn composer_shown_after_denied_while_task_running() {
|
||||
let (tx_raw, _rx) = unbounded_channel::<AppEvent>();
|
||||
|
||||
Reference in new issue
Block a user