Repository navigation
Description
- 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 thecompaction.backgroundsettings. Do not introduce a second summarization implementation. - Respect
compaction.autoandcompaction.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:
- [FEATURE]: plugin hook to write a refused compaction summary on another model #64280 states that native compaction, background precompute, and interrupts never reach the compaction hook.
- Background compaction: hardcoded 64k floor makes it unreachable on smaller context windows #58818 states that only
precompute,auto,buffer, andkeep.tokensare exposed to the config plugin, and that "This can't be done with a plugin today." - [FEATURE]: plugin session step hook for plugin-requested compaction #56744 proposes a plugin step hook that can request a compaction, but it requests an ordinary compaction, not a background precompute.
- [FEATURE]: V2 plugin support for managing context-window transitions #47810 asks for plugin control over context-window transitions; [FEATURE]: Compaction hook can only return a summary string, so a plugin cannot replace the window with messages #50862 asks for richer compaction hook return values.
Alternatives considered
- Rely on
compaction.backgroundalone. The timing is owned by core and cannot be changed by a plugin (Background compaction: hardcoded 64k floor makes it unreachable on smaller context windows #58818). - Move the plugin's warning threshold into core's precompute window. Fragile and version-dependent.
- Generate a summary in the plugin and inject it through the compaction hook's
result. Background precompute does not reach the hook ([FEATURE]: plugin hook to write a refused compaction summary on another model #64280), so this cannot cover the precomputed path.
Related
- [FEATURE]: plugin session step hook for plugin-requested compaction #56744 plugin session step hook for plugin-requested compaction (open)
- [FEATURE]: let a compaction request say it is automatic #63365 let a compaction request say it is automatic (open)
- [FEATURE]: V2 plugin support for managing context-window transitions #47810 V2 plugin support for managing context-window transitions (open)
- [FEATURE]: Compaction hook can only return a summary string, so a plugin cannot replace the window with messages #50862 compaction hook can only return a summary string (open)
- [FEATURE]: plugin hook to write a refused compaction summary on another model #64280 plugin hook to write a refused compaction summary on another model (open)
- Background compaction: hardcoded 64k floor makes it unreachable on smaller context windows #58818 threshold tuning, closed as completed
- [FEATURE]: V2 background summary preparation with validated context swap #55896 background summary preparation, closed as completed
- PRs feat(core): add experimental background compaction summaries #57444, feat(core): rename precompute_compaction to background_compaction and document it #58294, fix(core): start background compaction a fixed lead before the threshold #60049, feat(core): run background compaction by default #64290 shipped the current config-only feature
- PR feat(plugin): expose session compaction #52385 exposed
ctx.session.compactto plugins
Observed on v2.4.0. The config key was not runtime-probed.
Activity
opencodejr commentedon Nov 24, 2026
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 aprepare/backgroundoption onctx.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 callscompact().From the code I read, plugins only get
session.compact, which runs an ordinary compaction. The precompute step already does nothing whencompaction.backgroundorcompaction.autois 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: