openclaw - 💡(How to fix) Fix [Bug]: Edit tool schema mismatch: "edits" array in schema vs flat "oldText"/"newText" in implementation [5 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58599Fetched 2026-04-08 02:00:23
View on GitHub
Comments
5
Participants
3
Timeline
7
Reactions
0
Author
Timeline (top)
commented ×5labeled ×2

The edit tool's JSON schema exposes an edits array parameter where each item has oldText/newText properties. However, the implementation in src/agents/pi-tools.params.ts reads oldText and newText as flat top-level keys on the params object using readStringParam(). This causes every edit call from the model to fail with: Missing required parameters: oldText alias, newText alias.

The implementation does accept aliases (old_string, old_text, oldString, etc.) but only at the top level — never from inside an edits array.

Relevant files:

• src/agents/pi-tools.params.ts — lines 24-28, 44-45 • src/agents/pi-tools.host-edit.ts — readEditToolParams() function

Error Message

  1. Tool returns error: Missing required parameters: oldText alias, newText alias. Supply correct parameters before retrying.
  2. The model retries with the same schema format, same error — infinite loop The edit tool rejects every call with "Missing required parameters: oldText alias, newText alias". The implementation reads oldText/newText as flat top-level keys from the params object, but the schema instructs the model to send them nested inside an edits array. This creates an infinite retry loop where the model keeps re-sending the same format and getting the same error.

Root Cause

Actual: Every call fails because the implementation looks for oldText as a top-level key, but it's nested inside edits[0].oldText.

RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

The edit tool's JSON schema exposes an edits array parameter where each item has oldText/newText properties. However, the implementation in src/agents/pi-tools.params.ts reads oldText and newText as flat top-level keys on the params object using readStringParam(). This causes every edit call from the model to fail with: Missing required parameters: oldText alias, newText alias.

The implementation does accept aliases (old_string, old_text, oldString, etc.) but only at the top level — never from inside an edits array.

Relevant files:

• src/agents/pi-tools.params.ts — lines 24-28, 44-45 • src/agents/pi-tools.host-edit.ts — readEditToolParams() function

Steps to reproduce

  1. Set up an OpenClaw agent with any model (e.g. zai/glm-5.1)
  2. Ask the agent to edit a file, e.g. "Change 'foo' to 'bar' in test.txt"
  3. The model calls the edit tool with:

{ "path": "test.txt", "edits": [{"oldText": "foo", "newText": "bar"}] }

  1. Tool returns error: Missing required parameters: oldText alias, newText alias. Supply correct parameters before retrying.
  2. The model retries with the same schema format, same error — infinite loop

Expected: Edit succeeds, file is modified.

Actual: Every call fails because the implementation looks for oldText as a top-level key, but it's nested inside edits[0].oldText.

Expected behavior

The edit tool accepts parameters matching its documented schema — an edits array with oldText/newText objects — and successfully replaces the matched text in the specified file.

Actual behavior

The edit tool rejects every call with "Missing required parameters: oldText alias, newText alias". The implementation reads oldText/newText as flat top-level keys from the params object, but the schema instructs the model to send them nested inside an edits array. This creates an infinite retry loop where the model keeps re-sending the same format and getting the same error.

OpenClaw version

OpenClaw 2026.3.30 (commit 566fb73)

Operating system

osx 26.4

Install method

don't remember

Model

zai/glm-5.1

Provider / routing chain

Provider routing chain: zai/glm-5.1

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

  • The edit tool's implementation needs to be updated to read oldText and newText from the edits array instead of as flat top-level keys.

Guidance

  • Review the readEditToolParams() function in src/agents/pi-tools.host-edit.ts to understand how parameters are being read from the request.
  • Update the readStringParam() calls in src/agents/pi-tools.params.ts (lines 24-28, 44-45) to access oldText and newText from the edits array.
  • Verify that the edits array is properly parsed and accessible in the readEditToolParams() function.
  • Test the updated implementation with the provided example edit call to ensure it succeeds and modifies the file as expected.

Example

// Example of how to access oldText and newText from the edits array
const edits = params.edits;
if (edits && edits.length > 0) {
  const oldText = edits[0].oldText;
  const newText = edits[0].newText;
  // Use oldText and newText for the edit operation
}

Notes

  • The current implementation only accepts aliases at the top level, which needs to be adjusted to support the documented schema.
  • The fix should ensure that the edit tool can handle the edits array correctly and perform the edit operation as expected.

Recommendation

  • Apply workaround: Update the readStringParam() calls to access oldText and newText from the edits array, as described in the guidance section. This will allow the edit tool to work with the documented schema and perform edit operations correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The edit tool accepts parameters matching its documented schema — an edits array with oldText/newText objects — and successfully replaces the matched text in the specified file.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING