mirror of
https://github.com/zed-industries/zed.git
synced 2026-12-04 02:23:21 +01:00
acp_thread: Use a subagent's latest run for its titlebar status (#66092)
A native subagent that's resumed gets one `spawn_agent` tool call per run. `AcpThread::tool_call_for_subagent` returned the first, so the subagent's titlebar showed the first run's failed or canceled marker instead of the current run's. It now returns the latest. The titlebar is its only caller. `test_tool_call_for_subagent_is_its_latest_run` covers a failed first run followed by a running one, and fails without the change. `cargo nextest run -p acp_thread -p agent_ui -p agent` (1668 tests), `./script/clippy` and `cargo fmt` pass locally. Release Notes: - N/A
This commit is contained in:
1 parent
78f5a535a3
commit
c5efa10ddd
1 file changed
+32
-1
@@ -6280,8 +6280,10 @@ impl AcpThread {
|
||||
})
|
||||
}
|
||||
|
||||
/// The latest tool call that ran the subagent `session_id`. A resumed subagent has one
|
||||
/// per run, and the latest says how the subagent's current work went.
|
||||
pub fn tool_call_for_subagent(&self, session_id: &acp_v2::SessionId) -> Option<&ToolCall> {
|
||||
self.entries.iter().find_map(|entry| match entry {
|
||||
self.entries.iter().rev().find_map(|entry| match entry {
|
||||
AgentThreadEntry::ToolCall(tool_call) => {
|
||||
if let Some(subagent_session_info) = &tool_call.subagent_session_info
|
||||
&& &subagent_session_info.session_id == session_id
|
||||
@@ -17191,6 +17193,35 @@ mod tests {
|
||||
cx.run_until_parked();
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_tool_call_for_subagent_is_its_latest_run(cx: &mut TestAppContext) {
|
||||
init_test(cx);
|
||||
let thread = new_test_thread(cx).await;
|
||||
thread.update(cx, |thread, cx| {
|
||||
for (id, status) in [
|
||||
("first-run", acp_v1::ToolCallStatus::Failed),
|
||||
("resumed-run", acp_v1::ToolCallStatus::InProgress),
|
||||
] {
|
||||
thread
|
||||
.upsert_tool_call(
|
||||
acp_v1::ToolCall::new(acp_v1::ToolCallId::new(id), "Run subagent")
|
||||
.status(status)
|
||||
.meta(acp_v1::Meta::from_iter([(
|
||||
SUBAGENT_SESSION_INFO_META_KEY.into(),
|
||||
json!({"session_id": "child", "message_start_index": 0}),
|
||||
)])),
|
||||
cx,
|
||||
)
|
||||
.expect("tool call");
|
||||
}
|
||||
let latest = thread
|
||||
.tool_call_for_subagent(&acp_v2::SessionId::new("child"))
|
||||
.expect("the subagent has a tool call");
|
||||
assert_eq!(latest.id, acp_v2::ToolCallId::new("resumed-run"));
|
||||
assert_eq!(latest.status(), ToolCallStatus::InProgress);
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_tool_patch_metadata_policy_preserves_legacy_hints_and_clears_v2_hints(
|
||||
cx: &mut TestAppContext,
|
||||
|
||||
Reference in new issue
Block a user