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.

fix(client): end the outage clock for a session that outlived the give-up window

RoversX2ced7cfc537e
diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs
index 18dff880..c870d7b3 100644
--- a/wezterm-client/src/client.rs
+++ b/wezterm-client/src/client.rs
@@ -1814,10 +1814,17 @@ impl Client {
// A session that was restored ends the outage, however
// briefly it lived: a flapping link keeps being retried,
// as it always was. One that never became usable keeps
- // the clock running.
- if was_ready {
- outage_started = None;
- }
+ // the clock running -- unless it stayed up longer than
+ // the whole give-up window, which no refused restore
+ // does; that is a connection that worked without ever
+ // being marked so, and its drop is a new outage, not the
+ // hours-old one parking us on the first try.
+ outage_started = outage_clock_after_session(
+ outage_started,
+ was_ready,
+ session_started.elapsed(),
+ GIVE_UP_AFTER,
+ );
let outage_started = outage_started.get_or_insert_with(std::time::Instant::now);
// A successful reattach closes the UI behind our back;
@@ -2461,10 +2468,58 @@ impl Client {
rpc!(adjust_pane_size, AdjustPaneSize, UnitResponse);
}
+/// The outage clock to carry into the next reconnect round, given how the
+/// session that just ended fared. `None` means no outage is in progress.
+fn outage_clock_after_session(
+ prior: Option<std::time::Instant>,
+ was_ready: bool,
+ session_length: Duration,
+ give_up_after: Duration,
+) -> Option<std::time::Instant> {
+ if was_ready || session_length >= give_up_after {
+ None
+ } else {
+ prior
+ }
+}
+
#[cfg(test)]
mod tests {
- use super::{is_auth_cancelled, Reconnectable};
+ use super::{is_auth_cancelled, outage_clock_after_session, Reconnectable};
use crate::domain::ClientDomainConfig;
+ use std::time::{Duration, Instant};
+
+ #[test]
+ fn a_restored_session_ends_the_outage() {
+ let old = Some(Instant::now() - Duration::from_secs(3600));
+ assert_eq!(
+ outage_clock_after_session(old, true, Duration::from_secs(3), Duration::from_secs(120)),
+ None
+ );
+ }
+
+ #[test]
+ fn a_short_refused_session_keeps_the_clock_running() {
+ let old = Some(Instant::now() - Duration::from_secs(3600));
+ assert_eq!(
+ outage_clock_after_session(old, false, Duration::from_secs(3), Duration::from_secs(120)),
+ old
+ );
+ }
+
+ #[test]
+ fn a_long_session_that_was_never_marked_ready_still_ends_the_outage() {
+ let old = Some(Instant::now() - Duration::from_secs(3600));
+ assert_eq!(
+ outage_clock_after_session(
+ old,
+ false,
+ Duration::from_secs(600),
+ Duration::from_secs(120)
+ ),
+ None
+ );
+ }
#[test]
fn only_the_local_session_host_reconnects_over_a_unix_socket() {
diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs
index cc954f07..06568bf7 100644
--- a/wezterm-client/src/domain.rs
+++ b/wezterm-client/src/domain.rs
@@ -1849,6 +1849,17 @@ impl ClientInner {
"releasing the frontend recovery barrier for mux generation {generation} after {waited:?}: {}",
if superseded { "superseded" } else { "never acknowledged" }
);
+ // An overdue barrier of the live generation was the last thing
+ // between this connection and Ready: the reattach returned early
+ // to wait for it, and nothing else marks the session usable.
+ // Left as it was, the panes sat behind "Restoring terminal
+ // state…" for as long as the connection lived, and the
+ // reconnect loop later read that as an outage still running.
+ if !superseded {
+ self.mark_server_recovered();
+ self.client.mark_ready();
+ wake_thinkterm_frontend();
+ }
}
}