Repository navigation
Propagate end-to-end accuracy guarantees for approximate-over-approximate plans #172
Description
Context
ASAPPlanner can structurally nest SummaryAgg nodes, but selected post-ASAP plans need machine-readable end-to-end error guarantees. Approximate parents must not consume approximate children unless their composed guarantee satisfies the callers existing AccuracyTarget`.
Accuracy legality and cost ranking are separate responsibilities.
Required planning pipeline
candidate generation
-> guarantee propagation
-> AccuracyTarget satisfaction check
-> legal candidates only
-> cost ranking/global selection
CostModel must not override accuracy legality.
Accuracy model and typed guarantees
The deployment-extensible AccuracyModel supplies local guarantees, propagates them through a CompositionOperator, and checks the result against AccuracyTarget. Guarantees retain typed metrics rather than reducing every error to an unqualified epsilon:
#[non_exhaustive]
enum ErrorMetric {
AbsoluteValue,
RelativeValue,
Rank,
Cardinality,
Frequency,
L2Frequency,
TopKMembership,
}
struct ResultGuarantee {
metric: ErrorMetric,
bound: BoundExpr,
failure_probability: ProbabilityExpr,
provenance: Vec<GuaranteeSource>,
}BoundExpr and ProbabilityExpr are serializable expression vocabularies. Provenance records selected parameters, child guarantees, composition steps, runtime observations, and unavailable statistics. Caller-visible guarantees belong on finalized/readout values; exact outputs have zero error.
Core propagation rules
The default model is conservative and fail-closed:
- Exact input contributes zero bound and zero failure probability.
- Compatible additive/Lipschitz errors compose bounds additively and probabilities by union bound.
- Supported non-negative relative errors compose as
e_inner + e_outer + e_inner * e_outer. - Exact sum over approximate values sums bounds; exact extrema take the maximum bound.
- Incompatible rank, cardinality, frequency, value, L2-frequency, and membership metrics require an explicit conversion rule.
- Unknown statistics remain unknown; unsupported compositions keep the raw/pre-ASAP alternative.
TopK membership requires widened per-key confidence intervals and is certified only when:
min_lower_bound(selected_top_k)
> max_upper_bound(non_selected)
CountSketch uses an L2-frequency theorem and must never reuse CMS`s L1 theorem.
Accuracy-budget allocation
The full root epsilon/delta must not be allocated independently to every approximate layer. An AccuracyBudgetAllocator enumerates finite allocations; each allocation produces parameters through existing sizing, and candidates whose propagated guarantees miss the target are rejected before global selection.
Initial additive allocation may split epsilon and delta evenly across approximate layers. Root QueryRequirements.accuracy and explicitly supplied local AggIntent.accuracy must have documented precedence.
Cost model
Accuracy allocation changes state/update/read costs, but correctness filtering happens first. Recurring costs use explicit units and rates; shared state is counted once. One-shot plus recurring work requires an explicit horizon. Unknown statistics must not become zero.
Acceptance criteria
- Selected approximate-over-approximate plans carry machine-readable end-to-end guarantees.
- Guarantees are checked against the existing
AccuracyTargetbefore costing. - Unsupported/unprovable compositions retain the raw/pre-ASAP candidate.
- Compatible basic compositions use typed metrics and documented formulas.
- DAG export carries guarantees, probability, provenance, allocation, and rejection reasons.
- TopK membership requires a strict margin certificate.
- CountSketch uses L2-specific sizing and guarantee propagation.
- Hydra composes inner error with shared-grid error.
- KLL/HLL/KMV/Theta have conservative parameter-derived confidence contracts.
- Integrate concrete posterior/runtime observations without making them implicit planning assumptions.
- Reuse the same propagation primitives for all roll-up work in Support accuracy-aware approximate Count roll-ups #278.
PR #303 implementation status
PR #303 implements the four requested Planner-side guarantees. ASAPPlanner remains a mathematical planner and does not import asap_sketchlib; runtime observations are a separate evidence source that can instantiate symbolic terms later.
Completed in ASAPPlanner
- TopK membership-margin certificates: carry widened selected/excluded boundary intervals and their union-bound failure probability; certify only strict separation and reject missing, invalid, or overlapping evidence.
- CountSketch L2 sizing and propagation: add
L2Frequency,sqrt(3 / width) * ||f||_2, epsilon-derived width, delta-derived odd median depth, and a conservative Hoeffding failure bound. CMS posterior L1 relaxation is not reused. - Hydra shared-grid composition: add inner and outer collision bounds and union-bound their failure probabilities. Deployment/data-dependent leaves stay symbolic and fail closed until instantiated.
- KLL/HLL/KMV/Theta confidence: attach conservative 99%-confidence contracts to committed parameters; reject tighter unsupported confidence and targets missed because of parameter caps.
- Check parameter-derived guarantees against targets even for exact inputs, before cost ranking.
- Add unit/integration coverage and document the contracts.
Remaining evidence/runtime integration
- Feed runtime or planning-time TopK boundary intervals into
PropagationStats; static candidates remain rejected without evidence. - Instantiate CountSketch stream-L2 and Hydra shared-grid symbolic statistics from a serving implementation when concrete absolute bounds are required.
- Add an implementation-specific amplification/confidence model if confidence tighter than the built-in 99% contract is required.
- Preserve imported evidence as
GuaranteeSource::RuntimeObservationand export it through DAG JSON. - Keep affected candidates fail-closed when required evidence is unavailable.
Non-goals and related follow-up
- Do not add a second correctness-policy enum.
- Do not assume statistical independence by default.
- Do not claim arbitrary cross-sketch or nonlinear composition.
- Advanced nonlinear and correlation-aware error propagation #297 tracks nonlinear and correlation-aware propagation.
- Exact/archive fallback execution and runtime integration remain separate from Planner mathematics.
Activity
docs(l4): reframe #171/#172 proposal as a shared accuracy algebra, fo…
docs(l4): separate the design from which issue it solves; norm-aware …
docs(l4): replace unified accuracy algebra with three grounded compos…
docs(l4): a taxonomy and recipe for composing summaries (bespoke) (#174)
docs: add an Interface section to each L1-L5 doc (#169)
zzylol commentedon Aug 26, 2026
Related open work
zzylol commentedon Aug 26, 2026
Rewritten scope and proposed stacked-PR design
Current-code audit
The original issue is directionally correct but should not be implemented by merely passing a child epsilon into
CostModel::size_params:AccuracyTarget::{Exact, Epsilon, EpsilonDelta}already models the caller's accuracy requirement; do not add another correctness-policy model.SummaryAggcan already nest structurally, so unsafe approximate-over-approximate plans can be constructed today.SummaryNode/SummaryEstimatecarries no machine-readable output guarantee or error provenance.post_asap::query_time::error_estimation, but they are runtime observations, not a general composition algebra.The missing functionality is therefore:
AccuracyTargetbefore cost ranking.Architectural boundary
Accuracy legality and cost ranking must remain separate:
Do not put correctness decisions into
CostModel. Introduce a separate deployment-extensible accuracy algebra:CostModelranks only candidates for whichsatisfiesis true. A deployment can provide both models, but one trait must not silently override the other.Guarantee representation
Do not reduce every sketch to one untyped epsilon. Error metrics are not interchangeable:
BoundExpr/ProbabilityExprshould be a small serializable expression vocabulary rather than a prose string, so planner-time symbolic bounds can later be instantiated using cardinality/fanout/runtime posterior observations.Examples of
GuaranteeSource:AccuracyTargetand selected sketch parameters;Attach the guarantee to the readout/value edge, not only to
SummaryAggstate:Summary-state edges may carry a state capability/error model, but a caller-visible result guarantee belongs after
SummaryEstimateor another finalized readout.Sound default propagation rules
The first implementation should be deliberately conservative.
Exact input
Composing an approximate operator over an exact input preserves only the outer local guarantee.
Additive absolute errors
Without an independence assumption:
The delta formula is the union bound. Do not multiply probabilities unless the model explicitly establishes independence.
For a deterministic
L-Lipschitz transformation:Relative errors
For compatible non-negative multiplicative guarantees:
Sign changes, values near zero, and incompatible relative/absolute metrics require an explicit conversion proof or rejection.
Aggregating several approximate children
For exact sum over finalized estimates:
For exact max/min value bounds:
This bounds the returned value but does not necessarily identify the true winning key.
TopK over approximate values
Do not claim TopK membership accuracy by adding epsilons. Given per-key intervals
[lower_i, upper_i], membership is certified only when the selected boundary is separated:If an outer frequency sketch adds error, widen each interval by its compatible outer bound before applying this test. When the margin condition fails:
AccuracyTargetsemantics support it later;Incompatible metrics
Examples such as HLL cardinality error fed into a CMS frequency guarantee, or quantile rank error fed into value-additive logic, require a registered cross-metric propagation rule. The default is
AccuracyError::UnsupportedComposition, never “treat child as exact.”Budget allocation and candidate enumeration
Do not assign the full root epsilon independently to every approximate layer. For a root target
(epsilon, delta), generate a finite set of local budget splits:Start with a deterministic conservative allocator:
Expose allocation as a separate hook because equal splitting is rarely cost-optimal:
Each allocation produces candidate parameters through the existing sizing path. Search retains only candidates whose propagated guarantee satisfies the root target;
global_selectionthen chooses by cost.Existing per-node
AggIntent.accuracyremains the local declared requirement where explicitly supplied. The workload/rootQueryRequirements.accuracy, when present, is the end-to-end target. This PR must document precedence and must not silently reinterpret every frontend-copied per-node target as an already valid end-to-end allocation.Cost model
For a two-layer maintained composition, use cost units per second:
Raw fallback:
For shared repeating consumers:
State accounting:
Shared state is counted once. If one-shot and recurring work are compared over horizon
H:Accuracy allocation affects sketch parameters and therefore maintenance/state/readout costs. Cost ranking happens after legality for each allocation. Every estimate carries unit, input provenance, and model version; missing statistics are unknown, not zero.
Recommended stacked PRs
PR 1 — Represent guarantees and fail closed
ErrorMetric, symbolic bound/probability expressions, provenance, andResultGuarantee.AccuracyModelrule exists.This PR fixes the current correctness risk even before any composition is admitted.
PR 2 — Conservative same-metric propagation
AccuracyModeland default additive/relative/union-bound rules.PR 3 — TopK stability and runtime posterior refinement
Tests
Acceptance criteria
AccuracyTarget.CostModelcannot override accuracy legality.Non-goals
CorrectnessPolicy;AccuracyTargetremains authoritative.[-]Nested approximate-over-approximate composition has no error-propagation model[/-][+]Propagate end-to-end accuracy guarantees for approximate-over-approximate plans[/+]Merge pull request #299 from ProjectASAP/feat/accuracy-guarantee-prop…
zzylol commentedon Aug 28, 2026
PR #299 (guarantee representation, fail-closed legality, conservative propagation, and budget allocation) has merged after reconciliation with current recurrence and cross-consumer accuracy work. This issue remains open for the explicitly deferred TopK membership-margin certificate/runtime-observation phase described in the PR.
Merge pull request #303 from ProjectASAP/review-pr-299-work