Skip to content

feat(data_plane): intent round loop with parameter-slot binding: run a planned SIL intent round by round - #900

Draft
zzylol wants to merge 20 commits into
mainfrom
feat/intent-round-loop
Draft

zzylol wants to merge 20 commits into
mainfrom
feat/intent-round-loop

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: an intent (SIL) is a set of planned queries where a downstream query reads the values an upstream query answered (host IN $Y). The data plane answered one query at a time, ran no SQL plan, and had no way to bind one answer into the next query's plan.
  • Change: data_plane::intent runs the planner's intent output (IntentPlan, SIL contract final schema v1) round by round. The default binding substitutes each round's bound values for the planner's placeholder literals in a copy of the plan (BindMode::ParameterSlot, data_plane::placeholders). Bound runs are compiled per round, and a shared query-time node that holds a placeholder is cached under the binding's key. The data plane now stores a SQL table's rows as the series named after it. data_plane --intent runs an intent beside the server for the eval harness.
  • Effect (test every_planning_mode_answers_exactly_round_by_round):
    • A 3-query SQL intent was planned by ASAPPlanner#1553 in each of its three modes: query-at-a-time; intent with on-demand holes (intent_on_demand_holes, holes filled at query time); and full intent (intent_full).
    • q1 = the top 2 hosts by sum(value), binding $Y; q2 and q3 = per-user sum and max over host IN $Y.
    • Each mode ran 2 rounds. Every answer equals the exact one, q2's and q3's for the hosts q1 issued.
    • Before: SQL plans were refused ("the data plane stores time series only"), and there was no binding.

Review guide

Behavior: before → after

The planner writes intent_plan.json (its IntentPlan):

{"planning_mode": "intent_on_demand_holes", "plan": {...}, "lightcone_query_indices": [],
 "intent_rounds": [{"intent_name": "triage", "round_interval_ms": 10000, "queries": [
  {"query_id": "q1", "query_index": 0, "depends_on": [], "bind_slots": [], "rate": 1.0, "skip_if_empty": false},
  {"query_id": "q2", "query_index": 1,
   "depends_on": [{"variable": "Y", "upstream_query_id": "q1", "output_position": 1}],
   "bind_slots": [{"variable": "Y", "position": "in_list", "planned_value_count": 2,
                   "placeholder_values": [{"Utf8": "__sil_Y_0"}, {"Utf8": "__sil_Y_1"}], "plan_node_ids": [...]}],
   "rate": 1.0, "skip_if_empty": true}, ...]}]}

The plan's q2 is ... WHERE host IN ('__sil_Y_0', '__sil_Y_1') .... Each round, q1 answers {h1, h3}. The loop hands the engine the slot {placeholders: [__sil_Y_0, __sil_Y_1], values: {h1, h3}}. The engine binds a copy of the plan to host IN ('h1', 'h3') and runs q2 over it.

jq .plan intent_plan.json > plan.json
data_plane --plan plan.json --no-forward --stream-start-ms $S \
    --intent intent_plan.json --intent-name triage --intent-out rounds.jsonl \
    --intent-first-evaluation-ms $((S + LONGEST_LOOKBACK_MS)) --intent-rounds 30

rounds.jsonl has one line per round: per-query status, latency, bindings issued and answer; per-group latency (from round start to the last member's end); and overrun / missed. A table's rows are sent by Remote Write as samples of {__name__="<table>", <text columns>...} with the value column as the sample value.

Interfaces

data_plane/src/placeholders.rs (new)

+/// Where a hole sits in its query.
+pub enum SlotPosition {
+    /// `col IN $Y`: any number of values.
+    InList,
+    /// `col > $T`: exactly one value.
+    Comparison,
+}
+/// One hole of a query and the values bound to it this round.
+pub struct SlotBinding {
+    pub position: SlotPosition,
+    /// The literals the planner put in the plan for this hole.
+    pub placeholders: Vec<ScalarValue>,
+    /// The bound values as the upstream answer's text; converted to the placeholders' type.
+    pub values: BTreeSet<String>,
+}
+/// A copy of the (serialized) DAG with every slot's placeholders replaced, and the nodes that changed.
+/// Fails on a value of the wrong type, a comparison bound to other than one value, or a placeholder left over.
+pub fn bind(dag: &Json, slots: &[SlotBinding]) -> Result<(PhysicalASAPDAG, BTreeSet<PhysicalASAPNodeId>), String>;
+/// Rewrites one serialized part of a plan for `slot`; whether it changed.
+pub fn bind_json(json: &mut Json, slot: &SlotBinding) -> Result<bool, String>;

data_plane/src/intent.rs

 pub struct IntentPlan {
     pub plan: asap_planner::InstallablePlan,
+    /// Plan queries the planner added (lightcone queries): never issued; a round listing one is refused.
+    pub lightcone_query_indices: Vec<usize>,
     pub intent_rounds: Vec<PlannedIntent>,
 }
 pub struct PlannedBindSlot {
     pub variable: String,
+    pub position: SlotPosition,
+    /// The literals that stand for the hole in the plan.
+    pub placeholder_values: Vec<ScalarValue>,
 }
 pub struct BindSlot {
     pub variable: String,
     pub column: String,
+    /// Where the hole sits (ParameterSlot); default in_list.
+    pub position: SlotPosition,
+    /// The placeholders ParameterSlot replaces; default none.
+    pub placeholder_values: Vec<ScalarValue>,
 }
 pub enum BindMode {
     FilterGroupedResult,
-    /// Follow-up: fails with the reason.
+    /// Placeholders replaced by the bound values in a copy of the plan; the default for --intent.
     ParameterSlot,
 }
 pub trait QueryRunner: Sync {
     fn answer(&self, query: &str, time_ms: i64) -> impl Future<Output = Result<Answer, Unanswered>> + Send;
+    /// The answer with each slot's placeholders replaced by its values.
+    fn answer_bound(&self, query: &str, time_ms: i64, slots: &[SlotBinding]) -> impl Future<Output = Result<Answer, Unanswered>> + Send;
 }

data_plane/src/query.rs, engine.rs, store.rs

 impl QueryEngine {
+    /// `query` at `time_ms` over a bound copy of the plan: nodes depending on the binding are recompiled,
+    /// a shared one is cached under the binding's key, the others are read as usual; no result cache.
+    pub fn evaluate_bound(&self, query: &str, time_ms: i64, snapshot: &Snapshot, slots: &[SlotBinding]) -> Result<Answer, Unanswered>;
 }
 impl EngineHandle {
+    /// QueryEngine::evaluate_bound on a query worker.
+    pub async fn evaluate_bound(&self, query: String, time_ms: i64, slots: Vec<SlotBinding>) -> Result<Answer, Unanswered>;
 }
+/// The binding key of a query-time result computed with no intent binding.
+pub const UNBOUND: u64 = 0;
 impl<E: Clone> QueryTimeResults<E> {
+    /// get_or_compute under one binding (`binding` != UNBOUND): kept apart from other bindings' results at the same time.
+    pub fn get_or_compute_bound(&self, node: PhysicalASAPNodeId, time_ms: i64, binding: u64, watermark_ms: Option<i64>, compute: impl FnOnce() -> Result<Vec<Batch>, E>) -> Result<Arc<Vec<Batch>>, E>;
 }

data_plane/src/main.rs: --intent-bind-mode now defaults to parameter-slot (filter-grouped-result is the fallback).

The interfaces from the first part of this PR (loop, records, IntentSchedule::from_intent_plan, --intent* flags) are unchanged; see the commits.

Usage (data_plane/tests/intent_sil_modes.rs):

// The planner's plan of the SIL text in one mode (catalog: flows(ts, host, user, value)).
let (plan, _) = plan_intents(&parse_intents(INTENT)?, &catalog, &data, models, &options).await?;
// The data plane's reading of it; round "triage" with q1 -> {q2, q3}.
let plan: IntentPlan = serde_json::from_value(serde_json::to_value(&plan)?)?;
let schedule = IntentSchedule::from_intent_plan(&plan, "triage")?;
// The data plane installing plan.plan, the rows written by Remote Write, windows closed by the barrier.
let state = install(&plan, &tables).await;
// Rounds bind q1's hosts into q2's and q3's plans.
let intent = IntentLoop::new(schedule, BindMode::ParameterSlot, Duration::from_secs(30))?;
let round = intent.run_round(&state.engine, 0, EVALUATION_MS).await;
// q2's answer equals the exact per-user sum over the hosts q1 issued (round.queries[1].bindings["Y"]).

Algorithm changes

Binding an intent query's holes (new)

  • Problem: the planner plans a downstream query with placeholder literals (host IN ('__sil_Y_0', '__sil_Y_1')). Run as installed, the query matches no row.
  • Steps:
    1. placeholders::bind copies the plan's serialized DAG and, per slot, rewrites every form it knows:
      • an IN-list (or a bare value list in a selection property) whose items are all the slot's placeholders → the bound values, however many;
      • the rollup form col = p0 OR ... → col IN (v...);
      • for a comparison hole, the single placeholder → the one value.
    2. It returns the changed nodes and refuses any placeholder left anywhere.
    3. QueryEngine::evaluate_bound marks the changed nodes and every node above them.
      • A marked node is compiled over the bound copy with the view slots its installed run had.
      • A marked shared node is kept under (time, node, hash(binding)).
      • Every other node, including materialized views and unmarked shared nodes, is read exactly as for an HTTP query.
      • The result cache is bypassed.
  • Correctness: the planner guarantees that every placeholder-holding node is query-time and not kept across evaluations, so no precomputed state depends on the binding. The tests are:
    • the unit tests of each rewrite form and of the leftover guard;
    • the keyed-results unit test;
    • the three-mode e2e against exact answers, including q2 bound to {h0}, then {h2, h3}, then {h0} again at one evaluation time.
    • Mutation check: with the cache key ignoring the binding, the e2e fails (q2 bound to {h0} answers 1530, the {h1, h3} result; exact is 165).
  • Complexity: per bound query, one clone and rewrite of the DAG's JSON (O(plan size)) plus one compile per marked run. Unmarked work is shared as before.
  • Limits:
    • Bound runs are compiled every round. There is no compile cache keyed by binding.
    • Bound values cross as text (labels or a formatted value) and are converted to the placeholder's type: Utf8, Int64, Float64 or Timestamp; other types are refused.

SQL tables as series (new)

A Scan of Source::Table { table_ref } reads the series whose __name__ is the table: text columns are labels, the time column is the time, and the value column is the value. This is the minimal mapping that lets SIL plans run. A table needs exactly one numeric column, named value.

Decisions and open questions

Needs reviewer decision

  1. Pin to an unmerged planner head plus ported migration. This PR is draft-only. Merge order would be ASAPPlanner#1553 → chore: pin ASAPPlanner 566b35c and its asap_sketchlib d050037 (view format 5) #886 → this PR rebased (dropping the two port commits).
  2. Table → series mapping. A SQL table is stored as the samples of {__name__=table, labels...} with one value column. Alternative: a real columnar table source in the store (more numeric columns, no series semantics).
  3. Per-round compile. The bound run is recompiled every round. Alternative: cache compiled bound runs by binding, or give the executor a parameter-slot entry point that takes values without recompiling.
  4. Overrun, group-latency start, upstream failure, rate / WHEN, positional PromQL. Unchanged from the first part of this PR: rounds whose start passed are missed; group latency is measured from the round's actual start; a failed upstream skips its consumers; only rate == 1; position is resolved through the root's output schema.

Decided

  • 2026-12-03: the binding mechanism is the planner's placeholder substitution (SIL contract final schema). ParameterSlot is the default for --intent, and FilterGroupedResult stays as the fallback (coordinator).
  • 2026-12-03: a shared query-time node holding a placeholder is keyed by the binding too (coordinator).

Verification

Scope Result Notes
cargo clippy -p data_plane -p control_plane --all-targets -D warnings clean
cargo fmt --all --check clean
cargo test -p data_plane -p control_plane all passed (parity T2 needed the port of the planner-bump PR's retention fix; rerun alone: passed) everything else passed; 3 ignored as on main
intent_sil_modes 1 passed 3 planning modes x 2 rounds + 3 bindings at one time, exact
intent_rounds 1 passed IntentPlan JSON → round on a PromQL plan; lightcone guard
data_plane --lib 91 passed incl. 7 placeholder rewrites, keyed results, 14 loop tests

What the modes planned for the test intent (all three plan q1's per-host state as a materialized view; none kept a lightcone query, since intent_full judged it not cheaper):

Mode Plan queries Lightcone Views Shared query-time nodes
query-at-a-time 3 0 1 0
intent, on-demand holes 3 0 1 1 (q2/q3's scan of $Y)
intent, full 3 0 1 1

New tests:

  • placeholders::tests::*: each rewrite form, type conversion, the one-value comparison, and the leftover-placeholder error.
  • store::tests::bound_results_are_keyed_by_their_binding: per-binding results at one time.
  • intent::tests::parameter_slot_mode_binds_the_plan / parameter_slot_without_placeholders_fails.
  • every_planning_mode_answers_exactly_round_by_round (above).

Follow-ups

  • Exercise a lightcone plan (intent_full keeping per-host state for every value) end to end. This test's workload never makes it cheaper.
  • A compile cache for bound runs, or an executor entry point taking slot values.
  • rate < 1 and WHEN triggers.
  • A run.py arm driving --intent with the paced feeder.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi

zzylol and others added 9 commits December 3, 2026 07:25
The intent round loop's schedule, record and binding-step types, with
the bodies left as todo!, and the tests of the spec: empty binding skip,
chain of three, fan-out, diamond, duplicate values, upstream error and
timeout, round overrun, group latency, accuracy against the issued
binding, schedule validation, parameter-slot mode, and one round over a
real installed plan. Every test fails at the todo!.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IntentLoop::new refuses an unknown upstream or latency-group member, a
variable bound by two different upstream outputs, a variable read with
no dependency (or bound with no slot), a rate other than 1, and a
dependency cycle; it orders the queries topologically, keeping the
schedule's order among ready queries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_round runs the queries in order: each variable's binding is the
distinct values of its upstream answer's output column; a query is
skipped when an upstream failed or was skipped, or when a binding is
empty. The binding step (bind_and_run) filters the downstream query's
grouped answer by the bound values (BindMode::FilterGroupedResult);
BindMode::ParameterSlot fails with the reason until the plan has
parameter slots. Each run is bounded by the query timeout; the round
records each query's latency, bindings and answer, and each latency
group's span. The engine answers like an HTTP instant query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_rounds starts round r at start + r x interval and evaluates it at
first_evaluation_ms + r x interval. Rounds never overlap: a round ending
after the next round's start is marked overrun, and the rounds whose
start passed meanwhile are recorded as missed, not run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With --intent <schedule.json> and --intent-first-evaluation-ms, the
data plane runs the intent round loop against its own engine while it
ingests Remote Write as usual: round r starts --intent-delay-ms after
its evaluation time and is written to --intent-out as one JSON line
(per query status, latency, bindings and answer; per group its span).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The planner's intent output (IntentPlan, the SIL contract's final
schema v1) types the round loop reads, with the adapter to the loop's
schedule left as todo!; the end-to-end round now starts from that JSON.
Group latency follows the contract: from the round's start to the last
member's end (group_latency_runs_from_the_round_start fails: the loop
still measures from the first member's start).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IntentSchedule::from_intent_plan reads one intent of the planner's
IntentPlan: each query's text is plan.query_texts[query_index], and each
dependency's output_position is resolved through the upstream root's
output schema to a label name, or __value__ for the value column. Group
latency is now measured from the round's start to the last member's
end, as the contract defines L_G.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--intent now takes the planner's IntentPlan with --intent-name; the
harness doc installs its plan and runs the named intent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol zzylol added enhancement New feature or request area: data plane Runtime ingestion, storage, and query-serving data paths integration: ASAPPlanner ASAPPlanner API, IR, candidate, and selected-plan integration labels Dec 3, 2026
zzylol and others added 11 commits December 3, 2026 08:39
ASAPPlanner#1553's head (3ef265d) plans SIL intents; its sketch library
pin (c5f7866) now holds the merge-in-place DDSketch the backend patched
in, so the patch goes. The executor's state view API was renamed:
StateColumn::from_mapped -> from_views, family_has_mapped_form ->
family_has_view_layout, and per-state view bytes now come from a state
column (segment::column_views). SketchAlgorithm variants take the
Planner's names (KLL, CountMinSketch, ...). Adds asap-frontend-sil as a
dev-dependency for the intent end-to-end test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in three modes

Failing tests for binding an intent query's holes in the plan:
- placeholders: IN-lists and the rollup form `col = p0 OR ..` take the
  bound values; a comparison takes exactly one; values convert to the
  placeholder's type; a placeholder left in an unknown form is an error.
- QueryTimeResults keeps a node's result under each binding apart.
- The loop hands the runner each slot's placeholders and values
  (BindMode::ParameterSlot); a slot without placeholders fails.
- intent_sil_modes: a SQL intent planned by the Planner as
  query-at-a-time, intent with on-demand holes and full intent, run two
  rounds each, answers exact; q2 bound to other hosts at one time.
The unit tests fail at todo!; the end-to-end test fails because the data
plane does not store SQL tables yet.

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

placeholders::bind rewrites the serialized DAG for each slot:
`col IN (p..)` and bare placeholder lists take the bound values, the
rollup form `col = p0 OR ..` becomes `col IN (v..)`, a comparison takes
its one value; values convert to the placeholder's type. It returns the
nodes that changed, and refuses a placeholder left anywhere in the plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shared query-time node computed under an intent's binding is kept
under (time, node, binding hash), apart from its unbound result and from
its result under any other binding at the same time
(QueryTimeResults::get_or_compute_bound).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Scan of a SQL table (Source::Table) reads the series whose __name__ is
the table: its text columns are their labels, its time column their time
and its `value` column their value. Before, the data plane refused any
source but a PromQL time series, so no SQL plan (and no SIL intent) ran.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The planner API changes between 1d527bc and the SIL head, as the open
planner-bump PR adapts them on the new crate layout, applied to this
branch's layout in place of the partial adaptation in the pin commit:
- storage: view bytes from each window batch's state column, cold reads
  via StateColumn::from_views, family_has_view_layout (VIEW_STATES).
- state_codec: the compact DDSketch codec follows the new 64-byte
  DDSketch view head (no sum, min, max); FORMAT_VERSION 4 -> 5.
- query: a shared query-time slot carries the plan's plan_id and a
  view_state_key, now required MaterializedView fields.

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

The first three-mode workload planned identically in every mode (no
view, no shared node). Now q2 and q3 read `$Y` over the same table and
the declared data is at production scale: q1's per-host state is kept,
and the jointly planned modes share the query-time scan holding `$Y`'s
placeholders, so q2 bound to other hosts at one evaluation time checks
the binding keys that shared result. (Checked by mutation: with the key
ignoring the binding, q2 bound to {h0} answers the {h1, h3} result.)
A round listing one of the planner's lightcone queries is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BindMode::ParameterSlot, now the default for --intent: each round the
loop hands the engine each slot's placeholders and bound values
(QueryRunner::answer_bound). The query engine binds a copy of the plan
(placeholders::bind over the plan's serialized DAG; the DAG itself is
not Send), compiles the runs of the nodes that depend on the binding
over it with their usual view slots, keeps a shared one under the
binding's key, reads every other node as usual, and bypasses the result
cache (QueryEngine::evaluate_bound, EngineHandle::evaluate_bound). A
slot without placeholders fails rather than running unbound; a round
listing a lightcone query is refused. FilterGroupedResult stays as the
fallback.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pending planner-bump PR's fix to
push_precompute_stores_the_window_paths_view_rows, which the new Planner
pin makes fail on windows older than a view's retention that linger by
timing: both sides are cut to the windows kept by retention.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol zzylol changed the title feat(data_plane): intent round loop: run a planned SIL intent round by round feat(data_plane): intent round loop with parameter-slot binding: run a planned SIL intent round by round Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request integration: ASAPPlanner ASAPPlanner API, IR, candidate, and selected-plan integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant