Repository navigation
chore(agent-core-v2): remove same-file Edit restriction and re-read requirement - #4708
Conversation
…equirement The Edit description forbade several Edit calls on one file and required a full Read before each next Edit. Same-file Edits already run in response order, each Edit reads the file from disk, and a stale old_string fails safely with a reload hint, so the rule only added a full-file Read per edit. It also contradicted the Read description and the Edit result note, which both say not to re-read after a successful edit.
🦋 Changeset detectedLatest commit: 0d6afd9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d6afd9dce
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -3,5 +3,3 @@ Perform exact replacements in existing files. | |||
| - Drop the line-number prefix and tab; match only file content. | |||
| - `old_string` must be unique unless `replace_all` is set. | |||
| - If `old_string` is ambiguous, add surrounding context. | |||
There was a problem hiding this comment.
Add an escape hatch or obtain approval before removing the policy
For every session exposing the built-in Edit tool, this unconditionally removes both the same-file batching restriction and the reread requirement: EditTool.description loads this template directly, without a flag preserving the old policy. The commit description explicitly lists no escape hatch and says maintainer confirmation is still required. Although the runtime protections justify considering this change, they do not satisfy the removal requirement in AGENTS.md. Provide a config/env/flag restoring the old policy with a guard test, or obtain and record explicit maintainer sign-off before shipping.
AGENTS.md reference: AGENTS.md:L116-L116
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🔵 Needs a closer look
Maintainer sign-off is needed because removing Edit safeguards affects all built-in sessions without an escape hatch, and the impact on edit correctness and reread frequency remains unvalidated.
No open issues 🎉
What changed in this PR
本 PR 精简内置 Edit 工具的提示词,允许模型读取一次文件后连续编辑多处,旨在减少重复读取带来的上下文开销和交互轮次;不修改工具参数、执行逻辑或权限检查。
Changes:
- 删除同一响应内不能对同一文件多次调用 Edit 的限制,以及连续编辑前必须重读文件的要求。
- 新增 CLI patch changeset,说明移除的两项行为限制。
| File | Description |
|---|---|
packages/agent-core-v2/src/agent/tools/edit/edit.md |
删除同文件多次编辑限制和重读要求,保留精确匹配指导。 |
.changeset/edit-same-file-without-reread.md |
记录面向用户的 Edit 行为变化。 |
Review effort: Balanced
Requirement or Bug
模型要对同一个文件改好几处时,Edit 工具描述要求它每改一次之前都重新 Read 一遍这个文件。轨迹就变成"读、改、读、改"串行进行,整份文件内容一次次进入上下文(Read 默认最多返回 100k 字符),后面每一轮都要带着,轮数也跟着变多。本 PR 删掉这条限制,让模型可以读一次、改多次。无关联 issue。
Bug Reproduction Steps
N/A
Root Cause
这两句来自 #540。那个 PR 讨论的是 Edit 和 Write 怎么选,顺手把 Edit 描述最初的写法(同一文件的多个 Edit 可以放在一个响应里,写锁按顺序执行)改成了"禁止同一文件连续 Edit、每次 Edit 前重读",没有附数据。后来 "Read the target file before every Edit" 和 "Edit is mandatory" 先后被删,这两句一直留着。
它还和另外两处文本矛盾:Read 描述写着 "After a successful
Edit/Write, do not re-read solely to prove the write landed",Edit 成功后的返回也写着 "there is no need to Read the file back to check it"。模型会按更具体的 Edit 描述来,结果就是每次改之前都重读。删掉规则是根本修复。Code Changes
只删两行工具描述,不改工具参数、执行逻辑或权限检查。旧规则想防的是"前一个 Edit 让后一个 Edit 的
old_string失效",这件事运行时已经兜住了:toolScheduler.ts对读写同一路径的调用排队)。fileEditService.ts)。old_string匹配不到时只报错、不写文件,报错文本会提示用 Read 重新加载(editService.ts)。所以删掉之后,最坏情况是一次可恢复的报错,换来的是每次编辑不再整读一遍文件。Codex 的做法相同:
apply_patch一次调用就能改同一文件的多处,它的基础指令还写着 "Do not waste tokens by re-reading files after callingapply_patchon them. The tool call will fail if it didn't work."Behavior Changes and Affected Users
受影响的是所有拿到内置 Edit 工具的会话,包括主 agent 和子 agent,覆盖 TUI、print 模式、desktop/web、VS Code、ACP 和 SDK。
Multiple Edit calls may run in one response only when they do not target the same file.old_string not found的用户。DO NOT issue consecutive Edit calls on the same file. A previous Edit can invalidate a later Edit's old_string, causing old_string not found. Read the file again before the next Edit.改完后可能出现的情况:
old_string引用了前一个 Edit 已经改掉的文本,会报old_string not found,多花一轮,文件不受影响。new_string恰好包含后一个 Edit 的old_string,而原来那处已经被替换掉,后一个 Edit 会改到新插入的文本上,并且不报错。这需要两次编辑的文本互相重叠。没有测试锁定 Edit 描述的原文,本 PR 不新增测试。模型行为上的效果(每次 Edit 前的 Read 次数、
old_string not found比例、input token、轮数、通过率)还没有用 A/B 验证。验证详情
在
packages/agent-core-v2下运行,结果:2 个测试文件通过,182 个测试通过,1 个跳过。returns the spawned agent id when a foreground subagent times out在本分支和未修改的main上都以同样的 30 秒超时失败,所以排除。未运行全量测试。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.