Repository navigation
fix(agents): clarify errors for malformed JSON-string edits - #163577
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 12:48 PM ET / 16:48 UTC (Revision 4). ClawSweeper reviewWhat this changesThe agent’s file-edit tool reports malformed JSON-string replacements clearly while preserving legacy replacement and deletion inputs. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release still swallow malformed serialized-edit parse errors. The updated patch has no actionable findings, and the earlier runtime proof remains applicable to its unchanged preparation and execution logic. Priority: P2 Review scores
Verification
How this fits togetherThe file-edit tool receives replacement arguments from an agent, prepares and validates them, then applies changes to a file. Its error results return to the model so it can correct invalid arguments. flowchart TD
A[Agent replacement arguments] --> B[Repair and parse serialized edits]
B --> C{Parse succeeds or legacy pair exists}
C -->|Neither| D[Return actionable parse error]
C -->|Yes| E[Validate and apply replacements]
E --> F[Verify file and return result]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +6, Tests +48. Total +54 across 2 files. View PR surface stats
Review metricsNone. 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: Keep the diagnostic in the existing argument preparer, preserving bounded JSON repair, strict replacement validation, and legacy fallback behavior. Do we have a high-confidence way to reproduce the issue? Yes: a malformed serialized edits value without a complete legacy pair reaches main’s empty parse-error catch and then generic validation. This is source-established; no current-main runtime reproduction was executed here. Is this the best way to solve the issue? Yes: handling the failed parse in the existing preparer gives the model an actionable error without changing valid input semantics or adding another normalization owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e0ec9b048f0c. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
28fb89a to
51213dc
Compare
|
@clawsweeper re-review Rebased onto current main. Independent P0–P2 review is clean; fresh Linux regression tests, formatting, and lint pass. Please review the updated head. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* commit 'c39d9b0692dbaafa5b1bfe02514c9f6411ab5546': (30 commits) fix(ci): clear MCP audit and service-worker test blockers (#166217) test(gateway): wait for steering admission in FIFO fixtures fix(llama-cpp): managed setup crashes and loops on macOS below 13.3 (#163358) perf(worktrees): avoid full session parsing during GC (#166072) fix(update): recover stopped legacy managed services (#166232) perf(gateway): stream bounded link preview metadata (#166195) perf(diagnostics): release completed Git operation state (#166214) chore(deps): update fs-safe to 0.24.1 and clone plugin source captures (#166189) feat(clients): adopt worker-local inference placement (#163647) test: serialize PowerShell completion process suites (#166229) test: stabilize release timing boundaries (#166218) refactor(sessions): persist run outcomes only; liveness comes from the run registry (#165733) test(gateway): prove mention refresh after config retargeting fix(team-reports): keep the missed closed day when catch-up runs after midnight (#165780) test(gateway): join WebChat queue admission and drain completion fix(logging): reject blank diagnostic stability query fields (#145532) fix(agents): report unparseable serialized edit arguments (#163577) improve(anthropic): log Claude Code version probe failures (#157697) fix(agents): clarify prompt-size provider failures (#159712) fix(memory): re-throw non-ENOENT/ENOTDIR errors in root memory file lookup (#107921) ...
Fixes #153486
What Problem This Solves
The edit tool reports a generic replacement validation error when a JSON-string
editsvalue cannot be parsed, hiding the actual problem.User Impact
Malformed serialized edits now receive a JSON parse hint before editing starts. Valid legacy
oldText/newTextreplacements still work, including deletion with an emptynewText.Why This Change Was Made
Surface parse failures after the existing JSON escape repair only when no complete legacy pair is available. Preserve the existing fallback and valid-input behavior. The restored merge integrates upstream snapshot
c190df12716a17d23a1c00eaf106044d2f2c9317, retaining all six PR regressions and upstream's consolidated legacy-input cases.Evidence
Published head:
28fb89aa96a2303eff09a41f096c0ed9b3f57968, treeb69c46c9d35afdb4236144e97b340a1f926feba8. One normal Git push updated the original fork branch on 2026-10-04. Git and GitHub both confirmed the exact head; the original commit bytes, ordered parents, and author/committerJin Long <[email protected]>were preserved.ENOENT) after 24 successful items. With the task-local tool/cache environment corrected, all three native Knip export scans passed in 112.12 seconds, followed by the nine remaining checks. The original aggregate is not reported as exit 0; source inputs were unchanged and no guard was skipped.c190df127…, leaving the candidate tree unchanged. The commit was restored intact without creating or rewriting a commit.autoreviewhelper had no findings but one context-incomplete part; it is not counted as a complete helper review.59d3a13….Current-head CI
Verified on 2026-10-04 13:15 UTC for exact head
28fb89aa96a2303eff09a41f096c0ed9b3f57968: CI run 37204368736, CodeQL, and CodeQL Critical Quality completed successfully.openclaw/ci-gate, dependency-review, and security-sensitive-review statuses are successful. The main CI run recorded 41 successful and 26 skipped jobs, with no failed jobs; skipped checks are not counted as passes. The earlier local validation and historical head59 CI evidence retain their separate scope.Validation commands and environment
The earlier Linux validation checkout used its own frozen dependencies with Node 24.19.0 and pnpm 12.5.1. The initial aggregate's nested launcher selected global pnpm 11.19.0; follow-up commands used the verified task-local pnpm 12.5.1 entry and writable cache. The final publication used a separate Debian 13 cloud executor without installing dependencies or repeating valid checks.
node scripts/run-vitest.mjs run \ src/agents/sessions/tools/edit.legacy-input.test.ts \ src/agents/sessions/tools/edit.test.ts \ src/agents/sessions/tools/edit-diff.test.ts \ src/agents/sessions/tools/edit-formatting.test.ts \ --maxWorkers=1 node scripts/check-changed.mjs --base c190df12716a17d23a1c00eaf106044d2f2c9317 -- \ src/agents/sessions/tools/edit.ts src/agents/sessions/tools/edit.legacy-input.test.ts # Follow-up native checks on unchanged source: node --import tsx scripts/check-deadcode-exports.mts node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json \ src/agents/sessions/tools/edit.legacy-input.test.ts src/agents/sessions/tools/edit.ts node scripts/check-native-state-schema-version.mjs pnpm check:database-first-legacy-stores pnpm check:media-download-helpers pnpm check:runtime-sidecar-loaders pnpm check:import-cycles pnpm lint:webhook:no-low-level-body-read pnpm lint:auth:no-pairing-store-group pnpm lint:auth:pairing-account-scopeHistorical runtime verification (
59d3a13)Verified head
59d3a13a81d7fbac7999f31d8099998e739d462don macOS with Node 24.19.0 through the supported local agent CLI:pnpm openclaw --profile edit-json-proof agent --local --agent main \ --session-id edit-json-proof \ --message 'Run the three supplied edit fixture cases, then finish.' \ --thinking off --timeout 180 --jsonThe run used isolated config, state, and workspace directories. A localhost OpenAI-compatible HTTP fixture supplied three deterministic
editcalls. The OpenClaw CLI,openclawagent harness, argument preparation, filesystem operations, and tool-result transport ran unchanged. Only model responses were simulated; this is not live LLM or Gateway transport proof.Each file initially contained
"alpha\nbefore\nomega\n". The following results were captured from the next HTTP request OpenClaw sent to the provider, rather than inferred from the final assistant text:The persisted agent transcript independently records these three tool results with
isError: true,false, andfalse. The run completed four assistant turns, exited 0, and took 15.783 seconds wall time after the runtime build. No tracked files changed.Historical CI failure
The type-check job failed at
src/gateway/worker-environments/worker-turn-launcher.claim-recovery.test.ts:346:appendMessagedoes not exist onPromise<SessionManager>.CI tested merge commit
3abe74c4a4064ef7136c9dab8e11469517286dde. The failing test file is byte-identical to its upstream parent3932cbe4c91c5f3838a141f6a8cdeeb48fdf50b6(blob03590b533fc515682a7ef9072978adb10db25087). The merge delta contains only the two edit-related files in this PR. This identifies a separate upstream test error in that historical run; it does not describe current-head CI.