Skip to main content

aggregate

Function aggregate 

Source
pub fn aggregate(members: &[SessionStats]) -> SessionStats
Expand description

Sum per-session views into a total (the /usage total row).

Contract:

  • turns, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, cache_turns, tool_errors: plain sums.
  • tools: merged BY NAME — calls/errors/result_bytes summed per name — then re-sorted calls desc, name asc, so the total reads like a single session.
  • cost: Some(Cost { micro_usd: Σ, unpriced_turns: Σ }) when AT LEAST ONE member has Some; None when none does. A member with cost: None contributes nothing — its sessions are unknown, not “0 unpriced turns”.
  • last_input_tokens: always None. A total has no “last request”; the context gauge is a per-surface fact and must never be summed.
  • empty slice ⇒ SessionStats::default().

Does NOT promise: deduplication. Two members that share a transcript (a peer and its mirror) are counted twice — a caller passes each session once.