atuinsh/atuin · error

issue in stats duration over time query

Error message

issue in stats duration over time query

What it means

The last stats expect() panic (database.rs:959), rendering duration_over_time — the per-month average-duration query that uses SQLite strftime/ROUND(timestamp / 1000000000) to bucket by month and a HAVING duration > 0. The comment above it explains the bucketing exists because SQLite lacks a datetime type and string-sorting months would be wrong. As with all seven, the expect is an internal regression guard on a fixed query shape.

Source

Thrown at crates/atuin-client/src/database.rs:959

        let mut duration_over_time = SqlBuilder::select_from("history");
        duration_over_time
            .fields(&[
                "strftime('01-%m-%Y', ROUND(timestamp / 1000000000), 'unixepoch') AS month_year",
                "avg(duration) as duration",
            ])
            .and_where("command = ?1")
            .group_by("month_year")
            .having("duration > 0");

        let prev = prev.sql().expect("issue in stats previous query");
        let next = next.sql().expect("issue in stats next query");
        let total = total.sql().expect("issue in stats average query");
        let average = average.sql().expect("issue in stats previous query");
        let exits = exits.sql().expect("issue in stats exits query");
        let day_of_week = day_of_week.sql().expect("issue in stats day of week query");
        let duration_over_time = duration_over_time
            .sql()
            .expect("issue in stats duration over time query");

        // The queries are all independent, so run them concurrently on the pool.
        let (prev, next, total, average, exits, day_of_week, duration_over_time): (
            _,
            _,
            (i64,),
            (f64,),
            Vec<(i64, i64)>,
            Vec<(String, i64)>,
            Vec<(String, f64)>,
        ) = tokio::try_join!(
            sqlx::query(sqlx::AssertSqlSafe(prev))
                .bind(h.timestamp.unix_timestamp_nanos() as i64)
                .bind(&h.session)
                .map(Self::query_history)
                .fetch_optional(&self.pool),
            sqlx::query(sqlx::AssertSqlSafe(next))
                .bind(h.timestamp.unix_timestamp_nanos() as i64)

View on GitHub (pinned to 202f6ad98e)

Solutions

  1. Update Atuin and report the panic upstream
  2. Developers: verify the strftime format string and group_by alias stay consistent when editing
  3. Add a unit test asserting the rendered SQL contains the month_year grouping
  4. Smoke-test `atuin stats` after any change in this block
Defensive patterns

Strategy: validation

Try / catch

let handle = std::thread::spawn(move || db.stats());
if handle.join().is_err() { /* duration-over-time builder panic: report upstream */ }

Prevention

When it happens

Trigger: Running `atuin stats` on a build where the duration_over_time builder was broken; the strftime expression and group_by/having clauses are the likely regression points.

Common situations: Development regressions around the duration-over-time feature (e.g. changing the timestamp division or month format string); not reachable via data.

Related errors


AI-assisted analysis of atuinsh/atuin@202f6ad98e (2026-08-16). Data as JSON: /api/errors/bc9b6d7fe0198ecf. Report an issue: GitHub.