Skip to content

[FEATURE]: Implement V2 manual compaction #40614

Description

@MagnumGoYB

Feature hasn't been suggested before.

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

Describe the enhancement you want to request

SessionV2.compact is a stub that fails with OperationUnavailableError (packages/core/src/session.ts), which the server maps to a 503. So on V2 there is no manual compaction: /compact only appears to work in the app because the compat shim rewrites it to the legacy V1 session.summarize.

V2 already has automatic compaction (request-budget) and overflow-triggered compaction. What's missing is the explicit, user-initiated path.

This is already recorded as a follow-up in specs/v2/session.md:

Add explicit manual compaction on top of automatic request-budget compaction.

and in specs/v2/schema-changelog.md:

Defer provider-overflow recovery, explicit manual compaction, and deterministic old tool-result pruning.

Overflow recovery has since landed; manual compaction has not.

Notes on what makes it distinct from the automatic path:

  • It should not be a provider turn — no inbox promotion, no tool materialization, no assistant reply.
  • The two budget conditions shouldn't apply, since the request is explicit rather than a response to context pressure. In particular, automatic compaction declines when a model declares no limits.context, which would make /compact silently do nothing on such models.
  • Automatic compaction retains compaction.keep.tokens of verbatim recent context because it only needs to free enough budget to continue. An explicit request should compress the whole active history.
  • It needs to be serialized against that session's provider turns without joining an active drain or coalescing with another request.

No schema change is needed: SessionEvent.Compaction.{Started,Ended} and SessionMessage.Compaction already declare reason: "auto" | "manual", and "manual" currently has no producer outside tests.

Activity

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