Repository navigation
fix(agents): verify apply_patch writes before reporting success - #117990
chenyangjun-xy wants to merge 3 commits into
Conversation
apply_patch reported success immediately after the delegated write completed, so a write that silently failed to persist the requested bytes surfaced as a false-success mutation — the same invariant gap openclaw#117938 fixed for write/edit. Verify every add/update/move write through the shared verifyPersistedUtf8File helper (stat + readback) and throw a verification error when the persisted regular file does not match the requested content. Add delegated-write regression tests that fail on the unverified code and pass with the fix.
b7e929b to
b5b0c95
Compare
|
Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 9:38 PM ET / August 3, 2026, 01:38 UTC. ClawSweeper reviewWhat this changesThe PR verifies that Merge readiness⛔ Blocked until stronger real behavior proof is added - 6 items remain Keep this PR open. The refreshed head fixes the maintainer-identified false-success receipts for deletes and move-source removals, but it makes Priority: P1 Review scores
Verification
How this fits together
flowchart LR
A[Agent patch request] --> B[Apply patch engine]
B --> C[Host or sandbox bridge]
C --> D[Write or removal operation]
D --> E[Content or entry check]
E --> F[Truthful patch receipt]
C --> G[Plugin-provided backend]
Decision needed
Why: Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +254, Tests +481. Total +735 across 14 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the truthful-removal invariant, but introduce it as an additive sandbox SDK capability with an explicit compatibility strategy: existing backends must either retain safe behavior through a supported fallback or receive an actionable unsupported-backend error before a removal can produce a receipt. Do we have a high-confidence way to reproduce the issue? Yes, from current-main source and the maintainer’s concrete review path: a bridge whose Is this the best way to solve the issue? No. The removal verification is the right invariant, but making Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f2af4e97b356. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
The unit regression suite runs against an in-memory bridge; these tests run the real applyPatch against real node:fs I/O: - happy path persists exact UTF-8 bytes for add/update/move without false rejection; - a real write that persists the wrong bytes is rejected with the verification error and the corrupted bytes are what the disk holds.
|
补充真机验证(Real-filesystem proof)——此前 Evidence 只有单元回归(in-memory bridge),未在真实文件系统上验证。新增
Red/green:将 (未修复代码对持久化错误字节的写入报告成功。)恢复修复后变绿。 结果: |
|
@clawsweeper re-review — real-filesystem behavior proof is now in the PR body and the proof test was added on head 3929d5e (verified red/green against the pre-fix commit). |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Maintainer hard validation found a blocking gap, so I am holding this open rather than merging or closing it. The branch correctly verifies add/update/destination writes, but the same false-success mutation invariant remains for removals:
On the reviewed head
The submitted write-corruption regressions pass, and exact-head CI is green, but this makes the repair one-sided rather than the canonical fix for truthful The next revision needs an authoritative entry-absence check after delete and move-source removal, including dangling symlink behavior. A simple reuse of the current |
…ract A delete and a move source removal recorded success right after remove() resolved, so a delegated bridge that resolved without deleting produced false D/M receipts. Add an authoritative lstat-semantics entryExists contract at the SandboxFsBridge owner boundary (Docker, remote, MXC, OpenShell), wire it into PatchFileOps, and reject any removal whose entry — including a dangling symlink — still exists. Focused delete/move no-op regressions on a memory bridge and the real filesystem, plus a shell-plan unit test for the anchored lstat probe.
What Problem This Solves
apply_patchreported "Success. Updated the following files: ..." immediately after each delegated write completed, so a write that silently failed to persist the requested bytes surfaced as a false-success mutation — the same invariant gap #117938 fixed for thewrite/edittools.Why This Change Was Made
Every add/update/move write now shares the same verification contract as
write/edit: the target must be a regular file with the exact requested UTF-8 bytes before a success receipt is returned. The change reuses the existingverifyPersistedUtf8Filehelper (src/agents/sessions/tools/file-write-verification.ts), which stats the target and readbacks the persisted bytes.PatchFileOpsgains astatFileoperation wired through all three adapters (sandbox bridge, host fs, fs-safe workspace root); no provider, config, schema, SDK, or fallback surface changes.User Impact
The agent no longer reports that an
apply_patchmutation succeeded when the target stayed stale, persisted different bytes, or became a non-file entry. A verification failure throwsApplyPatch verification failed for <path>: the persisted regular file does not match the requested content. Inspect the target and retry.— a visible, actionable outcome instead of a silent false success.Evidence
writeFile/createFileExclusiveresolves while persistingcorruptedbytes; before this repairapply_patchreturned a success summary, after it rejects with the verification error. Tests fail on the unverified code and pass with the fix (src/agents/apply-patch-verification.test.ts).src/agents/apply-patch-write-verification.host-fs.proof.test.ts), run against realnode:fsI/O:workspaceOnly: false+ a real temp dir applies one patch doing Add / Update / Move with multi-byte UTF-8 content.applyPatchreports success and the disk bytes byte-for-byte match the requested content; move source is removed and destination exists — the size + readback check does not false-reject normal writes.SandboxFsBridge(all I/O persisted) whose only injection iswriteFilepersisting the wrong bytes.applyPatchrejects withApplyPatch verification failed for source.txtand the disk holds exactly thecorruptedbytes — no false-success receipt.apply-patch.ts/apply-patch-file-ops.tsto the pre-fix commit (2de2fa3d673) makes the fault test red (promise resolved ... instead of rejecting— the unfixed code reports success for a corrupted write); with the fix it is green.node scripts/run-vitest.mjs src/agents/apply-patch-write-verification.host-fs.proof.test.ts→ 2 passed; together withapply-patch.test.tsandapply-patch-verification.test.ts→ 56 passed.node scripts/run-vitest.mjs src/agents/apply-patch.test.ts src/agents/apply-patch-verification.test.ts src/agents/apply-patch-paths.test.ts src/agents/apply-patch-context-bytes.test.ts src/agents/agent-tools.read.host-operations.test.ts— 91/91 tests passed.tsgo:coreandtsgo:core:testtypechecks clean;oxlintclean on all changed files;oxfmt --checkclean.git diff --checkclean.AI-assisted implementation; reviewed the full owner path, caller adapters, sibling tool behavior, and focused tests.