Skip to content

test(selection): latency bounds under cost model 1 (tests only) - #1572

Draft
zzylol wants to merge 1 commit into
eval/2026-12-plannerfrom
test/cm1-latency-bounds
Draft

zzylol wants to merge 1 commit into
eval/2026-12-plannerfrom
test/cm1-latency-bounds

Conversation

@zzylol

@zzylol zzylol commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: cost model 1 (UsageOverTime) ignores SIL latency targets. In an intent evaluation at 4x scale, three p99 queries with LATENCY <= 1000ms and GROUP ... LATENCY <= 2000ms were merged into one shared exact raw scan at query time. The planner predicted 3,627 ms per query and measured 2.7 s. The plan won because it cost less: 779 vs 2,283 cost/s.
  • Change: tests only. They specify how cost model 1 respects latency targets, at three levels:
    • Per query: query-time latency l_q <= max_latency_ms.
    • Per group, by Graham's list-scheduling bound: CP_G + W_G / P_eff <= L_G.
    • Per round: W_round / P_eff <= interval.
  • Effect: 17 integration tests and 1 SIL lowering test. 13 integration tests and the SIL test fail today for the intended reason; 4 pass (the oracle self-check and 3 regression guards). There is no production change.

Review guide

  • Base: eval/2026-12-planner (fa22fa2). Draft, not for merge. The implementation waits for approval of the formulation and the open questions below.
  • Read first: the module doc and the oracle in crates/integration-tests/tests/cm1_latency_bounds.rs (Combination, Bounds, assert_matches_oracle).
  • Mechanical: one mod line in tests/main.rs.
  • Expected plans come from a brute-force oracle, not from the selection MILP:
    1. Each scan/chain combination is planned alone, with the other plans excluded through excluded_candidates.
    2. The oracle reads each forced plan's report: query_execution_ms, cost_per_second, per-node query_ms_per_step, and ingest/precompute busy cores.
    3. It keeps the cheapest combination that meets every bound.
  • Bounds are swept between consecutive oracle values, so no sweep point sits on a threshold. Each test asserts its instance first (the bound binds; the dependency, background or sharing changes the oracle). Those assertions pass today.

Behavior: before → after

The workload is max_over_time(m[5m]) every 10 s with max_latency_ms set between its two plans: a query-time scan (30.3 ms, 3.03 cost/s) and an ingestion-time chain (0.13 ms of query time, about 100 cost/s).

selected plan
before (base) the scan, 30.3 ms, over the bound
after (these tests) the chain, with query_execution_ms within the bound. A bound below both plans is an error naming LatencyBoundExceeded.

Interfaces

None in this PR (tests only). The tests write two proposed inputs as JSON. Both are refused at load today, which is how those tests fail. Their definitions await approval; see the decisions below.

Algorithm changes

None in this PR. The proposed formulation is under Decisions.

Decisions and open questions

Needs reviewer decision. The full list is in the test plan (A1–A12). The main items:

  1. A1. Bounded latency. Bound query_execution_ms (E_q) under cost model 1, not cost model 3's L_q = F_q + E_q.
    • Each summary read in the 4x plan has a freshness wait of about 1,163 ms (742 queueing + 421 refresh). Bounding L_q at 1,000 ms rejects every plan.
    • Measured latency excludes that wait.
  2. A2. Dependencies. A proposed workload field:
     pub struct QueryWorkload {
         pub language: QueryLanguage,
         pub query_batch: Option<Vec<BatchEntry>>,
         pub repeating_queries: Option<Vec<RepeatingEntry>>,
         pub group_latency_bounds: Vec<GroupLatencyBound>,
         pub optional_query_count: usize,
    +    /// Query `dependent` starts after query `upstream` returns (a SIL
    +    /// dependent after its binder); Stage 3 reads it for a group's
    +    /// critical path. Default empty.
    +    pub query_dependencies: Vec<QueryDependency>,
     }
    +/// One dependency, as positions in `QueryWorkload::entries`.
    +pub struct QueryDependency { pub upstream: usize, pub dependent: usize }
    • JSON form: "query_dependencies": [{"upstream": 0, "dependent": 1}].
    • lower_intents fills it from depends_on.
    • select_plan takes it beside group_latency_bounds. It has two callers.
  3. A3. Cores P. A proposed field for the cores shared by ingest, precompute and query work. Without it there is no W/P term and no round check.
     pub struct DataPlaneExecution {
    +    /// Cores the data plane's ingest, precompute and query work share;
    +    /// `P_eff = cpu_cores` less the plan's ingest and precompute cores.
    +    /// `None` (default): no group work term and no round check.
    +    pub cpu_cores: Option<u32>,
     }
    (The existing fields of DataPlaneExecution are unchanged and omitted here; see crates/cost/src/model.rs.)
  4. A4. Linear form. W_G + L_G·B(x) + P·CP_G <= P·L_G is sufficient: it is exact when B = 0 and conservative by CP·B otherwise.
  5. A5. Exclusive alternatives count in W at their fraction p. A node they share counts at min(1, Σp). CP takes the longest alternative. This makes the bound an expected-work bound, not a worst-case one.
  6. A6. Without P, a group still enforces CP_G <= L_G.
  7. A10. Errors:
    • a per-query or group bound no plan meets: NoValidCandidate([LatencyBoundExceeded]);
    • a round that cannot fit: LatencyOverRepeatInterval.

Calibration (do first). Predicted vs measured per-query latency from the evaluation's runs: 816 query-run points. The median ratio measured/predicted is 1.94, with p10 0.40 and p90 33.5; 60 % of the points are off by more than 2x. The breakdown:

  • Full raw scans (the case above): close. The ratio is 0.75–0.89.
  • Raw scans filtered by a bound IN-list: over-predicted 25–50x. For example, 3,341 ms predicted vs 59–78 ms measured.
  • Some dependents' raw reads: under-predicted 100–600x. For example, 43 ms predicted vs 12 s measured.
  • Sub-millisecond summary reads: measured at 2–35 ms. This points to a per-request floor the cost inputs do not have.

These should be fixed, or fed into CostInputs, before the constraints are relied on.

Decided: 2026-12-05, the three-step formulation and no queueing model.

Verification

scope passed failed ignored newly failing vs base notes
cargo test -p asap-integration-tests --test integration cm1_latency_bounds 4 13 0 new tests every failure is the intended one
cargo test -p asap-planner --test planner dependencies_lower_to_query_indices 0 1 0 new test query_dependencies is null
cargo fmt --all -- --check clean

Why each test fails today:

tests failure
L1, L2, L4, L5, L7, G5 assertion: cost model 1 enforces no bound
G1, G3, G4, G6, R1 cpu_cores refused at load
G2, X2 query_dependencies refused at load

The 4 tests that pass today:

  • O1: the oracle's arithmetic on hand-computed values.
  • L3: a loose bound changes nothing.
  • L6: an optional (lightcone) query's bound is not enforced.
  • X1: without bounds, the plan is the cheapest combination.

Existing tests that phase 4 replaces, untouched here: lowest_mean_latency.rs::r1_cost_model_1_enforces_no_latency_bound and group_latency.rs::g3_cost_model_1_enforces_no_group_latency.

Follow-ups

  • Phase 4 implementation, after approval.
  • Calibration fixes:
    • IN-list and series-key selectivity for query-time scans under a bound IN-list;
    • a per-request latency floor;
    • the dependents' under-prediction.
  • Not covered:
    • several clocks (A8);
    • query_at_a_time mode, where groups span separately planned queries (A9);
    • moving cost model 3's group semantics to Graham's bound (A12).

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bpWvKMxYBvtAgpDYGp

Acceptance tests for cost model 1 respecting each query's max_latency_ms
(query-time latency), each group's bound by Graham's list-scheduling
bound (CP_G + W_G / P_eff <= L_G) and each round's interval. Expected
plans come from a brute-force oracle over forced plan combinations, not
the selection MILP. The new inputs (cpu_cores, query_dependencies) are
written as JSON, so the tests compile today and fail until implemented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bpWvKMxYBvtAgpDYGp
@zzylol zzylol added enhancement New feature or request cost-model Cost formulas, statistics, ranking, and selection optimizer Workload optimization and plan selection testing Corpus, regression, differential, or benchmark tests labels Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cost-model Cost formulas, statistics, ranking, and selection enhancement New feature or request optimizer Workload optimization and plan selection testing Corpus, regression, differential, or benchmark tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant