tursodatabase/turso · critical

Cannot eval AggregateOperator with Uninitialized state

Error message

Cannot eval AggregateOperator with Uninitialized state

What it means

AggregateOperator.eval is a state machine that must be driven from Initialized/Ready states; reaching eval with EvalState::Uninitialized means the caller skipped the initialization step of the incremental (DBSP-style) evaluation. This is an internal invariant panic in the Turso engine, not an error a SQL user should normally see.

Source

Thrown at core/incremental/aggregate_operator.rs:1458

    }

    pub fn has_min_max(&self) -> bool {
        !self.column_min_max.is_empty()
    }

    /// Check if this operator has any DISTINCT aggregates or plain DISTINCT
    pub fn has_distinct(&self) -> bool {
        !self.distinct_columns.is_empty() || self.is_distinct_only
    }

    fn eval_internal(
        &mut self,
        state: &mut EvalState,
        cursors: &mut DbspStateCursors,
    ) -> IOResultOr<(Delta, ComputedStates)> {
        match state {
            EvalState::Uninitialized => {
                panic!("Cannot eval AggregateOperator with Uninitialized state");
            }
            EvalState::Init { deltas } => {
                // Aggregate operators only use left_delta, right_delta must be empty
                assert!(
                    deltas.right.is_empty(),
                    "AggregateOperator expects right_delta to be empty"
                );

                if deltas.left.changes.is_empty() {
                    *state = EvalState::Done;
                    return Ok(IOResult::Done((Delta::new(), HashMap::default())));
                }

                let mut groups_to_read = BTreeMap::new();
                for (row, _weight) in &deltas.left.changes {
                    let group_key = self.extract_group_key(&row.values);
                    let group_key_str = Self::group_key_to_string(&group_key);
                    groups_to_read.insert(group_key_str, group_key);

View on GitHub (pinned to 6c72522679)

Solutions

  1. File a bug with the query that triggered it; this is an internal engine invariant violation.
  2. Upgrade to a newer Turso build where the incremental aggregation state machine may be fixed.
  3. As a workaround, disable incremental view maintenance / use a regular query plan instead of the incremental operator.
  4. If developing the engine, ensure the driver always transitions EvalState from Uninitialized via the Init path before calling eval.
Defensive patterns

Strategy: fallback

Try / catch

// Rust: this is a panic, not a catchable error; guard at process/test boundary
let result = std::panic::catch_unwind(|| run_incremental_query(query));
match result {
    Ok(v) => v,
    Err(_) => run_regular_query(query), // fallback to non-incremental plan
}

Prevention

When it happens

Trigger: A bug in the incremental query engine's evaluation driver: eval is called on an AggregateOperator whose EvalState was never initialized (e.g. Init step skipped after a cursor/IO interruption path).

Common situations: Engine development or fuzzing of incremental view maintenance; running an experimental incremental build where an aggregate over a delta path hits an untested state transition.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-09-06). Data as JSON: /api/errors/c0a3d116ba02421c. Report an issue: GitHub.