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.

acp_thread: Separate agent-reported activity from prompt submission (#65912)

Ben Brandt70277c019330
diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rs
index e0816ce698c..237b07166f8 100644
--- a/crates/acp_thread/src/acp_thread.rs
+++ b/crates/acp_thread/src/acp_thread.rs
@@ -3623,7 +3623,8 @@ pub enum OutputTokensUpdate {
#[derive(Debug)]
pub enum AcpThreadEvent {
StatusChanged,
- /// Initial Idle confirmation is not a foreground completion.
+ /// Idle confirmed after unconfirmed or unknown activity, without completing
+ /// foreground work.
ActivityConfirmedIdle,
SubmissionUpdated(SubmissionId),
PromptUpdated,
@@ -3842,7 +3843,11 @@ impl AcpThread {
project,
running_turn: None,
turn_id: 0,
- submissions: SessionSubmissions::new(receipt_submissions),
+ submissions: SessionSubmissions::new(
+ receipt_submissions.map_or(SubmissionTransport::Completion, |transport| {
+ SubmissionTransport::Receipt(transport)
+ }),
+ ),
activity: SessionActivity::default(),
received_session_state: false,
reported_usage: None,
@@ -3869,6 +3874,15 @@ impl AcpThread {
}
}
+ /// Marks a session whose work the agent owns, such as an ACP subagent. Zed cannot
+ /// submit prompts to it, and its foreground state is unconfirmed until the agent
+ /// reports one.
+ pub fn agent_owned(mut self) -> Self {
+ self.submissions = SessionSubmissions::new(SubmissionTransport::AgentOwned);
+ self.activity.mark_unconfirmed();
+ self
+ }
+
pub fn parent_session_id(&self) -> Option<&acp_v2::SessionId> {
self.parent_session_id.as_ref()
}
@@ -4050,14 +4064,23 @@ impl AcpThread {
pub fn status(&self) -> ThreadStatus {
match self.foreground_activity() {
- ForegroundActivity::Unconfirmed => ThreadStatus::Unconfirmed,
+ ForegroundActivity::Unconfirmed | ForegroundActivity::Unknown => {
+ ThreadStatus::Unconfirmed
+ }
ForegroundActivity::Idle => ThreadStatus::Idle,
- _ => ThreadStatus::Generating,
+ ForegroundActivity::Running | ForegroundActivity::RequiresAction => {
+ ThreadStatus::Generating
+ }
}
}
+ /// Whether the agent reports this session's foreground state, rather than Zed
+ /// deriving it from its own prompt turns.
pub fn uses_reported_activity(&self) -> bool {
- self.submissions.receipt_transport().is_some()
+ !matches!(
+ self.submissions.transport(),
+ SubmissionTransport::Completion
+ )
}
pub fn foreground_state(&self) -> Option<&acp_v2::StateUpdate> {
@@ -4319,7 +4342,9 @@ impl AcpThread {
) -> Submission {
let (sender, receiver) = oneshot::channel();
let (disconnect_sender, disconnect_receiver) = self
- .uses_reported_activity()
+ .submissions
+ .receipt_transport()
+ .is_some()
.then(oneshot::channel::<()>)
.unzip();
let task = cx.spawn(async move |this, cx| {
@@ -4340,7 +4365,7 @@ impl AcpThread {
response => response,
};
let update = this.update(cx, |this, cx| {
- if this.uses_reported_activity()
+ if this.submissions.receipt_transport().is_some()
&& response.as_ref().err().is_some_and(|error| {
error.is::<SubmissionDisconnected>()
|| error
@@ -4394,11 +4419,10 @@ impl AcpThread {
}
fn set_foreground_state(&mut self, state: acp_v2::StateUpdate, cx: &mut Context<Self>) {
- let previous = self.foreground_activity();
+ let previous_generation = self.activity.generation();
self.activity
.update(state, self.entries.len().saturating_sub(1));
- let current = self.foreground_activity();
- if !previous.is_active() && current.is_active() {
+ if self.activity.generation() != previous_generation {
self.had_error = false;
self.local_execution_error = None;
}
@@ -4437,7 +4461,7 @@ impl AcpThread {
"Session does not report foreground state"
);
let previous = self.foreground_activity();
- let was_active = previous.is_active();
+ let was_in_progress = self.activity.in_progress();
self.received_session_state = true;
self.set_foreground_state(state, cx);
if let Some(acp_v2::StateUpdate::Idle(idle)) = self.activity.state() {
@@ -4462,7 +4486,7 @@ impl AcpThread {
));
}
}
- if was_active {
+ if was_in_progress {
self.flush_streaming_text(cx);
self.shrink_message_source_capacity(self.activity.first_entry_index());
if self.parent_session_id.is_none() {
@@ -4488,7 +4512,11 @@ impl AcpThread {
if previous != self.foreground_activity() {
cx.emit(AcpThreadEvent::StatusChanged);
}
- if previous == ForegroundActivity::Unconfirmed
+ if !was_in_progress
+ && matches!(
+ previous,
+ ForegroundActivity::Unconfirmed | ForegroundActivity::Unknown
+ )
&& self.foreground_activity() == ForegroundActivity::Idle
{
cx.emit(AcpThreadEvent::ActivityConfirmedIdle);
@@ -4931,7 +4959,7 @@ impl AcpThread {
previous_entry_count: usize,
cx: &mut Context<Self>,
) {
- if self.uses_reported_activity()
+ if self.submissions.receipt_transport().is_some()
&& let Some(AgentThreadEntry::UserMessage(message)) =
self.entries.get(location.entry_index())
&& let MessageIdentity::Keyed(id) = &message.identity
@@ -6583,16 +6611,29 @@ impl AcpThread {
push_user_message: bool,
cx: &mut Context<Self>,
) -> Submission {
- if let Some(submissions) = self.submissions.receipt_transport().cloned() {
- let id = self.register_submission(message.clone().into(), cx);
- let request = submissions.submit(message, cx);
- self.track_receipt_submission(id, request, cx)
- } else {
- let id = self.register_submission(message.clone().into(), cx);
- self.send_inner(id, message, push_user_message, cx)
+ let id = self.register_submission(message.clone().into(), cx);
+ match self.submissions.transport().clone() {
+ SubmissionTransport::Receipt(submissions) => {
+ let request = submissions.submit(message, cx);
+ self.track_receipt_submission(id, request, cx)
+ }
+ SubmissionTransport::Completion => self.send_inner(id, message, push_user_message, cx),
+ SubmissionTransport::AgentOwned => self.reject_agent_owned_submission(id, cx),
}
}
+ fn reject_agent_owned_submission(
+ &mut self,
+ id: SubmissionId,
+ cx: &mut Context<Self>,
+ ) -> Submission {
+ self.track_submission(id, None, cx, async move |_, _| {
+ Err(anyhow!(
+ "The agent owns this session, so it does not accept prompts"
+ ))
+ })
+ }
+
pub fn submit_receipt(
&mut self,
content: Vec<acp_v2::ContentBlock>,
@@ -6774,14 +6815,19 @@ impl AcpThread {
}
pub fn can_retry(&self, cx: &App) -> bool {
- self.submissions.receipt_transport().map_or_else(
- || self.connection.retry(self.session_id(), cx).is_some(),
- |submissions| submissions.supports_retry(),
- ) && self
- .submissions
- .latest_id()
- .and_then(|id| self.submissions.get(id))
- .is_none_or(|submission| self.validate_prompt_content(&submission.content).is_ok())
+ let supports_retry = match self.submissions.transport() {
+ SubmissionTransport::Receipt(submissions) => submissions.supports_retry(),
+ SubmissionTransport::Completion => {
+ self.connection.retry(self.session_id(), cx).is_some()
+ }
+ SubmissionTransport::AgentOwned => false,
+ };
+ supports_retry
+ && self
+ .submissions
+ .latest_id()
+ .and_then(|id| self.submissions.get(id))
+ .is_none_or(|submission| self.validate_prompt_content(&submission.content).is_ok())
}
pub fn retry(&mut self, cx: &mut Context<Self>) -> Submission {
@@ -6795,9 +6841,15 @@ impl AcpThread {
if let Err(error) = self.validate_prompt_content(&content) {
return self.track_submission(id, None, cx, async move |_, _| Err(error));
}
- if let Some(submissions) = self.submissions.receipt_transport() {
- let request = submissions.retry(cx);
- return self.track_receipt_submission(id, request, cx);
+ match self.submissions.transport() {
+ SubmissionTransport::Receipt(submissions) => {
+ let request = submissions.retry(cx);
+ return self.track_receipt_submission(id, request, cx);
+ }
+ SubmissionTransport::AgentOwned => {
+ return self.reject_agent_owned_submission(id, cx);
+ }
+ SubmissionTransport::Completion => {}
}
self.run_turn(id, cx, async move |this, cx| {
this.update(cx, |this, cx| {
@@ -11297,6 +11349,160 @@ mod tests {
(thread, connection)
}
+ async fn new_agent_owned_test_thread(cx: &mut TestAppContext) -> Entity<AcpThread> {
+ let project = Project::test(FakeFs::new(cx.executor()), [], cx).await;
+ let connection = Rc::new(StubAgentConnection::new());
+ cx.update(|cx| {
+ let action_log = cx.new(|_| ActionLog::new(project.clone()));
+ cx.new(|cx| {
+ AcpThread::new(
+ Some(acp_v2::SessionId::new("parent")),
+ None,
+ None,
+ connection,
+ project,
+ action_log,
+ acp_v2::SessionId::new("child"),
+ watch::Receiver::constant(acp_v2::PromptCapabilities::new()),
+ cx,
+ )
+ .agent_owned()
+ })
+ })
+ }
+
+ #[gpui::test]
+ async fn test_agent_owned_sessions_report_activity_without_accepting_prompts(
+ cx: &mut TestAppContext,
+ ) {
+ init_test(cx);
+ let thread = new_agent_owned_test_thread(cx).await;
+ thread.update(cx, |thread, cx| {
+ assert!(thread.uses_reported_activity());
+ assert_eq!(
+ thread.foreground_activity(),
+ ForegroundActivity::Unconfirmed
+ );
+ assert!(!thread.can_retry(cx));
+ thread
+ .update_session_state(
+ acp_v2::StateUpdate::Running(acp_v2::RunningStateUpdate::new()),
+ cx,
+ )
+ .expect("agent-owned sessions accept reported state");
+ assert_eq!(thread.status(), ThreadStatus::Generating);
+ });
+
+ let submission = thread.update(cx, |thread, cx| thread.send(vec!["prompt".into()], cx));
+ let submission_id = submission.id;
+ cx.run_until_parked();
+ assert!(submission.await.is_err());
+ thread.read_with(cx, |thread, _| {
+ assert!(matches!(
+ thread
+ .submission(submission_id)
+ .expect("rejected prompt")
+ .state,
+ SubmissionState::Failed(_)
+ ));
+ });
+
+ let retry = thread.update(cx, |thread, cx| thread.retry(cx));
+ cx.run_until_parked();
+ assert!(retry.await.is_err());
+ thread.read_with(cx, |thread, _| {
+ assert!(thread.entries().is_empty());
+ assert!(thread.running_turn.is_none());
+ assert_eq!(thread.foreground_activity(), ForegroundActivity::Running);
+ assert_eq!(thread.activity_generation(), 1);
+ });
+ }
+
+ #[gpui::test]
+ async fn test_unknown_activity_is_unconfirmed_without_ending_work(cx: &mut TestAppContext) {
+ init_test(cx);
+ let (thread, _) = new_receipt_test_thread(cx).await;
+ let events = Rc::new(RefCell::new(Vec::new()));
+ let _subscription = cx.update(|cx| {
+ cx.subscribe(&thread, {
+ let events = events.clone();
+ move |_, event, _| match event {
+ AcpThreadEvent::Stopped {
+ activity_generation,
+ stop_reason,
+ ..
+ } => events.borrow_mut().push(format!(
+ "stopped {activity_generation} {}",
+ matches!(stop_reason, Some(acp_v2::StopReason::Error(_)))
+ )),
+ AcpThreadEvent::ActivityConfirmedIdle => {
+ events.borrow_mut().push("confirmed idle".to_string())
+ }
+ _ => {}
+ }
+ })
+ });
+ let running = || acp_v2::StateUpdate::Running(acp_v2::RunningStateUpdate::new());
+ let unknown = || acp_v2::StateUpdate::Unknown(acp_v2::UnknownStateUpdate::new());
+
+ thread.update(cx, |thread, cx| {
+ thread.update_session_state(running(), cx).expect("running");
+ });
+ cx.run_until_parked();
+ assert_eq!(cx.active_idle_sleep_preventions(), 1);
+
+ thread.update(cx, |thread, cx| {
+ thread.update_session_state(unknown(), cx).expect("unknown");
+ assert_eq!(thread.foreground_activity(), ForegroundActivity::Unknown);
+ assert_eq!(thread.status(), ThreadStatus::Unconfirmed);
+ assert!(!thread.is_waiting_for_confirmation());
+ });
+ cx.run_until_parked();
+ assert_eq!(cx.active_idle_sleep_preventions(), 0);
+
+ thread.update(cx, |thread, cx| {
+ thread
+ .update_session_state(running(), cx)
+ .expect("running again");
+ assert_eq!(
+ thread.activity_generation(),
+ 1,
+ "unknown must not end the work that was in progress"
+ );
+ thread
+ .update_session_state(unknown(), cx)
+ .expect("unknown again");
+ thread
+ .update_session_state(
+ acp_v2::StateUpdate::Idle(
+ acp_v2::IdleStateUpdate::new()
+ .stop_reason(acp_v2::StopReason::Error(acp_v2::ErrorStopReason::new())),
+ ),
+ cx,
+ )
+ .expect("failed idle");
+ assert!(thread.had_error());
+ });
+ cx.run_until_parked();
+ assert_eq!(*events.borrow(), ["stopped 1 true"]);
+
+ events.borrow_mut().clear();
+ thread.update(cx, |thread, cx| {
+ thread
+ .update_session_state(unknown(), cx)
+ .expect("unknown while idle");
+ thread
+ .update_session_state(
+ acp_v2::StateUpdate::Idle(acp_v2::IdleStateUpdate::new()),
+ cx,
+ )
+ .expect("idle");
+ assert_eq!(thread.activity_generation(), 1);
+ });
+ cx.run_until_parked();
+ assert_eq!(*events.borrow(), ["confirmed idle"]);
+ }
+
#[gpui::test]
async fn test_cancel_send_failure_preserves_legacy_turn(cx: &mut TestAppContext) {
init_test(cx);
diff --git a/crates/acp_thread/src/submission.rs b/crates/acp_thread/src/submission.rs
index 10c2e6d3ea3..ff54bc17473 100644
--- a/crates/acp_thread/src/submission.rs
+++ b/crates/acp_thread/src/submission.rs
@@ -160,25 +160,45 @@ impl SubmissionRecord {
}
}
+#[derive(Clone)]
+pub(crate) enum SubmissionTransport {
+ /// Each prompt is a request whose response ends the turn, so Zed derives
+ /// foreground state from its own turns.
+ Completion,
+ /// The agent acknowledges each prompt when it accepts it and reports
+ /// foreground state separately.
+ Receipt(Rc<dyn ReceiptSessionSubmissions>),
+ /// The agent owns the session's work, such as an ACP subagent: Zed cannot
+ /// submit prompts, and foreground state comes only from agent reports.
+ AgentOwned,
+}
+
pub(crate) struct SessionSubmissions {
- receipt_transport: Option<Rc<dyn ReceiptSessionSubmissions>>,
+ transport: SubmissionTransport,
records: BTreeMap<SubmissionId, SubmissionRecord>,
next_id: u64,
latest_id: Option<SubmissionId>,
}
impl SessionSubmissions {
- pub(crate) fn new(receipt_transport: Option<Rc<dyn ReceiptSessionSubmissions>>) -> Self {
+ pub(crate) fn new(transport: SubmissionTransport) -> Self {
Self {
- receipt_transport,
+ transport,
records: BTreeMap::default(),
next_id: 0,
latest_id: None,
}
}
+ pub(crate) fn transport(&self) -> &SubmissionTransport {
+ &self.transport
+ }
+
pub(crate) fn receipt_transport(&self) -> Option<&Rc<dyn ReceiptSessionSubmissions>> {
- self.receipt_transport.as_ref()
+ match &self.transport {
+ SubmissionTransport::Receipt(transport) => Some(transport),
+ SubmissionTransport::Completion | SubmissionTransport::AgentOwned => None,
+ }
}
pub(crate) fn get(&self, id: SubmissionId) -> Option<&SubmissionRecord> {
@@ -201,7 +221,7 @@ impl SessionSubmissions {
pub(crate) fn recoverable(&self) -> impl Iterator<Item = (SubmissionId, &SubmissionRecord)> {
self.records.iter().filter_map(|(id, record)| {
- (self.receipt_transport.is_some() && record.is_recoverable()).then_some((*id, record))
+ (self.receipt_transport().is_some() && record.is_recoverable()).then_some((*id, record))
})
}
@@ -262,7 +282,7 @@ impl SessionSubmissions {
}
pub(crate) fn disconnect(&mut self) -> Vec<SubmissionId> {
- if self.receipt_transport.is_none() {
+ if self.receipt_transport().is_none() {
return Vec::new();
}
let mut changed = Vec::new();
@@ -319,10 +339,11 @@ impl SessionSubmissions {
}
fn prune(&mut self) {
+ let retains_recoverable = self.receipt_transport().is_some();
self.records.retain(|id, record| {
Some(*id) == self.latest_id
|| record.is_unsettled()
- || (self.receipt_transport.is_some() && record.is_recoverable())
+ || (retains_recoverable && record.is_recoverable())
});
}
}
@@ -333,6 +354,9 @@ pub enum ForegroundActivity {
Idle,
Running,
RequiresAction,
+ /// The agent reported that it cannot currently determine foreground activity.
+ /// Earlier activity is no longer confirmed, but its work has not ended either.
+ Unknown,
}
impl ForegroundActivity {
@@ -344,6 +368,9 @@ impl ForegroundActivity {
pub(crate) struct SessionActivity {
state: Option<acp_v2::StateUpdate>,
generation: u64,
+ /// Whether the current generation's work has started and not yet been confirmed
+ /// idle. Unlike the phase, this stays set while activity is `Unknown`.
+ in_progress: bool,
started_at: Option<Instant>,
duration: Option<Duration>,
first_entry_index: usize,
@@ -356,6 +383,7 @@ impl Default for SessionActivity {
Self {
state: Some(acp_v2::StateUpdate::Idle(acp_v2::IdleStateUpdate::new())),
generation: 0,
+ in_progress: false,
started_at: None,
duration: None,
first_entry_index: 0,
@@ -379,6 +407,7 @@ impl SessionActivity {
None => ForegroundActivity::Unconfirmed,
Some(acp_v2::StateUpdate::Idle(_)) => ForegroundActivity::Idle,
Some(acp_v2::StateUpdate::RequiresAction(_)) => ForegroundActivity::RequiresAction,
+ Some(acp_v2::StateUpdate::Unknown(_)) => ForegroundActivity::Unknown,
Some(_) => ForegroundActivity::Running,
}
}
@@ -387,15 +416,19 @@ impl SessionActivity {
self.generation
}
+ pub(crate) fn in_progress(&self) -> bool {
+ self.in_progress
+ }
+
pub(crate) fn started_at(&self) -> Option<Instant> {
self.started_at
}
pub(crate) fn duration(&self) -> Option<Duration> {
- if self.phase() == ForegroundActivity::Idle {
- self.duration
- } else {
+ if self.in_progress {
self.started_at.map(|started| started.elapsed())
+ } else {
+ self.duration
}
}
@@ -404,15 +437,16 @@ impl SessionActivity {
}
pub(crate) fn update(&mut self, state: acp_v2::StateUpdate, first_entry_index: usize) {
- let previous = self.phase();
self.state = Some(state);
let current = self.phase();
- if !previous.is_active() && current.is_active() {
+ if !self.in_progress && current.is_active() {
+ self.in_progress = true;
self.generation += 1;
self.started_at = Some(Instant::now());
self.duration = None;
self.first_entry_index = first_entry_index;
- } else if previous.is_active() && current == ForegroundActivity::Idle {
+ } else if self.in_progress && current == ForegroundActivity::Idle {
+ self.in_progress = false;
self.duration = self.started_at.map(|started| started.elapsed());
}
if current == ForegroundActivity::Idle {
diff --git a/crates/agent_ui/src/conversation_view.rs b/crates/agent_ui/src/conversation_view.rs
index 2d7f6495099..e1cb4963d41 100644
--- a/crates/agent_ui/src/conversation_view.rs
+++ b/crates/agent_ui/src/conversation_view.rs
@@ -5254,6 +5254,66 @@ pub(crate) mod tests {
});
}
+ #[gpui::test]
+ async fn test_unknown_activity_hides_generating_without_ending_the_turn(
+ cx: &mut TestAppContext,
+ ) {
+ init_test(cx);
+ let connection = StubAgentConnection::new().with_receipt_submissions(true);
+ let (conversation, cx) =
+ setup_conversation_view(StubAgentServer::new(connection.clone()), cx).await;
+ add_to_workspace(conversation.clone(), cx);
+ let view = active_thread(&conversation, cx);
+ let thread = view.read_with(cx, |view, _| view.thread.clone());
+
+ thread.update(cx, |thread, cx| {
+ thread
+ .update_session_state(
+ acp_v2::StateUpdate::Running(acp_v2::RunningStateUpdate::new()),
+ cx,
+ )
+ .expect("running");
+ });
+ cx.run_until_parked();
+ let turn_started_at = view.read_with(cx, |view, _| {
+ assert!(view.generating_indicator_in_list);
+ view.turn_fields
+ .turn_started_at
+ .expect("reported activity starts a turn")
+ });
+
+ thread.update(cx, |thread, cx| {
+ thread
+ .update_session_state(
+ acp_v2::StateUpdate::Unknown(acp_v2::UnknownStateUpdate::new()),
+ cx,
+ )
+ .expect("unknown");
+ });
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("activity-unknown").is_some());
+ view.read_with(cx, |view, _| {
+ assert!(!view.generating_indicator_in_list);
+ assert_eq!(view.turn_fields.turn_started_at, Some(turn_started_at));
+ assert!(view.turn_fields.last_turn_duration.is_none());
+ });
+
+ thread.update(cx, |thread, cx| {
+ thread
+ .update_session_state(
+ acp_v2::StateUpdate::Running(acp_v2::RunningStateUpdate::new()),
+ cx,
+ )
+ .expect("running again");
+ });
+ cx.run_until_parked();
+ assert!(cx.debug_bounds("activity-unknown").is_none());
+ view.read_with(cx, |view, _| {
+ assert!(view.generating_indicator_in_list);
+ assert_eq!(view.turn_fields.turn_started_at, Some(turn_started_at));
+ });
+ }
+
#[gpui::test]
async fn test_unconfirmed_stop_and_send_waits_for_confirmed_idle(cx: &mut TestAppContext) {
init_test(cx);
diff --git a/crates/agent_ui/src/conversation_view/thread_view.rs b/crates/agent_ui/src/conversation_view/thread_view.rs
index 4ea83eb4ae2..44f1c201fb0 100644
--- a/crates/agent_ui/src/conversation_view/thread_view.rs
+++ b/crates/agent_ui/src/conversation_view/thread_view.rs
@@ -1623,25 +1623,31 @@ impl ThreadView {
let duration = thread.activity_duration();
let output_tokens = thread.reported_activity_output_tokens();
- if activity == ForegroundActivity::Unconfirmed {
- self.turn_fields.reported_activity_generation = None;
- } else if activity.is_active() {
- if self.turn_fields.reported_activity_generation != Some(activity_generation) {
- self.initialize_turn(cx);
- self.turn_fields.turn_started_at = started_at;
- self.turn_fields.reported_activity_generation = Some(activity_generation);
- }
- } else {
- if self.turn_fields.turn_started_at.is_some() {
- self.stop_turn(self.turn_fields.turn_generation, cx);
+ match activity {
+ ForegroundActivity::Unconfirmed => {
+ self.turn_fields.reported_activity_generation = None;
}
- if self.turn_fields.reported_activity_generation != Some(activity_generation) {
- self.turn_fields.last_turn_tokens = None;
+ // Unknown activity neither ends the current turn nor starts a new one.
+ ForegroundActivity::Unknown => {}
+ ForegroundActivity::Running | ForegroundActivity::RequiresAction => {
+ if self.turn_fields.reported_activity_generation != Some(activity_generation) {
+ self.initialize_turn(cx);
+ self.turn_fields.turn_started_at = started_at;
+ self.turn_fields.reported_activity_generation = Some(activity_generation);
+ }
}
- self.turn_fields.reported_activity_generation = Some(activity_generation);
- self.turn_fields.last_turn_duration = duration;
- if let Some(output_tokens) = output_tokens {
- self.turn_fields.last_turn_tokens = Some(output_tokens);
+ ForegroundActivity::Idle => {
+ if self.turn_fields.turn_started_at.is_some() {
+ self.stop_turn(self.turn_fields.turn_generation, cx);
+ }
+ if self.turn_fields.reported_activity_generation != Some(activity_generation) {
+ self.turn_fields.last_turn_tokens = None;
+ }
+ self.turn_fields.reported_activity_generation = Some(activity_generation);
+ self.turn_fields.last_turn_duration = duration;
+ if let Some(output_tokens) = output_tokens {
+ self.turn_fields.last_turn_tokens = Some(output_tokens);
+ }
}
}
cx.notify();
@@ -5338,25 +5344,7 @@ impl ThreadView {
.min_w_0()
.flex_wrap()
.gap_1()
- .when(
- self.thread.read(cx).foreground_activity()
- == ForegroundActivity::Unconfirmed,
- |row| {
- row.child(
- div()
- .id("activity-unconfirmed")
- .debug_selector(|| "activity-unconfirmed".into())
- .child(
- Label::new("Activity unconfirmed")
- .size(LabelSize::Small)
- .color(Color::Muted),
- )
- .tooltip(Tooltip::text(
- "The session is attached, but the agent has not reported its activity. You can send manually; automatic sends wait for confirmed Idle.",
- )),
- )
- },
- )
+ .children(self.render_activity_status_label(cx))
.children(discard_draft_button)
.children(self.render_token_usage(cx))
.children(self.profile_selector.clone())
@@ -5373,6 +5361,31 @@ impl ThreadView {
.into_any()
}
+ fn render_activity_status_label(&self, cx: &Context<Self>) -> Option<impl IntoElement> {
+ let (id, label, tooltip) = match self.thread.read(cx).foreground_activity() {
+ ForegroundActivity::Unconfirmed => (
+ "activity-unconfirmed",
+ "Activity unconfirmed",
+ "The session is attached, but the agent has not reported its activity. You can send manually; automatic sends wait for confirmed Idle.",
+ ),
+ ForegroundActivity::Unknown => (
+ "activity-unknown",
+ "Activity unknown",
+ "The agent can't currently tell whether it is working. You can send manually; automatic sends wait for confirmed Idle.",
+ ),
+ ForegroundActivity::Idle
+ | ForegroundActivity::Running
+ | ForegroundActivity::RequiresAction => return None,
+ };
+ Some(
+ div()
+ .id(id)
+ .debug_selector(move || id.into())
+ .child(Label::new(label).size(LabelSize::Small).color(Color::Muted))
+ .tooltip(Tooltip::text(tooltip)),
+ )
+ }
+
fn render_queue_steer_button(
&self,
entry_id: QueueEntryId,