Repository navigation
fix(editor): prevent concurrent str_replace_editor corruption - #52
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upstream editor reference · Upstream filesystem coordination
Why the change
Concurrent
str_replace_editorcalls could read the same original file, independently rewrite it, and all report success while overwriting each other's changes. Concurrent truncating writes could also leave NUL bytes or stale tails.Before the fix, a local diagnostic through the native handler with real temporary files produced three success responses in all 50 parallel trials, but never the complete expected result; one trial contained NUL bytes. The sequential control was byte-exact in all 20 trials. This did not require a model or an OpenCode host process.
The DeepSeek Harness editor delegates to a filesystem with version-guarded writes, canonical-target coordination, and staged atomic publication. Our adapter used an uncoordinated
writeFile; the fix restores the relevant safety properties without importing the upstream filesystem or expanding the tool API.Special things to note
str_replace_editorcalls within one process, not host-owned editors, shell commands, other processes, or crash/power-loss durability.bun run check(2338 pass, 7 live-host skips),bun run pack:check,grace lint --path ., andgrace status --path .(zero integrity errors/warnings). The original three-call real-file diagnostic was exact in 50/50 trials, without NUL bytes. Full OpenCode-host execution and Windows behavior were not exercised.Change outline
Regression coverage pins concurrent disjoint replacements, growing/shrinking and empty payloads, exact UTF-8 bytes without NUL or duplicate tails, alias and session behavior, create conflicts, cancellation/failure recovery, and unrelated-file progress. A smoke through the built public plugin also applied three concurrent replacements with exact Unicode/BOM/CRLF bytes and no NUL or staging residue.
Native reads and editor views use the same session-isolated canonical freshness records; a later handler instance or another path alias cannot bypass an existing observation. Handler disposal is idempotent and releases the shared cache after its last owner.
Fault-injection tests also cover partially written staging files, corrupted staged bytes, cancellation during staging, external changes during staging, ownership refusal, and a competing creator winning publication. These cases were exercised independently of the scheduler-dependent stress diagnostic.