Repository navigation
Description
StrReplace reads the file and then writes the edited text back. Each is a request to the Host of its own. If another task changes the file between the two, the write holds the whole file as the read found it, and the other task's change is lost.
What happens
crates/plugin-std/src/replace.rs calls crate::read::load(source, tool, path), edits the text in memory, and then calls source.write(path, edited). Nothing ties the write to the version that was read.
- Task A runs
StrReplaceon/project/notes.md. It reads the file. - Task B writes the same file, or appends to it.
- Task A writes its edited copy. Task B's change is gone, and neither tool call reports a problem.
The edit itself is right. Only a change made by someone else in the gap is lost.
What the Harness already covers
Write, StrReplace, and Delete set changes_files, so the Host runs a call of one of them by itself among the calls of one model reply, in the order the reply lists them. Two file-changing calls of one reply do not interleave. It does not cover:
- a change from another run, or from another task in the Host that is not a call of this reply;
- a change from outside Runvil, such as an editor or a build on the real folder.
Why it is open
The contract has no way to say "write this only if the file is still what I read". Closing the gap takes one of these in runvil-plugin-api, and the matching work in runvil-harness:
- an edit as one operation, where the Host reads, replaces, and writes without a return to the tool in between;
- a write that is conditional on a version of the file, such as its size and modified time, or a hash;
- a lock or a claim that the tool holds across the read and the write.
Which of these fits is a decision for the contract. This is why the plan lists "a contract function for an edit as one operation" as out of scope for the change that added the file effects.
Where it came up
- It is a known gap in the plan for tool file operations, and the docs in
replace.rsandlib.rsstate it. It has no test, because a test needs two tasks that interleave on purpose. - Move to contract 0.5 and implement Write, StrReplace, and Delete #2
What a fix needs
- A contract function from the list above, in
runvil-plugin-api, and the Harness side of it. StrReplaceuses it. When the file changed since the read, it fails with a sentence that tells the model to read the file again.- A test with two tasks that interleave: the second one's change must either survive or make the edit fail, and never be lost without a word.
- The docs in
replace.rsandlib.rslose the sentence about the lost edit.
Related
Write replaces a whole file by design, so a lost update there is the caller's choice. The gap here is specific to a tool that reads first and writes after.
Activity
Make the pages state what the `std` file tools do