@@ -113,10 +113,10 @@ impl Compactor {
113113 // chains. After compaction, this consistency can break if the first
114114 // remaining assistant lacks reasoning.
115115 //
116- // Solution: Extract the LAST reasoning from compacted messages and inject it
117- // into the first assistant message after compaction. This preserves
118- // chain continuity while preventing exponential accumulation across
119- // multiple compactions.
116+ // Solution: Extract the LAST reasoning from compacted messages and
117+ // inject it into the first assistant message after compaction.
118+ // This preserves chain continuity while preventing exponential
119+ // accumulation across multiple compactions.
120120 //
121121 // Example: [U, A+r, U, A+r, U, A] → compact → [U-summary, A+r, U, A]
122122 // └─from last
@@ -133,8 +133,8 @@ impl Compactor {
133133 _ => None ,
134134 } ) ;
135135
136- // Accumulate usage from all messages in the compaction range before they are
137- // destroyed
136+ // Accumulate usage from all messages in the compaction range before
137+ // they are destroyed
138138 let compacted_usage = context. messages . get ( start..=end) . and_then ( |slice| {
139139 slice
140140 . iter ( )
@@ -143,7 +143,8 @@ impl Compactor {
143143 . reduce ( |a, b| a. accumulate ( & b) )
144144 } ) ;
145145
146- // Replace the range with the summary, transferring the accumulated usage
146+ // Replace the range with the summary, transferring the accumulated
147+ // usage
147148 let mut summary_entry = MessageEntry :: from ( ContextMessage :: user ( summary, None ) ) ;
148149 summary_entry. usage = compacted_usage;
149150 context
@@ -289,7 +290,8 @@ mod tests {
289290
290291 let context = compactor. compress_single_sequence ( context, ( 0 , 2 ) ) . unwrap ( ) ;
291292
292- // Verify reasoning didn't accumulate - should still be just 1 reasoning block
293+ // Verify reasoning didn't accumulate - should still be just 1 reasoning
294+ // block
293295 let first_assistant = context
294296 . messages
295297 . iter ( )
@@ -318,7 +320,8 @@ mod tests {
318320 ..Default :: default ( )
319321 } ] ;
320322
321- // Most recent message in range has empty reasoning, earlier has non-empty
323+ // Most recent message in range has empty reasoning, earlier has
324+ // non-empty
322325 let context = Context :: default ( )
323326 . add_message ( ContextMessage :: user ( "M1" , None ) )
324327 . add_message ( ContextMessage :: assistant (
@@ -647,8 +650,9 @@ mod tests {
647650 "Summary message should carry accumulated usage from compacted messages"
648651 ) ;
649652
650- // accumulate_usage() must sum both the compacted range usage (on the summary
651- // message) and the surviving outside_usage — total = inside + inside2 + outside
653+ // accumulate_usage() must sum both the compacted range usage (on the
654+ // summary message) and the surviving outside_usage — total =
655+ // inside + inside2 + outside
652656 let expected_total_usage = Usage {
653657 total_tokens : TokenCount :: Actual ( 100000 ) ,
654658 prompt_tokens : TokenCount :: Actual ( 90000 ) ,
@@ -855,17 +859,19 @@ mod tests {
855859 // - Safe threshold (89.6K): ~95K tokens, SHOULD compact (true)
856860 //
857861 // At turn 2:
858- // - Unsafe threshold (100K): ~110K tokens, SHOULD compact (true) - but too
859- // late!
862+ // - Unsafe threshold (100K): ~110K tokens, SHOULD compact (true) - but
863+ // too late!
860864 // - Safe threshold (89.6K): ~110K tokens, already compacted at turn 1
861865
862- // Verify that safe threshold triggers at turn 1 (providing early warning)
866+ // Verify that safe threshold triggers at turn 1 (providing early
867+ // warning)
863868 let safe_token_count_turn1 = 95_000 ; // Approximate
864869 let safe_should_compact_turn1 =
865870 safe_compact. should_compact ( & safe_context, safe_token_count_turn1) ;
866871
867- // The key fix: safe threshold (89.6K) triggers at ~95K, while unsafe (100K)
868- // doesn't This provides a safety margin before we hit the 128K limit
872+ // The key fix: safe threshold (89.6K) triggers at ~95K, while unsafe
873+ // (100K) doesn't This provides a safety margin before we hit
874+ // the 128K limit
869875 assert ! (
870876 safe_should_compact_turn1 || safe_token_count_turn1 < 89_600 ,
871877 "Safe threshold (89.6K) should trigger compaction at ~95K tokens to provide safety margin"
@@ -876,8 +882,8 @@ mod tests {
876882 let final_unsafe = unsafe_context. token_count_approx ( ) ;
877883 let final_safe = safe_context. token_count_approx ( ) ;
878884
879- // Both should be identical since we're just testing threshold logic, not actual
880- // compaction
885+ // Both should be identical since we're just testing threshold logic,
886+ // not actual compaction
881887 assert_eq ! (
882888 final_unsafe, final_safe,
883889 "Both contexts should have same token count"
0 commit comments