From c5efa10dddf57e31f1f501da9d53cd1eda07030a Mon Sep 17 00:00:00 2001 From: Ben Brandt Date: Sun, 25 Oct 2026 08:55:49 +0000 Subject: [PATCH] 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 --- crates/acp_thread/src/acp_thread.rs | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs index 630218054ea..b57ad43eb0b 100644 --- a/crates/acp_thread/src/acp_thread.rs +++ b/crates/acp_thread/src/acp_thread.rs @@ -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,