Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Fix slow file edits when using Opus 4.6 (#49904)
Bennet Bo Fennerd9b7d77d7a9c
diff --git a/crates/agent/src/edit_agent.rs b/crates/agent/src/edit_agent.rsindex cab1f8ca888..3e67cba1b63 100644--- a/crates/agent/src/edit_agent.rs+++ b/crates/agent/src/edit_agent.rs@@ -81,6 +81,7 @@ pub struct EditAgent {project: Entity<Project>,templates: Arc<Templates>,edit_format: EditFormat,+ thinking_allowed: bool,}impl EditAgent {@@ -90,6 +91,7 @@ impl EditAgent {action_log: Entity<ActionLog>,templates: Arc<Templates>,edit_format: EditFormat,+ allow_thinking: bool,) -> Self {EditAgent {model,@@ -97,6 +99,7 @@ impl EditAgent {action_log,templates,edit_format,+ thinking_allowed: allow_thinking,}}@@ -731,7 +734,7 @@ impl EditAgent {tools,stop: Vec::new(),temperature: None,- thinking_allowed: true,+ thinking_allowed: self.thinking_allowed,thinking_effort: None,};@@ -1407,6 +1410,10 @@ mod tests {}async fn init_test(cx: &mut TestAppContext) -> EditAgent {+ init_test_with_thinking(cx, true).await+ }++ async fn init_test_with_thinking(cx: &mut TestAppContext, thinking_allowed: bool) -> EditAgent {cx.update(settings::init);let project = Project::test(FakeFs::new(cx.executor()), [], cx).await;@@ -1418,6 +1425,7 @@ mod tests {action_log,Templates::new(),EditFormat::XmlTags,+ thinking_allowed,)}@@ -1493,6 +1501,45 @@ mod tests {);}+ #[gpui::test]+ async fn test_thinking_allowed_forwarded_to_request(cx: &mut TestAppContext) {+ let agent = init_test_with_thinking(cx, false).await;+ let buffer = cx.new(|cx| Buffer::local("hello\n", cx));+ let (_apply, _events) = agent.edit(+ buffer.clone(),+ String::new(),+ &LanguageModelRequest::default(),+ &mut cx.to_async(),+ );+ cx.run_until_parked();++ let pending = agent.model.as_fake().pending_completions();+ assert_eq!(pending.len(), 1);+ assert!(+ !pending[0].thinking_allowed,+ "Expected thinking_allowed to be false when EditAgent is constructed with allow_thinking=false"+ );+ agent.model.as_fake().end_last_completion_stream();++ let agent = init_test_with_thinking(cx, true).await;+ let buffer = cx.new(|cx| Buffer::local("hello\n", cx));+ let (_apply, _events) = agent.edit(+ buffer,+ String::new(),+ &LanguageModelRequest::default(),+ &mut cx.to_async(),+ );+ cx.run_until_parked();++ let pending = agent.model.as_fake().pending_completions();+ assert_eq!(pending.len(), 1);+ assert!(+ pending[0].thinking_allowed,+ "Expected thinking_allowed to be true when EditAgent is constructed with allow_thinking=true"+ );+ agent.model.as_fake().end_last_completion_stream();+ }+fn drain_events(stream: &mut UnboundedReceiver<EditAgentOutputEvent>,) -> Vec<EditAgentOutputEvent> {diff --git a/crates/agent/src/edit_agent/evals.rs b/crates/agent/src/edit_agent/evals.rsindex 5c30aa46c2f..cdf6c1c0b3f 100644--- a/crates/agent/src/edit_agent/evals.rs+++ b/crates/agent/src/edit_agent/evals.rs@@ -1468,6 +1468,7 @@ impl EditAgentTest {action_log,Templates::new(),edit_format,+ true,),project,judge_model,diff --git a/crates/agent/src/tools/edit_file_tool.rs b/crates/agent/src/tools/edit_file_tool.rsindex 7259ce21623..788bf06529a 100644--- a/crates/agent/src/tools/edit_file_tool.rs+++ b/crates/agent/src/tools/edit_file_tool.rs@@ -263,6 +263,10 @@ impl AgentTool for EditFileTool {ToolCallUpdateFields::new().locations(vec![acp::ToolCallLocation::new(abs_path)]),);}+ let allow_thinking = self+ .thread+ .read_with(cx, |thread, _cx| thread.thinking_enabled())+ .unwrap_or(true);let authorize = self.authorize(&input, &event_stream, cx);cx.spawn(async move |cx: &mut AsyncApp| {@@ -283,6 +287,7 @@ impl AgentTool for EditFileTool {action_log.clone(),self.templates.clone(),edit_format,+ allow_thinking,);let buffer = project