From 59dd7955aa7f8cf50faf0e0eb2f46da3d22e394b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?m=C3=BCde?= Date: Sun, 5 Jul 2026 22:53:16 +0200 Subject: [PATCH] fix(stats): last_usage orders by id (insertion order); clarify Window default --- hive-ag3nt/src/stats.rs | 1 + hive-ag3nt/src/turn_stats.rs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hive-ag3nt/src/stats.rs b/hive-ag3nt/src/stats.rs index cad8fce5..eb3f6152 100644 --- a/hive-ag3nt/src/stats.rs +++ b/hive-ag3nt/src/stats.rs @@ -42,6 +42,7 @@ impl Window { "7d" => Self::Week, "30d" => Self::Month, "all" => Self::All, + // Default (incl. `label()`'s own canonical `"24h"`/`"1d"`). _ => Self::Day, } } diff --git a/hive-ag3nt/src/turn_stats.rs b/hive-ag3nt/src/turn_stats.rs index 31682712..0734d581 100644 --- a/hive-ag3nt/src/turn_stats.rs +++ b/hive-ag3nt/src/turn_stats.rs @@ -289,7 +289,10 @@ impl TurnStats { last_input_tokens, last_output_tokens, last_cache_read_input_tokens, last_cache_creation_input_tokens FROM turn_stats - ORDER BY started_at DESC + -- `id` (AUTOINCREMENT) is monotonic with insertion, so this is + -- the most-recently-inserted row even among same-second turns + -- (which `started_at DESC` would order arbitrarily). + ORDER BY id DESC LIMIT 1", [], |row| {