Fix attach modal showing local processes in SSH sessions (#37608)

Closes #37520

This change makes the attach modal load processes from the remote server
when connecting via SSH, rather than showing local processes from the
client machine.

This works by using the new GetProcessesRequest RPC message to allow
downstream clients to get the correct processes to display. It also only
works with downstream ssh clients because the message handler is only
registered on headless projects.

Release Notes:

- debugger: Fix bug where SSH attach modal showed local processes
instead of processes from the server
This commit is contained in:
Anthony Eid
2025-09-05 17:03:42 -04:00
committed by GitHub
parent c45177e296
commit ea363466aa
6 changed files with 130 additions and 24 deletions
@@ -32,6 +32,7 @@ use std::{
path::{Path, PathBuf},
sync::{Arc, atomic::AtomicUsize},
};
use sysinfo::System;
use util::ResultExt;
use worktree::Worktree;
@@ -230,6 +231,7 @@ impl HeadlessProject {
session.add_request_handler(cx.weak_entity(), Self::handle_get_path_metadata);
session.add_request_handler(cx.weak_entity(), Self::handle_shutdown_remote_server);
session.add_request_handler(cx.weak_entity(), Self::handle_ping);
session.add_request_handler(cx.weak_entity(), Self::handle_get_processes);
session.add_entity_request_handler(Self::handle_add_worktree);
session.add_request_handler(cx.weak_entity(), Self::handle_remove_worktree);
@@ -719,6 +721,34 @@ impl HeadlessProject {
log::debug!("Received ping from client");
Ok(proto::Ack {})
}
async fn handle_get_processes(
_this: Entity<Self>,
_envelope: TypedEnvelope<proto::GetProcesses>,
_cx: AsyncApp,
) -> Result<proto::GetProcessesResponse> {
let mut processes = Vec::new();
let system = System::new_all();
for (_pid, process) in system.processes() {
let name = process.name().to_string_lossy().into_owned();
let command = process
.cmd()
.iter()
.map(|s| s.to_string_lossy().to_string())
.collect::<Vec<_>>();
processes.push(proto::ProcessInfo {
pid: process.pid().as_u32(),
name,
command,
});
}
processes.sort_by_key(|p| p.name.clone());
Ok(proto::GetProcessesResponse { processes })
}
}
fn prompt_to_proto(