opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Auto-compaction enabled by default, but context_length_exceeded errors still occur in agent workflows

Open diegonix opened this issue 2 days ago • 1 comments

Description

Auto-compaction enabled by default, but context_length_exceeded errors still occur in agent workflows

Description

According to the opencode documentation, auto-compaction is enabled by default:

https://opencode.ai/docs/config/#compaction

Example default configuration:

{
  "$schema": "https://opencode.ai/config.json",
  "compaction": {
    "auto": true,
    "prune": true
  }
}

However, I am still encountering frequent context_length_exceeded errors during agent execution, which suggests that auto-compaction may not be triggering as expected.

Error message

{
  "type": "error",
  "sequence_number": 2,
  "error": {
    "type": "invalid_request_error",
    "code": "context_length_exceeded",
    "message": "Your input exceeds the context window of this model. Please adjust your input and try again.",
    "param": "input"
  }
}

Expected behavior

With compaction.auto = true and compaction.prune = true, I would expect:

  • Context compaction to occur automatically before the model context window is exceeded.
  • Agent and sub-agent workflows to be protected from context_length_exceeded errors in long-running or multi-step executions.

Environment

  • opencode version: 1.1.14
  • Model: GPT-5.2 (OpenAI)
  • Authentication: OpenAI OAuth via /connect
  • Usage pattern: Build agent invoking multiple custom sub-agents

Questions / Clarification

  • Is auto-compaction currently supported for agent and sub-agent contexts, or only for top-level interactions?
  • Are there known limitations when using multiple agents that could cause compaction not to trigger?
  • Is additional configuration required to ensure compaction works correctly in agent-based workflows?

Any guidance or confirmation of expected behavior would be greatly appreciated. Thanks for the great project!

Plugins

No response

OpenCode version

1.1.4

Steps to reproduce

  • The error appears to occur inside an agent execution, not during a single prompt.
  • I am using the build agent, which in turn invokes multiple custom sub-agents.
  • Over time, the accumulated context across agent/sub-agent interactions seems to exceed the model’s context window.
  • Auto-compaction does not appear to reduce or prune context early enough to prevent this error.

Screenshot and/or share link

No response

Operating System

Ubuntu 24.04

Terminal

Ghostty

diegonix avatar Jan 12 '26 23:01 diegonix