Skip to content

compaction.auto: false is ignored when provider throws a context overflow error #16882

Closed

Description

@timwkosatec

Description

Setting compaction: { "auto": false } prevents proactive compaction (the token threshold check), but compaction still runs when the provider returns a hard context overflow error. The auto: false flag is completely ignored in this path.


The catch block for ContextOverflowError in processor.ts bypasses isOverflow() entirely and schedules compaction unconditionally. Once scheduled, the compaction task marker is written into the session message stream and SessionCompaction.process() runs on every subsequent loop iteration regardless of config.
The practical consequence: when a session hits the context limit, stopping and switching to a model with a higher token limit has no effect. The session remains stuck in the compaction task. The only escape is starting a new session entirely or manually changing the session json and removing the error entirely.


Reverting the last message is not an option as the agent would lose track of file edits already made in the session

Plugins

None

OpenCode version

1.2.24

Steps to reproduce

  1. Set compaction: { "auto": false } in opencode.json
  2. Run a session until the provider returns a context overflow error (this triggers the auto compaction task)
    (optional)
  3. Stop the session and switch to a model with a higher context limit
  4. Resume - the session is stuck in the compaction task

Screenshot and/or share link

No response

Operating System

Windows 11 Enterprise

Terminal

Windows Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 10, 2026
  2. MaheshBhushan commented on Mar 10, 2026

    @MaheshBhushan

    this looks like a clear config-consistency bug in the overflow path.

    suggested fix:

    1. in the ContextOverflowError catch path, apply the same compaction.auto gate used by proactive overflow checks (isOverflow() path)
    2. if compaction.auto === false, do not enqueue a compaction task marker; surface a recoverable error instead
    3. on resume / model-switch, clear any stale queued compaction marker when auto compaction is disabled (or when current model context no longer overflows)

    right now the session can get trapped in a compaction loop, and switching to a higher-context model doesn’t recover because the queued task keeps re-running.

    expected behavior: auto:false should consistently mean no automatic compaction, regardless of whether overflow is predicted proactively or returned by provider error.

  3. timwkosatec commented on Mar 10, 2026

    @timwkosatec
    Author

    Found the PR where the auto flag was overlooked:

    packages/opencode/src/session/processor.ts, lines 356-364 in the diff:
    // Before (fell through to error → stop):
    if (MessageV2.ContextOverflowError.isInstance(error)) {
      // TODO: Handle context overflow error
    }
    // After (forces compaction, skips error path):
    if (MessageV2.ContextOverflowError.isInstance(error)) {
      needsCompaction = true          // line 360
      Bus.publish(Session.Event.Error, {
        sessionID: input.sessionID,
        error,
      })
    } else {
    The else on line 365 is the bug — overflow no longer reaches input.assistantMessage.error = error (line 379), so the session never stops.
  4. timwkosatec commented on Mar 10, 2026

    @timwkosatec
    Author

    Proposed Design:

    When auto: false: treat ContextOverflowError as a normal error → set assistantMessage.error → return "stop". No compaction marker is written. Session stops cleanly. User can resume the same session with a bigger model.


    When auto: true (default): keep current behavior — needsCompaction = true → compacts and recovers. PR #14707's fix stays intact for the majority of users.

  5. timwkosatec commented on Mar 18, 2026

    @timwkosatec
    Author

    Opened PR #17936 with a fix for this. The change adds a compaction.auto === false gate to the ContextOverflowError catch block in processor.ts so the session stops cleanly instead of being forced into compaction.

  6. one-pyy commented on Apr 25, 2026

    @one-pyy

    The PR is taking a long time to be merged. Perhaps you could configure the model as follows:

    "limit": {
    "context": 1000000000,
    "input": 1000000000,
    "output": 1000000,
    }
    
  7. assigned and unassigned on Apr 26, 2026
  8. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  9. danielxxomg commented on Jun 5, 2026

    @danielxxomg

    I was looking into the recent compaction-loop reports, and this issue seems like the best place to keep the related context together.

    From tracing the current code and the related PRs, it looks like there are a few separate pieces involved:

    So far, none of these seem to have landed as a complete fix, and they appear to cover different parts of the same failure mode rather than being exact duplicates.

    Would it make sense to consolidate the useful parts into a single PR against the current dev branch? I'd be happy to put one together if that would be useful.

  10. timwkosatec commented on Jun 5, 2026

    @timwkosatec
    Author

    I was looking into the recent compaction-loop reports, and this issue seems like the best place to keep the related context together.

    From tracing the current code and the related PRs, it looks like there are a few separate pieces involved:

    So far, none of these seem to have landed as a complete fix, and they appear to cover different parts of the same failure mode rather than being exact duplicates.

    Would it make sense to consolidate the useful parts into a single PR against the current dev branch? I'd be happy to put one together if that would be useful.

    #30749

    Nexxeln already made yesterday a merge, his merge is related to the problem we had, so this issue can be closed

  11. danielxxomg commented on Jun 5, 2026

    @danielxxomg

    Thanks for clarifying — that makes sense for the specific scope of this issue.

    For the compaction.auto: false path reported here, #30749 does look like the relevant fix.

    I was separating that from the remaining auto-enabled loop case, where auto-compaction is allowed but keeps running because compaction does not reduce tokens enough. That seems better tracked by #28543 / #30680 and the stalled-compaction approach in #29150.

    So for this issue's original auto: false case, #30749 seems to cover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions