Skip to content

feat(sketch_algebra): realize Frequency (AggIntent::Extension) as a real Cms sketch - #413

Merged
zzylol merged 3 commits into
mainfrom
feat/control-plane-frequency-extension-realize
Jul 27, 2026
Merged

zzylol merged 3 commits into
mainfrom
feat/control-plane-frequency-extension-realize

Conversation

@zzylol

@zzylol zzylol commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Phase 2 of 5 toward supporting named-key SketchQuery::PointCount (count(cms_metric{item="x"})) — see the earlier phase (data_plane's SketchQuery::TopK support, #412) and the upstream prep (ASAPController#162, not yet merged).

Blocked on ASAPController#162 merging. This PR temporarily bumps control_plane's asap-ir/asap-l2/asap-sketch/asap-plan rev pins to e4cea66 (the feat/extension-realization-hook branch commit, ASAPController#162) so this can be built/tested now. Re-pin to the actual merged commit once #162 lands — same pattern as the fc09c3ad4c1756 bump before ASAPController#161 merged.

AggIntent::Extension{ext_kind: "frequency"} (control_plane's point-frequency-via-CMS intent, count(*) WHERE key = k) has always mapped to Implementation::PassThrough — a documented, accepted regression (typed_binding_endpoint_request_freq_declines_pending_upstream_extension_support) since Step B of the plan-shaped-serving migration adopted asap_plan::bind::implement_tree_in_with without a local Frequency-binding workaround. ASAPController#150/#162 added the CostModel::{realize_extension, readout_extension} hooks needed to close this; this PR implements both on ControlPlaneCostModel:

  • realize_extension("frequency", payload) parses the accuracy out of payload and returns Implementation::Sketch{kind: SummaryKind::Cms, params: Cms{width, depth}}.
  • readout_extension builds SketchQuery::PointCount, falling back to {key: SampleValue, value: None} (the bare bucket total) until the actual filter value is threaded through payload — a separate, later change (Phase 3).
  • ForcedFamilyCostModel (used by optimizer::rules::bind_workload_typed) delegates both new methods to its inner ControlPlaneCostModel, so the endpoint_request_freq contract row now commits instead of declining.

A genuine discrepancy found and resolved along the way: the legacy sketch_catalog::sketch_type_for_op's as_frequency arm maps Frequency to SketchType::CountSketch, while the newer, actively-tested capability_matching::pick_family/is_valid_pair maps it to SummaryKind::Cms — these are genuinely different sketch algorithms (SketchType has separate CountSketch/CountMinSketch variants), not a naming coincidence. Went with capability_matching's mapping since it's the tested, current source of truth for the typed binding path this change lives in; the legacy sketch_catalog-driven planner (a separate, still-coexisting code path, untouched by this PR) keeps its own CountSketch choice — not something this PR should or does reconcile.

Also updates emit::stage_config's SketchQuery::PointCount wire-JSON builder for the new value field (ASAPController#162).

Test plan

  • cargo test -p control_plane --lib — 765 passed, 1 failed (the same single pre-existing, unrelated failure — invalid_sketch_type_override_falls_back_to_default — present on unmodified main too).
  • 3 tests flipped from "declines pending feat(sketch_db): Phase 5 M2 — derive sketch sid from content hash #150" to "binds successfully": typed_binding_endpoint_request_freq_binds_cms (renamed), sketch_algebra::tests::frequency_extension_binds_cms (renamed), plus the CountMinSketch-override case in override_pins_nonquantile_family_over_misclassified_query and the two routing-table fixtures in emit::mod.rs.
  • cargo test --workspace — same single pre-existing failure, nothing else.
  • cargo build --workspace — clean.
  • cargo clippy -p control_plane --lib --tests — verified every warning falls outside this diff's touched line ranges (all pre-existing).
  • rustfmt scoped to touched files only.

🤖 Generated with Claude Code

zzylol and others added 2 commits July 27, 2026 06:35
…eal Cms sketch

Bumps the ASAPController rev pin to feat/extension-realization-hook
(ASAPController#162, not yet merged) to pick up
CostModel::{realize_extension, readout_extension} (ASAPController#150).

ControlPlaneCostModel now implements both for ext_kind == "frequency":
realize_extension parses the accuracy out of payload and returns
Implementation::Sketch{kind: Cms, params: Cms{width,depth}} -- matching
capability_matching::pick_family's own Frequency -> Cms mapping (NOT the
older sketch_catalog::sketch_type_for_op's SketchType::CountSketch,
which is a genuinely different sketch algorithm under a similar name and
predates/disagrees with capability_matching -- kept the newer, tested
mapping). readout_extension builds SketchQuery::PointCount, falling back
to {key: SampleValue, value: None} until the filter value is threaded
through payload (a separate, later change) -- correct as the bare
bucket total in the meantime.

ForcedFamilyCostModel (used by optimizer::rules::bind_workload_typed)
delegates both new methods to its inner ControlPlaneCostModel, so the
`endpoint_request_freq` contract row -- previously a documented, accepted
regression declining to Logical pending #150 -- now commits like every
other row. Flipped the tests that pinned the old decline behavior to
assert the new Cms binding instead.

Also updates emit::stage_config's SketchQuery::PointCount wire JSON for
the new `value` field (ASAPController#162).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
64df20d is ASAPController main's actual tip now that #162 merged --
replaces the temporary pre-merge pin at e4cea66.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zzylol
zzylol force-pushed the feat/control-plane-frequency-extension-realize branch from f6f34db to e697463 Compare July 27, 2026 12:36
…ding

Caught in review: the section header above frequency_extension_binds_cms
still described Frequency as declining to bind (pre-#150 behavior) and
pointed at the old, renamed test name. Corrected to describe current
behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zzylol
zzylol merged commit 77b8281 into main Jul 27, 2026
zzylol added a commit that referenced this pull request Jul 27, 2026
64df20d is ASAPController main's actual tip now that #162 merged --
replaces the temporary pre-merge pin at e4cea66, matching control_plane's
own pin from #413.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zzylol
zzylol deleted the feat/control-plane-frequency-extension-realize branch September 12, 2026 14:48
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