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

Open
opened 2026-02-16 17:48:22 -05:00 by yindo · 0 comments
Owner

Originally created by @diegonix on GitHub (Jan 12, 2026).

Originally assigned to: @rekram1-node on GitHub.

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

Originally created by @diegonix on GitHub (Jan 12, 2026). Originally assigned to: @rekram1-node on GitHub. ### 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](https://opencode.ai/docs/config/#compaction) Example default configuration: ```json { "$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 ```json { "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
yindo added the bugdocs labels 2026-02-16 17:48:22 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5071