Skip to content

fix: write tool skips overwrites after lossy UTF-8 decoding - #133282

Merged
steipete merged 1 commit into
mainfrom
codex/qa-20260830-write-byte-noop
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-20260830-write-byte-noop

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #133281

What Problem This Solves

Fixes an issue where an agent asking the write tool 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

  • Real host write tool, Node 24.20.0: before the fix, original bytes F0 90 80 remained after requesting EF BF BD, with changed:false and terminate:true. After the fix, the requested bytes are persisted and the result reports an overwrite.
  • The same five temporary-document fixtures pass after the repair, covering Unicode/CRLF creation and repeat, literal U+FFFD identity, the invalid-byte overwrite, already-encoded surrogate content, and same-size Unicode replacement. Both real-tool runs had empty stderr and isolated task state; no credentials or operator files were used.
  • Four regression cases fail on the original owner and pass after the repair; all 26 write tests pass, including Buffer and string delegated readbacks and rejection of a writer that leaves stale invalid bytes.
  • All 101 owner/sibling tests pass, including edit line-ending behavior, host-write rollback and filesystem result contracts. Fresh exact-commit review across P0–P3 and independent source/behavior review found no actionable findings.
  • The complete canonical changed-file gate passed on the exact reviewed bytes, including core/test types, lint, formatting, ratchets, boundaries and import cycles. The repository wrapper fell back to local execution before any remote checks started; no checks were skipped.

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.

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.
@steipete steipete self-assigned this Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 12:13
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:21 AM ET / 12:21 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Ready for maintainer review - 1 item remains

Keep 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
Reviewed head: 6e58241481b2b9cffc447dba9c6aac2d2aadbc74

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative production repair aligns the early no-op path with the existing exact-byte verification contract.
Proof confidence 🌊 off-meta tidepool Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body also documents a real host write-tool before/after terminal scenario aligned with the changed precheck.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body also documents a real host write-tool before/after terminal scenario aligned with the changed precheck.
Evidence reviewed 6 items Current-main defect: Fetched main still compares decoded text at the precheck, so invalid bytes that decode to the requested replacement character can incorrectly take the no-op branch.
Introduced repair: The PR retains decoded text only for display metadata and uses exact UTF-8 byte equality for the no-op decision, matching the post-write verifier’s representation.
Verifier contract: Successful writes already require a regular-file size match and exact encoded UTF-8 byte equality, so the changed precheck now uses the same contract.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the reviewed patch has no actionable defect; continue the normal exact-head CI and maintainer review process.
Agent review details

Security

None.

PR surface

Source -1, Tests +24. Total +23 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 7 -1
Tests 1 63 39 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 69 46 +23

Review metrics

Metric Value Why it matters
Production versus test delta production +6/-7 (net -1); tests +63/-39 (net +24) The repair reduces production code while focused table-driven coverage protects both byte identity and normal text behavior.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/tools/write.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133281
Summary: This PR explicitly implements the linked invalid-UTF-8 write-tool bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This fixes a deterministic but narrow file-overwrite correctness defect without evidence of broad runtime outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body also documents a real host write-tool before/after terminal scenario aligned with the changed precheck.

Label justifications:

  • P2: This fixes a deterministic but narrow file-overwrite correctness defect without evidence of broad runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This repository-member PR is exempt from the external-contributor proof gate; its body also documents a real host write-tool before/after terminal scenario aligned with the changed precheck.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Reviewed the latest ClawSweeper assessment at 6e58241481b2b9cffc447dba9c6aac2d2aadbc74: no actionable findings or separate Rank-up moves were listed. The remaining normal CI/maintainer step is being completed on that exact head.

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.

@steipete
steipete merged commit c0cafd7 into main Aug 30, 2026
308 checks passed
@steipete
steipete deleted the codex/qa-20260830-write-byte-noop branch August 30, 2026 12:31
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: write tool skips overwrites when invalid UTF-8 decodes identically

1 participant