Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

gui: show the retry engine as connecting, not as a failure

RoversXcfa5f622690c
diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs
index 897ee783..fa1642f4 100644
--- a/wezterm-client/src/domain.rs
+++ b/wezterm-client/src/domain.rs
@@ -1228,6 +1228,11 @@ pub struct ClientDomain {
/// True while an attach is in flight (state() stays Detached until
/// finish_attach installs the inner, so state alone can't dedupe).
attaching: std::sync::atomic::AtomicBool,
+ /// Count of attach retry loops currently running, backoff gaps included.
+ /// `attaching` covers only a single attempt; the UI needs to know the
+ /// engine has not given up between attempts, or every backoff gap paints
+ /// as a disconnect.
+ attach_retries: std::sync::atomic::AtomicUsize,
local_domain_id: DomainId,
}
@@ -1493,6 +1498,7 @@ impl ClientDomain {
label,
inner: Mutex::new(None),
attaching: std::sync::atomic::AtomicBool::new(false),
+ attach_retries: std::sync::atomic::AtomicUsize::new(0),
local_domain_id,
}
}
@@ -1558,6 +1564,13 @@ impl ClientDomain {
self.attaching.load(std::sync::atomic::Ordering::SeqCst)
}
+ /// True for the whole of an attach retry sequence, backoff gaps
+ /// included; `is_attaching` is per-attempt and reads false while the
+ /// engine waits between attempts.
+ pub fn is_attach_retrying(&self) -> bool {
+ self.attach_retries.load(std::sync::atomic::Ordering::SeqCst) > 0
+ }
+
pub fn perform_detach(&self) {
log::info!("detached domain {}", self.local_domain_id);
self.inner.lock().unwrap().take();
@@ -3834,6 +3847,16 @@ impl ClientDomain {
keep_going: impl FnMut() -> bool,
max_total: Option<Duration>,
) -> anyhow::Result<AttachRetryOutcome> {
+ struct RetryFlag<'a>(&'a std::sync::atomic::AtomicUsize);
+ impl Drop for RetryFlag<'_> {
+ fn drop(&mut self) {
+ self.0.fetch_sub(1, std::sync::atomic::Ordering::SeqCst);
+ }
+ }
+ self.attach_retries
+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);
+ let _in_flight = RetryFlag(&self.attach_retries);
+
let attempt_ui = ui.clone();
attach_with_retry_loop(
self.domain_name(),
diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs
index 0951d6d7..a7ecf156 100644
--- a/wezterm-gui/src/termwindow/mouseevent.rs
+++ b/wezterm-gui/src/termwindow/mouseevent.rs
@@ -6031,6 +6031,10 @@ impl super::TermWindow {
};
let domain_name = domain_name.to_string();
let mux_window_id = self.mux_window_id;
+ // Bridge the frames between this switch and the retry engine
+ // raising its own in-flight flag: without it the sidebar
+ // paints "Disconnected — Reconnect" for the gap.
+ self.space_reconnects_in_flight.insert(domain_name.clone());
promise::spawn::spawn(async move {
let result = async {
let mux = Mux::get();
@@ -6060,6 +6064,7 @@ impl super::TermWindow {
anyhow::Ok(matches!(outcome, crate::AttachRetryOutcome::Attached))
}
.await;
+ let cleanup_name = domain_name.clone();
match result {
// Cancelled (the hosting window went away mid-retry)
// leaves nothing to activate.
@@ -6080,6 +6085,12 @@ impl super::TermWindow {
log::error!("attaching {domain_name} for thread switch: {err:#}");
}
}
+ window.notify(TermWindowNotif::Apply(Box::new(move |term_window| {
+ term_window.space_reconnects_in_flight.remove(&cleanup_name);
+ if let Some(win) = term_window.window.as_ref() {
+ win.invalidate();
+ }
+ })));
})
.detach();
context.invalidate();
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 72de4499..e474da35 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -525,6 +525,12 @@ impl crate::TermWindow {
if client.is_attaching() {
return SpaceConnectionState::Connecting;
}
+ // The retry engine is between attempts. The backoff gap used to
+ // read as Disconnected, so a VPN that wakes on the first packet
+ // flashed a failure on every entry before attempt two succeeded.
+ if client.is_attach_retrying() {
+ return SpaceConnectionState::Connecting;
+ }
// The retry loop parked itself after two minutes of failures;
// it waits for the sidebar Reconnect button.
if client.is_reconnect_suspended() {
@@ -721,9 +727,13 @@ impl crate::TermWindow {
let space_menu_y = y;
let space_menu_height = top_action_height + self.ui_px(6);
y += space_menu_height + self.ui_px(SIDEBAR_INSET);
- let reconnect_row_height = if self.space_connection_state(self.workspace_sidebar_space_id())
- == SpaceConnectionState::Disconnected
- {
+ // Connecting keeps the row (as a spinner) so the whole retry
+ // sequence paints one stable row instead of flickering between
+ // "row while disconnected" and "no row while an attempt runs".
+ let reconnect_row_height = if matches!(
+ self.space_connection_state(self.workspace_sidebar_space_id()),
+ SpaceConnectionState::Disconnected | SpaceConnectionState::Connecting
+ ) {
ui_cell_height + self.ui_px(SIDEBAR_INSET)
} else {
0
@@ -912,8 +922,11 @@ impl crate::TermWindow {
ui_cell_height: usize,
register_ui_item: bool,
) -> anyhow::Result<()> {
- let reconnect_in_flight =
- workspace_threads::client_domain_for_space(self.workspace_sidebar_space_id())
+ // The domain-level retry flag covers every attach entry point; the
+ // local set still bridges the click-to-spawn gap for the button.
+ let reconnect_in_flight = self.space_connection_state(self.workspace_sidebar_space_id())
+ == SpaceConnectionState::Connecting
+ || workspace_threads::client_domain_for_space(self.workspace_sidebar_space_id())
.map_or(false, |name| {
self.space_reconnects_in_flight.contains(&name)
});
@@ -930,18 +943,28 @@ impl crate::TermWindow {
let row_icon_size = ui_cell_height.min(row_height.saturating_sub(6));
let row_icon_x = row_x + self.ui_px(SIDEBAR_INSET);
let row_icon_y = y + ((row_height.saturating_sub(row_icon_size)) / 2);
- self.paint_sidebar_icon(
- layers,
- if reconnect_in_flight {
- SvgIcon::LoaderCircle
- } else {
- SvgIcon::RotateCcw
- },
- row_icon_x,
- row_icon_y,
- row_icon_size,
- SPACE_DISCONNECTED_COLOR,
- )?;
+ if reconnect_in_flight {
+ // The spinning painter also schedules the next repaint; the
+ // static one would freeze the loader on frame zero.
+ self.paint_spinning_ui_icon(
+ layers,
+ 2,
+ SvgIcon::LoaderCircle,
+ row_icon_x,
+ row_icon_y,
+ row_icon_size,
+ SPACE_DISCONNECTED_COLOR,
+ )?;
+ } else {
+ self.paint_sidebar_icon(
+ layers,
+ SvgIcon::RotateCcw,
+ row_icon_x,
+ row_icon_y,
+ row_icon_size,
+ SPACE_DISCONNECTED_COLOR,
+ )?;
+ }
let row_text_x = row_icon_x + row_icon_size + self.ui_px(SIDEBAR_ICON_GAP);
let row_text_max =
(row_x + row_width).saturating_sub(row_text_x + self.ui_px(SIDEBAR_INSET));
@@ -1306,14 +1329,26 @@ impl crate::TermWindow {
},
),
};
- self.paint_sidebar_icon(
- layers,
- space_icon,
- space_icon_x,
- space_icon_y,
- space_icon_size,
- space_icon_color,
- )?;
+ if connection_state == SpaceConnectionState::Connecting {
+ self.paint_spinning_ui_icon(
+ layers,
+ 2,
+ space_icon,
+ space_icon_x,
+ space_icon_y,
+ space_icon_size,
+ space_icon_color,
+ )?;
+ } else {
+ self.paint_sidebar_icon(
+ layers,
+ space_icon,
+ space_icon_x,
+ space_icon_y,
+ space_icon_size,
+ space_icon_color,
+ )?;
+ }
self.paint_sidebar_text(
layers,
&ui_font,
@@ -2209,14 +2244,26 @@ impl crate::TermWindow {
)
.context("sidebar space menu button repaint")?;
}
- self.paint_sidebar_icon(
- layers,
- space_icon,
- space_icon_x,
- space_icon_y,
- space_icon_size,
- space_icon_color,
- )?;
+ if connection_state == SpaceConnectionState::Connecting {
+ self.paint_spinning_ui_icon(
+ layers,
+ 2,
+ space_icon,
+ space_icon_x,
+ space_icon_y,
+ space_icon_size,
+ space_icon_color,
+ )?;
+ } else {
+ self.paint_sidebar_icon(
+ layers,
+ space_icon,
+ space_icon_x,
+ space_icon_y,
+ space_icon_size,
+ space_icon_color,
+ )?;
+ }
self.paint_sidebar_text(
layers,
&ui_font,