Skip to content

Plan→Compact→Re-Plan infinite loop in Copilot CLI (217 cycles, zero execution) #3158

@Akhi-microsoft

Description

@Akhi-microsoft

👋 Hey Copilot CLI team — filing a high-severity bug. John (Agency team) routed me here from aka.ms/copilotcli/support since I don't have access to the form.

What happened

Coding session in copilot (via agency copilot wrapper). At ~75% context, the agent compacted, re-read the summary, and resumed PLANNING instead of executing. Repeated 217 times before I killed it. Zero file edits. Hours of compute and quota gone.

Root cause (hypothesis)

Compaction preserves the plan as the most salient signal post-compact. The agent treats "we have a plan" as a fresh prompt to plan against, instead of as decided work to execute. Structural, not prompt-specific.

Repro

  1. copilot (or agency copilot)
  2. Moderately complex prompt (feature across files A/B/C with tests)
  3. No AGENTS.md guardrails
  4. Let session run past auto-compact threshold
  5. Post-compact: agent plans again instead of editing files. Loops.

Appears deterministic.

Impact

  • Hundreds of model calls, zero output
  • Full session lost, manual recovery required
  • Undermines trust in long-running autonomous tasks
  • Likely under-reported (users blame themselves before the tool)

Proposed fixes (priority order)

  1. Compaction summarizer: label plans as "DECIDED — do not re-plan"
  2. Default post-compact rule: "Resume from next file edit, do not re-validate the plan" (ref: https://github.com/Dicklesworthstone/post_compact_reminder)
  3. Add --mode execute session flag biased against planning preambles
  4. Loop detector: N consecutive turns with zero file edits → halt (default N=3)
  5. Better /compact defaults: drop planning history
  6. Telemetry signal for "planning loop suspected"

Workarounds I'm using

AGENTS.md "no re-plan after compact" rule + post-compact reminder hook + manual /compact at ~60% + HANDOFF.md as ground-truth state file. These work but shouldn't be required of every user.

Environment

  • Copilot CLI: 1.0.41
  • Node: v22.22.2
  • OS: Windows

Happy to share session logs and join a triage call.

— Akhi Shukla, Senior PM, IC3 / UED, Prague

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agentsarea:context-memoryContext window, memory, compaction, checkpoints, and instruction loading

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions