Fix ACP connection and thread leak (#35670)

When you switched away from an ACP thread, the `AcpThreadView` entity
(and thus thread, and subprocess) was leaked. This happened because we
were using `cx.processor` for the `list` state callback, which uses a
strong reference.

This PR changes the callback so that it holds a weak reference, and adds
some tests and assertions at various levels to make sure we don't
reintroduce the leak in the future.

Release Notes:

- N/A
This commit is contained in:
Agus Zubiaga 2025-08-05 19:10:51 -03:00 committed by GitHub
parent f27dc7dec7
commit b7469f5bc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 73 additions and 27 deletions

View file

@ -125,8 +125,7 @@ impl AgentConnection for ClaudeAgentConnection {
session_id.clone(),
&mcp_config_path,
&cwd,
)
.await?;
)?;
let pid = child.id();
log::trace!("Spawned (pid: {})", pid);
@ -262,7 +261,7 @@ enum ClaudeSessionMode {
Resume,
}
async fn spawn_claude(
fn spawn_claude(
command: &AgentServerCommand,
mode: ClaudeSessionMode,
session_id: acp::SessionId,