Skip to content

fix(precompute): factory routes CountSketch[WithHeap] to CmsAccumulator - #261

Merged
zzylol merged 1 commit into
mainfrom
accumulator-factory-countsketch-withheap
May 16, 2026
Merged

zzylol merged 1 commit into
mainfrom
accumulator-factory-countsketch-withheap

Conversation

@zzylol

@zzylol zzylol commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes a silent correctness bug surfaced by the audit in PR #259's follow-up. The precompute accumulator factory was falling through to the catch-all tracing::warn! + SumAccumulatorUpdater default for both AggregationType::CountSketch and AggregationType::CountSketchWithHeap. Any raw-input ingest path hitting one of those policies would produce a Sum accumulator instead of a frequency sketch.

What changed

  • New factory arm: CountSketch | CountSketchWithHeap routes to CmsAccumulatorUpdater (parallel to the existing CountMinSketch | CountMinSketchWithHeap arm). Both families share the (rows, cols) matrix shape, so the same updater works as a correctness floor.
  • config_is_keyed lists the four CountSketch / CMS variants now (was missing CountMinSketchWithHeap, CountSketch, CountSketchWithHeap).
  • Test: test_config_is_keyed covers all four arms.

Limitation (called out in code comment)

This drops the per-policy top-k heap — same limitation as the existing CountMinSketchWithHeap arm. The dedicated heap-bearing updaters (CountSketchAccumulatorUpdater, CountMinSketchWithHeapAccumulatorUpdater) are tracked as follow-up. The accumulator structs exist (count_sketch_accumulator.rs, count_min_sketch_with_heap_accumulator.rs) but lack the AccumulatorUpdater wrapper trait impl.

The OTLP modified-sketch wire-format path uses SketchEnvelope ingest (not raw), so this arm only matters for Mode 2 / raw-input ingest — not the gateway-less path that today's tests exercise.

Test plan

  • cargo test --workspace --lib — 1549 pass, 0 fail
  • New keyed-coverage assertions for all four CountSketch / CMS variants

🤖 Generated with Claude Code

The precompute accumulator factory was silently falling through to
the catch-all `tracing::warn! + SumAccumulatorUpdater` default for
both `AggregationType::CountSketch` and `AggregationType::CountSketchWithHeap`.
Any raw-input ingest path (precompute worker + sketch_db backfill
window_builder) hitting one of those policies would produce a Sum
accumulator instead of a frequency sketch — silently wrong results.

Route both to `CmsAccumulatorUpdater` (which already handles the
shared `(rows, cols)` matrix shape) for parity with the existing
`CountMinSketch | CountMinSketchWithHeap` arm at line 729. This
is the correctness floor: a registered policy yields a working
accumulator, not a Sum default.

Limitation called out in the doc comment: like the existing
`CountMinSketchWithHeap` arm, this drops the per-policy top-k
heap. Dedicated `CountSketchAccumulatorUpdater` /
`CountMinSketchWithHeapAccumulatorUpdater` impls (the accumulator
structs exist but lack the updater wrapper) are tracked as
follow-up — the present arm only matters for Mode 2 / raw-input
ingest, which the OTLP sketch-envelope path doesn't exercise.

`config_is_keyed` updated correspondingly (the four new variants
are all multi-population by shape, parallel to CountMinSketch),
plus a test covering all four arms.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 0c86007 into main May 16, 2026
@zzylol
zzylol deleted the accumulator-factory-countsketch-withheap branch July 17, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant