Repository navigation
Description
What happened
The Rust rust-preview branch still accepts an ambiguous Edit when two exact matches overlap, and modifies the file instead of rejecting the request.
Related: #5589, specifically “Edit misses overlapping exact matches.” That issue was reported against the TypeScript runtime and is closed as completed. This issue tracks the same observable defect in the separate Rust implementation, reproduced at cd1a6d82fda3adbd9753dc94254ff2aaed65e1de. It does not reopen the other FormatJson/Read problems in #5589.
The Rust Edit description promises to replace one unique span and reject ambiguous matches. Repeated lines or blocks violate that guarantee: the first candidate is written even though a second overlapping candidate exists.
How to reproduce
- Check out
rust-previewatcd1a6d82fda3adbd9753dc94254ff2aaed65e1de. - Create a UTF-8 file containing exactly
item\nitem\nitem\n. - Invoke the Rust
MutationExecutor'sEdittool with:{"path":"text","old_string":"item\nitem\n","new_string":"changed\n"} - There are two exact spans, starting at byte offsets 0 and 5. Expected: reject the ambiguous request and leave the original bytes unchanged.
- Actual: success with
matchedVia: "exact",replacements: 1,startLine: 1,endLine: 2; the file becomeschanged\nitem\n.
Deterministic regression test
Append the following test to plugins/workspace/workspace-files/engine/tests/edit.rs. It uses that file's existing executor and edit helpers, invoking the real Rust tool against a temporary file:
#[tokio::test]
async fn audit_overlapping_exact_matches_must_be_rejected() {
let temp = tempfile::tempdir().unwrap();
let root = dunce::canonicalize(temp.path()).unwrap();
let executor = executor(&root);
let source = "item\nitem\nitem\n";
fs::write(root.join("text"), source).unwrap();
let result = edit(
&executor,
json!({
"path": "text",
"old_string": "item\nitem\n",
"new_string": "changed\n"
}),
)
.await;
println!(
"result={result:?}; after={:?}",
fs::read_to_string(root.join("text")).unwrap()
);
assert!(
result.is_err(),
"ambiguous edit must be rejected; actual file was modified"
);
assert_eq!(fs::read_to_string(root.join("text")).unwrap(), source);
}Run:
cargo test -p maka-fs-tools --test behavior edit:: -- --nocaptureEnvironment
- Branch:
rust-preview - Commit:
cd1a6d82fda3adbd9753dc94254ff2aaed65e1de - OS: macOS 26.5.2, Apple Silicon
- Rust:
rustc 1.99.1 (58cf8f9c3 2026-10-13) - Surface: Rust filesystem tool executor (
maka-fs-tools), exercised through its integration-test entry point - No real provider/model call or Desktop UI interaction was used for this reproduction.
- Production source was unmodified; only the regression test was added to an isolated source snapshot.
Logs, screenshots, or additional context
The actual run used --offline with dependencies already cached. All three existing Edit tests passed; the added regression failed:
running 4 tests
test edit::audit_overlapping_exact_matches_must_be_rejected ... FAILED
test edit::invalid_ambiguous_and_missing_edits_leave_bytes_intact ... ok
test edit::fuzzy_edits_report_the_original_span_and_write_replacements_literally ... ok
test edit::exact_edit_large_utf8_source_preserves_bytes_inode_and_mode ... ok
ambiguous edit must be rejected; actual file was modified
test result: FAILED. 3 passed; 1 failed; 0 ignored; 0 measured; 17 filtered out
The diagnostic printed before the failing assertion confirmed Ok(...) and after="changed\nitem\n"; this is an actual file mutation, not just an incorrect match count.
Cause: edit_match.rs, lines 57–63 checks uniqueness using source.match_indices(old). That iterator enumerates non-overlapping matches, so its second next() misses the overlapping occurrence. The exact-match path then accepts the first span.
Acceptance: overlapping exact matches must be rejected before writing, with original bytes preserved; retain successful unique exact/fuzzy edits and rejection of ordinary non-overlapping duplicates.
Submitted by kesonm.
Activity
fix(rust): reject overlapping exact Edit matches (#6859)