anomalyco / anomalyco/opencode

DeepSeek compaction can get stuck replaying reasoning/tool history instead of producing a summary

Open
#42,363 1 comment 1 reaction 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 13, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Description

Automatic compaction can become stuck when using a DeepSeek reasoning model through an OpenAI-compatible provider.

I reproduced this twice.

Instead of producing a compaction summary, the model starts continuing patterns from the conversation history inside its reasoning, including sequences that look like prior tool calls and tool results. The compaction request never successfully completes, no summary is stored, and the session becomes effectively unusable.

Environment

  • OpenCode: 1.18.15
  • Model: DeepSeek V4 Flash
  • Provider: @ai-sdk/openai-compatible
  • Context limit: 262144
  • Output limit: 65536
  • macOS

Verified:

Inspected:

  • OpenCode's SQLite session database
  • OpenCode logs
  • the installed OpenCode binary
  • the serialized session history
  • the inference backend logs

For one reproduced session, the sequence was:

  • A normal assistant request completed successfully with reason=tool-calls
  • OpenCode created a compaction marker:
    {"type":"compaction","auto":true,"overflow":false}
  • An assistant message with agent=compaction was started
  • The compaction request ran for several minutes and was eventually aborted
  • The compaction assistant message contained a large reasoning part
  • No completed summary was produced
  • No normal post-compaction message was created

The failure therefore occurs during the compaction request itself, not after a successful compaction.

Relevant behavior

The history rendered into the compaction prompt includes hidden assistant reasoning and tool interaction history, for example:

[Assistant reasoning]: ...

[Assistant tool call]: ...

[Tool result]: ...

During the failed compaction, the model began generating similar structures inside its own reasoning instead of producing the requested summary.

For example, it repeatedly generated content resembling:

[Assistant tool call]: bash(...)

followed by synthetic-looking tool-result text such as:

The user wants to continue the investigation...

These were not real tool executions.

The synthetic text was not present in the stored tool results and was not found as a hardcoded OpenCode template. It was generated by the model while processing the compaction prompt.

The same general failure mode occurred in a second independent session.

Expected behavior

The compaction agent should summarize the visible conversation history and return a completed summary.

Hidden reasoning from previous assistant turns should not be necessary for summarization, and should not cause the compaction model to continue prior agent/tool behavior.

ikely cause

The compaction history renderer includes hidden assistant reasoning when constructing the summarization prompt.

For reasoning models such as DeepSeek, replaying this hidden reasoning and tool-oriented history appears capable of causing the model to continue the prior reasoning/tool pattern rather than follow the summarization instruction.

This is closely related to #31188, although the failure mode is different.

In #31188, replayed reasoning causes Anthropic extended-thinking requests to fail because reasoning metadata/signatures are no longer valid.

In this case, the request is accepted, but the DeepSeek model begins continuing the injected reasoning/tool history and never produces the compaction summary.

Both cases suggest that hidden reasoning should not be included in compaction input.

Possible fix

A likely fix is to exclude assistant reasoning parts when constructing the history sent to the compaction agent.

This is similar to the stripReasoning approach proposed in #31188.

Tool history may also need to be rendered so that the compaction prompt cannot resemble an unfinished assistant/tool continuation.

I have not modified OpenCode, so I cannot yet confirm which exact change is sufficient.

Related issues

  • #31188 - Related underlying issue: assistant reasoning is replayed into compaction input. Different failure mode.
  • #22329 - Similar DeepSeek/compaction loop behavior, but the observed mechanism appears different.

Workaround

Disabling automatic compaction avoids this failure:

"compaction": {
  "auto": false,
  "prune": false
}

This is only a workaround, since automatic compaction is then unavailable for long-running sessions.

Plugins

None

OpenCode version

1.18.15

Steps to reproduce

No response

Screenshot and/or share link
  1. Configure OpenCode with a DeepSeek reasoning model through an OpenAI-compatible provider.

Example relevant config:

"provider": {
"ds4": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "http://127.0.0.1:8000/v1"
},
"models": {
"deepseek-v4-flash": {
"limit": {
"context": 262144,
"output": 65536
}
}
}
}
},

"model": "ds4/deepseek-v4-flash",

"compaction": {
"auto": true,
"prune": false,
"reserved": 16000
}

  1. Start a long-running agent session that contains multiple reasoning turns and tool calls.

  2. Continue until OpenCode triggers automatic compaction.

  3. Observe the compaction request.

  4. In the reproduced failures, instead of producing a summary, the DeepSeek model starts continuing patterns from the injected conversation history inside its reasoning, including text resembling:
    [Assistant tool call]: ...
    [Tool result]: ...

  5. The compaction request does not successfully produce a summary and the session becomes unusable.

This has been reproduced in two independent sessions.

Inspection of OpenCode's stored session data showed that the failure occurs inside the compaction request itself. The compaction history includes previous hidden assistant reasoning and tool-call history. During the failed compaction, the model begins continuing those patterns instead of following the summarization instruction.

Operating System

MacOs 26.6.1

Terminal

Terminal.app on macOS

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.