Skip to content

No type-level distinction between order-sensitive and order-insensitive accumulator merges #604

Description

@milindsrivastava1997

MergeableAccumulator<T>::merge_accumulators(accumulators: Vec<T>) (asap-query-engine/src/data_model/traits.rs) takes a plain, unordered Vec<T>. Every accumulator implemented against it today (Sum, KLL, HLL, CountMinSketch, MinMax, SetAggregator, ...) is commutative/order-insensitive, so this has never mattered.

DeltaSetAggregatorAccumulator breaks that assumption: its correct merge is a chronological fold over added/removed deltas, not a commutative union (see #586). But nothing in the trait signature — or at the call site — distinguishes "this accumulator's merge is order-sensitive" from "this one isn't":

  • The call site that gathers buckets for merging, merge_precomputed_outputs (asap-query-engine/src/engines/simple_engine/mod.rs), discards each bucket's timestamp before invoking merge (timestamped_buckets.iter().map(|(_, bucket)| bucket.clone_boxed_core())), so by the time any accumulator's merge logic runs, order information is already gone regardless of whether that accumulator type needs it.
  • There is no marker, trait bound, or naming convention that would make an order-sensitive accumulator's requirements visible to someone adding a new accumulator type, or to someone touching the merge call path.
  • The bug in DeltaSetAggregator: merge is order-insensitive, store returns buckets out of order, and get_keys() drops all keys on any removal #586 was able to exist (order-insensitive dedup logic, unsorted bucket delivery from the store) without any compiler or interface signal that DeltaSetAggregator's contract differed from its neighbors.

This is a systemic gap, not specific to DeltaSetAggregator: any future accumulator that needs order-sensitive/stateful-over-time merging (e.g. other "delta"-style accumulators, counter-reset-aware rate tracking, etc.) will silently inherit the same class of bug, because the current interfaces give no way to express or enforce "this accumulator's merge must see buckets in chronological order with timestamps intact."

Related: #586 (the concrete DeltaSetAggregator bugs), #588 (DeltaSetAggregator's tumbling-window requirement, a related but separate contract that's also currently unenforced).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions