mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Cancel folder trust prompts when the app server disconnects (#63262)
## Why A daemon restart can invalidate the connection while a folder trust prompt is open. A queued confirmation can otherwise still be handled against that closed connection. ## What changed Dismiss the folder trust prompt when the connection closes, giving the disconnect priority over queued input. Leave the disconnect event for the Agents overview to handle. During startup, exit with a message asking the user to restart Codex. ## Testing Add tests for daemon restarts during folder consent in the Agents overview and at startup. Both check that the restart leaves the trust setting unset. A unit test checks that disconnect wins over queued Enter. GitOrigin-RevId: 21ee1ca625ed8bc2266a9a37a260254d4e87369d
This commit is contained in:
committed by
copyberry
parent
326bac6ce0
commit
794584993e
@@ -2069,6 +2069,14 @@ async fn run_ratatui_app(
|
||||
trust_decision_was_made = true;
|
||||
}
|
||||
} else if consent.should_exit {
|
||||
// Startup cannot return to the overview's reconnect loop until bootstrap completes.
|
||||
if let codex_app_server_client::AppServerRequestHandle::Remote(handle) =
|
||||
app_server.request_handle()
|
||||
&& handle.is_closed()
|
||||
{
|
||||
shutdown_startup_session(Some(app_server), &mut terminal_restore_guard).await;
|
||||
color_eyre::eyre::bail!(onboarding::SETUP_CONNECTION_LOST);
|
||||
}
|
||||
if !uses_remote_workspace {
|
||||
config = load_config_or_exit_with_fallback_cwd(
|
||||
cli_kv_overrides.clone(),
|
||||
|
||||
@@ -58,6 +58,7 @@ use crate::tui::Tui;
|
||||
use crate::tui::TuiEvent;
|
||||
use color_eyre::eyre::Result;
|
||||
use color_eyre::eyre::WrapErr;
|
||||
use std::ops::ControlFlow;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use uuid::Uuid;
|
||||
@@ -697,6 +698,19 @@ pub(super) async fn run_onboarding_screen(
|
||||
result.and_then(|result| restore.map(|()| result).map_err(Into::into))
|
||||
}
|
||||
|
||||
// A queued confirmation must not accept a disconnected folder, even when opening
|
||||
// restricted would complete without an RPC. Leave the disconnect event for the app.
|
||||
async fn folder_input(
|
||||
closed: impl Future<Output = ()>,
|
||||
input: impl Future<Output = Option<TuiEvent>>,
|
||||
) -> ControlFlow<(), Option<TuiEvent>> {
|
||||
tokio::select! {
|
||||
biased;
|
||||
() = closed => ControlFlow::Break(()),
|
||||
event = input => ControlFlow::Continue(event),
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_onboarding_screen_inner(
|
||||
mut onboarding_screen: OnboardingScreen,
|
||||
app_server_request_handle: Option<AppServerRequestHandle>,
|
||||
@@ -718,6 +732,14 @@ async fn run_onboarding_screen_inner(
|
||||
tokio::pin!(tui_events);
|
||||
let mut trust_step_was_active = onboarding_screen.is_trust_step_active();
|
||||
|
||||
let folder_connection = match (
|
||||
&app_server_request_handle,
|
||||
onboarding_screen.steps.as_slice(),
|
||||
) {
|
||||
(Some(AppServerRequestHandle::Remote(handle)), [Step::TrustDirectory(_)]) => Some(handle),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
while !onboarding_screen.is_done() {
|
||||
tokio::select! {
|
||||
() = async {
|
||||
@@ -726,7 +748,20 @@ async fn run_onboarding_screen_inner(
|
||||
None => std::future::pending().await,
|
||||
}
|
||||
} => {}
|
||||
event = tui_events.next() => {
|
||||
event = async {
|
||||
let input = tui_events.next();
|
||||
match folder_connection {
|
||||
Some(handle) => folder_input(handle.closed(), input).await,
|
||||
None => ControlFlow::Continue(input.await),
|
||||
}
|
||||
} => {
|
||||
let ControlFlow::Continue(event) = event else {
|
||||
tui.discard_pending_input_before_interactive_screen()?;
|
||||
return Ok(OnboardingResult {
|
||||
should_exit: true,
|
||||
..Default::default()
|
||||
});
|
||||
};
|
||||
if let Some(event) = event {
|
||||
tui.screen_size_for_event(&event)?;
|
||||
match event {
|
||||
@@ -1013,6 +1048,14 @@ mod tests {
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[tokio::test]
|
||||
async fn folder_disconnect_wins_over_queued_enter() {
|
||||
let enter = super::TuiEvent::Key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
|
||||
let event =
|
||||
super::folder_input(std::future::ready(()), std::future::ready(Some(enter))).await;
|
||||
assert!(event.is_break());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suppresses_printable_quit_key_during_api_key_entry() {
|
||||
let suppressed = suppress_quit_while_typing(
|
||||
|
||||
Reference in New Issue
Block a user