MoonshotAI / MoonshotAI/kimi-code
Edit 失败后陷入死循环:反复"Edit 失败 → 重读 → 再失败",并逐步删空了被编辑文件的多个章节
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
What version of Kimi Code is running?
kimi-code 0.29.1(本次问题发生在 Kimi Web 网页端,UI 显示为中文"读取/编辑"工具卡片;此处提供本机 CLI 版本作参考)
Which open platform/subscription were you using?
Kimi Web(网页版)
Which model were you using?
K2.7 Coding,发现反复修改失败后,切换K3-256K也无法成功修改
What platform is your computer?
0.29.1 / Windows 11 22631 / Windows Terminal
What issue are you seeing?
让 agent 对 C:/Users/keen/.kimi-code/skills/teach-me/SKILL.md 做一处很小的文档修改(新增一条规则:“代码块、表格、长格式化内容要先在正文展示,题干只做引用”),结果 agent 陷入病态的 Edit 失败循环,并在此过程中把正在编辑的文件改坏了:
一次 Edit 调用失败(old_string 找不到 / 文件内容已变化)后,agent 没有先诊断、再一次性重读受影响区域,而是连续 十余次 重复"Edit 失败 → 重读一小段 → 再次 Edit 失败"的循环。
其中多次 Edit 是破坏性的:把匹配到的大段区域替换成空/近乎空的内容(diff 显示为 +0 −1、+0 −19、+0 −5、+0 −9、+0 −4),先后删掉了整个 “Programming” 小节、整个 “Practice Phase” 章节(标题+正文)、以及 3e/3f/3g 的内容。
agent 自己的叙述显示它已经发现了破坏(“Programming 部分被我删掉了”、“现在 Practice Phase 标题和内容都被删了”),但仍然继续对一份它已经完全失去状态认知的文件盲目发起 Edit,反复念叨"文件内容可能已经变化。让我再读一次",然后下一次 Edit 继续失败。
每次重读只用 40/50/30/12 行的小窗口,而不是一次读完整个 492 行的文件,导致 agent 始终无法在下次 Edit 前重建对文件的准确认知。
任务最终被半途放弃,文件处于损坏状态(“让我先读取整个文件……修复” → 用户不得不手动输入"继续")。
agent 自己的叙述节选,可见循环过程:
编辑 SKILL.md ✗(old_string 未找到)
读取 SKILL.md ✓ 40 行
编辑 SKILL.md ✓ +0 −19 ← 删掉了 Practice Phase 标题和正文
编辑 SKILL.md ✗
读取 SKILL.md ✓ 50 行
编辑 SKILL.md ✓ +0 −5 ← 又删掉一段内容
编辑 SKILL.md ✗
读取 SKILL.md ✓ 30 行
编辑 SKILL.md ✓ +0 −9
…如此重复十余次
What steps can reproduce the bug?
该 bug 是模型行为问题,触发有一定概率,但在以下场景稳定复现过一次:
打开 Kimi Web,进入一个已有较长上下文的会话(本次触发时会话中已有较多轮次,且包含大段代码粘贴)。
准备一份约 500 行、包含多个结构相似小节的 Markdown 文件(本次为 ~/.kimi-code/skills/teach-me/SKILL.md,492 行,含 #### 3e、#### 3f、#### 3g 等多个连续小节)。
要求 agent 对该文件做一处"插入式"文档修改,例如:“加一条规则:代码块、表格、长格式化内容要先展示,题干引用”,并要求同步修改文件中的相关示例段落(即需要在多个相似位置各做一次 Edit)。
观察 agent 的工具调用序列:当某次 Edit 因 old_string 与当前文件内容不匹配而失败时,agent 不会先完整重读文件再改,而是进入"Edit 失败 → 读 30~50 行小窗口 → 再次 Edit"的循环。
循环中会出现多次 +0 −N(纯删除)的 Edit——agent 把匹配到的大段区域替换成空内容,逐步删掉整个 “Practice Phase” 章节和 “Programming” 小节;agent 在叙述中已自知文件被改坏,仍继续盲目 Edit,直至任务失败、需要用户介入。
关键复现条件(缺一不可的程度较低,但叠加后极易触发):
文件较长且含多个相似段落,old_string 容易误匹配或过期;
任务要求在同一文件做多处修改,产生连续多次同文件 Edit;
会话上下文较长,agent 对文件当前状态的记忆已经过期。
本次触发时的会话信息:
产品端:Kimi Web
Session id:(请从 Web 端会话 URL 或设置中复制后填入)
上下文用量:(触发时未记录,会话中已有约数十轮对话和多次大文件 Read/Edit)
本机 CLI 版本(参考):kimi-code 0.29.1 / Windows 11 22631 / Windows Terminal
What is the expected behavior?
期望行为:
第一次 Edit 失败后,必须先重读文件(或相关区域)再尝试下一次 Edit;绝不能基于过期视图连续发起针对同一文件的 Edit。
当意图是"插入内容"而 Edit 实际把大段匹配区域替换成空内容时,这种"大删除、零新增"的同文件 Edit 至少应触发一次自检或向用户确认,而不是静默执行成功。
当 agent 已丢失对文件状态的认知时,应一次性读完整个文件(492 行远在限制之内)重建上下文,而不是用 40 行小窗口反复试探。
实际行为:
经过十余次工具调用,文件的 “Practice Phase” 和 “Programming” 章节被 agent 自己的 Edit 删除,任务没有完成,直到用户介入。
Additional information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the reported C:/Users/keen/.kimi-code/skills/teach-me/SKILL.md reproduction: a long Markdown file with repeated sections and multiple edits. Start by tracing the Edit failure and retry behavior described in the issue. Done means a failed edit causes a fresh read before retrying, destructive zero-addition edits trigger a check or confirmation, and the file is not silently damaged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100