Skip to content

feat(data_plane): one intent round loop per clock; dependents triggered by the upstream's result - #901

Draft
zzylol wants to merge 5 commits into
feat/intent-round-loopfrom
feat/intent-trigger-rate
Draft

zzylol wants to merge 5 commits into
feat/intent-round-loopfrom
feat/intent-trigger-rate

Conversation

@zzylol

@zzylol zzylol commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: an intent's queries need not share one rhythm (an independent query has its own EVERY; a dependent query runs on its upstream's clock), but the round loop ran one interval per intent and refused any trigger rate other than 1.
  • Change: one round loop per clock: IntentSchedule::per_clock_from_intent_plan gives one schedule per intent_rounds entry (the planner now writes one entry per clock), and run_clocks runs them concurrently. The trigger rate is a planner cost input only: the loop never reads it; a dependent query is not_triggered when its binding is empty (the upstream's WHERE/HAVING/LIMIT is the trigger).
  • Effect (test each_clock_runs_its_queries_exactly): an intent with q1 every 10 s (top 2 hosts), q2 dependent with WITH RATE 0.2, q3 every 20 s, planned jointly by ASAPPlanner#1553 (61679203), installs as one plan and runs as two loops (10 s: q1, q2; 20 s: q3); every answer equals the exact one. Before: the planner output for this intent did not exist (one interval per intent), and a rate != 1 was refused at load.

Review guide

  • Base: feat/intent-round-loop (feat(data_plane): intent round loop with parameter-slot binding: run a planned SIL intent round by round #900, draft); stacked on it. Draft. Pins ASAPPlanner#1553's head b9c7fdfa (unmerged; was 61679203: adds the binder column fix 98bb53b and Int64 exact SUM/MIN/MAX b9c7fdf).
  • Commits:
    1. 53b670ec + 80b05f68: tests for running a rate as every k-th round, then their revert. Superseded by the user's decision that the data plane never uses the rate; kept for history (squash on merge).
    2. 0bcd8cb0 tests + interface stubs only (review first), data_plane/src/intent.rs tests B1–B8. Every new test failed for the expected reason (e.g. B1: "rate 0.1 is not supported"; B5: one schedule instead of two).
    3. c30ebf69 implementation, the pin bump, a two-clock e2e test, docs.
    4. fb773b89 repin to b9c7fdfa (pin files only).
  • Read first: run_clocks, rounds_per_clock, per_clock_from_intent_plan, and the not_triggered / group-completeness logic in IntentLoop::run_round.
  • Mechanical: Cargo.toml/Cargo.lock pin, e2e tests calling per_clock_from_intent_plan(..).remove(0), the harness README.

Behavior: before → after

The user writes (SIL; planned by ASAPPlanner plan_intents):

INTENT triage;
q1 EVERY 10s: ($Y, _) := SELECT host, sum(value) AS s FROM flows
    WHERE ts > $now - INTERVAL '100 seconds' GROUP BY host ORDER BY s DESC LIMIT 2 REQUIRE EXACT;
q2: WITH RATE 0.2 SELECT user, sum(value) AS s FROM flows
    WHERE host IN $Y AND ts > $now - INTERVAL '100 seconds' GROUP BY user REQUIRE EXACT;
q3 EVERY 20s: SELECT user, max(value) AS m FROM flows
    WHERE ts > $now - INTERVAL '100 seconds' GROUP BY user REQUIRE EXACT;
before after
planner output (not expressible: one EVERY per intent) intent_rounds: [{triage, 10000, [q1, q2]}, {triage, 20000, [q3]}], rate on q2 for the record
data_plane --intent … --intent-rounds 6 one loop; a rate != 1 refused at load two loops, concurrently: 10 s clock rounds 0..5, 20 s clock rounds 0..2, same first evaluation time
q2 in a round where q1 returns no host skipped_empty_binding not_triggered (also for queries below it)
group (q1, q2) in that round complete: false complete: true (a not-triggered member is not missing)
rounds.jsonl line {round, evaluation_ms, …} {round_interval_ms, round, evaluation_ms, …}

Serves the SIL eval: intents whose queries run at different rhythms, and the dependent queries' real trigger frequency (measured, not scheduled).

Interfaces

Files at c30ebf69.

data_plane/src/intent.rs

 /// One query of an intent (the type stays).
 pub struct IntentQuery {
     pub query_id: String,
     pub query: String,
     pub depends_on: Vec<Dependency>,
     pub bind_slots: Vec<BindSlot>,
-    /// Fraction of rounds it runs in; only 1 (every round) is supported.
-    pub rate: f64,
     pub skip_if_empty: bool,
 }
 /// What happened to one query in one round (the type stays).
 pub enum QueryStatus {
     Answered,
-    /// A binding it reads was empty: not run.
-    SkippedEmptyBinding,
     /// An upstream query failed or was skipped for a failure: not run.
     SkippedUpstream,
     Failed,
+    /// A binding it reads is empty, or an upstream was not triggered: the upstream's result did not trigger it.
+    NotTriggered,
 }
 /// One latency group in one round (the type stays).
 pub struct GroupRecord {
     pub query_ids: Vec<String>,
     pub max_latency_ms: f64,
     pub latency_ms: Option<f64>,
-    /// Whether every member ran.
+    /// Whether every member ran or was not triggered.
     pub complete: bool,
     pub met: bool,
 }
 /// One round (the type stays).
 pub struct RoundRecord {
+    /// The interval of the clock this round belongs to; `(round_interval_ms, round)` names a round.
+    pub round_interval_ms: u64,
     pub round: u64,
     pub evaluation_ms: i64,
     pub status: RoundStatus,
     pub start_lag_ms: f64,
     pub duration_ms: f64,
     pub overrun: bool,
     pub queries: Vec<QueryRecord>,
     pub groups: Vec<GroupRecord>,
 }
 /// One planned intent query, as the planner writes it (the type stays; `rate` is no longer read).
 pub struct PlannedIntentQuery {
     pub query_id: String,
     pub query_index: usize,
     pub depends_on: Vec<PlannedDependency>,
     pub bind_slots: Vec<PlannedBindSlot>,
-    pub rate: f64,
     pub skip_if_empty: bool,
 }
 impl IntentSchedule {
-    pub fn from_intent_plan(intent_plan: &IntentPlan, intent_name: &str) -> anyhow::Result<Self>;
+    /// One schedule per clock (`intent_rounds` entry) of the intent, in order; error when it has none.
+    pub fn per_clock_from_intent_plan(intent_plan: &IntentPlan, intent_name: &str) -> anyhow::Result<Vec<Self>>;
 }
+/// The rounds each clock runs so that every clock covers `rounds` rounds of the fastest: ceil(rounds × min / interval).
+pub fn rounds_per_clock(intervals_ms: &[u64], rounds: u64) -> Vec<u64>;
+/// Runs every clock's rounds concurrently from one first evaluation time; `emit` gets every round of every clock.
+pub async fn run_clocks<R: QueryRunner>(loops: &[IntentLoop], runner: &R, first_evaluation_ms: i64, rounds: u64, start: Instant, emit: impl FnMut(RoundRecord) + Send);

Removed: IntentQuery::rate / PlannedIntentQuery::rate (the loop never uses the rate; serde ignores the planner's field), from_intent_plan (an intent may have several clocks).

data_plane CLI: --intent runs one loop per clock; --intent-rounds counts the fastest clock's rounds; rounds.jsonl lines carry round_interval_ms; status not_triggered replaces skipped_empty_binding.

Usage (as each_clock_runs_its_queries_exactly runs it):

// The planner's output for the SIL text above (two clocks: 10 s {q1, q2}, 20 s {q3}).
let plan: IntentPlan = planned_text(TWO_CLOCKS, IntentPlanningMode::IntentFull).await;
// One schedule per clock: [(10_000, [q1, q2]), (20_000, [q3])]; q2's `rate` 0.2 is not read.
let schedules = IntentSchedule::per_clock_from_intent_plan(&plan, "triage")?;
// The plan installed on a data plane fed the `flows` rows.
let state = install(&plan, &tables).await;
// One loop per clock, binding holes in the plan's query-time nodes.
let loops: Vec<IntentLoop> = schedules.into_iter()
    .map(|s| IntentLoop::new(s, BindMode::ParameterSlot, Duration::from_secs(30)))
    .collect::<anyhow::Result<_>>()?;
// In production `run_clocks(&loops, &state.engine, t0, rounds, start, emit)` runs both concurrently;
// here one round each: q1 answers the 2 top hosts, q2 runs since $Y is non-empty, and q3 runs on its own clock.
let fast = loops[0].run_round(&state.engine, 0, EVALUATION_MS).await; // round_interval_ms 10_000; q1, q2 exact
let slow = loops[1].run_round(&state.engine, 0, EVALUATION_MS).await; // round_interval_ms 20_000; q3 exact

Algorithm changes

Triggering. Before: a dependent query with an empty binding was skipped_empty_binding; a query below a skipped one was skipped_upstream; groups with a skipped member were incomplete. After: (1) empty binding → not_triggered; (2) an upstream not_triggered → not_triggered (an upstream failure still → skipped_upstream); (3) a group is complete iff every member ran or was not triggered; (4) a group with no triggered member emits no record that round (no latency sample).

Clocks. run_clocks joins one run_rounds per clock (one futures::join_all on the caller's task, so a slow clock delays only its own rounds' starts within the shared runtime; an overrun is per clock as before). Clock c runs ceil(rounds × Δ_min / Δ_c) rounds; all clocks start at --intent-first-evaluation-ms.

Decisions and open questions

  • Rate not read (user 12-03): the data plane executes the intent; the rate only steers the planner (cost of the dependent's requests, lightcone or not).
  • skipped_empty_binding → not_triggered (rename, not a new status): an empty binding is the trigger saying no.
  • Group completeness counts not-triggered members as done; a group with no triggered member has no record (rec.; alternative: a record with met: false, which would bias met fractions).
  • Rounds per clock: --intent-rounds counts the fastest clock; every clock covers the same span (alternative: an --intent-duration-ms).
  • First evaluation alignment (open): all clocks start at the same T_0; the harness should pass a T_0 that is a multiple of every interval (phase 0 in the planner's sense). The loop does not check it.

Verification

Scope Result
cargo test -p data_plane --lib 98 passed (20 in intent::, incl. B1–B8)
cargo test -p data_plane --test intent_rounds --test intent_sil_modes 1 + 2 passed (new each_clock_runs_its_queries_exactly)
cargo test -p data_plane --no-fail-fast (at fb773b8) 27 targets passed; ingest_shards::a_shard_running_ahead_does_not_close_windows_early failed once in an earlier full run and passed 3 times since (timing flake, unrelated)
cargo clippy -p data_plane --tests --bins -- -D warnings, cargo fmt --check clean

New tests: B1 the loop loads and runs a schedule with rate 0.1 on every round with a non-empty binding; B2 empty binding → not_triggered; B3 a query below a not-triggered query is not triggered; B4 a not-triggered member keeps its group complete; B5 two clocks → two schedules; B6 records name their clock; B7 rounds per clock cover one span; B8 two clocks run concurrently at their own evaluation times (paused time); e2e two clocks answer exactly.

Follow-ups

  • Harness summary per clock (round_interval_ms) and the measured trigger frequency per dependent query (to compare with the planner's rate).

🤖 Generated with Claude Code

zzylol and others added 4 commits December 3, 2026 17:00
Tests for running planned_rate = 1/k deterministically: a query runs in
rounds r % k == 0 (from the first evaluation), is recorded not_triggered
otherwise, downstream k must be a multiple of upstream k, when_condition
is recorded not evaluated, and group latency covers the members that ran.
Adds only the interface stubs the tests need; the 10 new tests fail until
the loop implements them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (failing)"

This reverts commit 53b670e. Superseded (user, 2026-12-03): the data
plane never reads the trigger rate; a dependent query is triggered iff its
bound input set is non-empty in that round, so there is no every-k-th-round
schedule to test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d loop per clock (failing)

Tests for: the loop never reads the trigger rate (a planning input); a
dependent query with an empty binding, or below a not-triggered query,
is not_triggered; a not-triggered member leaves its latency group
complete; one schedule per intent_rounds entry (clock); round records
name their clock; every clock covers the fastest clock's span; clocks
run concurrently. The rate row of invalid_schedules_are_refused goes.

Interface stubs only: QueryStatus::NotTriggered (unused),
RoundRecord::round_interval_ms (0), per_clock_from_intent_plan (the
first schedule only), rounds_per_clock (rounds for every clock),
run_clocks (the first clock only).

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

The planner's intent output now has one intent_rounds entry per clock
(an intent's queries on one interval). per_clock_from_intent_plan
(replacing from_intent_plan) gives one schedule per entry, and
run_clocks runs their round loops concurrently from one first
evaluation time, each clock covering the fastest clock's span
(--intent-rounds counts the fastest clock's rounds). Round records name
their clock (round_interval_ms).

The trigger rate is a planner cost input only: the loop no longer reads
or refuses it. A dependent query is not_triggered (was
skipped_empty_binding) when a binding is empty or an upstream was not
triggered; such a member leaves its latency group complete, and a group
with no triggered member has no record that round.

Pins ASAPPlanner 61679203 (#1553 head: per-query intervals, one entry
per clock). New e2e: an intent on two clocks planned jointly answers
exactly on each.

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
… exact SUM/MIN/MAX)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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