mirror of
https://github.com/openai/codex.git
synced 2026-11-19 23:05:23 +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
+73
-3
@@ -164,7 +164,7 @@ use toml::Value as TomlValue;
|
||||
use uuid::Uuid;
|
||||
mod agent_navigation;
|
||||
mod app_server_adapter;
|
||||
mod app_server_requests;
|
||||
pub(crate) mod app_server_requests;
|
||||
mod loaded_threads;
|
||||
mod pending_interactive_replay;
|
||||
|
||||
@@ -5895,8 +5895,13 @@ impl App {
|
||||
.handle_server_notification(notification, /*replay_kind*/ None);
|
||||
}
|
||||
ThreadBufferedEvent::Request(request) => {
|
||||
self.chat_widget
|
||||
.handle_server_request(request, /*replay_kind*/ None);
|
||||
if self
|
||||
.pending_app_server_requests
|
||||
.contains_server_request(&request)
|
||||
{
|
||||
self.chat_widget
|
||||
.handle_server_request(request, /*replay_kind*/ None);
|
||||
}
|
||||
}
|
||||
ThreadBufferedEvent::HistoryEntryResponse(event) => {
|
||||
self.chat_widget.handle_history_entry_response(event);
|
||||
@@ -6884,6 +6889,11 @@ mod tests {
|
||||
let approval_request =
|
||||
exec_approval_request(thread_id, "turn-1", "call-1", /*approval_id*/ None);
|
||||
|
||||
assert_eq!(
|
||||
app.pending_app_server_requests
|
||||
.note_server_request(&approval_request),
|
||||
None
|
||||
);
|
||||
app.enqueue_primary_thread_request(approval_request).await?;
|
||||
app.enqueue_primary_thread_session(
|
||||
test_thread_session(thread_id, test_path_buf("/tmp/project")),
|
||||
@@ -6926,6 +6936,66 @@ mod tests {
|
||||
panic!("expected approval action to submit a thread-scoped op");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn resolved_buffered_approval_does_not_become_actionable_after_drain() -> Result<()> {
|
||||
let (mut app, mut app_event_rx, _op_rx) = make_test_app_with_channels().await;
|
||||
let thread_id = ThreadId::new();
|
||||
let approval_request =
|
||||
exec_approval_request(thread_id, "turn-1", "call-1", /*approval_id*/ None);
|
||||
|
||||
app.enqueue_primary_thread_session(
|
||||
test_thread_session(thread_id, test_path_buf("/tmp/project")),
|
||||
Vec::new(),
|
||||
)
|
||||
.await?;
|
||||
while app_event_rx.try_recv().is_ok() {}
|
||||
|
||||
assert_eq!(
|
||||
app.pending_app_server_requests
|
||||
.note_server_request(&approval_request),
|
||||
None
|
||||
);
|
||||
app.enqueue_thread_request(thread_id, approval_request)
|
||||
.await?;
|
||||
|
||||
let resolved = app
|
||||
.pending_app_server_requests
|
||||
.resolve_notification(&AppServerRequestId::Integer(1))
|
||||
.expect("matching app-server request should resolve");
|
||||
app.chat_widget.dismiss_app_server_request(&resolved);
|
||||
while app_event_rx.try_recv().is_ok() {}
|
||||
|
||||
let rx = app
|
||||
.active_thread_rx
|
||||
.as_mut()
|
||||
.expect("primary thread receiver should be active");
|
||||
let event = time::timeout(Duration::from_millis(50), rx.recv())
|
||||
.await
|
||||
.expect("timed out waiting for buffered approval event")
|
||||
.expect("channel closed unexpectedly");
|
||||
|
||||
assert!(matches!(
|
||||
&event,
|
||||
ThreadBufferedEvent::Request(ServerRequest::CommandExecutionRequestApproval {
|
||||
params,
|
||||
..
|
||||
}) if params.turn_id == "turn-1"
|
||||
));
|
||||
|
||||
app.handle_thread_event_now(event);
|
||||
app.chat_widget
|
||||
.handle_key_event(KeyEvent::new(KeyCode::Char('y'), KeyModifiers::NONE));
|
||||
|
||||
while let Ok(app_event) = app_event_rx.try_recv() {
|
||||
assert!(
|
||||
!matches!(app_event, AppEvent::SubmitThreadOp { .. }),
|
||||
"resolved buffered approval should not become actionable"
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn enqueue_primary_thread_session_replays_turns_before_initial_prompt_submit()
|
||||
-> Result<()> {
|
||||
|
||||
Reference in new issue
Block a user