Skip to content

refactor(planner): replace the summary lifecycle with #509 materialization options - #667

Merged
zzylol merged 8 commits into
mainfrom
stack/528-08b-query-time-default
Oct 13, 2026
Merged

zzylol merged 8 commits into
mainfrom
stack/528-08b-query-time-default

Conversation

@zzylol

@zzylol zzylol commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Why

#509 Stage 2 (Physical ASAP-aware optimization) decides, per sub-DAG, whether its output is materialized and whether that happens at ingestion or at query time. The Planner's summary maintenance lifecycle made this choice with its own cost model, so Stage 2 and the lifecycle would both own the same decision.

What

Behavior change: planner output no longer materializes anything. Every SummaryAgg and MaintainPopulation is NotMaterialized until Stage 2 materialization (#604) picks an option.

  • Remove the summary maintenance lifecycle.
    • Deleted: summary_maintenance_lifecycle, summary_maintenance_cost/, summary_maintenance_dag_export, post_asap::{summary_maintenance, summary_maintenance_lifecycle}, SummaryWindowFramework, the lifecycle CostModel hooks, CandidateCostOverrides, EmpiricalEvidenceProvider::lifecycle_cost_inputs, LifecycleInput and its planning horizon, the lifecycle errors, the lifecycle e2e test, the workload-demand-and-summary-lifecycle.md proposal and the viewer's lifecycle-plan UI.
    • MajorPass is now: candidate search → cost-based global_selection → assemble_selected_query per root → share_common_sub_dags. Each plan is a QueryPlan { entry_index, root }.
    • The pane primitives stay; Pass 2 window composition uses them.
  • Materialization options per docs: propose workload-wide planning, summary sharing, and materialization #509 (Stage 2).
    • New types: Materialization { NotMaterialized, MatAtIngestion(Medium), MatAtQuery(Medium) } and Medium { Memory, Disk }. Only MatAtIngestion runs at ingestion time.
    • MaterializationAssignment::set accepts any node: per docs: propose workload-wide planning, summary sharing, and materialization #509 every sub-DAG output can be materialized ("Materialization decides, for each sub-DAG, whether its output is stored"; Example 4 stores panes). MatAtIngestion puts the node and everything upstream of it at ingestion time, and a query-time consumer reads its stored output. Default is NotMaterialized everywhere. with_default gives unassigned SummaryAgg and MaintainPopulation nodes a default option where the DAG allows one, and leaves them NotMaterialized where it does not.
    • The assignment holds Rc clones of its keys, so a reused address cannot match a stale entry. split_shared_by_phase returns the assignment remapped onto the rebuilt nodes, so explicit assignments survive the split.
    • MaintainPopulation follows its assignment, as SummaryAgg does; it no longer always runs at ingestion time. EvaluatePopulation reads a timed MaintainPopulation.
  • Timing rules (ir::timing). Nothing is silently moved to the other timing; an infeasible assignment is an error:
    • Upstream rule (docs: propose workload-wide planning, summary sharing, and materialization #509 Algorithm 3, line 13): an ingestion-time node over input that exists only at query time fails with UpstreamNotAtIngestion. This covers an explicit MatAtIngestion and nodes a candidate builder fixed at ingestion time (e.g. a fixed-window rate finalize), which previously failed with IllegalChildDataState.
    • Fixed-timing rule: a node whose timing a candidate builder fixed (e.g. the query-time FinalizeExactAccumulator read boundary) keeps that timing. An explicit assignment that agrees is kept; one that needs the other timing fails with MaterializationConflictsWithFixedTiming.
    • Root rule: a root may be MatAtIngestion; the query reads its stored output. A row-producing root that runs at ingestion time without being stored there fails with UnstoredIngestionRoot, which replaces MaintenanceRowsAtRoot.
  • Export. OperatorNode, FlatNode and PhysicalASAPDAGNode carry their Materialization. PhysicalASAPDAG validation rejects a materialization that contradicts the node's timing (MaterializationTimingMismatch). Wire version 10. PhysicalASAPDAG::with_execution_phases is removed (docs: propose workload-wide planning, summary sharing, and materialization #509 Assumption 8: the deployment executes the plan as given).
  • Workload export. PlanOutput::execution_timed_dag (feat(planner): export a planned workload as one physical ASAP DAG #666) now times the operator roots and the scalar roots' references with apply_materialization_timings under the default assignment and one shared memo, and returns ExecutionDataStateError instead of the lifecycle timing error.
  • Query roots are finalized in assembly. With the lifecycle gone, MajorPass assembles each root with assemble_selected_query (before share_common_sub_dags), so an exact-state root is read through FinalizeExactAccumulator, as in refactor(planner): plan the workload on the unified operator IR #542.
  • Physical planner. frontier_from_timing reads only ingestion timing and documents that MatAtQuery storage is not reflected yet (Stage 2 adds it). The maintained precompute compilers in promql_rows assign MatAtIngestion explicitly.
  • Docs and remaining tests use the materialization vocabulary and the Operator<NodeId> payloads.

How

The PR removes the lifecycle and replaces the two-way timing assignment with the three #509 options. Candidate legality in Pass 1 is still checked as if every summary were MatAtIngestion where the DAG allows it (validate_at_ingestion, formerly validate_default), so a candidate stays executable if Stage 2 later materializes it at ingestion; candidate generation is unchanged. planned_data_state uses the same assumption. Tests that exercise ingestion-time execution assign it explicitly (at_ingestion helpers). The four execution tests removed with the lifecycle are ported to crates/integration-tests/tests/materialization_e2e.rs and check that NotMaterialized and MatAtIngestion give the same answers.

Before this PR

MajorPass chose a lifecycle per summary state (maintain at ingestion, or recompute at query time) using lifecycle costing, and timed plans with that choice. MaintainPopulation always ran at ingestion time, and a candidate-fixed timing that conflicted with its upstream failed with a generic IllegalChildDataState.

After this PR

MajorPass selects candidates by cost and assembles them. Nothing is materialized unless a caller assigns an option; choosing options is Stage 2's job (#604).

API changes:

  • UserInput::new / OptimizationInput::new drop the lifecycle argument; LifecycleInput, OptimizationInputError::InvalidHorizon and OptimizeError::{LifecycleSelection, LifecycleAssembly} are removed (assembly errors are OptimizeError::Realization).
  • QueryLifecyclePlan becomes QueryPlan { entry_index, root }.
  • LifecycleAssignment / apply_lifecycle_timings / validate_default become MaterializationAssignment / apply_materialization_timings / validate_at_ingestion.
  • MaterializationAssignment::set takes any node; split_shared_by_phase returns the remapped assignment.
  • ExecutionDataStateError gains UpstreamNotAtIngestion, MaterializationConflictsWithFixedTiming and UnstoredIngestionRoot (replacing MaintenanceRowsAtRoot); PhysicalASAPDAGValidationError gains MaterializationTimingMismatch.
  • PlanOutput::execution_timed_dag returns ExecutionDataStateError.
  • PhysicalASAPDAG::with_execution_phases is removed; PHYSICAL_ASAP_DAG_WIRE_VERSION is 10.

Evidence

  • A unit test pins the default: nothing is materialized.
  • Where lifecycle selection used to force raw recompute, the default cost model now picks sketches. See the rewired e2e_plan, summary_sharing, operator_design_examples and weighted_topk_binding tests.
  • ir::timing unit tests cover each rule: ingestion_time_node_over_query_time_upstream_is_rejected, ingestion_pinned_finalize_over_query_time_state_is_upstream_not_at_ingestion, fixed_timing_keeps_an_agreeing_assignment_and_rejects_a_conflict, a_root_may_be_stored_at_ingestion_time, any_node_may_be_materialized, split_keeps_explicit_assignments. promql_to_post_asap covers UpstreamNotAtIngestion through a frontend.
  • materialization_e2e.rs executes the KLL quantile, the current-series population, and sum_over_time arithmetic over one and over different selectors with NotMaterialized and with MatAtIngestion, and gets the same results.
  • types/tests/physical_export.rs covers MaterializationTimingMismatch (materialization_inconsistent_with_timing_is_rejected), including on a scalar-only DAG.
  • Screenshots and measurements: not applicable.

Verification

  • Unit and integration tests: lifecycle-only tests are deleted with the lifecycle; the rule tests above are new. materialization_e2e.rs: materialization_decides_precompute_contents, population_materialization_decides_precompute_contents, arithmetic_over_one_selector_executes, arithmetic_over_different_selectors_matches_prometheus.
  • Viewer: dag-viewer test_render (29 passed; the lifecycle-plan UI tests are removed).
  • Other checks on the PR head: cargo fmt --check; workspace all-target Clippy with -D warnings; cargo test --workspace (1,540 passed, 0 failed, 2 ignored); tools/verify_metricsql_external_consumer.sh OK. The test count is lower than refactor(ir): remove the legacy QueryExpr and SummaryExpr IRs; move docs and DAG viewer to the unified IR #543's 1,635 because the lifecycle tests are deleted with the lifecycle.

Architectural decisions

Limitations and follow-up

Stack: tracker #528 · main → #542 → #665 → #666 → #543 → #667 → #561.

Human review — do not complete with an agent

  • The MVP boundary is correct.
  • New conceptual layers or public interfaces are necessary.
  • The before/after description matches the intended product behavior.
  • Human reviewer:
  • Decision and rationale:

🤖 Generated with Claude Code

https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

zzylol and others added 8 commits October 13, 2026 02:36
Stage 2 materialization (#509) will decide per sub-DAG whether and when to
materialize, so the Planner no longer chooses a maintenance lifecycle.

- MajorPass now runs search_workload_with_targets -> global_selection ->
  assemble_selected_dag per root -> share_common_sub_dags.
- QueryLifecyclePlan becomes QueryPlan { entry_index, root }; PlanOutput's
  execution_timed_dag times the roots directly. LifecycleInput, the
  lifecycle errors and UserInput's `lifecycle` field are gone (public API
  break).
- Delete summary_maintenance_lifecycle, summary_maintenance_cost,
  summary_maintenance_dag_export, post_asap::{summary_maintenance,
  summary_maintenance_lifecycle} and SummaryWindowFramework (the pane
  primitives stay), the lifecycle CostModel hooks, CandidateCostOverrides
  and EmpiricalEvidenceProvider::lifecycle_cost_inputs.
- Delete the lifecycle e2e test and the viewer's lifecycle-plan UI; rewire
  e2e_plan, summary_sharing, operator_design_examples and
  weighted_topk_binding to the new pipeline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename LifecycleAssignment to MaterializationAssignment and
apply_lifecycle_timings to apply_materialization_timings. The default
assignment is now all_query_time(): nothing is materialized until Stage 2
materialization (#509) decides per sub-DAG. all_ingestion_time() and set()
assign maintenance explicitly.

- validate_default becomes validate_maintained: candidate legality is still
  checked with every summary maintained, so candidate generation is
  unchanged. planned_data_state and fixed_window_rate_candidates use the
  same maintained assumption, and the maintained precompute compilers in
  promql_rows assign ingestion time explicitly.
- PlanOutput::execution_timed_dag, show_post_asap_ir and the default test
  helpers now emit query-time summaries.
- forces_query_time (#541) treats a SummaryAgg as query time when the
  assignment, including its default, puts it there.
- Tests that exercise maintenance assign it explicitly (new `maintained`
  helpers); a new unit test pins the query-time default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ime default

Remove the lifecycle APIs, recipes and viewer section from the docs, delete
the workload-demand-and-summary-lifecycle proposal, and point materialization
questions to Stage 2 (#509). Rename LifecycleAssignment/apply_lifecycle_timings/
validate_default to their new names and describe the all-query-time default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow #537: the remaining tests read Operator<NodeId> payloads from the
physical DAG, and docs name ir::flat / ir::physical_export instead of the
removed ir::export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on, MatAtQuery

options. Replace the two-way timing assignment with them:

- New Materialization { NotMaterialized, MatAtIngestion(Medium),
  MatAtQuery(Medium) } and Medium { Memory, Disk }; only MatAtIngestion
  runs at ingestion time.
- MaterializationAssignment maps a SummaryAgg or MaintainPopulation to its
  option (set); Default is NotMaterialized everywhere, and with_default
  gives unassigned sub-DAGs an option where the DAG allows it
  (validate_maintained, planned_data_state and the maintained precompute
  compilers use MatAtIngestion). all_query_time, all_ingestion_time and
  summary_timing are gone.
- MaintainPopulation follows its assignment like SummaryAgg instead of
  always running at ingestion time.
- An explicit MatAtIngestion over something that only exists at query
  time fails with UpstreamNotAtIngestion ("upstream of ingestion-time node
  not at ingestion time") instead of silently moving to query time.
- OperatorNode and PhysicalASAPDAGNode carry their Materialization;
  PhysicalASAPDAG validation rejects a materialization inconsistent with
  the node's timing.
- Remove PhysicalASAPDAG::with_execution_phases (#509 Assumption 8: the
  deployment executes the plan as given). Tests place summaries through
  the assignment instead.

Retention and choosing the option per sub-DAG stay with Stage 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
Per #509 ("Materialization decides, for each sub-DAG, whether its output is
stored"; Example 4 stores panes), `MaterializationAssignment::set` accepts
any node. `MatAtIngestion` puts it at ingestion time, or fails with
`UpstreamNotAtIngestion` when something below can only run at query time,
and a query-time consumer reads its stored output. An ingestion-pinned node
(e.g. a fixed-window rate finalize) over a query-time state now fails the
same way instead of with `IllegalChildDataState`.

`split_shared_by_phase` returns the assignment remapped onto the rebuilt
nodes, so an explicit `MatAtIngestion` is no longer silently lost, and the
assignment holds `Rc` clones of its keys so a reused address cannot match a
stale entry. Renames the remaining "maintained" names to the docs'
vocabulary (`validate_at_ingestion`, `at_ingestion` test helpers), notes that
`frontier_from_timing` does not store `MatAtQuery` outputs yet (Stage 2),
and bumps PHYSICAL_ASAP_DAG_WIRE_VERSION to 10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
Ports the four execution tests removed with the summary-maintenance
lifecycle to MaterializationAssignment: NotMaterialized and MatAtIngestion
placements of the KLL quantile, the current-series population, and
sum_over_time arithmetic over one and over different selectors execute to
the same results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
…stored roots

A node whose timing its candidate fixed keeps an agreeing explicit
assignment and rejects a conflicting one
(MaterializationConflictsWithFixedTiming) instead of dropping it. A root
assigned MatAtIngestion is valid; only an ingestion-time root of rows that
is not stored there errors (UnstoredIngestionRoot, was MaintenanceRowsAtRoot).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
@zzylol
zzylol force-pushed the stack/528-08b-query-time-default branch from 88650a0 to 0b4173d Compare October 13, 2026 02:36
@zzylol
zzylol changed the base branch from stack/528-08-cleanup to main October 13, 2026 02:36
@zzylol zzylol mentioned this pull request Oct 13, 2026
2 tasks done
@zzylol
zzylol merged commit 2a075a6 into main Oct 13, 2026
3 of 6 checks passed
zzylol added a commit that referenced this pull request Oct 13, 2026
…#667 materialization

Stage 2 takes query roots, scalar ones included (#542), times every sub-DAG
with Materialization::NotMaterialized (#667) and keeps the guarantee Stage 1
composed on every node it implements; a MaintainPopulation is no longer
rejected, since it now runs at query time when not materialized.

Stage 3 accepts a query's output when its root guarantee meets the target,
or when the deployment's accuracy model shows this candidate's output does
(AccuracyModel::output_guarantee, none by default). A certified estimate
inside the plan is not enough: a difference of two quantile estimates stays
listed as invalid, with a reason, under the built-in models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…#667 materialization

Stage 2 takes query roots, scalar ones included (#542), times every sub-DAG
with Materialization::NotMaterialized (#667) and keeps the guarantee Stage 1
composed on every node it implements; a MaintainPopulation is no longer
rejected, since it now runs at query time when not materialized.

Stage 3 accepts a query's output when its root guarantee meets the target,
or when the deployment's accuracy model shows this candidate's output does
(AccuracyModel::output_guarantee, none by default). A certified estimate
inside the plan is not enough: a difference of two quantile estimates stays
listed as invalid, with a reason, under the built-in models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…#667 materialization

Stage 2 takes query roots, scalar ones included (#542), times every sub-DAG
with Materialization::NotMaterialized (#667) and keeps the guarantee Stage 1
composed on every node it implements; a MaintainPopulation is no longer
rejected, since it now runs at query time when not materialized.

Stage 3 accepts a query's output when its root guarantee meets the target,
or when the deployment's accuracy model shows this candidate's output does
(AccuracyModel::output_guarantee, none by default). A certified estimate
inside the plan is not enough: a difference of two quantile estimates stays
listed as invalid, with a reason, under the built-in models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
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