Adds an `"Agent Compaction Completed"` telemetry event that fires for both threshold-triggered auto-compaction and the manual `/compact` command (both already behind the `handoff` flag). The event records the model, model provider, thinking effort, the model's context window size, the token counts immediately before and after compaction, whether the compaction succeeded/failed/canceled (with the error string on failure), the user's configured auto-compaction threshold (both the raw form and the resolved absolute token count), whether auto-compaction is enabled, and the number of retries. Both compaction paths funnel through `stream_compaction`, so a `CompactionTelemetry` snapshot is captured when a compaction starts and stashed on the thread. On success, emission is deferred until the next completion request reports usage, so `tokens_after` reflects the real post-compaction context size rather than an estimate (we have no token-counting API, and it's safe to assume a compaction is always followed by another request). On failure or cancellation the event fires immediately with no `tokens_after`. Retries are accumulated across attempts so a single logical compaction produces exactly one event. While wiring up retry counting I noticed the existing auto-compaction retry path in `run_turn_internal` never increments `attempt`, so a repeatedly-failing retryable compaction could retry without bound. I left that behavior untouched as out of scope, but the new `retries` field will surface it if it happens. Release Notes: - N/A --------- Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
2 files changedLine totals unavailable