Skip to content

fix(core): honor compaction.auto on provider overflow#17936

Open
timwkosatec wants to merge 2 commits intoanomalyco:devfrom
timwkosatec:fix/compaction-auto-overflow
Open

fix(core): honor compaction.auto on provider overflow#17936
timwkosatec wants to merge 2 commits intoanomalyco:devfrom
timwkosatec:fix/compaction-auto-overflow

Conversation

@timwkosatec
Copy link
Copy Markdown

@timwkosatec timwkosatec commented Mar 17, 2026

Issue for this PR

Closes #16882

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

PR #14707 added auto-compaction recovery for 413/context overflow errors, but the ContextOverflowError catch block in processor.ts unconditionally sets needsCompaction = true without checking the compaction.auto config. Users who set compaction: { "auto": false } still get forced into a compaction loop on overflow, and switching to a model with a larger context window doesn't recover the session.

This adds a config.compaction?.auto === false gate to the overflow catch path:

  • auto: false — treats the overflow as a normal error: persists it on the assistant message, publishes the error event, sets the session to idle, and returns "stop". The user can then resume with a different model.
  • auto: true / undefined (default) — keeps the existing behavior from fix: recover from 413 Request Entity Too Large via auto-compaction #14707 (needsCompaction = true → compact and recover).

The strict === false check means the default (undefined) still compacts, so this is backward-compatible. Manual compaction (/compact) remains available regardless of the auto setting.

How did you verify your code works?

Added two tests in compaction.test.ts:

  1. stops on provider overflow when compaction.auto is false — verifies result is "stop", error is persisted as ContextOverflowError, no compaction parts written.
  2. compacts on provider overflow when compaction.auto is true — verifies result is "compact", no error on assistant message.

Run with:

cd packages/opencode && bun test test/session/compaction.test.ts
cd packages/opencode && bun typecheck

Also verified no regressions in:

  • bun test test/session/retry.test.ts (18 pass)
  • bun test test/session/message-v2.test.ts -t "fromError" (6 pass)

Screenshots / recordings

N/A — no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@timwkosatec
Copy link
Copy Markdown
Author

The failing e2e checks look unrelated to this fix.
Both e2e (linux) and e2e (windows) fail with:
OPENCODE_API_KEY is required when OPENCODE_E2E_REQUIRE_PAID=true


This PR comes from a fork, so it looks like the paid-model e2e workflow cannot access that secret here. The code-related checks are green.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant