feat(memory): track trajectory elongation from hard compaction (#1739)#1787
Merged
feat(memory): track trajectory elongation from hard compaction (#1739)#1787
Conversation
Add compaction_hard_count and turns_after_hard_compaction metrics to MetricsSnapshot. Increment hard compaction counter and record per-segment turn counts at each hard compaction event. Log both at agent shutdown via tracing::info! for session-level trajectory analysis. Turn counter is incremented before all early-return guards in maybe_compact so proactive compression and exhaustion paths are counted accurately.
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
compaction_hard_count: u64andturns_after_hard_compaction: Vec<u64>toMetricsSnapshotCompactionTier::Hardevent inmaybe_compact()compacted_this_turn) so no turns are silently droppedshutdown()and both fields are logged viatracing::info!when at least one hard compaction occurredMotivation
JetBrains Research (Dec 2025) found LLM summarization causes agents to run 13-15% longer on average. This change adds the instrumentation needed to detect and measure trajectory elongation in real Zeph sessions via
.local/testing/debug/session.log.Test plan
cargo +nightly fmt --check— passcargo clippy --workspace --features full -- -D warnings— passcargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins— 5581 passed, 12 skippedcompaction_hard_count_zero_by_default,compaction_hard_count_increments_on_hard_tier,compaction_turns_after_hard_tracks_segments,compaction_turn_counter_increments_before_exhaustion_guard