From 35720710f2aa70447a3e7959d69d542cc7365d00 Mon Sep 17 00:00:00 2001 From: Bennet Bo Fenner Date: Thu, 5 Mar 2026 14:48:44 +0100 Subject: [PATCH] agent: Add debug logging to `StreamingEditFileTool` (#50826) Add some debug logging to the streaming edit file tool, to make it easier to debug errors. Can be enabled with ``` "log": { "agent": "debug", } ``` Release Notes: - N/A --- .../src/tools/streaming_edit_file_tool.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/agent/src/tools/streaming_edit_file_tool.rs b/crates/agent/src/tools/streaming_edit_file_tool.rs index 804c4be018db59e0e9b712acf1b6b2fc088c4dd3..81846ec282a52cc694a0f1c8e8418b5202d7e0d6 100644 --- a/crates/agent/src/tools/streaming_edit_file_tool.rs +++ b/crates/agent/src/tools/streaming_edit_file_tool.rs @@ -567,6 +567,17 @@ impl EditSession { })?; let events = self.parser.finalize_edits(&edits); self.process_events(&events, tool, event_stream, cx)?; + + if log::log_enabled!(log::Level::Debug) { + log::debug!("Got edits:"); + for edit in &edits { + log::debug!( + " old_text: '{}', new_text: '{}'", + edit.old_text.replace('\n', "\\n"), + edit.new_text.replace('\n', "\\n") + ); + } + } } } @@ -699,6 +710,7 @@ impl EditSession { ToolEditEvent::OldTextChunk { chunk, done: false, .. } => { + log::debug!("old_text_chunk: done=false, chunk='{}'", chunk); self.pipeline.ensure_resolving_old_text(&self.buffer, cx); if let Some(EditPipelineEntry::ResolvingOldText { matcher }) = @@ -725,6 +737,8 @@ impl EditSession { chunk, done: true, } => { + log::debug!("old_text_chunk: done=true, chunk='{}'", chunk); + self.pipeline.ensure_resolving_old_text(&self.buffer, cx); let Some(EditPipelineEntry::ResolvingOldText { matcher }) = @@ -767,6 +781,14 @@ impl EditSession { let old_text_in_buffer = snapshot.text_for_range(range.clone()).collect::(); + log::debug!( + "edit[{}] old_text matched at {}..{}: {:?}", + edit_index, + range.start, + range.end, + old_text_in_buffer, + ); + let text_snapshot = self .buffer .read_with(cx, |buffer, _cx| buffer.text_snapshot()); @@ -786,6 +808,8 @@ impl EditSession { ToolEditEvent::NewTextChunk { chunk, done: false, .. } => { + log::debug!("new_text_chunk: done=false, chunk='{}'", chunk); + let Some(EditPipelineEntry::StreamingNewText { streaming_diff, edit_cursor, @@ -821,6 +845,8 @@ impl EditSession { ToolEditEvent::NewTextChunk { chunk, done: true, .. } => { + log::debug!("new_text_chunk: done=true, chunk='{}'", chunk); + let Some(EditPipelineEntry::StreamingNewText { mut streaming_diff, mut edit_cursor, @@ -835,6 +861,8 @@ impl EditSession { let mut final_text = reindenter.push(chunk); final_text.push_str(&reindenter.finish()); + log::debug!("new_text_chunk: done=true, final_text='{}'", final_text); + if !final_text.is_empty() { let char_ops = streaming_diff.push_new(&final_text); apply_char_operations(