github / github/copilot-cli

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

Ouverte
#4,553 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

area:models area:tools
Langage dominant
Shell
Étoiles
11.2k
Forks
1.9k
Merge moyen
14 h 16 min
PR mergées (30 j)
6

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Aucun fichier source ni test n’est nommé. Commencez par reproduire le problème dans Copilot CLI 1.0.80 sur Ubuntu, en utilisant une session interactive et un prompt de programmation de niveau moyen qui modifie des fichiers, puis comparez le comportement de la CLI avec VS Code Copilot Chat. C’est terminé lorsque apply_patch accepte la charge utile de l’outil et que la CLI cesse de réessayer la même requête ayant échoué.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
shell
Domaine
cli, tooling
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Active
Clarté
À clarifier
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.