Refresh status line providers on config and connection changes (#61985)

## What changed

- Refresh the status line after reloading configuration so provider and feature-gate changes take effect.
- Restart the provider reader after saving a selection, including reselecting the same provider to retry a failed read.
- Cancel provider reads and show the built-in status line while disconnected, then restart the provider after reconnecting.

## Testing

Add regression coverage for configuration reloads, provider changes, retrying failed reads, and discarding stale results after provider changes or reconnects. Extend the terminal integration test to verify that a new thread picks up a provider changed in `config.toml`.

GitOrigin-RevId: e86531321d190786e8a41a0a0c93167c8a5298e6
This commit is contained in:
Joe Savona
2026-11-17 07:26:02 +00:00
committed by copyberry
parent 10a3126a03
commit 47d9cde20e
10 changed files with 143 additions and 3 deletions
@@ -513,6 +513,7 @@ impl App {
self.config = config;
self.refresh_transcript_document_links();
self.chat_widget.sync_plugin_mentions_config(&self.config);
self.chat_widget.refresh_status_line();
Ok(())
}
+2
View File
@@ -651,6 +651,8 @@ impl App {
self.refresh_agents_overview_threads(app_server);
}
self.chat_widget.forget_inherited_quota_provider();
self.chat_widget.statusline_disconnected = false;
self.chat_widget.refresh_status_line();
self.chat_widget.update_account_state(
bootstrap.status_account_display,
bootstrap.plan_type,
@@ -37,6 +37,7 @@ impl App {
self.local_settings.tui.status_line_provider = Some(Box::new(provider.clone()));
self.chat_widget.local_settings.tui.status_line_provider = Some(Box::new(provider));
self.chat_widget.reselect_statusline_provider();
Ok(())
}
}
@@ -2,6 +2,7 @@
use crate::AppServerTarget;
use crate::app::test_support::make_test_app;
use crate::chatwidget::tests::render_bottom_popup;
use codex_config::types::BuiltinStatusLine;
use codex_config::types::StatusLineProviderId;
use codex_config::types::StatusLineSelection;
@@ -121,3 +122,42 @@ async fn failed_write_preserves_the_file_and_the_live_selection() -> anyhow::Res
}
Ok(())
}
#[tokio::test]
async fn reloading_the_effective_feature_gate_and_reselecting_an_unchanged_preference() {
let mut app = make_test_app().await;
let path = app.local_settings.user_config_path.clone();
let configured = "[features]\ntui_extensions_statusline = true\n[tui]\nstatus_line = []\nstatus_line_provider = { tool='line', server='fixture' } # local formatting\n";
std::fs::write(&path, configured).unwrap();
app.cli_kv_overrides = vec![(
"tui.status_line_provider".into(),
toml::toml! {
server = "fixture"
tool = "line"
}
.into(),
)];
app.refresh_in_memory_config_from_disk().await.unwrap();
assert!(render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Initializing…"));
let selected = app
.local_settings
.tui
.status_line_provider
.as_deref()
.unwrap()
.clone();
std::fs::write(&path, configured.replace("tool='line'", "tool='elsewhere'")).unwrap();
app.save_status_line_provider(selected).await.unwrap();
let stored: toml::Table = toml::from_str(&std::fs::read_to_string(&path).unwrap()).unwrap();
assert_eq!(
stored["tui"]["status_line_provider"]["tool"].as_str(),
Some("line")
);
std::fs::write(&path, configured.replace("= true", "= false")).unwrap();
app.refresh_in_memory_config_from_disk().await.unwrap();
assert!(!render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Initializing…"));
std::fs::write(&path, configured).unwrap();
app.refresh_in_memory_config_from_disk().await.unwrap();
assert!(render_bottom_popup(&app.chat_widget, /*width*/ 80).contains("Initializing…"));
}
+1
View File
@@ -578,6 +578,7 @@ pub(crate) struct ChatWidget {
status_account_display: Option<StatusAccountDisplay>,
pub(crate) remote_connection: Option<RemoteConnectionStatus>,
statusline_read: Option<statusline_reader::ActiveStatuslineRead>,
pub(crate) statusline_disconnected: bool,
/// Remote app servers cannot read image paths on the TUI host.
pub(crate) snapshot_local_images: bool,
pub(crate) thread_params_mode: crate::app_server_session::ThreadParamsMode,
@@ -149,6 +149,7 @@ impl ChatWidget {
status_account_display,
remote_connection: None,
statusline_read: None,
statusline_disconnected: false,
snapshot_local_images: false,
thread_params_mode: crate::app_server_session::ThreadParamsMode::Embedded,
pending_image_submission: None,
+2
View File
@@ -53,6 +53,8 @@ impl ChatWidget {
crate::key_hint::ctrl(KeyCode::Char('c')).display_label(),
"quit".into(),
)]));
self.statusline_disconnected = true;
self.refresh_status_line();
}
/// Restore local input only after replay, which can otherwise move interrupted queues into the draft.
@@ -70,7 +70,8 @@ impl StatuslineReadEvent {
impl ChatWidget {
pub(super) fn selected_statusline_provider(&self) -> Option<&StatusLineProviderId> {
if self.read_only_history
if self.statusline_disconnected
|| self.read_only_history
|| self
.app_event_tx
.voice_only
@@ -88,6 +89,11 @@ impl ChatWidget {
}
}
pub(crate) fn reselect_statusline_provider(&mut self) {
self.statusline_read = None;
self.refresh_status_line();
}
pub(super) fn refresh_provider_footer(&mut self) -> bool {
let Some(selection) = self.selected_statusline_provider() else {
self.statusline_read = None;
@@ -258,11 +258,12 @@ impl Reader {
(params.server_name.as_deref(), params.thread_id),
(Some("fixture"), thread)
);
let tool = json!({"name":"line","title":"Calendar","inputSchema":{},"_meta":{
let name = &self.chat.selected_statusline_provider().unwrap().tool;
let tool = json!({"name":name,"title":"Calendar","inputSchema":{},"_meta":{
"openai/ui":{"entrypoints":[{"type":"statusline","resourceUri":URI}]}
}});
reply.send(Ok(Ok(json!({"data":[{"name":"fixture","httpOrigin":null,"runtimeStatus":"connected",
"tools":{"line":tool},"resources":[],"resourceTemplates":[],"authStatus":"unsupported"}],"nextCursor":null})))).unwrap();
"tools":{(name):tool},"resources":[],"resourceTemplates":[],"authStatus":"unsupported"}],"nextCursor":null})))).unwrap();
}
}
@@ -478,3 +479,80 @@ async fn statusline_startup_timeout_stops_before_the_first_read() {
advance(/*millis*/ 60_000).await;
reader.assert_idle();
}
#[tokio::test(start_paused = true)]
async fn statusline_changing_provider_or_reconnecting_discards_the_previous_read() {
enum Change {
Provider,
Connection,
}
let mut reader = Reader::new().await;
reader.resolve().await;
let mut held = reader.read(URI).await;
for change in [Change::Provider, Change::Connection] {
let old = reader.chat.statusline_read.as_ref().unwrap().token;
match change {
Change::Provider => {
reader.chat.local_settings.tui.status_line_provider =
Some(Box::new(StatusLineSelection::Mcp(StatusLineProviderId {
server: "fixture".into(),
tool: "other".into(),
})));
}
Change::Connection => {
reader.chat.local_settings.tui.status_line = Some(vec!["model".into()]);
reader.chat.local_settings.tui.terminal_title = Some(vec!["run-state".into()]);
reader.chat.pause_for_disconnect();
assert_eq!(
footer(&reader.chat),
Some(reader.chat.model_display_name().into())
);
reader.assert_idle();
reader.chat.statusline_disconnected = false;
let (client, requests, _) = CloudClient::channel(/*capacity*/ 8);
reader.requests = requests;
reader.owner = AppServerSession::new(
reader.owner.backend_id(),
AppServerClient::Cloud(client),
ThreadParamsMode::Cloud,
);
}
}
reader.chat.refresh_status_line();
reader.dispatch().await;
reader.resolve().await;
let next = reader.read(URI).await;
held.closed().await;
for result in [Ok(UiTree(None)), Err("retired".into())] {
let step = ReadStep::Finished(reader.owner.backend_id(), result);
reader
.chat
.handle_statusline_read(StatuslineReadEvent { token: old, step }, &reader.owner);
}
assert_eq!(footer(&reader.chat).as_deref(), Some("Initializing…"));
held = next;
}
}
#[tokio::test(start_paused = true)]
async fn statusline_explicit_reselection_restarts_a_failed_reader() {
let mut reader = Reader::new().await;
reader.resolve().await;
let _held = reader.read(URI).await;
advance(/*millis*/ 1000).await;
reader.dispatch().await;
reader.chat.refresh_status_line();
reader.assert_idle();
assert!(
footer(&reader.chat)
.unwrap()
.contains("Error loading statusline contents from Calendar")
);
reader.chat.reselect_statusline_provider();
reader.dispatch().await;
reader.resolve().await;
respond(reader.read(URI).await, r#""restored""#);
reader.dispatch().await;
assert_eq!(footer(&reader.chat).as_deref(), Some("restored"));
}