anomalyco / anomalyco/opencode

Auto-compaction infinite loop when assistant ended its turn (finish !== tool-calls)

Open
#15,533 25 comments 12 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
Avg merge
7h 2m
Merged PRs (30d)
384

Description

Bug Description

When auto-compaction triggers after the assistant has naturally ended its turn (e.g., asked a question via the question tool, or simply finished responding with finish === "stop"), SessionCompaction.process() unconditionally injects a synthetic "Continue..." user message, creating an infinite loop.

Steps to Reproduce

  1. Start a long conversation that approaches the context window limit
  2. Have the assistant end its turn naturally (ask a question, or finish responding)
  3. Auto-compaction triggers due to context overflow
  4. Synthetic "Continue if you have next steps..." message is injected
  5. Agent responds to the synthetic continue → context overflows again → compaction → synthetic continue → ...

Expected Behavior

When the assistant had naturally ended its turn (finish === "stop"), the compaction should complete without injecting a synthetic continue message. The session loop should exit and wait for real user input.

The synthetic continue should only be injected when the assistant was in the middle of tool execution (finish === "tool-calls" or "unknown").

Actual Behavior

The synthetic continue is always injected during auto-compaction, regardless of the assistant's state. This causes an unbounded loop:

assistant responds → context overflow → auto-compaction → synthetic "Continue..." →
agent responds → overflow → compaction → synthetic "Continue..." → …

Root Cause

In packages/opencode/src/session/compaction.ts, the process() function (line ~202) checks result === "continue" && input.auto but does not check the assistant's finish reason before injecting the synthetic continue.

Environment

  • OpenCode v1.2.15
  • Observed with oh-my-opencode plugin (Sisyphus/Ultraworker agent)
  • Model: Claude Sonnet 4

Related

  • #10123 — addresses continuous compaction with min_messages threshold (different approach)
  • #12970 — addresses the opposite problem (continue NOT being injected when it should be)
  • #14245 — fixes other compaction bugs in headless mode

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.