Let users open the command center from provider error screens (#62335)

## Why

Read-only chats offer a Left Arrow shortcut to the command center when
agent navigation is available. Chats blocked by model provider errors
were missing that shortcut.

## What changed

Share notice rendering and shortcut availability between provider
errors and read-only threads. Show `← command center` on provider error
notices when the shortcut is available, and open it on a plain Left
Arrow press even when offline.

## Testing

Add a regression test that checks the shortcut hint, verifies that
repeat events leave the notice open, and confirms that opening the
command center preserves the draft both online and offline. Update
provider error snapshots to cover the new hint, including at narrow
terminal widths.

GitOrigin-RevId: be2ce80cade02c84baeff7fd48fa8973f0dcc1dc
This commit is contained in:
Benjamin Carlsson
2026-11-18 18:48:22 +00:00
committed by copyberry
parent 0a82fdf49d
commit 58ad62ce09
7 changed files with 201 additions and 160 deletions
+5 -4
View File
@@ -1294,10 +1294,11 @@ impl App {
{
if self.overlay.is_none()
&& self.chat_widget.no_modal_or_popup_active()
&& self.chat_widget.is_read_only_view()
&& (crate::key_hint::plain(KeyCode::Esc).is_press(*key)
|| (crate::key_hint::plain(KeyCode::Left).is_press(*key)
&& self.chat_widget.agents_navigation_key_available()))
&& ((self.chat_widget.is_read_only_view()
&& crate::key_hint::plain(KeyCode::Esc).is_press(*key))
|| self
.chat_widget
.blocked_thread_command_center_key_pressed(*key))
{
self.open_agents_overview(app_server);
} else if self
+8 -9
View File
@@ -708,18 +708,17 @@ impl App {
return;
}
if self.chat_widget.is_read_only_view()
&& self.overlay.is_none()
&& self.chat_widget.no_modal_or_popup_active()
{
if key_event.kind == KeyEventKind::Press
&& key_event.code == KeyCode::Left
&& key_event.modifiers == KeyModifiers::NONE
&& self.chat_widget.agents_navigation_key_available()
if self.overlay.is_none() && self.chat_widget.no_modal_or_popup_active() {
if self
.chat_widget
.blocked_thread_command_center_key_pressed(key_event)
{
self.open_agents_overview(app_server);
return;
}
if self.chat_widget.is_read_only_view() {
return;
}
return;
}
if self.should_handle_unavailable_thread_key(key_event) {
@@ -133,6 +133,51 @@ async fn externally_archived_thread_keeps_advertised_agents_navigation() -> Resu
Ok(())
}
#[tokio::test]
async fn provider_error_opens_command_center_with_left() -> Result<()> {
for offline in [false, true] {
let (mut app, _, _) = make_test_app_with_channels().await;
app.chat_widget.insert_str("Retained draft");
app.chat_widget.show_provider_error(
codex_app_server_protocol::ModelProviderError::ModelProviderNotConfigured {
model_provider: "missing".into(),
},
/*rejected_message_id*/ None,
);
app.reconnect.offline = offline;
let mut app_server = start_config_write_test_app_server(&app).await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
tui.set_owned_screen(/*owned*/ true)?;
assert!(render_bottom_popup(&app.chat_widget, /*width*/ 96).contains("← command center"));
app.handle_tui_event(
&mut tui,
&mut app_server,
TuiEvent::Key(KeyEvent::new_with_kind(
KeyCode::Left,
KeyModifiers::NONE,
KeyEventKind::Repeat,
)),
)
.await?;
assert!(app.chat_widget.no_modal_or_popup_active());
app.handle_tui_event(
&mut tui,
&mut app_server,
TuiEvent::Key(KeyCode::Left.into()),
)
.await?;
assert!(app.chat_widget.active_view_is(AGENTS_OVERVIEW_VIEW_ID));
assert_eq!(
app.chat_widget.composer_text_with_pending(),
"Retained draft"
);
tui.set_owned_screen(/*owned*/ false)?;
app_server.shutdown().await?;
}
Ok(())
}
#[tokio::test]
async fn pending_windows_sandbox_setup_blocks_thread_replacement() -> Result<()> {
use crate::app_event::WindowsSandboxEnableMode;
@@ -1,84 +1,7 @@
//! Provider admission failures keep history readable and drafts recoverable.
use super::*;
use crate::render::renderable::ColumnRenderable;
use crate::wrapping::RtOptions;
use crate::wrapping::adaptive_wrap_lines;
use crate::wrapping::word_wrap_lines;
use codex_app_server_protocol::ModelProviderError;
use ratatui::widgets::Block;
use ratatui::widgets::Padding;
pub(super) struct ProviderErrorNotice {
pub(super) title: &'static str,
pub(super) message: String,
pub(super) configuration_location: Option<String>,
pub(super) can_continue: bool,
}
impl Renderable for ProviderErrorNotice {
fn render(&self, area: Rect, buf: &mut Buffer) {
self.as_renderable(area.width).render(area, buf);
}
fn desired_height(&self, width: u16) -> u16 {
self.as_renderable(width).desired_height(width)
}
}
impl ProviderErrorNotice {
fn as_renderable(&self, width: u16) -> ColumnRenderable<'_> {
let content_width = usize::from(width.saturating_sub(/*rhs*/ 4));
let mut lines = word_wrap_lines(
&[Line::from(vec!["🔒 ".into(), self.title.bold()])],
content_width,
);
let mut description = vec![Line::from(self.message.as_str().dim())];
if let Some(location) = &self.configuration_location {
description.push(Line::from(location.as_str().dim()));
}
lines.extend(adaptive_wrap_lines(
&description,
RtOptions::new(content_width)
.initial_indent(" ".into())
.subsequent_indent(" ".into()),
));
let mut notice = ColumnRenderable::new();
notice.push(
Paragraph::new(lines).block(
Block::default()
.style(crate::style::user_message_style())
.padding(Padding::new(
/*left*/ 2, /*right*/ 2, /*top*/ 1, /*bottom*/ 1,
)),
),
);
let mut shortcuts = Vec::new();
if self.can_continue {
shortcuts.extend([
crate::key_hint::plain(KeyCode::Char('c')).into(),
" continue in new chat · ".into(),
]);
}
shortcuts.extend([
crate::key_hint::plain(KeyCode::Char('n')).into(),
" start fresh · ".into(),
crate::key_hint::plain(KeyCode::Esc).into(),
" other chats".into(),
]);
let footer = Line::from(shortcuts).style(crate::style::secondary_text_style());
notice.push(
Paragraph::new(word_wrap_lines(
&[footer],
usize::from(width.saturating_sub(/*rhs*/ 2)),
))
.inset(Insets::tlbr(
/*top*/ 0, /*left*/ 2, /*bottom*/ 0, /*right*/ 0,
)),
);
notice
}
}
impl ChatWidget {
pub(super) fn provider_error_message(&self, error: &ModelProviderError) -> String {
+28
View File
@@ -1,6 +1,14 @@
//! Frozen transcript views preserve drafts while their live attachment is unavailable.
use super::*;
use codex_app_server_protocol::ModelProviderError;
/// The blocked transcript notice currently replacing the composer.
#[derive(Clone, Copy)]
pub(super) enum BlockedThreadView<'a> {
ProviderError(&'a ModelProviderError),
ReadOnly(ReadOnlyThread),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum ReadOnlyThread {
@@ -25,6 +33,26 @@ impl ReadOnlyThread {
}
impl ChatWidget {
pub(super) fn blocked_thread_view(&self) -> Option<BlockedThreadView<'_>> {
self.provider_error
.as_ref()
.map(BlockedThreadView::ProviderError)
.or_else(|| self.read_only_thread.map(BlockedThreadView::ReadOnly))
}
pub(super) fn blocked_thread_command_center_key(&self) -> Option<crate::key_hint::KeyBinding> {
self.blocked_thread_view()?;
self.agents_navigation_key_available()
.then(|| crate::key_hint::plain(KeyCode::Left))
}
pub(crate) fn blocked_thread_command_center_key_pressed(&self, key: KeyEvent) -> bool {
key.kind == KeyEventKind::Press
&& self
.blocked_thread_command_center_key()
.is_some_and(|binding| binding.is_press(key))
}
pub(crate) fn show_external_writer_thread(&mut self) {
self.show_read_only_thread(ReadOnlyThread::ExternalWriter);
}
+109 -64
View File
@@ -1,6 +1,6 @@
//! Shared composer and live-history composition for inline and owned transcript surfaces.
use super::provider_error::ProviderErrorNotice;
use super::read_only::BlockedThreadView;
use super::transcript::ActiveCellLayoutCache;
use super::transcript::ActiveCellLayoutCacheKey;
use super::*;
@@ -10,8 +10,8 @@ use crate::line_truncation::truncate_line_with_ellipsis_if_overflow;
use crate::render::RectExt;
use crate::terminal_hyperlinks::HyperlinkParagraph;
use crate::wrapping::RtOptions;
use crate::wrapping::adaptive_wrap_lines;
use crate::wrapping::word_wrap_lines;
use ratatui::style::Styled as _;
use ratatui::text::Span;
use ratatui::widgets::Block;
use std::cell::Cell;
@@ -37,16 +37,14 @@ impl Renderable for NewBackendControl<'_> {
}
}
struct ReadOnlyThreadNotice {
reason: ReadOnlyThread,
agents_navigation_key_available: bool,
transcript_hint: Option<crate::key_hint::ShortcutHint>,
struct BlockedThreadNotice<'a> {
widget: &'a ChatWidget,
view: BlockedThreadView<'a>,
}
impl Renderable for ReadOnlyThreadNotice {
impl Renderable for BlockedThreadNotice<'_> {
fn render(&self, area: Rect, buf: &mut Buffer) {
let content_width = area.width.saturating_sub(/*rhs*/ 4);
let card_lines = self.card_lines(content_width);
let card_lines = self.card_lines(area.width.saturating_sub(/*rhs*/ 4));
let card_height = (card_lines.len() as u16).saturating_add(/*rhs*/ 2);
let card = Rect::new(area.x, area.y, area.width, card_height.min(area.height));
Widget::render(
@@ -81,16 +79,56 @@ impl Renderable for ReadOnlyThreadNotice {
}
}
impl ReadOnlyThreadNotice {
impl BlockedThreadNotice<'_> {
fn card_lines(&self, width: u16) -> Vec<Line<'static>> {
let (prefix, title, indent) = match self.reason {
match self.view {
BlockedThreadView::ProviderError(error) => {
let title = if self.can_continue()
&& matches!(
error,
codex_app_server_protocol::ModelProviderError::ModelProviderMismatch { .. }
) {
"Continue in a new chat"
} else {
error.title()
};
let mut lines = word_wrap_lines(
&[Line::from(vec!["🔒 ".into(), title.bold()])],
usize::from(width),
);
let mut description =
vec![Line::from(self.widget.provider_error_message(error).dim())];
if let Some(remote) = self
.widget
.remote_connection
.as_ref()
.filter(|remote| !remote.is_local_daemon)
{
description.push(Line::from(
format!("Configuration on {}", remote.address).dim(),
));
}
lines.extend(adaptive_wrap_lines(
&description,
RtOptions::new(usize::from(width))
.initial_indent(" ".into())
.subsequent_indent(" ".into()),
));
lines
}
BlockedThreadView::ReadOnly(reason) => Self::read_only_card_lines(reason, width),
}
}
fn read_only_card_lines(reason: ReadOnlyThread, width: u16) -> Vec<Line<'static>> {
let (prefix, title, indent) = match reason {
ReadOnlyThread::ExternalWriter => {
("🔒 ", "This conversation is open in another app", " ")
}
ReadOnlyThread::Archived => ("", "This thread was archived", ""),
};
let title: Line<'static> = vec![prefix.into(), title.bold()].into();
let (key, action) = self.reason.action();
let (key, action) = reason.action();
let retry: Line<'static> = vec![
Span::styled(key, crate::style::accent_style()),
format!(" to {action}").into(),
@@ -105,7 +143,7 @@ impl ReadOnlyThreadNotice {
lines.push(retry);
}
lines.extend(word_wrap_lines(
&[Line::from(self.reason.message().dim())],
&[Line::from(reason.message().dim())],
RtOptions::new(usize::from(width))
.initial_indent(indent.into())
.subsequent_indent(indent.into()),
@@ -113,37 +151,70 @@ impl ReadOnlyThreadNotice {
lines
}
fn can_continue(&self) -> bool {
self.widget.thread_id.is_some() && self.widget.current_rollout_path.is_some()
}
fn footer_lines(&self, width: u16) -> Vec<Line<'static>> {
let (key, action) = self.reason.action();
let mut items = vec![(key.to_string(), action.to_string())];
if self.reason == ReadOnlyThread::ExternalWriter {
items.push(("f".to_string(), "fork".to_string()));
let mut items = Vec::new();
match self.view {
BlockedThreadView::ProviderError(_) => {
if self.can_continue() {
items.push(("c".to_string(), "continue in new chat".to_string()));
}
items.push(("n".to_string(), "start fresh".to_string()));
}
BlockedThreadView::ReadOnly(reason) => {
let (key, action) = reason.action();
items.push((key.to_string(), action.to_string()));
if reason == ReadOnlyThread::ExternalWriter {
items.push(("f".to_string(), "fork".to_string()));
}
}
}
let escape = crate::key_hint::plain(KeyCode::Esc).display_label();
let quit_keys = [
crate::key_hint::ctrl(KeyCode::Char('c')).display_label(),
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
];
let key = if self.agents_navigation_key_available {
let left = crate::key_hint::plain(KeyCode::Left).display_label();
format!("{left}/{escape}")
} else {
escape
let left = self
.widget
.blocked_thread_command_center_key()
.map(|key| key.display_label());
let command_center_key = match self.view {
BlockedThreadView::ReadOnly(_) => {
Some(left.map_or_else(|| escape.clone(), |left| format!("{left}/{escape}")))
}
BlockedThreadView::ProviderError(_) => left,
};
items.push((key, "command center".to_string()));
items.push((quit_keys.join("/"), "exit".to_string()));
if let Some(hint) = self.transcript_hint {
items.push((hint.display_label(), "transcript".to_string()));
if let Some(key) = command_center_key {
items.push((key, "command center".to_string()));
}
let mut spans = vec![" ".set_style(crate::style::footer_hint_label_style())];
for (idx, (key, label)) in items.into_iter().enumerate() {
if idx > 0 {
spans.push(" ".set_style(crate::style::footer_hint_label_style()));
match self.view {
BlockedThreadView::ProviderError(_) => items.push((escape, "other chats".to_string())),
BlockedThreadView::ReadOnly(_) => {
let quit_keys = [
crate::key_hint::ctrl(KeyCode::Char('c')).display_label(),
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
];
items.push((quit_keys.join("/"), "exit".to_string()));
if let Some(hint) = self.widget.bottom_pane.transcript_shortcut_hint() {
items.push((hint.display_label(), "transcript".to_string()));
}
}
}
let (leading, separator) = match self.view {
BlockedThreadView::ProviderError(_) => ("", " · "),
BlockedThreadView::ReadOnly(_) => (" ", " "),
};
let mut spans = vec![leading.into()];
for (index, (key, label)) in items.into_iter().enumerate() {
if index > 0 {
spans.push(separator.into());
}
spans.extend(crate::key_hint::key_label_spans(&key));
spans.push(format!(" {label}").set_style(crate::style::footer_hint_label_style()));
spans.push(format!(" {label}").into());
}
word_wrap_lines(&[Line::from(spans)], usize::from(width))
word_wrap_lines(
&[Line::from(spans).style(crate::style::footer_hint_label_style())],
usize::from(width),
)
}
}
@@ -272,36 +343,10 @@ impl ChatWidget {
/*top*/ 1, /*left*/ 2, /*bottom*/ 1, /*right*/ 2,
)),
))
} else if let Some(error) = &self.provider_error
} else if let Some(view) = self.blocked_thread_view()
&& !self.bottom_pane.has_active_view()
{
let can_continue = self.thread_id.is_some() && self.current_rollout_path.is_some();
RenderableItem::Owned(Box::new(ProviderErrorNotice {
title: if can_continue
&& matches!(
error,
codex_app_server_protocol::ModelProviderError::ModelProviderMismatch { .. }
) {
"Continue in a new chat"
} else {
error.title()
},
message: self.provider_error_message(error),
can_continue,
configuration_location: self
.remote_connection
.as_ref()
.filter(|remote| !remote.is_local_daemon)
.map(|remote| format!("Configuration on {}", remote.address)),
}))
} else if let Some(reason) = self.read_only_thread
&& !self.bottom_pane.has_active_view()
{
RenderableItem::Owned(Box::new(ReadOnlyThreadNotice {
reason,
agents_navigation_key_available: self.agents_navigation_key_available(),
transcript_hint: self.bottom_pane.transcript_shortcut_hint(),
}))
RenderableItem::Owned(Box::new(BlockedThreadNotice { widget: self, view }))
} else {
let right_reserve = if self
.bottom_pane
@@ -7,14 +7,14 @@ provider_error_local_80
This chat uses model provider “old-provider”, which is no longer
configured. Restore this provider’s configuration to continue.
c continue in new chat · n start fresh · esc other chats
c continue in new chat · n start fresh · ← command center · esc other chats
provider_error_mismatch_local_80
🔒 Continue in a new chat
This chat uses Team Gateway, but Codex now uses Amazon Bedrock Runtime,
so this chat is read-only.
c continue in new chat · n start fresh · esc other chats
c continue in new chat · n start fresh · ← command center · esc other chats
provider_error_mismatch_local_40
🔒 Continue in a new chat
@@ -24,7 +24,7 @@ provider_error_mismatch_local_40
only.
c continue in new chat · n start fresh
· esc other chats
· ← command center · esc other chats
provider_error_mismatch_remote_80
🔒 Continue in a new chat
@@ -32,7 +32,7 @@ provider_error_mismatch_remote_80
so this chat is read-only.
Configuration on ws://devbox.example.com:4500/
c continue in new chat · n start fresh · esc other chats
c continue in new chat · n start fresh · ← command center · esc other chats
provider_error_policy_provider_local_80
🔒 Model provider blocked by policy
@@ -40,7 +40,7 @@ provider_error_policy_provider_local_80
“Amazon Bedrock”. Contact your administrator or start a new chat using
the required provider.
c continue in new chat · n start fresh · esc other chats
c continue in new chat · n start fresh · ← command center · esc other chats
provider_error_policy_settings_local_80
🔒 Model provider blocked by policy
@@ -48,4 +48,4 @@ provider_error_policy_settings_local_80
requirements. Contact your administrator or start a new chat using the
current provider settings.
c continue in new chat · n start fresh · esc other chats
c continue in new chat · n start fresh · ← command center · esc other chats