feat(planning): price the derived window layouts so they can be ranked - #697
Closed
zzylol wants to merge 1 commit into
Closed
feat(planning): price the derived window layouts so they can be ranked#697zzylol wants to merge 1 commit into
zzylol wants to merge 1 commit into
Conversation
A sliding window has two legal physical layouts, and they trade opposite
resources. `Pane { P }` takes each sample once and composes `W / P`
states per read; `FullWindow` takes each sample into all `ceil(W / S)`
overlapping windows and is read whole. Which is cheaper depends on how
hard the source is pushing, and nothing was comparing them: the
derivation emitted only the pane form, and a lone candidate is selected
by a `min_by` over one element.
Emit both for a sliding shape and price each from the snapshot's own
lifecycle unit costs.
`ImplementationCostEvidence` is normally measured evidence, so becoming
its producer here is only sound if nothing is invented. Every unit cost
is supplied (`implementation.lifecycle_costs`), and every multiplier is
a structural count that follows from the layout's definition: states
sealed per horizon, update fanout, finalizations per read, and
`retained_state_count` -- the same function that fills
`num_aggregates_to_retain`, so quote and plan cannot disagree.
Concurrent in-flight full windows are not charged twice; the fanout term
already prices that write amplification.
The byte fields stay exactly as the snapshot supplied them. State size
needs sketch parameters that do not exist yet at this point, and
guessing them would be the fabrication this avoids. Only `cpu_cost` and
`weighted_cost` are derived, and only those two are read -- by
`validate_window_implementations` and by the ranking `min_by`.
`model_version` records that the quote is derived.
Against the planning snapshot's own evidence the crossover lands where
it should: idle, the full window wins because its fanout is free and the
pane's ten merges per read are not; at the declared 100 updates/s the
tenfold fanout dominates and panes win. Tumbling shapes are unchanged --
the validator pairs them only with `Pane`, so there is no alternative to
rank and their identity keeps the snapshot's label.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A sliding window has two legal physical layouts and they trade opposite
resources:
Pane { P }takes each sample into exactly one pane, and composesW / Pofthem per read.
FullWindowtakes each sample into allceil(W / S)overlapping windows, andis read whole.
Which is cheaper depends entirely on how hard the source is pushing. Nothing was
comparing them. #696 emits only the pane form, and a lone candidate is selected
by
complete_summary_candidate_estimate'smin_byover a one-element list —the cost value cannot change the outcome, so the deployment never gets the
choice.
What
For a sliding derived shape, both layouts are emitted and each is priced, so the
existing ranking has something real to compare. Tumbling shapes are untouched:
the validator's framework/layout table pairs
Tumblingonly withPane, sothere is no alternative to rank.
Plan-compile time only. Snapshots that supply their own
window_candidatesareunaffected.
How
derived_window_costcomposes the snapshot's own lifecycle unit costs with eachlayout's structural counts, over
horizon_seconds, for windowWand slideS:Pane { P }FullWindowhorizon / Phorizon / S1ceil(W / S)ceil(W / P)1retained_state_count(…)retained_state_count(…)Nothing here is invented. Every unit cost is supplied evidence
(
implementation.lifecycle_costs); every multiplier is a structural count thatfollows from the layout's own definition — the same fanout
worker.rs'sstores_full_windowsbranch actually performs. Retention reusesretained_state_count, the function that fillsnum_aggregates_to_retain, sothe quote and the plan cannot disagree. Concurrent in-flight full windows are
not charged twice: the fanout term already prices that write amplification.
The byte fields are passed through from the snapshot unchanged. State size needs
sketch parameters that do not exist at this point, and guessing them would be
exactly the fabrication this otherwise avoids. Only
cpu_costandweighted_costare derived, and only those two are read — byvalidate_window_implementationsand by the rankingmin_by.model_versionis suffixed
+derived-window-layout-v1so a derived quote is never mistaken fora producer's measurement.
Before this PR
One layout per window, chosen structurally. A deployment could only get the
other by hand-supplying both candidates with its own priced evidence, which
nothing in the backend produces.
After this PR
Both layouts are offered for a sliding shape and the cheaper one wins on the
deployment's own numbers. Against the planning snapshot's evidence
(
build 10.0,maintenance_per_update 0.001,read 0.1,retention_per_second 0.001,retirement 1.0, horizon 300s,W=300,S=30):Pane{30}FullWindowFullWindowFullWindowPane{30}The crossover is where the tenfold update fanout overtakes the ten merges per
read. At the snapshot's own declared rate panes win, so
five_minute_lookback_evaluated_every_thirty_seconds_slides_by_thirtystillplans
Pane{30}retaining 11 — this PR changes no selection for that workload,it makes the selection a decision instead of a default.
Evidence
Execution example — the table above is produced by
derived_window_layout_prices_write_against_read_amplification, which assertsthe two directions rather than the magnitudes:
Performance measurement: not applicable — no runtime path changes. The numbers
above are the cost model's own output on supplied evidence, not measurements of
either layout.
Screenshot: not applicable.
Verification
derived_window_layout_prices_write_against_read_amplification— with noarriving data the full window is cheaper; at the snapshot's declared rate
panes are. Pins the crossover direction, deliberately not the magnitudes.
tumbling_shapes_have_no_layout_alternative_to_rank— a tumbling shapestill yields one candidate keeping the snapshot's identity.
derived_window_candidate_follows_the_evaluation_cadence— extended: asliding shape now offers both layouts, in a stable order.
derived_window_candidate_shapes_are_accepted_by_validation— alreadywalked every emitted shape through
validate_window_implementations; it nowcovers the
FullWindowcandidates too, so a mispriced or malformedalternative is a compile error rather than a plan.
cargo test -p control_plane— 809 passed, 0 failed (770 lib =768 from fix(planning): derive the fallback window implementations from the query #696 + 2 new, plus 31 api + 8 integration). No existing
assertion changed.
cargo test -p data_plane --libdoes not compilein this checkout —
asap_sketchlibis missingaccepts_standard_updates(
univmon_accumulator.rs:48) andquantile_interpolated(
summary_executor.rs:1053). Pre-existing and unrelated (this PR touches onecontrol-plane file), but it means no data-plane evidence is offered here.
cargo fmt -p control_plane -- --checkclean;cargo clippy -p control_plane --all-targetswarning count unchanged against the base branch(66 → 66).
Architectural decisions
Compose supplied unit costs; never synthesize a magnitude. Rejected
alternative: give both candidates the snapshot's single quote verbatim. Then
min_bytie-breaks alphabetically onimplementation_idand the "choice" isarbitrary. Rejected alternative: attach plausible constants per layout. That is
fabricating measurement, which the
weighted_costcontract exists to prevent.Composition keeps every number traceable to either supplied evidence or the
layout's definition.
Reuse
retained_state_countfor the retention term rather than modellingretention independently. It is what actually drives
num_aggregates_to_retain,so a second formula could price a plan the backend will not build.
Leave the byte fields alone. They are for auditability, and a derived
guess would make the audit worse, not better.
model_versioncarries theprovenance instead.
Limitations and follow-up
directions the tests pin, but its absolute magnitudes are only as good as
lifecycle_costs. A deployment with real per-layout measurements shouldsupply
window_candidatesand bypass this entirely — that path is unchangedand still takes precedence.
HierarchicalRollupis priced but never derived.derived_window_costhandles it (a base pane behaves like
Pane), so a snapshot supplying one iscosted consistently, but nothing emits one: it needs the
Extension("backend.exact-hierarchical-rollup.v1")framework.implementation_idnow encodes the layout for sliding shapes(
…-pane-30s,…-full-window), because two candidates for one window musthave distinct ids. Single-candidate tumbling shapes keep the snapshot's label
unchanged.
FullWindowcan reach the derived-maintenance gate.maintenance_runtime.rs:1108/:1269still reject a sliding cohort formaterializations with a
derived_input. Live-ingest is unaffected. Notevalidated_source_window_cohortrequiresFullWindowfor a sliding derivedcohort, so this PR makes that layout reachable — lifting the runtime gate
remains its own change, with its own validation, for the reasons recorded on
fix(planning): derive the fallback window implementations from the query #696.
Human review — do not complete with an agent
🤖 Generated with Claude Code