Compare commits

...
Author SHA1 Message Date
DuProcess f8693f08b5 Release v1.0.0-rc49
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
2026-07-17 21:39:01 -04:00
DuProcess 26532fc0e1 Stop idle keepalives from repainting terminals
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
2026-07-17 21:36:44 -04:00
DuProcess c5f699a6ef Release v1.0.0-rc48
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
2026-07-17 21:25:28 -04:00
DuProcess 60403ba4c3 Stop repainting healthy idle TUIs
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
2026-07-17 21:19:31 -04:00
4 changed files with 181 additions and 87 deletions
Generated
+1 -1
View File
@@ -436,7 +436,7 @@ dependencies = [
[[package]]
name = "dosh"
version = "1.0.0-rc47"
version = "1.0.0-rc49"
dependencies = [
"anyhow",
"base64",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "dosh"
version = "1.0.0-rc47"
version = "1.0.0-rc49"
edition = "2024"
license = "MIT"
+16 -85
View File
@@ -77,7 +77,6 @@ const POST_SUBMIT_ALL_INPUT_HOLD: Duration = Duration::from_millis(120);
const STALE_TERMINAL_INPUT_AFTER: Duration = Duration::from_secs(2);
const POST_RECONNECT_STALE_INPUT_GRACE: Duration = Duration::from_secs(5);
const FOCUS_REPAINT_COOLDOWN: Duration = Duration::from_secs(1);
const ALT_SCREEN_IDLE_REPAINT_AFTER: Duration = Duration::from_secs(15);
const LOCAL_SLEEP_REPAINT_AFTER: Duration = Duration::from_secs(5);
const LOCAL_SLEEP_REPAINT_RETRY_AFTER: Duration = Duration::from_secs(1);
const LOCAL_SLEEP_REPAINT_RETRY_WINDOW: Duration = Duration::from_secs(10);
@@ -6614,9 +6613,8 @@ async fn run_terminal(
let mut startup_input_hold_until: Option<Instant> = None;
let mut startup_gate_mode = StartupGateMode::HoldControl;
let mut stale_terminal_input_suppress_until: Option<Instant> = None;
let mut last_terminal_frame_at = Instant::now();
let mut last_focus_repaint_at = Instant::now() - FOCUS_REPAINT_COOLDOWN;
let mut last_idle_repaint_attempt_at = Instant::now() - ALT_SCREEN_IDLE_REPAINT_AFTER;
let mut last_idle_repaint_attempt_at = Instant::now() - LOCAL_SLEEP_REPAINT_RETRY_AFTER;
let mut last_status_tick_at = Instant::now();
let mut wake_repaint_retry_until: Option<Instant> = None;
if let Some(frame) = first_frame {
@@ -6624,7 +6622,6 @@ async fn run_terminal(
render_frame(&frame)?;
note_snapshot_rendered(&frame, &mut disconnect_status, &mut status_restore_pending);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
}
if frame.closed {
return Ok(());
@@ -6694,7 +6691,6 @@ async fn run_terminal(
&mut disconnect_status,
&mut status_restore_pending,
);
last_terminal_frame_at = Instant::now();
wake_repaint_retry_until = None;
send_ack(&socket, addr, &cred, &mut send_seq).await?;
if frame.closed {
@@ -6779,7 +6775,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
last_packet_at = Instant::now();
last_focus_repaint_at = Instant::now();
wake_repaint_retry_until = None;
@@ -6839,7 +6834,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
last_packet_at = Instant::now();
wake_repaint_retry_until = None;
flush_pending_user_input(
@@ -7063,7 +7057,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
}
last_packet_at = Instant::now();
flush_pending_user_input(
@@ -7137,7 +7130,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
wake_repaint_retry_until = None;
}
last_packet_at = Instant::now();
@@ -7202,7 +7194,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
wake_repaint_retry_until = None;
}
last_packet_at = Instant::now();
@@ -7232,7 +7223,6 @@ async fn run_terminal(
predictor.clear_pending()?;
if !forward_only {
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
wake_repaint_retry_until = None;
if render_resync_needed {
if frame.closed {
@@ -7388,7 +7378,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
wake_repaint_retry_until = None;
}
last_packet_at = Instant::now();
@@ -8008,7 +7997,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
last_idle_repaint_attempt_at = Instant::now();
wake_repaint_retry_until = None;
repainted_this_tick = true;
@@ -8058,8 +8046,6 @@ async fn run_terminal(
.await?;
let now = Instant::now();
if !repainted_this_tick && !render_resync_needed && !frame_renderer.has_pending() && should_repaint_idle_terminal(
predictor.alternate_screen,
last_terminal_frame_at,
last_idle_repaint_attempt_at,
status_tick_gap,
wake_repaint_retry_until,
@@ -8095,7 +8081,6 @@ async fn run_terminal(
&mut status_restore_pending,
);
predictor.observe_output(&frame.bytes);
last_terminal_frame_at = Instant::now();
last_packet_at = Instant::now();
wake_repaint_retry_until = None;
flush_pending_user_input(
@@ -8670,8 +8655,6 @@ fn strip_terminal_focus_reports(bytes: &[u8]) -> Vec<u8> {
}
fn should_repaint_idle_terminal(
alternate_screen: bool,
last_terminal_frame_at: Instant,
last_attempt_at: Instant,
status_tick_gap: Duration,
wake_repaint_retry_until: Option<Instant>,
@@ -8679,12 +8662,8 @@ fn should_repaint_idle_terminal(
) -> bool {
let sleep_wake_gap = status_tick_gap >= LOCAL_SLEEP_REPAINT_AFTER;
let wake_retry_active = wake_repaint_retry_until.is_some_and(|deadline| now < deadline);
let stale_alternate_screen = alternate_screen
&& now.duration_since(last_terminal_frame_at) >= ALT_SCREEN_IDLE_REPAINT_AFTER;
if sleep_wake_gap || wake_retry_active {
return now.duration_since(last_attempt_at) >= LOCAL_SLEEP_REPAINT_RETRY_AFTER;
}
stale_alternate_screen && now.duration_since(last_attempt_at) >= ALT_SCREEN_IDLE_REPAINT_AFTER
(sleep_wake_gap || wake_retry_active)
&& now.duration_since(last_attempt_at) >= LOCAL_SLEEP_REPAINT_RETRY_AFTER
}
fn arm_stale_terminal_input_suppression(suppress_until: &mut Option<Instant>) {
@@ -10697,9 +10676,12 @@ const TERMINAL_SNAPSHOT_RESET: &[u8] = concat!(
.as_bytes();
/// Seconds of silence from the server before the disconnect status line appears.
/// Short enough to give quick feedback on a lost link, long enough that a normal
/// idle period (the run loop only pings after 2s of quiet) never flashes it.
const DISCONNECT_STATUS_THRESHOLD_SECS: u64 = 2;
/// Short enough to give quick feedback on a lost link, but later than the first
/// idle ping. Using the same threshold as the first ping races its Pong: the bar
/// is painted just before the authenticated reply arrives, which then requests a
/// snapshot to restore row 1 and turns every healthy idle connection into a
/// periodic reconnect loop.
const DISCONNECT_STATUS_THRESHOLD_SECS: u64 = 3;
/// Mosh-style disconnect status bar with snapshot-backed restoration.
///
@@ -11206,8 +11188,8 @@ const TERMINAL_CLEANUP: &[u8] = concat!(
#[cfg(test)]
mod tests {
use super::{
ALT_SCREEN_IDLE_REPAINT_AFTER, CachedCredential, DisconnectStatus, DynamicForward,
FRAME_GAP_RESYNC_AFTER_MS, FrameBuffer, LOCAL_SLEEP_REPAINT_AFTER,
CachedCredential, DisconnectStatus, DynamicForward, FRAME_GAP_RESYNC_AFTER_MS, FrameBuffer,
LOCAL_SLEEP_REPAINT_AFTER, LOCAL_SLEEP_REPAINT_RETRY_AFTER,
LOCAL_SLEEP_REPAINT_RETRY_WINDOW, LocalForward, MAX_PENDING_USER_INPUT_BYTES,
NativeIdentityContext, POST_RECONNECT_STALE_INPUT_GRACE, POST_SUBMIT_ALL_INPUT_HOLD,
PendingStreamControl, PendingStreamOpen, PendingWindowAdjust, PredictMode, Predictor,
@@ -14478,86 +14460,35 @@ mod tests {
}
#[test]
fn idle_repaint_runs_for_stale_alternate_screen_or_sleep_gap() {
fn idle_repaint_runs_only_after_sleep_or_an_armed_wake_retry() {
let now = Instant::now();
let stale = now - ALT_SCREEN_IDLE_REPAINT_AFTER - Duration::from_secs(1);
let recent = now - Duration::from_secs(1);
let stale = now - LOCAL_SLEEP_REPAINT_RETRY_AFTER - Duration::from_secs(1);
let just_attempted = now - Duration::from_millis(500);
assert!(should_repaint_idle_terminal(
true,
stale,
assert!(!should_repaint_idle_terminal(
stale,
Duration::from_secs(1),
None,
now
));
assert!(should_repaint_idle_terminal(
false,
recent,
stale,
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(1),
None,
now
));
assert!(should_repaint_idle_terminal(
false,
recent,
recent,
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(1),
stale,
Duration::from_secs(1),
Some(now + LOCAL_SLEEP_REPAINT_RETRY_WINDOW),
now
));
assert!(!should_repaint_idle_terminal(
false,
recent,
just_attempted,
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(1),
Some(now + LOCAL_SLEEP_REPAINT_RETRY_WINDOW),
now
));
assert!(!should_repaint_idle_terminal(
false,
stale,
stale,
Duration::from_secs(1),
None,
now
));
assert!(!should_repaint_idle_terminal(
true,
recent,
stale,
Duration::from_secs(1),
None,
now
));
assert!(should_repaint_idle_terminal(
true,
stale,
recent,
LOCAL_SLEEP_REPAINT_AFTER + Duration::from_secs(1),
None,
now
));
assert!(should_repaint_idle_terminal(
false,
recent,
stale,
Duration::from_secs(1),
Some(now + LOCAL_SLEEP_REPAINT_RETRY_WINDOW),
now
));
assert!(!should_repaint_idle_terminal(
false,
recent,
just_attempted,
Duration::from_secs(1),
Some(now + LOCAL_SLEEP_REPAINT_RETRY_WINDOW),
now
));
assert!(!should_repaint_idle_terminal(
false,
recent,
stale,
Duration::from_secs(1),
Some(now - Duration::from_millis(1)),
+163
View File
@@ -50,6 +50,7 @@ struct CachedCredentialWire {
enum ServerObservation {
BulkSent,
Input(Vec<u8>),
Ping,
Reconnected,
RenderResynced,
Resize(u16, u16),
@@ -300,6 +301,87 @@ fn idle_reconnect_restores_snapshot_and_orders_reordered_frames() {
assert!(status.success(), "Dosh client exited with {status:?}");
}
#[test]
fn authenticated_idle_pongs_do_not_trigger_snapshot_reconnects() {
let dir = tempfile::tempdir().unwrap();
let home = dir.path().join("home");
let cache = dir.path().join("credentials");
fs::create_dir_all(home.join(".config/dosh")).unwrap();
fs::create_dir_all(&cache).unwrap();
let socket = UdpSocket::bind("127.0.0.1:0").unwrap();
socket
.set_read_timeout(Some(Duration::from_millis(100)))
.unwrap();
let port = socket.local_addr().unwrap().port();
write_client_fixture(&home, &cache, port, 5);
let config_path = home.join(".config/dosh/client.toml");
let mut config: ClientConfig =
toml::from_str(&fs::read_to_string(&config_path).unwrap()).unwrap();
config.disconnect_status = true;
fs::write(&config_path, toml::to_string(&config).unwrap()).unwrap();
let (observation_tx, observation_rx) = mpsc::channel();
let server = thread::spawn(move || run_idle_keepalive_server(socket, observation_tx));
let pty = NativePtySystem::default();
let pair = pty
.openpty(PtySize {
rows: 24,
cols: 80,
pixel_width: 0,
pixel_height: 0,
})
.unwrap();
let mut reader = pair.master.try_clone_reader().unwrap();
let mut command = client_command(dir.path(), port);
command.env("HOME", home.to_string_lossy().to_string());
command.env("USERPROFILE", home.to_string_lossy().to_string());
command.env("APPDATA", home.to_string_lossy().to_string());
command.env("LOCALAPPDATA", home.to_string_lossy().to_string());
command.env("TERM", "xterm-256color");
let mut child = pair.slave.spawn_command(command).unwrap();
drop(pair.slave);
let output = Arc::new(Mutex::new(Vec::new()));
let reader_output = Arc::clone(&output);
let reader_thread = thread::spawn(move || {
let mut buf = [0u8; 4096];
loop {
match reader.read(&mut buf) {
Ok(0) | Err(_) => break,
Ok(n) => reader_output.lock().unwrap().extend_from_slice(&buf[..n]),
}
}
});
let status = child.wait().unwrap();
drop(pair.master);
reader_thread.join().unwrap();
server.join().unwrap();
assert!(status.success(), "Dosh client exited with {status:?}");
let observations: Vec<_> = observation_rx.try_iter().collect();
assert!(
observations
.iter()
.filter(|event| matches!(event, ServerObservation::Ping))
.count()
>= 2,
"idle session did not exercise repeated authenticated keepalives: {observations:?}"
);
assert!(
!observations
.iter()
.any(|event| matches!(event, ServerObservation::Reconnected)),
"healthy idle pongs caused a snapshot reconnect: {observations:?}"
);
assert!(
!contains(&output.lock().unwrap(), b"[dosh] reconnecting"),
"healthy idle session flashed the disconnect overlay"
);
}
#[test]
fn renderer_overflow_resyncs_without_dropping_the_session() {
const PROBE: &[u8] = b"DOSH_OVERFLOW_INPUT\r";
@@ -713,6 +795,87 @@ fn run_reconnect_server(
}
}
fn run_idle_keepalive_server(socket: UdpSocket, observations: mpsc::Sender<ServerObservation>) {
let started = Instant::now();
let mut peer = None;
let mut attached = false;
let mut server_seq = 1u64;
let mut buf = [0u8; 65535];
loop {
if started.elapsed() >= Duration::from_secs(7)
&& let Some(source) = peer
{
server_seq += 1;
send_frame(
&socket,
source,
PacketKind::Frame,
server_seq,
11,
b"DOSH_IDLE_KEEPALIVE_DONE",
false,
true,
);
break;
}
let (n, source) = match socket.recv_from(&mut buf) {
Ok(value) => value,
Err(err)
if matches!(
err.kind(),
std::io::ErrorKind::WouldBlock | std::io::ErrorKind::TimedOut
) =>
{
continue;
}
Err(err) => panic!("idle keepalive server receive failed: {err}"),
};
let packet = protocol::decode(&buf[..n]).unwrap();
match packet.header.kind {
PacketKind::ResumeRequest => {
let plain =
protocol::decrypt_body(&packet, &SESSION_KEY, CLIENT_TO_SERVER).unwrap();
let request: protocol::ResumeRequest = protocol::from_body(&plain).unwrap();
assert_eq!(request.session, SESSION);
if attached {
observations.send(ServerObservation::Reconnected).unwrap();
}
attached = true;
peer = Some(source);
send_frame(
&socket,
source,
PacketKind::ResumeOk,
server_seq,
10,
b"DOSH_IDLE_KEEPALIVE_READY",
true,
false,
);
}
PacketKind::Ping => {
protocol::decrypt_body(&packet, &SESSION_KEY, CLIENT_TO_SERVER).unwrap();
observations.send(ServerObservation::Ping).unwrap();
server_seq += 1;
let pong = protocol::encode_encrypted(
PacketKind::Pong,
CLIENT_ID,
server_seq,
packet.header.seq,
&SESSION_KEY,
SERVER_TO_CLIENT,
b"",
)
.unwrap();
socket.send_to(&pong, source).unwrap();
}
PacketKind::Ack => {}
_ => {}
}
}
}
fn run_overflow_server(
socket: UdpSocket,
observations: mpsc::Sender<ServerObservation>,