github / github/copilot-cli

Copilot CLI loops infinitely and fails apply_patch due to JSON-wrapping error

未关闭
#4,553 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area:models area:tools
主要语言
Shell
星标
11.2k
派生
1.9k
平均合并
14 小时 16 分钟
30 天内合并 PR
6

描述

Describe the bug

While executing regular coding tasks that require file modifications, the Copilot CLI frequently fails to apply patches. The CLI enters a loop where it attempts to edit a file, fails with a JSON-wrapping error, and retries the exact same payload repeatedly.

This causes a task that should take 2 steps to take 30+ steps, resulting in massive latency, tool frustration, and high token consumption before it either randomly recovers or fails entirely. Many models are failing to adapt to apply_patch. I havent seen issue with sonnet 4.6 and gpt-sol but other models like sonnet 5, luna, terra are failing most of the times.

Error Message / Trace
When the CLI attempts to apply an edit, it outputs the following error:

✗ Edit 
 └ Failed to parse patch: The first line of the patch must be '*** Begin Patch' 
   The input begins with '{' and appears to be JSON-wrapped. apply_patch is a 
   freeform tool; pass raw patch text directly. Do not retry this payload.

Behavior Details
Infinite Loop: Once this error is triggered, the model consistently retries the same payload 10 to 30+ times in a row despite the warning "Do not retry this payload".

Temporary Recovery: Eventually, the model might format the tool call correctly by accident, but the error quickly resurfaces on subsequent edits.

CLI vs. VS Code: This behavior is highly localized to the CLI. Using the same prompts and models in the VS Code Copilot Chat interface works perfectly without any patch-parsing issues.

Affected version

GitHub Copilot CLI 1.0.80

Steps to reproduce the behavior

This is intermittent but seen in most of medium complexity prompts.

  • Open Terminal ( I did on iterm)
  • start interactive session (copilot) - i did not append any flag options ( i opened a session on TMUX)
  • Trigger a medium complexity prompt which would need to change your sourcecode files.
  • It should trigger the error - It generally happens mid sessions not in the first prompt itself. but yea this is intermittent behaviour
Expected behavior

No response

Additional context
  • OS: Ubuntu server
    Tool: Github Copilot CLI (Latest Version)
    Comparison: Not observed in VS Code Copilot Chat (works successfully there)
    LLM Models tried : Both GPT-5.6-Luna and Claude-sonnet-5

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

未指定源文件或测试。首先在 Ubuntu 上的 Copilot CLI 1.0.80 中,使用会编辑文件的中等难度编码提示词和交互式会话重现该问题,然后将 CLI 的行为与 VS Code Copilot Chat 进行比较。当 apply_patch 接受工具载荷且 CLI 不再重试同一个失败的请求时,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
shell
领域
cli, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。