@@ -79,11 +79,13 @@ pub(super) struct AllAccumulator {
7979
8080impl AllAccumulator {
8181 pub ( super ) fn add ( & mut self , row : AllRow ) {
82- self . input_tokens += row. input_tokens ;
83- self . output_tokens += row. output_tokens ;
84- self . cache_creation_tokens += row. cache_creation_tokens ;
85- self . cache_read_tokens += row. cache_read_tokens ;
86- self . total_tokens += row. total_tokens ;
82+ self . input_tokens = self . input_tokens . saturating_add ( row. input_tokens ) ;
83+ self . output_tokens = self . output_tokens . saturating_add ( row. output_tokens ) ;
84+ self . cache_creation_tokens = self
85+ . cache_creation_tokens
86+ . saturating_add ( row. cache_creation_tokens ) ;
87+ self . cache_read_tokens = self . cache_read_tokens . saturating_add ( row. cache_read_tokens ) ;
88+ self . total_tokens = self . total_tokens . saturating_add ( row. total_tokens ) ;
8789 self . total_cost += row. total_cost ;
8890 self . models . extend ( row. models_used . iter ( ) . cloned ( ) ) ;
8991 if let Some ( agents) = row. metadata_agents . as_ref ( ) {
@@ -132,11 +134,15 @@ impl AllAccumulator {
132134}
133135
134136fn merge_agent_breakdown ( target : & mut AllRow , source : AllRow ) {
135- target. input_tokens += source. input_tokens ;
136- target. output_tokens += source. output_tokens ;
137- target. cache_creation_tokens += source. cache_creation_tokens ;
138- target. cache_read_tokens += source. cache_read_tokens ;
139- target. total_tokens += source. total_tokens ;
137+ target. input_tokens = target. input_tokens . saturating_add ( source. input_tokens ) ;
138+ target. output_tokens = target. output_tokens . saturating_add ( source. output_tokens ) ;
139+ target. cache_creation_tokens = target
140+ . cache_creation_tokens
141+ . saturating_add ( source. cache_creation_tokens ) ;
142+ target. cache_read_tokens = target
143+ . cache_read_tokens
144+ . saturating_add ( source. cache_read_tokens ) ;
145+ target. total_tokens = target. total_tokens . saturating_add ( source. total_tokens ) ;
140146 target. total_cost += source. total_cost ;
141147 let mut models: BTreeSet < String > = target. models_used . drain ( ..) . collect ( ) ;
142148 models. extend ( source. models_used ) ;
@@ -209,7 +215,7 @@ fn add_json_number(target: &mut Map<String, Value>, source: &Map<String, Value>,
209215 return ;
210216 } ;
211217 let value = match ( target_value. as_u64 ( ) , source_value. as_u64 ( ) ) {
212- ( Some ( target) , Some ( source) ) => json ! ( target + source) ,
218+ ( Some ( target) , Some ( source) ) => json ! ( target. saturating_add ( source) ) ,
213219 _ => {
214220 json_float ( target_value. as_f64 ( ) . unwrap_or ( 0.0 ) + source_value. as_f64 ( ) . unwrap_or ( 0.0 ) )
215221 }
@@ -301,11 +307,13 @@ fn merge_model_breakdowns(
301307 i
302308 } ) ;
303309 let b = & mut breakdowns[ index] ;
304- b. input_tokens += item. input_tokens ;
305- b. output_tokens += item. output_tokens ;
306- b. cache_creation_tokens += item. cache_creation_tokens ;
307- b. cache_read_tokens += item. cache_read_tokens ;
308- b. extra_total_tokens += item. extra_total_tokens ;
310+ b. input_tokens = b. input_tokens . saturating_add ( item. input_tokens ) ;
311+ b. output_tokens = b. output_tokens . saturating_add ( item. output_tokens ) ;
312+ b. cache_creation_tokens = b
313+ . cache_creation_tokens
314+ . saturating_add ( item. cache_creation_tokens ) ;
315+ b. cache_read_tokens = b. cache_read_tokens . saturating_add ( item. cache_read_tokens ) ;
316+ b. extra_total_tokens = b. extra_total_tokens . saturating_add ( item. extra_total_tokens ) ;
309317 b. cost += item. cost ;
310318 b. missing_pricing |= item. missing_pricing ;
311319 }
@@ -327,11 +335,13 @@ fn aggregate_model_breakdowns(rows: &[AllRow]) -> Vec<ModelBreakdown> {
327335 i
328336 } ) ;
329337 let b = & mut breakdowns[ index] ;
330- b. input_tokens += item. input_tokens ;
331- b. output_tokens += item. output_tokens ;
332- b. cache_creation_tokens += item. cache_creation_tokens ;
333- b. cache_read_tokens += item. cache_read_tokens ;
334- b. extra_total_tokens += item. extra_total_tokens ;
338+ b. input_tokens = b. input_tokens . saturating_add ( item. input_tokens ) ;
339+ b. output_tokens = b. output_tokens . saturating_add ( item. output_tokens ) ;
340+ b. cache_creation_tokens = b
341+ . cache_creation_tokens
342+ . saturating_add ( item. cache_creation_tokens ) ;
343+ b. cache_read_tokens = b. cache_read_tokens . saturating_add ( item. cache_read_tokens ) ;
344+ b. extra_total_tokens = b. extra_total_tokens . saturating_add ( item. extra_total_tokens ) ;
335345 b. cost += item. cost ;
336346 b. missing_pricing |= item. missing_pricing ;
337347 }
0 commit comments