Skip to content

feat(core): carry compaction usage on the compaction message - #47974

Open
nexxeln wants to merge 2 commits into
v2from
compaction-usage
Open

feat(core): carry compaction usage on the compaction message#47974
nexxeln wants to merge 2 commits into
v2from
compaction-usage

Conversation

@nexxeln

@nexxeln nexxeln commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

  • Feedback on provider compaction: it is hard to tell how many tokens compacting took. The usage was recorded in session totals through the internal session.usage.recorded event, but nothing attached it to the compaction message, and that event never reaches clients.
  • Carry cost/tokens on Compaction.Ended and Compaction.Failed, the same way Step.Ended carries a step's usage for the assistant message, and expose them on the completed and failed compaction messages. Applies to local summaries and provider checkpoints alike. session.usage.recorded is unchanged and remains the accounting source for session totals and stats; the event schema says so where the fields are repeated.
  • TUI divider becomes Provider compaction · 18.2K in · 263 out; session-ui gets the same through a new ui.messagePart.compaction.usage key. The client fold also copies providerContext on compaction.ended, so the "Provider compaction" label now matches a reloaded session instead of appearing only after refetch.

The two numbers are the compaction request's usage, not the resulting context size — that only shows on the next assistant step, and the label comment says so.

Validation

  • session-compaction.test.ts and session-native-compaction.test.ts assert cost/tokens on the completed compaction message for local and provider paths; solid-compaction.test.ts asserts the live client fold including providerContext.
  • Live: an isolated V2 server with provider compaction shows auto tokens.input 18163 / output 263 and manual 2672 (+8704 cached) / 391 on the compaction rows.
  • bun run generate in packages/client; typecheck clean for schema, core, client, tui, session-ui, ui. Tests: core 5,248 passed, client 160, tui 1,344, session-ui 180. (packages/schema contract-hygiene fails on v2 already: Schema.Any in integration.ts since 297a332.)

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