← Back to PRs

#18742: feat(edit): return current file content on match failure

by maximalmargin open 2026-02-17 01:15 View on GitHub →
agents stale size: XS
## Summary When the Edit tool fails because `oldText` doesn't match the file content, the agent currently has to make a separate `Read` call to see the current state before retrying. This wastes tokens and context window. **This PR wraps the Edit tool's `execute` method to return the current file content alongside the error message when a text mismatch occurs.** The agent can immediately see what changed and retry — no extra Read needed. ## Changes - `src/agents/pi-tools.read.ts`: Wrap `createSandboxedEditTool` execute to catch "Could not find the exact text" errors and append current file content to the error response. ## Impact - Saves 1 tool call (Read) per failed Edit retry - Reduces token usage and context window consumption - No behavior change for successful edits or non-mismatch errors Closes #18132

Most Similar PRs