Skip to content

feat(core): allow configurable compaction window - #61728

Open
ksmeltzer wants to merge 3 commits into
anomalyco:devfrom
ksmeltzer:compaction-window-cap
Open

ksmeltzer wants to merge 3 commits into
anomalyco:devfrom
ksmeltzer:compaction-window-cap

Conversation

@ksmeltzer

@ksmeltzer ksmeltzer commented Nov 4, 2026 •

Copy link
Copy Markdown

Issue for this PR

Related: #61696, #43703

Type of change

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

What does this PR do?

Adds an optional window (in tokens) to compaction configuration so automatic compaction can plan for a smaller target context window without reducing the model's actual request limit:

  • Top-level: compaction.window in opencode.jsonc sets a default automatic compaction window across models.
  • Per-provider / model / variant: settings.compaction.window overrides the top-level setting for a provider, model, or variant (including setting a larger value to opt back into a large model's full context window when a lower global compaction.window is set).
  • Per-agent: agents.<id>.compaction.window (or compaction.window in Markdown agent frontmatter) overrides the model and global window for that agent's sessions.

autoLimit caps the effective window at the model's actual limit so it never raises a model's window, and leaves the summary request's own budget at the model's limit so single-turn bursts past window still summarize cleanly.

How did you verify your code works?

  • bun --cwd packages/schema test (92 pass) and bun run --cwd packages/schema typecheck:tsc
  • bun --cwd packages/core test test/config/compaction.test.ts test/config/provider.test.ts test/config/agent.test.ts test/session-compaction.test.ts (116 pass) and bun run --cwd packages/core typecheck:tsc
  • bun run --cwd packages/protocol check:generated and bun run --cwd packages/client check:generated
  • Updated services/www/src/docs/content/config.mdx and services/www/src/docs/content/compaction.mdx

Screenshots / recordings

Not a UI change.

Checklist

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

Added by the opencode bot (AI-generated).

Related: #61696, #43703

Public API: adds compaction.window, settings.compaction.window and agents..compaction.window config keys; Provider.Compaction becomes { type?, window? } instead of a tagged union (configs compatible; generated client type changes)

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature works as described. The new tests cover precedence, the cap at the model's limit and config reload, and they pass along with tsc in packages/core and packages/schema. The new config shape decodes on this branch and is rejected on the base. I didn't run a full compaction end to end.

Public API impact:

  • Adds the config key compaction.window (positive integer).
  • Adds window to Provider.Compaction, so settings.compaction.window works on providers, models and variants.
  • Adds agents.<id>.request.settings (the full Config.Provider.Settings).
  • Changes Provider.Compaction from a tagged union {type:"summary"} | {type:"native"} to { type?: "summary" | "native"; window?: number }. This shows up in openapi.json and the generated client type ProviderCompaction.

Existing configs keep working. Clients that narrow on ProviderCompaction as a discriminated union with a required type will need updating, because type can now be missing.

Concerns:

  • The new agents.<id>.request.settings accepts every provider setting, but only compaction.window has any effect (see inline).
  • The untyped compactionWindow key duplicates compaction.window (see inline).
  • The docs aren't updated: services/www/src/docs/content/config.mdx and compaction.mdx cover compaction.* and per-model settings.compaction but not window.
  • #61698 adds the same autoLimit helper for the per-agent case and was opened earlier. Maintainers will want to settle on one approach.

Related: #61696, #43703

Comment thread packages/schema/src/config/provider.ts Resolved
Comment thread packages/core/src/session/compaction.ts Resolved
@ksmeltzer

Copy link
Copy Markdown
Author

Addressed the review feedback in e1d3f81:

  • Scoped per-agent configuration to agents.<id>.compaction.window (Config.Agent.Compaction) and reverted settings on Config.Provider.Request so agents.<id>.request stays { headers, body }.
  • Removed the duplicate untyped compactionWindow fallback in autoLimit.
  • Documented compaction.window, settings.compaction.window, and agents.<id>.compaction.window in services/www/src/docs/content/config.mdx and services/www/src/docs/content/compaction.mdx.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My earlier concerns are addressed:

  • agents.<id>.request is back to { headers, body }, and the window has its own agents.<id>.compaction.window field.
  • The untyped compactionWindow key is gone.
  • The docs now cover window.

I re-ran the 4 related test files in packages/core (116 pass) and the packages/schema tests (92 pass). tsc passes in both packages.

Public API impact:

  • Adds the config key compaction.window.
  • Adds window to Provider.Compaction (settings.compaction.window on providers, models and variants).
  • Adds agents.<id>.compaction.window (Config.Agent.Compaction), also accepted in Markdown agent frontmatter.
  • Provider.Compaction changes from the tagged union {type:"summary"} | {type:"native"} to { type?: "summary" | "native"; window?: number } in the OpenAPI spec and the generated client type ProviderCompaction.

Existing configs keep working. Clients that narrow ProviderCompaction on a required type need updating.

One remaining issue is in the docs example (see inline). Overlap with #61698 still needs a maintainer decision.

Related: #61696, #43703

@ksmeltzer
ksmeltzer force-pushed the compaction-window-cap branch from e1d3f81 to 3705741 Compare November 6, 2026 12:06

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since my last review the branch was rebased onto latest dev (the code is unchanged and the docs moved to services/site), plus one docs commit. That commit fixes my last point: the per-agent example in compaction.mdx now uses agents.build, which is the session's agent that autoLimit reads. On the new head, the 4 related test files in packages/core pass (120 tests), tsc passes in packages/core and packages/schema, and the generated OpenAPI spec and client types are up to date.

The public API impact hasn't changed since my last review:

  • Adds the config keys compaction.window, settings.compaction.window and agents.<id>.compaction.window.
  • Provider.Compaction becomes { type?, window? } instead of a tagged union.

Existing configs keep working. Clients that narrow ProviderCompaction on a required type need updating.

No new concerns. The overlap with #61698 is still for maintainers to decide.

This branch has not been deployed

No deployments
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.

1 participant