MoonshotAI / MoonshotAI/kimi-code
Agent in long sessions emits invalid Edit/Write tool calls due to context degradation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
Problem
After a long session, the agent can get stuck in a loop where it repeatedly calls
d it can no longer reconstruct the exact
d context. It also loses the precise text block it wants to replace.
This often happens when the agent is trying to update a small file like
.agents/MEMORY.md` after a long task. The failure cascade looks like:
- Agent reads the file successfully.
- It makes an Edit with an empty or malformed
d fails.
3. It retries multiple times, each time emitting another invalid Edit/Write call.
4. The runtime eventually interrupts the agent.
Impact
- Long-running sessions cannot reliably finish small edits.
- The user has to manually restart the session.
- The file can be left in a partially modified state (e.g., a missing markdown heading).
Suggested improvements
- Before every Edit, re-read the target file if the previous Edit failed.
- For small files or prepend operations, prefer Write with a full replacement instead of Edit.
- Consider a context-management safeguard that detects repeated invalid tool calls and forces a file re-read or session restart.
Environment
- kimi-code CLI built from main
- Agent working on
.agents/MEMORY.md` - Session interrupted after repeated Edit/Write failures
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
The report identifies the kimi-code CLI and .agents/MEMORY.md, but names no implementation file, entry point, or test. Start by reproducing a long-session failure involving Edit or Write, then trace the runtime handling of repeated invalid tool calls. Done means the recovery behavior is defined and verified for the reported failure cascade.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100