From 4fa7e82274bd70e145da05c66117865f7615e61d Mon Sep 17 00:00:00 2001 From: Darius Karel Date: Wed, 16 Sep 2026 21:48:50 +0000 Subject: [PATCH] Preserve config error causes when saving the approvals reviewer (#46036) ## Why Failures to save `approvals_reviewer` in the TUI hide the underlying configuration error, leaving users without the details needed to fix it. ## What changed Use `format_config_error` when displaying save failures so the message includes the error chain, including configuration file locations and parse errors. ## Testing Add a regression test that introduces an unclosed array in `config.toml` after startup, attempts to save the approvals reviewer through the app server, and verifies the rendered error retains the parse failure and its location. GitOrigin-RevId: bb29b5f8e61569e6c1c23a0c968e64091a95f72d --- codex-rs/tui/src/app/event_dispatch.rs | 6 ++- codex-rs/tui/src/app/tests.rs | 2 + .../tests/approvals_reviewer_error_tests.rs | 38 +++++++++++++++++++ ...ests__approvals_reviewer_config_error.snap | 6 +++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs create mode 100644 codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs index 318e4b933f..595b996be9 100644 --- a/codex-rs/tui/src/app/event_dispatch.rs +++ b/codex-rs/tui/src/app/event_dispatch.rs @@ -2335,8 +2335,10 @@ impl App { error = %err, "failed to persist approvals reviewer update" ); - self.chat_widget - .add_error_message(format!("Failed to save approvals reviewer: {err}")); + self.chat_widget.add_error_message(format!( + "Failed to save approvals reviewer: {}", + format_config_error(&err) + )); } } AppEvent::FetchExperimentalFeatures { thread_id, response_tx } => { diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rs index f82320005b..715ffbf4a9 100644 --- a/codex-rs/tui/src/app/tests.rs +++ b/codex-rs/tui/src/app/tests.rs @@ -9,6 +9,8 @@ mod math_interruption_tests; mod advanced_reasoning_tests; #[path = "tests/agents_navigation_tests.rs"] mod agents_navigation_tests; +#[path = "tests/approvals_reviewer_error_tests.rs"] +mod approvals_reviewer_error_tests; #[path = "tests/backend_banner_fallback_tests.rs"] mod backend_banner_fallback_tests; #[path = "tests/backend_banner_recovery_tests.rs"] diff --git a/codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs b/codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs new file mode 100644 index 0000000000..d0ca48d7f8 --- /dev/null +++ b/codex-rs/tui/src/app/tests/approvals_reviewer_error_tests.rs @@ -0,0 +1,38 @@ +//! Verify that approvals persistence failures retain the backend's actionable cause. + +use super::*; + +#[tokio::test] +async fn approvals_reviewer_error_retains_config_cause() -> Result<()> { + let (mut app, mut events, _op_rx) = make_test_app_with_channels().await; + let codex_home = tempdir()?; + app.config.codex_home = codex_home.path().to_path_buf().abs(); + let config_path = codex_home.path().join("config.toml"); + std::fs::write(&config_path, "")?; + let mut app_server = start_config_write_test_app_server(&app).await?; + let mut tui = crate::tui::test_support::make_test_tui()?; + while events.try_recv().is_ok() {} + + // Simulate an external config edit after startup so the real batch-write + // reload fails, rather than injecting an already-formatted UI error. + std::fs::write(&config_path, "approvals_reviewer = [\n")?; + Box::pin(app.handle_event( + &mut tui, + &mut app_server, + AppEvent::UpdateApprovalsReviewer(ApprovalsReviewer::User), + )) + .await?; + app_server.shutdown().await?; + + let cell = match events.try_recv() { + Ok(AppEvent::InsertHistoryCell(cell)) => cell, + other => panic!("expected the persistence error, got {other:?}"), + }; + let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 120)).replace( + &config_path.to_string_lossy().to_string(), + "/config.toml", + ); + assert!(rendered.contains("unclosed array"), "{rendered}"); + insta::assert_snapshot!("approvals_reviewer_config_error", rendered); + Ok(()) +} diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap new file mode 100644 index 0000000000..ed4e880e4d --- /dev/null +++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__approvals_reviewer_error_tests__approvals_reviewer_config_error.snap @@ -0,0 +1,6 @@ +--- +source: tui/src/app/tests/approvals_reviewer_error_tests.rs +assertion_line: 34 +expression: rendered +--- +■ Failed to save approvals reviewer: config/batchWrite failed in TUI: config/batchWrite failed: failed to load configuration: /config.toml:1:24: unclosed array, expected `]` (code -32603)