Repository navigation
fix: write tool skips overwrites after lossy UTF-8 decoding - #133282
Conversation
Compare requested and existing UTF-8 bytes before reporting a terminal no-op, matching persisted-write verification. Preserve bounded display diffs and remove the obsolete optional-stat guard from the same owner. Cover invalid-byte overwrites, encoded surrogate no-ops, delegated readbacks, and unchanged Unicode/CRLF content.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:21 AM ET / 12:21 UTC. ClawSweeper reviewWhat this changesThe PR changes the built-in write tool to compare persisted UTF-8 bytes before returning a no-op and adds regression coverage for invalid-byte and surrogate cases. Merge readinessKeep this PR open for normal maintainer handling: it is a focused owner-boundary repair for a current-main false no-op, with no verified correctness or security defect in the introduced patch. Priority: P2 Review scores
Verification
How this fits togetherThe built-in write tool receives an agent’s file request, checks existing file state, then either returns a terminal no-op or writes and verifies the requested content. Its host and sandbox adapters supply the file operations used by coding sessions. flowchart LR
A[Agent write request] --> B[Path and queue resolution]
B --> C[Existing file precheck]
C --> D{Same UTF-8 bytes?}
D -->|Yes| E[Terminal no-op receipt]
D -->|No| F[Write requested content]
F --> G[Byte-level readback verification]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -1, Tests +24. Total +23 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Land the byte-level precheck so no-op receipts and successful-write verification use one exact persisted-content contract. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main decodes the three invalid bytes to U+FFFD and compares that text to the requested U+FFFD before returning a no-op. This read-only review did not execute the supplied host-tool scenario. Is this the best way to solve the issue? Yes. The precheck is the sole branch that suppresses I/O, and matching it to the existing byte-level post-write verifier is the narrowest owner-boundary repair; stricter input validation or a post-write-only workaround would not repair the false no-op. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against be67a8bdf62e. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Reviewed the latest ClawSweeper assessment at The automatic “serialized state” note does not identify a data-model change here. This diff changes only the write tool's bounded comparison before an existing user-document overwrite; no OpenClaw database, schema, serialization, migration, adapter or stored-state format changes. Existing successful-write verification already requires these same UTF-8 bytes. The unchanged real host-tool before/after scenario proves that existing ordinary Unicode/CRLF documents and identical-byte no-ops retain their behavior, while incorrect skipped overwrites and surrogate change receipts are repaired. All 101 owner/sibling tests and the canonical changed gate pass; the full-priority review and independent immutable source/behavior review found no actionable issues. |
|
Merged via squash.
|
…#133282) Compare requested and existing UTF-8 bytes before reporting a terminal no-op, matching persisted-write verification. Preserve bounded display diffs and remove the obsolete optional-stat guard from the same owner. Cover invalid-byte overwrites, encoded surrogate no-ops, delegated readbacks, and unchanged Unicode/CRLF content.
Closes #133281
What Problem This Solves
Fixes an issue where an agent asking the
writetool to overwrite a file could receive “already has identical content” while different original bytes remained on disk. A three-byte truncated UTF-8 sequence and a literal replacement character expose the problem because they decode to the same text and have the same byte length. Repeating a write containing an unpaired surrogate could also incorrectly report a change when its UTF-8 bytes were already present.Why This Change Was Made
The write precheck now compares persisted UTF-8 bytes, matching the existing post-write verification contract. Decoded text remains available for bounded display diffs. The obsolete optional-stat branch is removed from that same owner; the operation is required and its invocation is already caught.
Read/diff budgets, per-file ordering, abort recovery, edit matching, filesystem adapters, and path policies are unchanged. No config, schema, dependency, or public option changes. Production: +6/−7, net −1; tests: +63/−39, net +24.
User Impact
Complete rewrites persist the requested bytes instead of silently returning a false no-op. Already-identical UTF-8 content returns an accurate no-op, including the encoding behavior already supported by the write verifier.
Evidence
writetool, Node 24.20.0: before the fix, original bytesF0 90 80remained after requestingEF BF BD, withchanged:falseandterminate:true. After the fix, the requested bytes are persisted and the result reports an overwrite.Reviewed commit:
6e58241481b2b9cffc447dba9c6aac2d2aadbc74. Both touched owners remain unchanged on current main compared with the before-proof baseline.The original precheck condition is also present in stable
v2026.7.1; exact introduction provenance is not established.