Skip to content

feat(compact): record checkpoint request usage telemetry - #453

Open
bobzhang wants to merge 1 commit into
mainfrom
agent/compaction-telemetry
Open

feat(compact): record checkpoint request usage telemetry#453
bobzhang wants to merge 1 commit into
mainfrom
agent/compaction-telemetry

Conversation

@bobzhang

Copy link
Copy Markdown
Collaborator

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_summary now returns a CompactionSummary struct: the summary content, the response usage, and the request's wall-clock duration_ms.
  • Both compaction_finished (manual /compact, sessions compact) and auto_compaction_finished (ceiling checkpoints, compact-on-finish) log usage and duration.
  • Wire-compatible: TUI and desktop decoders match on the event key 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

  • New end-to-end test: ceiling turn against the mock server with fabricated cache counters in the checkpoint body; asserts auto_compaction_finished carries the usage fields and a non-negative duration (captured via the existing MemoryLogHandler pattern).
  • moon test: 1045/1049 — the 4 failures are the known-flaky agent_tool/shell output-limit timing tests, failing on clean main in this checkout too.
  • moon check --deny-warn clean; moon fmt + moon info applied.
  • subal (codex) review of the commit: no actionable regressions found.

🤖 Generated with Claude Code

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>
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