acp: Reliably suppress gemini abort error (#36640)
https://github.com/zed-industries/zed/pull/36633 relied on the prompt request responding before cancel, but that's not guaranteed Release Notes: - N/A
This commit is contained in:
parent
c20233e0b4
commit
74c0ba980b
1 changed files with 15 additions and 18 deletions
|
@ -28,7 +28,7 @@ pub struct AcpConnection {
|
||||||
|
|
||||||
pub struct AcpSession {
|
pub struct AcpSession {
|
||||||
thread: WeakEntity<AcpThread>,
|
thread: WeakEntity<AcpThread>,
|
||||||
pending_cancel: bool,
|
suppress_abort_err: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const MINIMUM_SUPPORTED_VERSION: acp::ProtocolVersion = acp::V1;
|
const MINIMUM_SUPPORTED_VERSION: acp::ProtocolVersion = acp::V1;
|
||||||
|
@ -173,7 +173,7 @@ impl AgentConnection for AcpConnection {
|
||||||
|
|
||||||
let session = AcpSession {
|
let session = AcpSession {
|
||||||
thread: thread.downgrade(),
|
thread: thread.downgrade(),
|
||||||
pending_cancel: false,
|
suppress_abort_err: false,
|
||||||
};
|
};
|
||||||
sessions.borrow_mut().insert(session_id, session);
|
sessions.borrow_mut().insert(session_id, session);
|
||||||
|
|
||||||
|
@ -208,7 +208,16 @@ impl AgentConnection for AcpConnection {
|
||||||
let sessions = self.sessions.clone();
|
let sessions = self.sessions.clone();
|
||||||
let session_id = params.session_id.clone();
|
let session_id = params.session_id.clone();
|
||||||
cx.foreground_executor().spawn(async move {
|
cx.foreground_executor().spawn(async move {
|
||||||
match conn.prompt(params).await {
|
let result = conn.prompt(params).await;
|
||||||
|
|
||||||
|
let mut suppress_abort_err = false;
|
||||||
|
|
||||||
|
if let Some(session) = sessions.borrow_mut().get_mut(&session_id) {
|
||||||
|
suppress_abort_err = session.suppress_abort_err;
|
||||||
|
session.suppress_abort_err = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
match result {
|
||||||
Ok(response) => Ok(response),
|
Ok(response) => Ok(response),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if err.code != ErrorCode::INTERNAL_ERROR.code {
|
if err.code != ErrorCode::INTERNAL_ERROR.code {
|
||||||
|
@ -230,11 +239,7 @@ impl AgentConnection for AcpConnection {
|
||||||
|
|
||||||
match serde_json::from_value(data.clone()) {
|
match serde_json::from_value(data.clone()) {
|
||||||
Ok(ErrorDetails { details }) => {
|
Ok(ErrorDetails { details }) => {
|
||||||
if sessions
|
if suppress_abort_err && details.contains("This operation was aborted")
|
||||||
.borrow()
|
|
||||||
.get(&session_id)
|
|
||||||
.is_some_and(|session| session.pending_cancel)
|
|
||||||
&& details.contains("This operation was aborted")
|
|
||||||
{
|
{
|
||||||
Ok(acp::PromptResponse {
|
Ok(acp::PromptResponse {
|
||||||
stop_reason: acp::StopReason::Canceled,
|
stop_reason: acp::StopReason::Canceled,
|
||||||
|
@ -256,22 +261,14 @@ impl AgentConnection for AcpConnection {
|
||||||
|
|
||||||
fn cancel(&self, session_id: &acp::SessionId, cx: &mut App) {
|
fn cancel(&self, session_id: &acp::SessionId, cx: &mut App) {
|
||||||
if let Some(session) = self.sessions.borrow_mut().get_mut(session_id) {
|
if let Some(session) = self.sessions.borrow_mut().get_mut(session_id) {
|
||||||
session.pending_cancel = true;
|
session.suppress_abort_err = true;
|
||||||
}
|
}
|
||||||
let conn = self.connection.clone();
|
let conn = self.connection.clone();
|
||||||
let params = acp::CancelNotification {
|
let params = acp::CancelNotification {
|
||||||
session_id: session_id.clone(),
|
session_id: session_id.clone(),
|
||||||
};
|
};
|
||||||
let sessions = self.sessions.clone();
|
|
||||||
let session_id = session_id.clone();
|
|
||||||
cx.foreground_executor()
|
cx.foreground_executor()
|
||||||
.spawn(async move {
|
.spawn(async move { conn.cancel(params).await })
|
||||||
let resp = conn.cancel(params).await;
|
|
||||||
if let Some(session) = sessions.borrow_mut().get_mut(&session_id) {
|
|
||||||
session.pending_cancel = false;
|
|
||||||
}
|
|
||||||
resp
|
|
||||||
})
|
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue