Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent_ui: Fix crash when expanding an ACP subagent card (#66251)

Ben Brandtc693e6a89357
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs
index 80c42449d64..07e627ca320 100644
--- a/crates/agent_ui/src/conversation_view.rs
+++ b/crates/agent_ui/src/conversation_view.rs
@@ -501,6 +501,10 @@ impl Conversation {
))
}
+ pub(crate) fn thread(&self, session_id: &acp_v2::SessionId) -> Option<&Entity<AcpThread>> {
+ self.threads.get(session_id)
+ }
+
pub fn subagents_awaiting_permission(&self, cx: &App) -> Vec<(acp_v2::SessionId, usize)> {
self.permission_requests
.iter()
@@ -20595,6 +20599,28 @@ pub(crate) mod tests {
"Investigator"
);
});
+
+ // The expanded card renders the subagent's own view of the message, a row that
+ // names the parent.
+ child
+ .update(cx, |child, cx| {
+ child.upsert_session_message(
+ acp_v2::SessionMessage::new("task")
+ .sender_session_id(root_session_id.clone())
+ .recipient_session_id(acp_v2::SessionId::new("child"))
+ .content(vec!["Check the failure".into()]),
+ cx,
+ )
+ })
+ .expect("incoming message");
+ thread_view.update(cx, |view, cx| {
+ view.entry_view_state.update(cx, |state, _| {
+ state.toggle_session_message_card_expansion(&acp_v2::MessageId::new("launch"))
+ });
+ cx.notify();
+ });
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("subagent-card-0").is_some());
}
#[gpui::test]
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index 24be2377e8f..999dc9c500c 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -9009,9 +9009,10 @@ impl ThreadView {
session_id: &acp_v2::SessionId,
cx: &App,
) -> Option<SharedString> {
- let server_view = self.server_view.upgrade()?;
- let thread_view = server_view.read(cx).thread_view(session_id)?;
- let thread = thread_view.read(cx).thread.read(cx);
+ // Read the thread through the conversation rather than its view: an expanded subagent
+ // card renders the subagent's entries while the parent's view is being updated.
+ let conversation = self.conversation.read(cx);
+ let thread = conversation.thread(session_id)?.read(cx);
Some(if thread.parent_session_id().is_none() {
"Main Agent".into()
} else {