Skip to content

[FEATURE]: Expose background compaction to plugins via the plugin SDK #66084

Backlog

Description

@FAZuH
  • I have verified this feature I'm about to request hasn't been suggested before.

What to add

Expose the existing background compaction precompute step on the plugin ctx. For example:

ctx.session.precompute({ sessionID })

Semantics:

  • Start background summary generation for the session without applying it. Non-blocking.
  • Return a status or handle so the plugin can tell whether a summary was prepared or is in flight.
  • Reuse the existing SessionCompaction.precompute() path and the compaction.background settings. Do not introduce a second summarization implementation.
  • Respect compaction.auto and compaction.background. If precompute is disabled, the call is a no-op.

Alternative shape, if a separate method is not wanted: add a background?: boolean or prepare?: boolean option to ctx.session.compact() with the same semantics as above.

Benefits

Background compaction is available through the config key compaction.background (on by default as of PR #64290). Core starts a precompute about 60k tokens before the compaction ceiling, reuses the prompt cache, and holds the summary in memory until compaction swaps it in. This avoids a synchronous summarization at the moment of compaction.

Plugins cannot start this precomputation. The only callable compaction surface is ctx.session.compact({ sessionID, id?, delivery? }), which requests an ordinary compaction and does not start a background precompute. The internal SessionCompaction.precompute() method is not reachable from a plugin.

Concrete use case: a context-window watcher plugin warns at a configurable token or percentage threshold and can call ctx.session.compact(). That threshold is usually earlier than core's precompute window, so there is no held summary to swap in and the call blocks on a fresh summarization. The plugin has no way to say "start preparing a summary now" without applying it.

With the proposed API, a plugin that manages its own context-window threshold can trigger preparation at that threshold instead of waiting for core's fixed lead, then decide when actual compaction happens while still getting the cache-reuse benefit of a precomputed summary. It keeps the plugin in control of timing without duplicating core's compaction logic.

Evidence that this gap is known:

Alternatives considered

Related

Observed on v2.4.0. The config key was not runtime-probed.

Activity

  1. opencodejr commented on Nov 24, 2026

    @opencodejr
    Contributor

    Thanks for the detailed request, @FAZuH!

    To restate it: you'd like plugins to be able to start the existing background compaction precompute early, without applying the summary. That would be a ctx.session.precompute({ sessionID }) call, or a prepare/background option on ctx.session.compact(). A plugin with its own context-window threshold could then prepare a summary in advance, instead of waiting on a fresh summarization when it calls compact().

    From the code I read, plugins only get session.compact, which runs an ordinary compaction. The precompute step already does nothing when compaction.background or compaction.auto is off, so the guard you describe exists. It also only starts once the prompt estimate is within its fixed lead before the compaction ceiling. A plugin-triggered version would need a way past that check, or an early call would do nothing. Because of this gap, a plugin can't do this today.

    Maintainers will consider it. Related issues:

  2. added
    area/plugins
    type/feature
    version/v2
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/pluginstype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions