Skip to content

feat: Pass 1 prunes summaries no reading query can use for its accuracy target - #1116

Merged
zzylol merged 2 commits into
refactor/stage-boundariesfrom
feat/pass1-structural-accuracy-pruning
Oct 30, 2026
Merged

zzylol merged 2 commits into
refactor/stage-boundariesfrom
feat/pass1-structural-accuracy-pruning

Conversation

@zzylol

@zzylol zzylol commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Part of #1047 (per-query accuracy pruning in Pass 1) and #1095 §2.0 (accuracy A1). Merges into refactor/stage-boundaries.

Why

#1095's MILP checks accuracy with linear rows that count the budget shares a query uses. That works only if every candidate reaching Stage 3 can meet some query's target. Today, structurally hopeless candidates still reach Stage 3, which rejects them as no_accuracy_guarantee / AccuracyTargetMissed. Examples are a heap top-k with no guarantee, a relative bound under a rank target, and a relative bound through avg over an undeclared gauge. Under the new design these belong to Pass 1, which also states the reason.

What

The rule: PerComputationCandidates::without_summaries_no_query_can_use prunes a summary when no query that reaches its aggregate group can use it. For each such query, Pass 1 composes the output with only that summary approximate (the most favorable case). The query cannot use the summary if any of these holds:

  • the guarantee is None;
  • the error stays unknown after binding the data workload's sign declarations;
  • the accuracy model says the metric cannot meet the target (AccuracyModel::metric_can_meet, new, whose default keeps the built-in rule);
  • for a whole-result target with a failure probability, the number of values is unbounded and the guarantee can fail.

What is never pruned:

  • exact candidates;
  • a summary some reading query can use;
  • a summary whose family another aggregate over the same source also offers, because Pass 2 may build that aggregate's state from it (over-keeping is safe).

Other changes:

How

Composition uses asap-accuracy's existing propagation. Each check is per query; a summary is pruned only when it fails for all of them.

Key code interfaces added / modified

  • PruneReason::NoErrorBoundForQueryTarget
  • AccuracyModel::metric_can_meet(metric, target) -> bool, with a default method
  • Pass 1 takes &dyn AccuracyModel

Usage: with stage_pipeline --enforce-accuracy-guarantees, example 1's Q2 heap top-k candidates appear under pruned_candidates with reason no_error_bound_for_query_target.

Major algorithm changes

Pass 1 now prunes structurally unboundable summaries.

Before / After

With guarantees enforced:

Example Pruned for the new reason Selected cost/s
1 2 4.377 (unchanged)
2 0 3.420 (unchanged)
3a 0 126.8M (unchanged)
3b 1 2.3625 (unchanged)

Verification

  • logical: 168 + 35
  • planner: 11 + 81, including the two runtime_install tests
  • devtools stage_pipeline: 47
  • fmt and clippy --workspace --all-targets -D warnings: clean

New unit tests:

  • avg-of-p99 is pruned with its reason;
  • a summary used by one of two queries is kept;
  • exact candidates are never pruned;
  • a summary another aggregate over the same source offers is kept;
  • KLL under a whole-result target is pruned when the series count is undeclared and kept once it is declared.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw

zzylol and others added 2 commits October 30, 2026 20:04
…y target

Pass 1 now removes a summary candidate (own or fused) when, for every
query whose root reaches its aggregate group, the query's output composed
with that summary (every other target exact) has no error bound that can
meet the query's target at any size: guarantee propagation has no rule
above it (e.g. a rank error through avg, a value HAVING over an estimate),
its bound stays unknown once the data workload's sign declarations are
bound (a relative error through avg over an undeclared gauge), or its
metric is not one the target accepts. Other symbolic statistics are
assumed bindable. A summary one reading query can use is kept; exact
candidates are never pruned. The reason is the new
PruneReason::NoErrorBoundForQueryTarget, carried in Pass 1's
pruned_candidates.

The facade prunes only when Stage 3's accuracy model and evidence cannot
accept an output without its guarantee (not with
ignore_accuracy_guarantees). Stage 3 reports a query root group left with
no candidate as no valid candidate rather than a solver failure.

The two no-raw avg-of-p99 runtime_install tests assert the reason again,
on the facade's MemoSteps::pass1_pruned_candidates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw
… check whole-result scope

Follow-ups to the structural accuracy prune:

- Pass 1 cannot see Pass 2's reuse of one group's summary by another
  (rollup, window rollup, finer-aggregate reuse, top-k reuse). A summary
  is now kept whenever another target, over another aggregate reading one
  of the same sources, offers the same family. This keeps more than those
  rules' preconditions need and relies on no dominance argument.
- The metric check asks the deployment's accuracy model through a new
  default method, AccuracyModel::metric_can_meet. Its default is the
  built-in rule; the facade passes the model Stage 3 uses.
- The guarantee is stated over the target's scope, as Stage 3 states it.
  A per-value guarantee that may fail cannot meet a whole-result failure
  probability over a number of values the data does not bound, so it is
  pruned with the same reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw
@zzylol zzylol added accuracy Accuracy requirements, guarantees, and propagation optimizer Workload optimization and plan selection labels Oct 30, 2026
@zzylol
zzylol merged commit bd46e68 into refactor/stage-boundaries Oct 30, 2026
zzylol added a commit that referenced this pull request Oct 30, 2026
…ng guarantees (#1118)

#1116 makes Pass 1 prune a summary no reading query can use for its
accuracy target when guarantees are enforced. Seven integration tests
read the reference enumeration under the built-in strict model to check
the structure or execution of a summary whose output Stage 3 already
rejected at that target before #1116: a heap-backed Top-K and a value
filter or group key over an estimate have no guarantee, and a grouped KLL
quantile's per-value guarantee meets no whole-result target over groups
the data does not bound. Pass 1 now prunes those summaries, so the tests
found no candidate.

The tests now plan with every output accepted
(logical_candidates_ignoring_guarantees, ignore_accuracy_guarantees),
as they check rewrites and execution, not accuracy acceptance.


Claude-Session: https://claude.ai/code/session_01K1M6bqhAk7WA4MZcfbAoMw

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol
zzylol deleted the feat/pass1-structural-accuracy-pruning branch November 3, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accuracy Accuracy requirements, guarantees, and propagation optimizer Workload optimization and plan selection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant