mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
agent_servers: Update ACP SDK to 3.5.0 (#65982)
Updates `agent-client-protocol` to [v3.5.0](https://github.com/agentclientprotocol/rust-sdk/releases/tag/v3.5.0) and adopts its fixes for v2 integration feedback. - **Typed v1 fallback:** v2 startup uses `send_initialize`. A `LowerVersion` outcome or a v1-only `-32022` error triggers the v1 fallback directly, instead of recovering the agent's response from the debug log. The debug-log lookup is now only used when the agent exits right after answering and the process-exit error supersedes the in-band result. - **Termination-aware disconnects:** connection-loss checks now include `termination()` and `is_connection_terminated`, so transport or handler failures (not only clean EOF) are treated as a lost connection. Disconnect cleanup still uses `on_close` plus driver completion: `finish_connection` already runs once the driver ends, and `on_close` stays the ordered barrier for clean EOF. Release Notes: - N/A --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
This commit is contained in:
Generated
+6
-6
@@ -328,9 +328,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "agent-client-protocol"
|
||||
version = "3.4.0"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72adac0ce6b0d0390df9b7a498392b24ebcf9c65c3451e5d618d936f50256289"
|
||||
checksum = "9bbe69c878aef64a3d92041e256e75acdb1bf2ea8e55ef3313e69dbb2f5bd75a"
|
||||
dependencies = [
|
||||
"agent-client-protocol-derive",
|
||||
"agent-client-protocol-schema",
|
||||
@@ -346,9 +346,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "agent-client-protocol-derive"
|
||||
version = "3.4.0"
|
||||
version = "3.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "532fa6f1870bb7cb0bfe91fbcb5166393f7046e186bc590d1aa037d306d48716"
|
||||
checksum = "25b7ae92f0d1ba46ca61e7e03d4a9758e877d100b783aa1c62b140d5a9d59fb2"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 3.0.3",
|
||||
@@ -18953,7 +18953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fb391ac70462b3097a755618fbf9c8f95ecc1eb379a414f7b46f202ed10db1f"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"windows-targets 0.48.5",
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -20769,7 +20769,7 @@ dependencies = [
|
||||
"objc2-foundation 0.3.2",
|
||||
"objc2-metal 0.3.2",
|
||||
"objc2-quartz-core 0.3.2",
|
||||
"ordered-float 4.6.0",
|
||||
"ordered-float 5.5.0",
|
||||
"profiling",
|
||||
"range-alloc",
|
||||
"raw-window-handle",
|
||||
|
||||
+1
-1
@@ -530,7 +530,7 @@ accesskit = { version = "0.24.0", features = ["enumn"] }
|
||||
accesskit_macos = "0.26.0"
|
||||
accesskit_unix = "0.22"
|
||||
accesskit_windows = "0.34"
|
||||
agent-client-protocol = { version = "=3.4.0", features = ["schemars", "unstable", "unstable_protocol_v2"] }
|
||||
agent-client-protocol = { version = "=3.5.0", features = ["schemars", "unstable", "unstable_protocol_v2"] }
|
||||
aho-corasick = "1.1"
|
||||
alacritty_terminal = { git = "https://github.com/zed-industries/alacritty", rev = "4c129667ce56611becdc82de6e28218c80e2e88f" }
|
||||
any_vec = "0.14"
|
||||
|
||||
@@ -4427,7 +4427,10 @@ impl AcpThread {
|
||||
error.is::<SubmissionDisconnected>()
|
||||
|| error
|
||||
.downcast_ref::<agent_client_protocol::Error>()
|
||||
.is_some_and(agent_client_protocol::is_incoming_transport_closed)
|
||||
.is_some_and(|error| {
|
||||
agent_client_protocol::is_incoming_transport_closed(error)
|
||||
|| agent_client_protocol::is_connection_terminated(error)
|
||||
})
|
||||
})
|
||||
{
|
||||
this.handle_connection_lost(cx);
|
||||
|
||||
@@ -181,6 +181,11 @@ fn v1_only_mismatch(error: &agent_client_protocol::Error) -> bool {
|
||||
}
|
||||
|
||||
fn initialization_error(error: anyhow::Error, debug_log: &AcpDebugLog) -> anyhow::Error {
|
||||
// `connect` classifies the agent's answer in-band, but an agent that exits right after
|
||||
// answering surfaces as a process exit, so its answer is recovered from the debug log.
|
||||
if error.is::<UnsupportedVersion>() || error.is::<agent_client_protocol::Error>() {
|
||||
return error;
|
||||
}
|
||||
match debug_log.initialization_response() {
|
||||
Some(Ok(Some(value))) => {
|
||||
if serde_json::from_value::<acp::InitializeResponse>(value).is_ok_and(|response| {
|
||||
@@ -193,11 +198,8 @@ fn initialization_error(error: anyhow::Error, debug_log: &AcpDebugLog) -> anyhow
|
||||
}
|
||||
Some(Err(protocol_error)) => {
|
||||
let retry_v1 = v1_only_mismatch(&protocol_error);
|
||||
let error = if error.is::<agent_client_protocol::Error>() {
|
||||
error
|
||||
} else {
|
||||
anyhow!(protocol_error).context(format!("ACP initialization failed: {error}"))
|
||||
};
|
||||
let error =
|
||||
anyhow!(protocol_error).context(format!("ACP initialization failed: {error}"));
|
||||
if retry_v1 {
|
||||
error.context(UnsupportedVersion)
|
||||
} else {
|
||||
@@ -688,6 +690,15 @@ fn first_class_terminal_auth_task(
|
||||
})
|
||||
}
|
||||
|
||||
fn is_disconnect_error(error: &anyhow::Error) -> bool {
|
||||
error
|
||||
.downcast_ref::<agent_client_protocol::Error>()
|
||||
.is_some_and(|error| {
|
||||
agent_client_protocol::is_incoming_transport_closed(error)
|
||||
|| agent_client_protocol::is_connection_terminated(error)
|
||||
})
|
||||
}
|
||||
|
||||
fn map_acp_error(err: acp::Error) -> anyhow::Error {
|
||||
let error = anyhow!(err);
|
||||
match AuthRequired::from_error(&error) {
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{
|
||||
AcpDebugLog, AcpDebugMessage, AcpSession, ClientContext, ConfigOptions,
|
||||
ContextServerConfiguration, ForegroundWork, PendingSessionUpdates, UnsupportedVersion,
|
||||
apply_v2_session_notification, close_undelivered_session, drain_foreground_queue,
|
||||
enqueue_notification, first_class_terminal_auth_task, map_acp_error,
|
||||
enqueue_notification, first_class_terminal_auth_task, is_disconnect_error, map_acp_error,
|
||||
mcp_configurations_for_project, runtime, transport, with_v2_client_ingress,
|
||||
work_dirs_from_session_info,
|
||||
};
|
||||
@@ -13,8 +13,8 @@ use acp_thread::{
|
||||
};
|
||||
use action_log::ActionLog;
|
||||
use agent_client_protocol::{
|
||||
Agent, Client, ConnectTo, JsonRpcRequest, JsonRpcResponse, Lines, PreparedRequest,
|
||||
RequestCancellationHandle, V2ConnectionTo,
|
||||
Agent, Client, ConnectTo, InitializeOutcome, JsonRpcRequest, JsonRpcResponse, Lines,
|
||||
PreparedRequest, RequestCancellationHandle, V2ConnectionTo,
|
||||
schema::{ProtocolVersion, v2 as acp},
|
||||
};
|
||||
use anyhow::{Context as _, Result, anyhow};
|
||||
@@ -35,6 +35,10 @@ use task::SpawnInTerminal;
|
||||
use util::ResultExt as _;
|
||||
use util::path_list::PathList;
|
||||
|
||||
fn is_connection_closed(connection: &V2ConnectionTo<Agent>) -> bool {
|
||||
connection.is_incoming_closed() || connection.termination().is_some()
|
||||
}
|
||||
|
||||
fn cancel_request_elicitations(
|
||||
request_id: acp::RequestId,
|
||||
cx: &mut AsyncApp,
|
||||
@@ -410,14 +414,25 @@ impl AcpV2Connection {
|
||||
}
|
||||
let initialize_request =
|
||||
acp::InitializeRequest::new(ProtocolVersion::V2, info).capabilities(capabilities);
|
||||
let initialize_response = connection
|
||||
.send_request(initialize_request.clone())
|
||||
let initialize_response = match connection
|
||||
.send_initialize(initialize_request.clone())
|
||||
.block_task()
|
||||
.await
|
||||
.map_err(map_acp_error)?;
|
||||
if initialize_response.protocol_version != ProtocolVersion::V2 {
|
||||
return Err(UnsupportedVersion.into());
|
||||
}
|
||||
{
|
||||
Ok(InitializeOutcome::Initialized(response)) => response,
|
||||
Ok(InitializeOutcome::LowerVersion(mismatch)) => {
|
||||
return Err(anyhow!(mismatch).context(UnsupportedVersion));
|
||||
}
|
||||
Ok(outcome) => {
|
||||
return Err(anyhow!(
|
||||
"Unexpected ACP initialization outcome: {outcome:?}"
|
||||
));
|
||||
}
|
||||
Err(error) if super::v1_only_mismatch(&error) => {
|
||||
return Err(anyhow!(error).context(UnsupportedVersion));
|
||||
}
|
||||
Err(error) => return Err(map_acp_error(error)),
|
||||
};
|
||||
anyhow::ensure!(
|
||||
runtime.borrow().is_some(),
|
||||
"Agent connection shut down during startup"
|
||||
@@ -855,10 +870,8 @@ impl AcpV2Connection {
|
||||
.with_context(|| format!("Failed to apply default config option {config_id}"));
|
||||
if result.as_ref().err().is_some_and(|error| {
|
||||
error.is::<ResponseCallbackDropped>()
|
||||
|| self.connection.is_incoming_closed()
|
||||
|| error
|
||||
.downcast_ref::<agent_client_protocol::Error>()
|
||||
.is_some_and(agent_client_protocol::is_incoming_transport_closed)
|
||||
|| is_connection_closed(&self.connection)
|
||||
|| is_disconnect_error(&error)
|
||||
}) {
|
||||
return result.map(|_| ());
|
||||
}
|
||||
@@ -915,7 +928,7 @@ impl AcpV2Connection {
|
||||
replay_history: bool,
|
||||
cx: &mut App,
|
||||
) -> Task<Result<Entity<AcpThread>>> {
|
||||
if self.connection.is_incoming_closed() {
|
||||
if is_connection_closed(&self.connection) {
|
||||
return Task::ready(Err(anyhow!("Agent connection is closed")));
|
||||
}
|
||||
let path_style = project.read(cx).path_style(cx);
|
||||
@@ -1437,7 +1450,7 @@ impl AgentConnection for AcpV2Connection {
|
||||
if let Some(closing) = closing {
|
||||
return Self::observe_close(closing, thread.upgrade(), cx);
|
||||
}
|
||||
if self.connection.is_incoming_closed() {
|
||||
if is_connection_closed(&self.connection) {
|
||||
return Task::ready(Err(anyhow!("Agent connection is closed")));
|
||||
}
|
||||
if initializing {
|
||||
@@ -1602,7 +1615,7 @@ impl AgentConnection for AcpV2Connection {
|
||||
"Session has been released"
|
||||
);
|
||||
anyhow::ensure!(
|
||||
!self.connection.is_incoming_closed(),
|
||||
!is_connection_closed(&self.connection),
|
||||
"Agent connection is closed"
|
||||
);
|
||||
self.connection
|
||||
@@ -1859,10 +1872,8 @@ impl V2SessionSubmissions {
|
||||
let response = async move {
|
||||
response.await.map_err(|error| {
|
||||
if error.is::<ResponseCallbackDropped>()
|
||||
|| connection.is_incoming_closed()
|
||||
|| error
|
||||
.downcast_ref::<agent_client_protocol::Error>()
|
||||
.is_some_and(agent_client_protocol::is_incoming_transport_closed)
|
||||
|| is_connection_closed(&connection)
|
||||
|| is_disconnect_error(&error)
|
||||
{
|
||||
error.context(SubmissionDisconnected)
|
||||
} else {
|
||||
@@ -7023,7 +7034,11 @@ done
|
||||
.await
|
||||
.err()
|
||||
.expect("reject unimplemented fallback");
|
||||
assert!(error.to_string().contains("protocol"), "{error}");
|
||||
assert!(error.is::<UnsupportedVersion>(), "{error:?}");
|
||||
assert!(
|
||||
error.is::<agent_client_protocol::InitializationVersionMismatch>(),
|
||||
"{error:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
@@ -7325,24 +7340,12 @@ exec sleep 60
|
||||
assert_eq!(actual.code, expected.code);
|
||||
assert_eq!(actual.data, expected.data);
|
||||
} else {
|
||||
let actual = error
|
||||
.downcast_ref::<agent_client_protocol::Error>()
|
||||
assert!(error.is::<UnsupportedVersion>(), "{error:?}");
|
||||
let mismatch = error
|
||||
.downcast_ref::<agent_client_protocol::InitializationVersionMismatch>()
|
||||
.unwrap_or_else(|| panic!("version diagnostic was replaced: {error:?}"));
|
||||
assert_eq!(
|
||||
actual.code,
|
||||
agent_client_protocol::Error::new(-32600, "Invalid request").code
|
||||
);
|
||||
assert!(
|
||||
actual
|
||||
.data
|
||||
.as_ref()
|
||||
.and_then(|data| data.as_str())
|
||||
.is_some_and(
|
||||
|message| message.contains("required ACP protocol version 2")
|
||||
&& message.contains("peer negotiated 1")
|
||||
),
|
||||
"{actual:?}"
|
||||
);
|
||||
assert_eq!(mismatch.requested, ProtocolVersion::V2);
|
||||
assert_eq!(mismatch.selected, ProtocolVersion::V1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user