Skip to content

feat(agent-core): record context length before and after micro compaction#845

Closed
7Sageer wants to merge 3 commits into
MoonshotAI:mainfrom
7Sageer:feat/compaction-context-length-telemetry
Closed

feat(agent-core): record context length before and after micro compaction#845
7Sageer wants to merge 3 commits into
MoonshotAI:mainfrom
7Sageer:feat/compaction-context-length-telemetry

Conversation

@7Sageer

@7Sageer 7Sageer commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No related issue.

Problem

Full compaction already reports the estimated context length before and after compaction via the tokensBefore / tokensAfter fields on the compaction_finished telemetry event. Micro compaction only reported the token counts of the individual tool results it trimmed (beforeTokens / afterTokens), so there was no way to observe how the whole context length changed across a micro compaction, nor to compare the two compaction paths on the same axis.

What changed

Added two fields to the micro_compaction_applied telemetry event, mirroring tokensBefore / tokensAfter on compaction_finished:

  • contextTokensBefore: estimated token count of the whole context (history) before trimming.
  • contextTokensAfter: estimated token count of the whole context after trimming.

The existing beforeTokens / afterTokens fields are kept unchanged for backwards compatibility. Full and micro compaction can now be compared on the same axis. The existing micro compaction telemetry test now asserts the new fields.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 608a811

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@608a811
npx https://pkg.pr.new/@moonshot-ai/kimi-code@608a811

commit: 608a811

@7Sageer 7Sageer closed this Jun 17, 2026
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