github / github/copilot-cli

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

Aperta
#4,553 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

area:models area:tools
Lingua principale
Shell
Stelle
11.2k
Fork
1.9k
Merge medio
14h 16m
PR unite (30g)
6

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Non sono indicati file sorgente né test. Inizia riproducendo il problema in Copilot CLI 1.0.80 su Ubuntu, usando una sessione interattiva e un prompt di programmazione di media complessità che modifichi i file, quindi confronta il comportamento della CLI con VS Code Copilot Chat. Il lavoro è completato quando apply_patch accetta il payload dello strumento e la CLI smette di ritentare la stessa richiesta fallita.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
shell
Ambito
cli, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Da chiarire
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.