feat(compact): record checkpoint request usage telemetry - #453
Open
bobzhang wants to merge 1 commit into
Open
Conversation
The summary request resends the whole projected history, making it the most expensive single request an agent issues, yet its response usage — including DeepSeek's prompt-cache hit/miss counters — was discarded. generate_compaction_summary now returns the summary content together with the response usage and the request's wall-clock duration, and both compaction_finished and auto_compaction_finished log them, so checkpoint cost is measured instead of guessed. Absent usage still decodes as zeros, and both TUI and desktop decoders ignore unknown fields on known events, so the wire stays compatible. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First slice of the compaction production-hardening plan (R0: measure before changing behavior).
The checkpoint summary request resends the whole projected history, making it the most expensive single request an agent issues — yet its response usage (including DeepSeek's
prompt_cache_hit_tokens/prompt_cache_miss_tokens) and latency were discarded.generate_compaction_summarynow returns aCompactionSummarystruct: the summarycontent, the responseusage, and the request's wall-clockduration_ms.compaction_finished(manual/compact, sessions compact) andauto_compaction_finished(ceiling checkpoints, compact-on-finish) log usage and duration.eventkey and ignore unknown fields; absent usage still decodes as zeros.Why
Grounds the next steps of the plan with data instead of speculation: whether prefix-cache pricing offsets the summarizer's isolated system prompt (a26456b), what checkpoint latency actually costs a pressured turn, and how summary size tracks coverage.
Testing
auto_compaction_finishedcarries the usage fields and a non-negative duration (captured via the existingMemoryLogHandlerpattern).moon test: 1045/1049 — the 4 failures are the known-flakyagent_tool/shelloutput-limit timing tests, failing on clean main in this checkout too.moon check --deny-warnclean;moon fmt+moon infoapplied.🤖 Generated with Claude Code