From fec50f39251f9280e42f2ea137ae63b37d3e00a0 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Tue, 24 Nov 2026 12:15:56 +0800 Subject: [PATCH] fix(agents): show a sent message before recording the turn checkout (#5536) The user's message was only added to the conversation after the pre-turn checkout was recorded, which can take seconds in a large repository, so pressing Enter appeared to do nothing and the view did not scroll to the new message. --- crates/ide-agent/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/ide-agent/src/lib.rs b/crates/ide-agent/src/lib.rs index 23b489a9d..936ac1055 100644 --- a/crates/ide-agent/src/lib.rs +++ b/crates/ide-agent/src/lib.rs @@ -2523,6 +2523,8 @@ impl Task { /// the user stops one. The caller set `busy`. async fn run(self: Arc, mut prompt: AgentPrompt) { loop { + // The message shows before the checkout is recorded, which can take a while in a large repository. + self.show_prompt(&prompt); self.checkout_before_turn().await; let result = self.turn(&prompt).await; self.cancel_pending.store(false, Ordering::Release); @@ -2836,11 +2838,8 @@ impl Task { Ok(()) } - /// Sends one prompt, starting the agent first if needed; returns the stop reason. - async fn turn(self: &Arc, prompt: &AgentPrompt) -> Result { - self.turns.fetch_add(1, Ordering::AcqRel); - self.turn_started.store(false, Ordering::Release); - self.state.lock().task.resets_ms = None; + /// Adds the user's message to the conversation and shows the task starting. + fn show_prompt(self: &Arc, prompt: &AgentPrompt) { let attachments = prompt .files .iter() @@ -2858,6 +2857,13 @@ impl Task { // Launching the agent can take a while (`npx` fetches its adapter on first use). let starting = self.live.lock().as_ref().is_none_or(|l| l.peer.is_closed()); self.set_status(if starting { AgentStatus::Starting } else { AgentStatus::Running }, None); + } + + /// Sends one prompt, starting the agent first if needed; returns the stop reason. + async fn turn(self: &Arc, prompt: &AgentPrompt) -> Result { + self.turns.fetch_add(1, Ordering::AcqRel); + self.turn_started.store(false, Ordering::Release); + self.state.lock().task.resets_ms = None; let mut live = self.ensure_session().await.map_err(Failure::from)?; // Stopped while the agent started: the prompt is never sent. if self.cancel_pending.load(Ordering::Acquire) {