the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: retry a reconnecting machine immediately when selected (#5232)
JJ Liebigafd7aa94b04c
diff --git a/docs/next/website/src/content/docs/cli-reference.mdx b/docs/next/website/src/content/docs/cli-reference.mdxindex 82d3a2d79..7390243de 100644--- a/docs/next/website/src/content/docs/cli-reference.mdx+++ b/docs/next/website/src/content/docs/cli-reference.mdx@@ -67,7 +67,7 @@ In an interactive terminal, `machine add` discovers running sessions and lets yoChanges apply automatically to open local Herdr clients, normally within a second. Added or enabled machines connect in the background; renaming does not reconnect. Removing or disabling disconnects only that machine and leaves its remote sessions running. Removing the machine you are viewing returns to Local, or shows Local as unavailable until it reconnects. Each profile stores an opaque ID, label, SSH target, explicit remote session, and enabled state in client state. Herdr does not store passwords, private keys, or other SSH credentials.-Use `herdr machine status [<label-or-id>] [--json]` for fresh, noninteractive SSH and remote Herdr checks. `reachable` describes this check, not a TUI's current connection. Use `herdr machine reconnect <label-or-id>` in a terminal for SSH authentication and verification; it does not install or update Herdr. Open clients retry failed connections within 30 seconds. Clicking `! auth` or `! error` shows the latest error and CLI guidance; collapsed sidebars show `!`. See [Recovering SSH authentication](/docs/connecting-machines/#recovering-ssh-authentication) for platform limits. For remote setup, use `herdr --remote workbox`, adding `--session <name>` only for a named session.+Use `herdr machine status [<label-or-id>] [--json]` for fresh, noninteractive SSH and remote Herdr checks. `reachable` describes this check, not a TUI's current connection. Use `herdr machine reconnect <label-or-id>` in a terminal for SSH authentication and verification; it does not install or update Herdr. Open clients retry failed connections within 30 seconds. Clicking `! auth` or `! error` retries the connection; a failed attempt shows the latest error and CLI guidance; collapsed sidebars show `!`. See [Recovering SSH authentication](/docs/connecting-machines/#recovering-ssh-authentication) for platform limits. For remote setup, use `herdr --remote workbox`, adding `--session <name>` only for a named session.Workspace, tab, pane IDs, and agent names belong to a single server. Selecting a machine in the UI does not retarget CLI commands. Use the global **prefix** `--machine <label-or-id>` to route API commands to a saved SSH machine:diff --git a/docs/next/website/src/content/docs/connecting-machines.mdx b/docs/next/website/src/content/docs/connecting-machines.mdxindex 47bc19a59..75dccb1c2 100644--- a/docs/next/website/src/content/docs/connecting-machines.mdx+++ b/docs/next/website/src/content/docs/connecting-machines.mdx@@ -11,7 +11,7 @@ Herdr requests SSH compression to reduce screen-update traffic on limited connec### Recovering SSH authentication-On Linux and macOS clients, when `remote.manage_ssh_config=true`, Herdr shares an approved OpenSSH connection across machine add, the sidebar, and saved-machine API commands. Run `herdr machine status [<label-or-id>] [--json]` for fresh, noninteractive checks. **Reachable** means the remote Herdr server is available now, not that every open TUI is connected. Run `herdr machine reconnect <label-or-id>` in a terminal to complete native SSH authentication and verify the saved machine. It does not install or update Herdr. Open clients recheck failed connections within 30 seconds; no restart is needed. Clicking **`! auth`**, **`! error`**, or a failed connection's reconnecting status shows a notice with its latest error and the relevant CLI command. It never opens a credential popup. The rest of the machine row keeps its normal expand/collapse behavior.+On Linux and macOS clients, when `remote.manage_ssh_config=true`, Herdr shares an approved OpenSSH connection across machine add, the sidebar, and saved-machine API commands. Run `herdr machine status [<label-or-id>] [--json]` for fresh, noninteractive checks. **Reachable** means the remote Herdr server is available now, not that every open TUI is connected. Run `herdr machine reconnect <label-or-id>` in a terminal to complete native SSH authentication and verify the saved machine. It does not install or update Herdr. Open clients recheck failed connections within 30 seconds; no restart is needed. Clicking **`! auth`**, **`! error`**, or a reconnecting status retries the connection; if it fails, a notice shows the latest error and relevant CLI command. It never opens a credential popup.The shared connection uses `ControlPersist 600` (10 minutes of idle time); this is not MFA validity. Active connections can remain open, while corporate policy, the SSH server, or the network may end them sooner. Local Windows recovery is not supported yet. For unmanaged SSH connections, authentication remains your responsibility: running `ssh` by itself does not grant Herdr approval unless it uses the shared ControlPath. Host-key checking is unchanged; an unknown or changed host key remains **Attention**.@@ -88,7 +88,7 @@ Removing or disabling the machine you are viewing returns you to Local. If Local## Connection problems- **Reconnecting:** Herdr retries automatically after a network interruption, sleep, or SSH failure. Repeated failures increase the delay up to two minutes; brief successful connections do not reset it. A connection must remain healthy for a minute before the next interruption gets a fast retry. SSH connections are checked for application-level activity and probed when quiet, so a broken connection does not stay Online indefinitely. Local detects native connection closure or failure instead of using remote health probes.-- **Attention:** The target needs an action such as authentication, host-key approval, or a compatible server. Other machines remain usable. **`! auth`** means authentication failed; **`! error`** indicates another issue. Click the badge for the error and a CLI command. In a collapsed sidebar, either appears as `!`.+- **Attention:** The target needs an action such as authentication, host-key approval, or a compatible server. Other machines remain usable. **`! auth`** means authentication failed; **`! error`** indicates another issue. Click the badge to retry; if it fails, a notice shows the fresh error and a CLI command. In a collapsed sidebar, either appears as `!`.- **Saved-machine file error:** An unreadable or invalid catalog leaves current connections unchanged. Herdr shows a notice and automatically retries reading it.When both installations support bridge idle cleanup, saved-machine connections to Linux and macOS also close their remote bridge after a minute without traffic in either direction. Sleep counts toward that deadline, which is checked when the host wakes. Quiet healthy connections exchange health checks; watching continuous output does not require typing. Cleanup leaves the remote Herdr server, sessions, and pane processes running. Older installations remain compatible without this optional cleanup.diff --git a/docs/next/website/src/content/docs/ja/cli-reference.mdx b/docs/next/website/src/content/docs/ja/cli-reference.mdxindex 26ccb09a7..2a4e0f0ef 100644--- a/docs/next/website/src/content/docs/ja/cli-reference.mdx+++ b/docs/next/website/src/content/docs/ja/cli-reference.mdx@@ -65,7 +65,7 @@ herdr machine remove <profile-id>変更は、開いているローカルの Herdr クライアントに通常 1 秒以内に自動反映されます。追加または有効化したマシンにはバックグラウンドで接続し、名前の変更では再接続しません。削除または無効化すると、そのマシンだけが切断され、リモートセッションは動き続けます。表示中のマシンを削除すると Local に戻ります。Local に接続できない場合は、再接続するまで利用不可と表示します。各プロファイルは、不透明な ID、ラベル、SSH 接続先、明示的なリモートセッション名、有効状態をクライアントの状態ファイルに保存します。パスワード、秘密鍵、その他の SSH 認証情報は保存しません。-`herdr machine status [<label-or-id>] [--json]` は SSH とリモート Herdr を非対話式で確認します。`reachable` は今回の確認結果で、TUI の接続状態ではありません。ターミナルで `herdr machine reconnect <label-or-id>` を実行すると認証と検証を行いますが、インストールや更新は行いません。開いているクライアントは 30 秒以内に再試行します。`! auth` または `! error` をクリックすると最新のエラーと CLI コマンドを表示します。折りたたみ時は `!` です。対応環境は [SSH 認証の復旧](/ja/docs/connecting-machines/#ssh-認証の復旧)を参照してください。セットアップには `herdr --remote workbox` を使い、名前付きセッションの場合だけ `--session <name>` を追加します。+`herdr machine status [<label-or-id>] [--json]` は SSH とリモート Herdr を非対話式で確認します。`reachable` は今回の確認結果で、TUI の接続状態ではありません。ターミナルで `herdr machine reconnect <label-or-id>` を実行すると認証と検証を行いますが、インストールや更新は行いません。開いているクライアントは 30 秒以内に再試行します。`! auth` または `! error` をクリックすると再試行し、失敗した場合は最新のエラーと CLI コマンドを表示します。折りたたみ時は `!` です。対応環境は [SSH 認証の復旧](/ja/docs/connecting-machines/#ssh-認証の復旧)を参照してください。セットアップには `herdr --remote workbox` を使い、名前付きセッションの場合だけ `--session <name>` を追加します。ワークスペース、タブ、ペインの ID とエージェント名はサーバーごとに独立しています。UI での選択は CLI の接続先を変えません。保存済み SSH マシンへ API コマンドを送るには、グローバルな**プレフィックス** `--machine <label-or-id>` を指定します。diff --git a/docs/next/website/src/content/docs/ja/connecting-machines.mdx b/docs/next/website/src/content/docs/ja/connecting-machines.mdxindex 9a9e0dc74..05869cb81 100644--- a/docs/next/website/src/content/docs/ja/connecting-machines.mdx+++ b/docs/next/website/src/content/docs/ja/connecting-machines.mdx@@ -11,7 +11,7 @@ Herdr は、帯域が限られた接続で画面更新の通信量を減らす### SSH 認証の復旧-Linux と macOS で `remote.manage_ssh_config=true` の場合、マシン追加、サイドバー、API 操作は承認済み OpenSSH 接続を共有します。`herdr machine status [<label-or-id>] [--json]` は認証を求めず、現在の接続状態を確認します。**reachable** はリモート Herdr が利用可能という意味で、各 TUI の接続状態ではありません。ターミナルで `herdr machine reconnect <label-or-id>` を実行すると、SSH 認証後に保存済みマシンを検証します。インストールや更新は行いません。開いているクライアントは 30 秒以内に再試行し、再起動は不要です。**`! auth`**、**`! error`**、失敗後の再接続ステータスをクリックすると、最新のエラーと CLI コマンドが通知に表示されます。認証ポップアップは開きません。マシン行の展開・折りたたみは変更されません。+Linux と macOS で `remote.manage_ssh_config=true` の場合、マシン追加、サイドバー、API 操作は承認済み OpenSSH 接続を共有します。`herdr machine status [<label-or-id>] [--json]` は認証を求めず、現在の接続状態を確認します。**reachable** はリモート Herdr が利用可能という意味で、各 TUI の接続状態ではありません。ターミナルで `herdr machine reconnect <label-or-id>` を実行すると、SSH 認証後に保存済みマシンを検証します。インストールや更新は行いません。開いているクライアントは 30 秒以内に再試行し、再起動は不要です。**`! auth`**、**`! error`**、再接続ステータスをクリックすると再試行し、失敗した場合は最新のエラーと CLI コマンドを通知に表示します。認証ポップアップは開きません。共有接続の `ControlPersist 600` はアイドル状態の 10 分を表すもので、MFA の有効期間ではありません。通信中の接続は維持されますが、企業ポリシー、SSH サーバー、ネットワークによってはそれより早く終了します。ローカル Windows の復旧はまだ対応していません。管理対象外の SSH 接続の認証は利用者の責任です。共有 ControlPath を使わずに `ssh` を実行するだけでは、Herdr の承認にはなりません。ホスト鍵の検証は緩和されず、未知または変更されたホスト鍵は引き続き **Attention** です。@@ -88,7 +88,7 @@ herdr machine remove <profile-id>## 接続の問題- **Reconnecting:** ネットワーク中断、スリープ、SSH 障害の後は自動で再試行します。失敗が続くと待機間隔は最大 2 分まで延び、短時間だけ接続に成功してもリセットされません。1 分間安定して接続できると、次の中断では再び短い間隔で再試行します。SSH 接続はアプリケーションの通信を監視し、通信がない間はヘルスチェックを行うため、切れた接続が Online のままになりません。Local はリモート用のプローブではなく、ネイティブ接続の終了や失敗を検知します。-- **Attention:** 認証、ホスト鍵の承認、互換サーバーの準備などが必要です。ほかのマシンは利用できます。**`! auth`** は認証失敗、**`! error`** は別の問題を示します。バッジをクリックするとエラーと CLI コマンドを表示します。折りたたみ時はどちらも `!` です。+- **Attention:** 認証、ホスト鍵の承認、互換サーバーの準備などが必要です。ほかのマシンは利用できます。**`! auth`** は認証失敗、**`! error`** は別の問題を示します。バッジをクリックすると再試行し、失敗した場合は新しいエラーと CLI コマンドを通知に表示します。折りたたみ時はどちらも `!` です。- **保存済みマシンのファイルエラー:** カタログを読み取れない、または内容が不正な場合、現在の接続は変更しません。通知を表示して自動で読み取りを再試行します。両端のインストールがブリッジのアイドル終了に対応している場合、Linux と macOS への保存済みマシン接続は、どちらの方向にも通信がない状態が 1 分続くとリモートブリッジを終了します。スリープ時間も含み、復帰時に期限を確認します。正常なアイドル接続ではヘルスチェックを交換するため、継続的な出力を見るためにキーを入力する必要はありません。ブリッジ終了後もリモートサーバー、セッション、ペインのプロセスは動き続けます。古いインストールとは、この追加機能なしで接続できます。diff --git a/docs/next/website/src/content/docs/zh-cn/cli-reference.mdx b/docs/next/website/src/content/docs/zh-cn/cli-reference.mdxindex 6f55954b9..87333a69c 100644--- a/docs/next/website/src/content/docs/zh-cn/cli-reference.mdx+++ b/docs/next/website/src/content/docs/zh-cn/cli-reference.mdx@@ -65,7 +65,7 @@ herdr machine remove <profile-id>更改会自动应用到已打开的本地 Herdr 客户端,通常在一秒内生效。新增或启用的机器在后台连接;重命名不会重新连接。移除或禁用只会断开该机器,远程会话仍会继续运行。移除正在查看的机器会返回 Local;如果 Local 不可用,则显示不可用状态,直到重新连接。每份配置在客户端状态文件中保存一个不透明 ID、标签、SSH 目标、明确的远程会话名和启用状态。Herdr 不保存密码、私钥或其他 SSH 凭据。-`herdr machine status [<label-or-id>] [--json]` 可非交互式检查 SSH 和远程 Herdr。`reachable` 表示本次检查成功,不代表 TUI 当前已连接。在终端运行 `herdr machine reconnect <label-or-id>` 可认证并验证连接,不会安装或更新 Herdr。已打开的客户端会在 30 秒内重试。点击 `! auth` 或 `! error` 可查看最新错误和 CLI 命令;侧边栏折叠时显示 `!`。平台限制请参阅[恢复 SSH 认证](/zh-cn/docs/connecting-machines/#恢复-ssh-认证)。需要远程设置时使用 `herdr --remote workbox`,仅在命名会话时添加 `--session <name>`。+`herdr machine status [<label-or-id>] [--json]` 可非交互式检查 SSH 和远程 Herdr。`reachable` 表示本次检查成功,不代表 TUI 当前已连接。在终端运行 `herdr machine reconnect <label-or-id>` 可认证并验证连接,不会安装或更新 Herdr。已打开的客户端会在 30 秒内重试。点击 `! auth` 或 `! error` 会重试;失败后会显示最新错误和 CLI 命令;侧边栏折叠时显示 `!`。平台限制请参阅[恢复 SSH 认证](/zh-cn/docs/connecting-machines/#恢复-ssh-认证)。需要远程设置时使用 `herdr --remote workbox`,仅在命名会话时添加 `--session <name>`。工作区、标签页、窗格 ID 和智能体名称仅在所属服务器内有效。UI 中的选择不会改变 CLI 的目标。使用全局**前缀** `--machine <label-or-id>` 将 API 命令发送到已保存的 SSH 机器:diff --git a/docs/next/website/src/content/docs/zh-cn/connecting-machines.mdx b/docs/next/website/src/content/docs/zh-cn/connecting-machines.mdxindex 116cecbb0..373f1e142 100644--- a/docs/next/website/src/content/docs/zh-cn/connecting-machines.mdx+++ b/docs/next/website/src/content/docs/zh-cn/connecting-machines.mdx@@ -11,7 +11,7 @@ Herdr 会请求 SSH 压缩,以减少受限连接上的屏幕更新流量。这### 恢复 SSH 认证-在 Linux 和 macOS 上,启用 `remote.manage_ssh_config=true` 后,添加机器、侧边栏和 API 操作共享已批准的 OpenSSH 连接。运行 `herdr machine status [<label-or-id>] [--json]` 可进行新的非交互式检查。**reachable** 表示远程 Herdr 当前可用,不代表每个 TUI 都已连接。在终端运行 `herdr machine reconnect <label-or-id>` 完成原生 SSH 认证并验证已保存的机器;该命令不会安装或更新 Herdr。已打开的客户端会在 30 秒内重试,无需重启。点击 **`! auth`**、**`! error`** 或失败后的重连状态,会显示包含最新错误及 CLI 命令的通知,不会打开认证弹窗。机器行其余部分仍用于展开或折叠。+在 Linux 和 macOS 上,启用 `remote.manage_ssh_config=true` 后,添加机器、侧边栏和 API 操作共享已批准的 OpenSSH 连接。运行 `herdr machine status [<label-or-id>] [--json]` 可进行新的非交互式检查。**reachable** 表示远程 Herdr 当前可用,不代表每个 TUI 都已连接。在终端运行 `herdr machine reconnect <label-or-id>` 完成原生 SSH 认证并验证已保存的机器;该命令不会安装或更新 Herdr。已打开的客户端会在 30 秒内重试,无需重启。点击 **`! auth`**、**`! error`** 或重连状态会重试;失败后,通知会显示最新错误和相应 CLI 命令,不会打开认证弹窗。共享连接使用 `ControlPersist 600`,表示空闲 10 分钟,并不表示 MFA 有效期。活动连接可以继续保持,但企业策略、SSH 服务器或网络可能更早终止连接。Windows 本地恢复尚未支持。未受管理的 SSH 连接由你负责认证;单独运行 `ssh` 不会授予 Herdr 批准,除非它使用共享 ControlPath。主机密钥检查不会放宽;未知或已更改的主机密钥仍显示为 **Attention**。@@ -88,7 +88,7 @@ herdr machine remove <profile-id>## 连接问题- **Reconnecting:** 网络中断、睡眠或 SSH 故障后,Herdr 会自动重试。连续失败会将间隔增加到最多两分钟,短暂连接成功不会重置间隔。连接稳定一分钟后,下一次中断才会恢复快速重试。SSH 连接会监测应用层活动并在空闲时探测,避免已断开的连接一直显示 Online。Local 使用本地连接关闭或失败来判断断线,而不是远程健康探测。-- **Attention:** 目标需要认证、批准主机密钥或准备兼容服务器等操作。其他机器仍可使用。**`! auth`** 表示认证失败,**`! error`** 表示其他问题。点击徽章可查看错误和 CLI 命令。侧边栏折叠时两者都显示为 `!`。+- **Attention:** 目标需要认证、批准主机密钥或准备兼容服务器等操作。其他机器仍可使用。**`! auth`** 表示认证失败,**`! error`** 表示其他问题。点击徽章会重试;失败后,通知会显示本次错误和 CLI 命令。侧边栏折叠时两者都显示为 `!`。- **保存机器文件错误:** 目录文件无法读取或内容无效时,当前连接保持不变。Herdr 会显示通知并自动重试读取。当两端都支持空闲桥接清理时,连接 Linux/macOS 的保存机器会在双向均无流量一分钟后关闭远程桥接。睡眠时间也计入期限,并在唤醒时检查。正常的空闲连接会交换健康检查,持续查看输出无需键盘输入。清理不会停止远程 Herdr 服务器、会话或窗格进程。旧安装仍可兼容连接,只是不使用这项可选清理功能。diff --git a/src/client/endpoint/supervisor.rs b/src/client/endpoint/supervisor.rsindex efad076ba..471acd7d2 100644--- a/src/client/endpoint/supervisor.rs+++ b/src/client/endpoint/supervisor.rs@@ -242,6 +242,20 @@ impl EndpointSupervisors {true}+ /// A user asked for this machine now, so skip its pending backoff and restart the ladder.+ /// Returns false when no attempt is waiting: it is online, in flight, or not retried at all.+ pub(crate) fn retry_now(&mut self, endpoint_id: &ClientEndpointId, now: Instant) -> bool {+ let Some(state) = self.endpoints.get_mut(endpoint_id) else {+ return false;+ };+ if state.in_flight || state.next_attempt.is_none() {+ return false;+ }+ state.attempts = 0;+ state.next_attempt = Some(now);+ true+ }+pub(crate) fn disconnected(&mut self,endpoint_id: &ClientEndpointId,@@ -484,6 +498,55 @@ mod tests {);}+ #[test]+ fn requested_retry_skips_backoff_without_duplicating_attempts() {+ let now = Instant::now();+ let profile = profile();+ let id = ClientEndpointId::Ssh(profile.id.clone());+ let mut supervisors = EndpointSupervisors::new(&[profile], now);+ let state = supervisors.endpoints.get_mut(&id).unwrap();+ state.generation = Some(2);+ state.attempts = 9;+ assert!(supervisors.disconnected(&id, 2, now));+ assert_eq!(+ supervisors.endpoints[&id].next_attempt,+ Some(now + MAX_RETRY_DELAY)+ );++ let clicked = now + Duration::from_secs(5);+ assert!(supervisors.retry_now(&id, clicked));+ assert_eq!(supervisors.endpoints[&id].next_attempt, Some(clicked));+ // A failed requested attempt resumes from the shortest delay.+ assert!(supervisors.disconnected(&id, 2, clicked));+ assert_eq!(+ supervisors.endpoints[&id].next_attempt,+ Some(clicked + INITIAL_RETRY_DELAY)+ );++ supervisors.endpoints.get_mut(&id).unwrap().in_flight = true;+ assert!(!supervisors.retry_now(&id, clicked));+ assert!(supervisors.record_status(&id, 2, ClientEndpointStatus::Online, clicked));+ assert!(!supervisors.retry_now(&id, clicked));+ assert!(supervisors.endpoints[&id].next_attempt.is_none());+ }++ #[test]+ fn requested_retry_does_not_revive_local_needing_attention() {+ let now = Instant::now();+ let mut supervisors = EndpointSupervisors::new(&[], now);+ supervisors.add_local(PathBuf::from("local.sock"), Some(1), now);+ assert!(supervisors.record_status(+ &ClientEndpointId::Local,+ 1,+ ClientEndpointStatus::Attention,+ now+ ));+ assert!(!supervisors.retry_now(&ClientEndpointId::Local, now));+ assert!(supervisors.endpoints[&ClientEndpointId::Local]+ .next_attempt+ .is_none());+ }+#[test]fn retry_backoff_is_bounded() {assert_eq!(retry_delay(1), INITIAL_RETRY_DELAY);diff --git a/src/client/mod.rs b/src/client/mod.rsindex f55db195f..51c181906 100644--- a/src/client/mod.rs+++ b/src/client/mod.rs@@ -738,6 +738,7 @@ async fn run_client_loop(present_handoff_unavailable(&mut state,"Local is unavailable; reconnecting".into(),+ None,);}}@@ -765,9 +766,15 @@ async fn run_client_loop(}}}+ let now = std::time::Instant::now();+ if let Some(shell) = state.shell.as_mut() {+ for endpoint_id in shell.take_machine_retries() {+ supervisors.retry_now(&endpoint_id, now);+ }+ }if let Some(shell) = state.shell.as_ref() {supervisors.spawn_due(- std::time::Instant::now(),+ now,endpoint::EndpointConnectOptions {cols: state.reported_size.0,rows: state.reported_size.1,@@ -1331,20 +1338,7 @@ async fn run_client_loop(if status == endpoint::ClientEndpointStatus::Attention {warn!(endpoint = %endpoint_id.storage_key(), generation, error = %message, "endpoint needs attention");}- let unavailable = state.shell.as_mut().and_then(|shell| {- shell.set_endpoint_status(&endpoint_id, status);- shell.set_machine_diagnostic(&endpoint_id, message.clone());- (status == endpoint::ClientEndpointStatus::Attention- && shell.endpoint_is_active(&endpoint_id))- .then(|| format!("{}: {message}", shell.endpoint_label(&endpoint_id)))- });- if let Some(message) = unavailable {- present_handoff_unavailable(&mut state, message);- } else if let Some(frame) = state.shell.as_mut().and_then(|shell| {- shell.compose(state.reported_size.0, state.reported_size.1)- }) {- state.present_frame(frame);- }+ present_endpoint_connection_failure(&mut state, &endpoint_id, status, message);}endpoint::EndpointSupervisorEvent::Connected {endpoint_id,diff --git a/src/client/shell/endpoint_navigation.rs b/src/client/shell/endpoint_navigation.rsindex 3d99e5a62..f1e268c3b 100644--- a/src/client/shell/endpoint_navigation.rs+++ b/src/client/shell/endpoint_navigation.rs@@ -57,7 +57,12 @@ impl ClientShellState {};let endpoint_id = hit.endpoint_id.clone();let collapse_toggle = super::contains(hit.collapse_toggle, point);- if collapse_toggle || endpoint_id == self.active_endpoint_id {+ if collapse_toggle+ || (endpoint_id == self.active_endpoint_id+ && (endpoint_id.is_local()+ || self.endpoint_is_online(&endpoint_id)+ || self.endpoint_status(&endpoint_id) == Some(ClientEndpointStatus::Disabled)))+ {if !self.collapsed_endpoints.remove(&endpoint_id) {self.collapsed_endpoints.insert(endpoint_id.clone());}@@ -71,9 +76,7 @@ impl ClientShellState {target: None,});} else {- let label = self.endpoint_label(&endpoint_id).to_owned();- self.receive_endpoint_unavailable(format!("{label} is not ready"));- outcome.repaint = true;+ self.select_unready_machine(&endpoint_id, outcome);}true}@@ -225,6 +228,19 @@ impl ClientShellState {false}+ /// Selecting a machine that is waiting to reconnect asks for an attempt now.+ fn select_unready_machine(+ &mut self,+ endpoint_id: &ClientEndpointId,+ outcome: &mut ClientShellInput,+ ) {+ if !self.retry_machine(endpoint_id) {+ let label = self.endpoint_label(endpoint_id).to_owned();+ self.receive_endpoint_unavailable(format!("{label} is not ready"));+ }+ outcome.repaint = true;+ }+pub(super) fn activate_endpoint(&mut self,endpoint_id: ClientEndpointId,@@ -234,9 +250,7 @@ impl ClientShellState {self.pending_agent_reveal = None;let online = self.endpoint_is_online(&endpoint_id);if !online && !endpoint_id.is_local() {- let label = self.endpoint_label(&endpoint_id).to_owned();- self.receive_endpoint_unavailable(format!("{label} is not ready"));- outcome.repaint = true;+ self.select_unready_machine(&endpoint_id, outcome);return false;}if (endpoint_id.is_local() && (self.multi_endpoint_active() || !online))@@ -264,9 +278,7 @@ impl ClientShellState {self.pending_agent_reveal = None;let online = self.endpoint_is_online(&endpoint_id);if !online && !endpoint_id.is_local() {- let label = self.endpoint_label(&endpoint_id).to_owned();- self.receive_endpoint_unavailable(format!("{label} is not ready"));- outcome.repaint = true;+ self.select_unready_machine(&endpoint_id, outcome);return false;}// Local can still be displayed while a remote activation is pending.diff --git a/src/client/shell/machine_diagnostics.rs b/src/client/shell/machine_diagnostics.rsindex 679830243..3441d97b4 100644--- a/src/client/shell/machine_diagnostics.rs+++ b/src/client/shell/machine_diagnostics.rs@@ -6,6 +6,10 @@ use crossterm::event::{MouseButton, MouseEventKind};pub(super) struct MachineDiagnostics {errors: HashMap<ClientEndpointId, String>,hover: Option<ClientEndpointId>,+ /// Retries the client loop has not yet handed to the endpoint supervisors.+ retry_requests: Vec<ClientEndpointId>,+ /// Requested retries whose failure should reopen the fresh diagnostic.+ retry_reports: HashSet<ClientEndpointId>,}impl MachineDiagnostics {@@ -21,9 +25,7 @@ impl MachineDiagnostics {palette: &Palette,style: Style,) -> Style {- if self.hover.as_ref() == Some(&endpoint.endpoint_id)- && self.errors.contains_key(&endpoint.endpoint_id)- {+ if self.hover.as_ref() == Some(&endpoint.endpoint_id) && machine_retryable(endpoint) {style.bg(palette.active_row_bg).add_modifier(Modifier::REVERSED)@@ -33,7 +35,35 @@ impl MachineDiagnostics {}}+/// Saved machines wait out a reconnect backoff whenever they are not online or disabled.+fn machine_retryable(endpoint: &ClientShellEndpoint) -> bool {+ !endpoint.endpoint_id.is_local()+ && matches!(+ endpoint.status,+ ClientEndpointStatus::Connecting+ | ClientEndpointStatus::Reconnecting+ | ClientEndpointStatus::Attention+ )+}++fn machine_diagnostic_code(profile_id: &impl std::fmt::Display) -> String {+ format!("machine-diagnostic:{profile_id}")+}+impl ClientShellState {+ pub(crate) fn receive_machine_unavailable(+ &mut self,+ id: &ClientEndpointId,+ message: String,+ ) -> bool {+ self.push_endpoint_notice(+ ClientEndpointNoticeKind::Unavailable,+ format!("machine-unavailable:{}:{message}", id.storage_key()),+ "Endpoint unavailable",+ message,+ )+ }+pub(crate) fn set_machine_diagnostic(&mut self, id: &ClientEndpointId, message: String) {if !id.is_local() {self.machine_diagnostics.errors.insert(@@ -49,6 +79,49 @@ impl ClientShellState {pub(super) fn clear_machine_diagnostic(&mut self, id: &ClientEndpointId) {self.machine_diagnostics.errors.remove(id);+ self.machine_diagnostics.retry_reports.remove(id);+ }++ /// Asks for an immediate connection attempt instead of waiting out the backoff.+ /// Returns false when the machine has no pending reconnect to bring forward.+ pub(super) fn retry_machine(&mut self, id: &ClientEndpointId) -> bool {+ let ClientEndpointId::Ssh(profile_id) = id else {+ return false;+ };+ if !self+ .endpoints+ .iter()+ .any(|endpoint| &endpoint.endpoint_id == id && machine_retryable(endpoint))+ {+ return false;+ }+ // Clear the selected machine's diagnostic or active disconnect notice.+ let code = machine_diagnostic_code(profile_id);+ let unavailable = format!("machine-unavailable:{}:", id.storage_key());+ if self.visible_endpoint_notice.as_ref().is_some_and(|notice| {+ notice.key.code == code || notice.key.code.starts_with(&unavailable)+ }) {+ self.visible_endpoint_notice = None;+ }+ if !self.machine_diagnostics.retry_requests.contains(id) {+ self.machine_diagnostics.retry_requests.push(id.clone());+ }+ self.machine_diagnostics.retry_reports.insert(id.clone());+ self.set_endpoint_status(id, ClientEndpointStatus::Connecting);+ true+ }++ pub(crate) fn take_machine_retries(&mut self) -> Vec<ClientEndpointId> {+ std::mem::take(&mut self.machine_diagnostics.retry_requests)+ }++ /// Reports a failed connection attempt when the user asked for it.+ pub(crate) fn report_machine_retry(&mut self, id: &ClientEndpointId) -> bool {+ let requested = self.machine_diagnostics.retry_reports.remove(id);+ if requested {+ self.show_machine_diagnostic(id);+ }+ requested}pub(super) fn handle_machine_badge_event(@@ -70,12 +143,11 @@ impl ClientShellState {.hits.machines.iter()- .find(|hit| {- contains(hit.status_badge, (mouse.column, mouse.row))- && self- .machine_diagnostics- .errors- .contains_key(&hit.endpoint_id)+ .find(|hit| contains(hit.status_badge, (mouse.column, mouse.row)))+ .filter(|hit| {+ self.endpoints.iter().any(|endpoint| {+ endpoint.endpoint_id == hit.endpoint_id && machine_retryable(endpoint)+ })}).map(|hit| hit.endpoint_id.clone());if mouse.kind == MouseEventKind::Moved {@@ -94,25 +166,30 @@ impl ClientShellState {if mouse.kind != MouseEventKind::Down(MouseButton::Left) {return false;}- let Some(error) = self.machine_diagnostics.errors.get(&id) else {- return true;+ outcome.repaint |= self.retry_machine(&id);+ true+ }++ fn show_machine_diagnostic(&mut self, id: &ClientEndpointId) {+ let ClientEndpointId::Ssh(profile_id) = id else {+ return;};- let ClientEndpointId::Ssh(profile_id) = &id else {- return true;+ let Some(error) = self.machine_diagnostics.errors.get(id) else {+ return;};+ let code = machine_diagnostic_code(profile_id);let command = if crate::remote::ssh_error_requires_authentication(error) {format!("herdr machine reconnect {profile_id}")} else {format!("herdr machine status {profile_id}")};- let code = format!("machine-diagnostic:{}", profile_id);- // An explicit click can reopen its diagnostic, but must not replace another notice.+ // A requested retry can report its diagnostic, but must not replace another notice.if self.visible_endpoint_notice.as_ref().is_some_and(|notice| notice.key.code != code){- return true;+ return;}self.visible_endpoint_notice = Some(ClientVisibleEndpointNotice {key: ClientEndpointNoticeKey {@@ -120,11 +197,9 @@ impl ClientShellState {kind: ClientEndpointNoticeKind::Unavailable,code,},- title: format!("{}: {command}", self.endpoint_label(&id)),+ title: format!("{}: {command}", self.endpoint_label(id)),body: error.clone(),deadline: std::time::Instant::now() + std::time::Duration::from_secs(15),});- outcome.repaint = true;- true}}diff --git a/src/client/shell/tests/endpoints.rs b/src/client/shell/tests/endpoints.rsindex c0a7e5235..5d92c4531 100644--- a/src/client/shell/tests/endpoints.rs+++ b/src/client/shell/tests/endpoints.rs@@ -273,34 +273,75 @@ fn system_notification_clicks_keep_endpoint_and_boot_identity() {}}+fn click_machine(state: &mut ClientShellState, id: &ClientEndpointId, badge: bool) -> bool {+ state.compose(120, 40).unwrap();+ let hit = state+ .hits+ .machines+ .iter()+ .find(|hit| &hit.endpoint_id == id)+ .unwrap();+ let (column, row) = if badge {+ (hit.status_badge.x, hit.status_badge.y)+ } else {+ (hit.rect.x.saturating_add(3), hit.rect.y)+ };+ let mouse = MouseEvent {+ kind: MouseEventKind::Down(MouseButton::Left),+ column,+ row,+ modifiers: KeyModifiers::NONE,+ };+ state+ .handle_raw_events(vec![RawInputEvent::Mouse(mouse)])+ .repaint+}+#[test]-fn machine_diagnostic_badge_reopens_notice_without_collapsing_machine() {+fn machine_badge_retries_and_reports_the_fresh_diagnostic() {let (mut state, id) = state_with_remote();state.set_endpoint_status(&id, ClientEndpointStatus::Attention);- state.set_machine_diagnostic(&id, "Permission denied (keyboard-interactive)".into());+ state.set_machine_diagnostic(&id, "ssh: connect to host build: No route to host".into());+ state.retry_machine(&id);+ state.set_endpoint_status(&id, ClientEndpointStatus::Attention);+ state.report_machine_retry(&id);+ assert!(state+ .visible_endpoint_notice+ .as_ref()+ .unwrap()+ .body+ .contains("No route to host"));+ assert_eq!(state.take_machine_retries(), vec![id.clone()]);+for _ in 0..2 {- state.compose(120, 40).unwrap();- let hit = state- .hits- .machines- .iter()- .find(|hit| hit.endpoint_id == id)- .unwrap();- let mouse = MouseEvent {- kind: MouseEventKind::Down(MouseButton::Left),- column: hit.status_badge.x,- row: hit.status_badge.y,- modifiers: KeyModifiers::NONE,- };- let outcome = state.handle_raw_events(vec![RawInputEvent::Mouse(mouse)]);- assert!(outcome.repaint);+ assert!(click_machine(&mut state, &id, true));assert!(!state.collapsed_endpoints.contains(&id));- let notice = state.visible_endpoint_notice.take().unwrap();- assert!(notice.body.contains("Permission denied"));- assert!(notice- .title- .contains("herdr machine reconnect 0123456789abcdef0123456789abcdef"));+ assert_eq!(+ state.endpoint_status(&id),+ Some(ClientEndpointStatus::Connecting)+ );+ assert!(+ state.visible_endpoint_notice.is_none(),+ "the stale diagnostic must not outlive the retry it describes"+ );}+ assert_eq!(state.take_machine_retries(), vec![id.clone()]);++ state.set_endpoint_status(&id, ClientEndpointStatus::Attention);+ state.set_machine_diagnostic(&id, "Permission denied (keyboard-interactive)".into());+ state.report_machine_retry(&id);+ let notice = state.visible_endpoint_notice.take().unwrap();+ assert!(notice.body.contains("Permission denied"));+ assert!(notice+ .title+ .contains("herdr machine reconnect 0123456789abcdef0123456789abcdef"));+ state.set_machine_diagnostic(&id, "a later background failure".into());+ state.report_machine_retry(&id);+ assert!(+ state.visible_endpoint_notice.is_none(),+ "unrequested attempts stay quiet"+ );+state.set_endpoint_status(&id, ClientEndpointStatus::Online);state.compose(120, 40).unwrap();assert!(!state.machine_diagnostics.required_for(@@ -310,6 +351,146 @@ fn machine_diagnostic_badge_reopens_notice_without_collapsing_machine() {.find(|endpoint| endpoint.endpoint_id == id).unwrap()));+ click_machine(&mut state, &id, true);+ assert!(state.take_machine_retries().is_empty());+}++#[test]+fn active_retry_failure_preserves_diagnostic_and_presentation_freeze() {+ use crate::client::shell_runtime::{+ present_endpoint_connection_failure, present_handoff_unavailable,+ };+ use crate::client::state::ClientState;++ for (status, message, command) in [+ (+ ClientEndpointStatus::Attention,+ "Permission denied (keyboard-interactive)",+ "herdr machine reconnect",+ ),+ (+ ClientEndpointStatus::Reconnecting,+ "connection refused",+ "herdr machine status",+ ),+ ] {+ for previous in [+ None,+ Some("disconnect"),+ Some("attention"),+ Some("paste"),+ Some("other"),+ Some("duplicate-label"),+ ] {+ let (mut shell, id) = state_with_remote();+ assert!(shell.activate_endpoint_projection(&id));+ shell.mark_endpoint_disconnected(&id);+ let mut state = ClientState::test_new();+ state.shell = Some(shell);+ match previous {+ Some("disconnect") => {+ present_handoff_unavailable(+ &mut state,+ "Build connection was lost".into(),+ Some(&id),+ );+ }+ Some("attention") => {+ present_handoff_unavailable(&mut state, "Build: old failure".into(), Some(&id));+ }+ Some("paste") => {+ state+ .shell+ .as_mut()+ .unwrap()+ .receive_endpoint_error("another notice".into());+ }+ Some("other") => {+ state+ .shell+ .as_mut()+ .unwrap()+ .receive_endpoint_unavailable("Build west: connection lost".into());+ }+ Some("duplicate-label") => {+ state+ .shell+ .as_mut()+ .unwrap()+ .receive_endpoint_unavailable("Build: unrelated error".into());+ }+ _ => {}+ }+ assert!(click_machine(state.shell.as_mut().unwrap(), &id, false));+ present_endpoint_connection_failure(&mut state, &id, status, message.into());+ assert!(state.presentation_frozen);+ let notice = state+ .shell+ .as_ref()+ .unwrap()+ .visible_endpoint_notice+ .as_ref()+ .unwrap();+ if previous == Some("paste") {+ assert_eq!(notice.body, "another notice");+ } else if previous == Some("other") {+ assert_eq!(notice.body, "Build west: connection lost");+ } else if previous == Some("duplicate-label") {+ assert_eq!(notice.body, "Build: unrelated error");+ } else {+ assert_eq!(notice.body, message);+ assert!(notice.title.contains(command));+ }+ let frame = state+ .shell+ .as_mut()+ .unwrap()+ .compose(state.reported_size.0, state.reported_size.1)+ .unwrap();+ assert!(+ state.blit_encoder.is_current(&frame.frame),+ "the failure notice must reach the screen while frozen"+ );+ }+ }+}++#[test]+fn selecting_a_reconnecting_machine_retries_it() {+ for active in [false, true] {+ let (mut state, id) = state_with_remote();+ if active {+ assert!(state.activate_endpoint_projection(&id));+ }+ state.mark_endpoint_disconnected(&id);+ assert!(click_machine(&mut state, &id, false));+ assert_eq!(state.take_machine_retries(), vec![id.clone()]);+ assert!(state.visible_endpoint_notice.is_none());+ assert_eq!(+ state.endpoint_status(&id),+ Some(ClientEndpointStatus::Connecting)+ );++ // A successful attempt has nothing left to report.+ state.set_endpoint_status(&id, ClientEndpointStatus::Online);+ state.set_endpoint_status(&id, ClientEndpointStatus::Reconnecting);+ state.set_machine_diagnostic(&id, "connection refused".into());+ state.report_machine_retry(&id);+ assert!(state.visible_endpoint_notice.is_none());++ state.set_endpoint_status(&id, ClientEndpointStatus::Disabled);+ assert!(click_machine(&mut state, &id, false));+ assert!(state.take_machine_retries().is_empty());+ if active {+ assert!(state.visible_endpoint_notice.is_none());+ assert!(state.collapsed_endpoints.contains(&id));+ } else {+ assert!(state+ .visible_endpoint_notice+ .as_ref()+ .is_some_and(|notice| notice.body == "Build is not ready"));+ }+ }}fn state_with_scrollable_agents() -> (ClientShellState, ClientEndpointId) {diff --git a/src/client/shell_runtime.rs b/src/client/shell_runtime.rsindex 66a418642..52aba20a6 100644--- a/src/client/shell_runtime.rs+++ b/src/client/shell_runtime.rs@@ -268,7 +268,7 @@ pub(super) fn begin_endpoint_activation(let outcome = activation.supersede(endpoint_id, target, endpoints);if let endpoint::ActivationRollback::Unavailable(message) = outcome {*pending = None;- present_handoff_unavailable(state, message);+ present_handoff_unavailable(state, message, None);}}return Ok(());@@ -478,12 +478,55 @@ pub(super) fn complete_endpoint_activation(Ok(None)}-pub(super) fn present_handoff_unavailable(state: &mut ClientState, message: String) {+pub(super) fn present_endpoint_connection_failure(+ state: &mut ClientState,+ endpoint_id: &endpoint::ClientEndpointId,+ status: endpoint::ClientEndpointStatus,+ message: String,+) {+ let active_failure = state+ .shell+ .as_ref()+ .is_some_and(|shell| shell.endpoint_is_active(endpoint_id));+ if active_failure {+ state.freeze_presentation();+ }+ let unavailable = state.shell.as_mut().and_then(|shell| {+ shell.set_endpoint_status(endpoint_id, status);+ shell.set_machine_diagnostic(endpoint_id, message.clone());+ let requested = shell.report_machine_retry(endpoint_id);+ (active_failure && status == endpoint::ClientEndpointStatus::Attention && !requested)+ .then(|| format!("{}: {message}", shell.endpoint_label(endpoint_id)))+ });+ if let Some(message) = unavailable {+ present_handoff_unavailable(state, message, Some(endpoint_id));+ } else if let Some(frame) = state+ .shell+ .as_mut()+ .and_then(|shell| shell.compose(state.reported_size.0, state.reported_size.1))+ {+ if active_failure {+ state.present_frozen_chrome(frame);+ } else {+ state.present_frame(frame);+ }+ }+}++pub(super) fn present_handoff_unavailable(+ state: &mut ClientState,+ message: String,+ machine: Option<&endpoint::ClientEndpointId>,+) {// An unavailable committed endpoint has no presentation lease. Keep all pane input and late// source output blocked, while allowing this client-owned chrome frame through the freeze.state.freeze_presentation();let frame = state.shell.as_mut().and_then(|shell| {- shell.receive_endpoint_unavailable(message);+ if let Some(machine) = machine {+ shell.receive_machine_unavailable(machine, message);+ } else {+ shell.receive_endpoint_unavailable(message);+ }shell.compose(state.reported_size.0, state.reported_size.1)});if let Some(frame) = frame {@@ -507,7 +550,7 @@ pub(super) fn rollback_endpoint_activation(*pending = None;// No endpoint has been proven safe to present. Keep pane input frozen, but render// the client-owned unavailable chrome rather than silently swallowing the error.- present_handoff_unavailable(state, message);+ present_handoff_unavailable(state, message, None);}}}@@ -542,7 +585,7 @@ pub(super) fn handle_endpoint_disconnect(endpoint::ActivationRollback::Pending => {}endpoint::ActivationRollback::Unavailable(error) => {*pending_activation = None;- present_handoff_unavailable(state, error);+ present_handoff_unavailable(state, error, None);}}}@@ -556,7 +599,7 @@ pub(super) fn handle_endpoint_disconnect(endpoint_was_active.then(|| format!("{} {notice}", shell.endpoint_label(endpoint_id)))});if let Some(message) = unavailable {- present_handoff_unavailable(state, message);+ present_handoff_unavailable(state, message, Some(endpoint_id));} else if let Some(frame) = state.shell.as_mut()@@ -601,7 +644,7 @@ pub(super) fn handle_endpoint_attention();if let endpoint::ActivationRollback::Unavailable(error) = outcome {*pending_activation = None;- present_handoff_unavailable(state, error);+ present_handoff_unavailable(state, error, None);}}let endpoint_was_active = endpoints.active_id() == endpoint_id;@@ -615,7 +658,7 @@ pub(super) fn handle_endpoint_attention(endpoint_was_active.then(|| format!("{}: {message}", shell.endpoint_label(endpoint_id)))});if let Some(message) = unavailable {- present_handoff_unavailable(state, message);+ present_handoff_unavailable(state, message, Some(endpoint_id));} else if let Some(frame) = state.shell.as_mut()