Make code block eval resilient to indentation (#29633)

This reduces spurious failures in the eval.

Release Notes:

- N/A
This commit is contained in:
Richard Feldman 2025-04-29 22:13:13 -04:00 committed by GitHub
parent 75a9ed164b
commit d566864891
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 21 deletions

View file

@ -174,7 +174,6 @@ impl Tool for EditFileTool {
"The `old_string` and `new_string` are identical, so no changes would be made."
));
}
let old_string = input.old_string.clone();
let result = cx
.background_spawn(async move {
@ -214,21 +213,6 @@ impl Tool for EditFileTool {
input.path.display()
)
} else {
let old_string_with_buffer = format!(
"old_string:\n\n{}\n\n-------file-------\n\n{}",
&old_string,
buffer.text()
);
let path = {
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
let mut hasher = DefaultHasher::new();
old_string_with_buffer.hash(&mut hasher);
PathBuf::from(format!("failed_tool_{}.txt", hasher.finish()))
};
std::fs::write(path, old_string_with_buffer).unwrap();
anyhow!("Failed to match the provided `old_string`")
}
})?;