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_servers: Treat replayed ACP subagent outcomes as history too (#66098)

Ben Brandtad8a62df8211
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs
index 4e9cc92387d..630218054ea 100644
--- a/crates/acp_thread/src/acp_thread.rs
+++ b/crates/acp_thread/src/acp_thread.rs
@@ -3985,10 +3985,10 @@ impl AcpThread {
}
/// Ends a history replay into this session, after a successful load or resume. The
- /// subagents RFD treats what the replay reported about subagents as history: it may
- /// stay visible, but must not allow cancelling or confirm current activity until the
- /// agent reports it again. A replayed outcome, such as a completed or failed
- /// subagent, stays, since it confirms no activity.
+ /// subagents RFD treats the work states and cancel grants that the replay reported for
+ /// subagents as history, outcomes included: each subagent's work state is unconfirmed,
+ /// and it cannot be cancelled, until the agent reports current ones after the response.
+ /// Titles and transcripts stay.
pub fn invalidate_replayed_subagent_state(&mut self, cx: &mut Context<Self>) {
for subagent in self.subagents.values() {
subagent.update(cx, |subagent, cx| {
@@ -3996,9 +3996,7 @@ impl AcpThread {
association.can_cancel = false;
cx.notify();
}
- if subagent.foreground_activity().is_active() {
- subagent.clear_session_state(cx).log_err();
- }
+ subagent.clear_session_state(cx).log_err();
subagent.invalidate_replayed_subagent_state(cx);
});
}
diff --git a/crates/agent_servers/src/acp/v1.rs b/crates/agent_servers/src/acp/v1.rs
index 364b9082abe..b064ad2893f 100644
--- a/crates/agent_servers/src/acp/v1.rs
+++ b/crates/agent_servers/src/acp/v1.rs
@@ -9065,13 +9065,10 @@ exit 7
);
});
subagent("finished", cx).read_with(cx, |finished, _| {
- assert!(
- matches!(
- finished.foreground_state(),
- Some(acp_v2::StateUpdate::Idle(idle))
- if idle.stop_reason == Some(acp_v2::StopReason::Cancelled)
- ),
- "a replayed outcome confirms no activity, so it stays"
+ assert_eq!(
+ finished.foreground_activity(),
+ acp_thread::ForegroundActivity::Unconfirmed,
+ "a replayed outcome is history too, until the agent reports a current one"
);
});
subagent("live", cx).read_with(cx, |live, _| {
diff --git a/crates/agent_servers/src/acp/v2.rs b/crates/agent_servers/src/acp/v2.rs
index 1d2ae2ccfa5..b4752d9fb97 100644
--- a/crates/agent_servers/src/acp/v2.rs
+++ b/crates/agent_servers/src/acp/v2.rs
@@ -2598,7 +2598,7 @@ mod tests {
.expect("resume");
harness.resume_state(acp::StateUpdate::Idle(acp::IdleStateUpdate::new()));
announce_running_child();
- // A subagent whose replayed history ends, as claude-agent-acp replays each one.
+ // A subagent whose replayed history ends with an outcome.
harness.send_update(
"saved",
acp::SessionUpdate::SubagentUpdate(acp::SubagentUpdate::new("finished")),
@@ -2622,11 +2622,15 @@ mod tests {
let child = child.expect("the subagent was announced before the response");
let finished = finished.expect("the subagent was announced before the response");
finished.read_with(cx, |finished, _| {
- assert_eq!(
- finished.foreground_state(),
- Some(&cancelled()),
- "a replayed outcome confirms no activity, so it stays"
- );
+ if replay_history {
+ assert_eq!(
+ finished.foreground_state(),
+ None,
+ "a replayed outcome is history too"
+ );
+ } else {
+ assert_eq!(finished.foreground_state(), Some(&cancelled()));
+ }
});
child.read_with(cx, |child, _| {
let association = child.subagent_association().expect("subagent");
@@ -2649,7 +2653,9 @@ mod tests {
});
if replay_history {
+ // The agent reports current states after the response.
announce_running_child();
+ harness.send_update("finished", acp::SessionUpdate::StateUpdate(cancelled()));
harness.drain_updates(cx).await;
child.read_with(cx, |child, _| {
assert!(child.subagent_association().expect("subagent").can_cancel);
@@ -2658,6 +2664,9 @@ mod tests {
acp_thread::ForegroundActivity::Running
);
});
+ finished.read_with(cx, |finished, _| {
+ assert_eq!(finished.foreground_state(), Some(&cancelled()));
+ });
}
drop((parent, child, finished));
cx.run_until_parked();