Skip to content

fix: align replay-query quantile window with warm tier precompute window (④ ε bound) - #347

Merged
zzylol merged 1 commit into
mainfrom
fix/quantile-window-alignment
May 8, 2026
Merged

zzylol merged 1 commit into
mainfrom
fix/quantile-window-alignment

Conversation

@zzylol

@zzylol zzylol commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the DDSketch ε-bound mismatch for criterion ④ (Accuracy) in the MVP demo (issue #46). After PR #345 + PR #111, headline-2026-05-06 reported quantile rel_err mean=0.126, max=0.172 for 343 quantile rows — 12-17x over the controller-emitted ε=0.01. Sketch state itself is bounded by ε, so something else was inflating the error.

Root cause

Window mismatch between warm tier and replay query.

  • The warm-tier ASAPQuery streaming pre-compute runs with windowSize: 30 (see deploy/configs/backend-streaming.yaml). The warm response stamps this in its infos: precompute_window: [..) ms (width 30000 ms).
  • The replay queries used [1m] (quantile_over_time(0.99, http_requests_total_latency_ms[1m])).
  • Warm returned a 30s p99 while archive (Thanos) honored [1m], so the two sides computed over different data. The sketch's ε bound says nothing about agreement when the inputs differ.

Fix (Option 1 — workload-spec change)

Align the replay-query ranges to match the warm pre-compute window. Two surfaces need to move in lock-step:

  • deploy/configs/mvp-workload.yaml — controller workload spec. Analyzer parses the range string to derive time_window, which threads through to the agent's window_duration and the ASAPQuery aggregation windowSize.
  • deploy/scripts/run_mvp_demo.sh — controller plan POST body (line 404) and the inline replay-queries.json heredoc (lines 564, 567) the replay client issues during the soak.

Both DDSketch (http_requests_total_latency_ms) and KLL (request_size_bytes) quantile entries change from [1m] to [30s].

This was the cleanest of the three options listed in the bug — Option 2 (controller-side window calculation) would have re-touched controller/src/planner/, and Option 3 (backend infers query range) is out of scope for the MVP. Option 1 also matches the design intent that the planner pre-computes for the workload.

Expected post-fix rel_err

Family Pre-fix mean ε bound Post-fix expectation
DDSketch 0.126 0.01 ≤ 0.01 (sketch's own approximation only)
KLL 0.126 0.005 (1/k, k=200) ≤ 0.005

After alignment, the only error left is the sketch's own approximation. Both are well within their respective bounds.

What's pinned

New test file deploy/scripts/tests/test_window_alignment.py (6 tests, all passing) pins both halves of the alignment:

  1. Static config check — parses mvp-workload.yaml, the run_mvp_demo.sh heredoc, and backend-streaming.yaml, asserting every quantile replay range equals the warm windowSize. Any future edit that desyncs one surface fails this test.
  2. End-to-end rel_err — synthesizes a warm answer at the ε boundary and pipes it through accuracy_reduce.py, asserting rel_err ≤ ε. The negative twin reproduces the pre-fix scenario (warm 12.6% off truth) and confirms rel_err > ε, documenting the failure mode.

Test plan

  • pytest deploy/scripts/tests/test_window_alignment.py — 6 passed
  • No new failures in deploy/scripts/tests/ (the 13 failures in test_accuracy_reduce.py and test_mvp_report.py pre-exist on origin/main — they reference gorilla_archive / per-sketch labels other parallel agents are addressing)
  • Controller cargo build --release clean (no controller code changed; build is a sanity check only)
  • Re-run run_mvp_demo.sh end-to-end and confirm accuracy.csv rel_err mean drops below ε

Closes #46 (criterion ④ ε-bound mismatch).

🤖 Generated with Claude Code

…sue #46)

Bug 12 fix (DDSketch ε-bound mismatch). The headline-2026-05-06 demo
reported DDSketch quantile rel_err mean=0.126, max=0.172 — 12-17x above
the controller-emitted ε=0.01 bound — even though the sketch state
itself is bounded by ε. Root cause: window mismatch between the warm
tier and the replay query.

The warm-tier ASAPQuery streaming pre-compute is configured with
`windowSize: 30` (`deploy/configs/backend-streaming.yaml`); the warm
response confirms this with `precompute_window: [..) ms (width
30000 ms)`. The MVP demo's replay queries asked for `[1m]`, so the
warm tier returned a 30s p99 while the archive (Thanos) honored the
`[1m]` range. The two sides were computing over different data — the
sketch's ε bound is irrelevant when the inputs themselves disagree.

Fix: align the two quantile replay ranges (DDSketch `http_requests_
total_latency_ms`, KLL `request_size_bytes`) from `[1m]` to `[30s]`,
matching the warm pre-compute window. The change touches both
surfaces that need to stay in lock-step:

  - `deploy/configs/mvp-workload.yaml` — controller workload spec.
    The analyzer parses the range string to derive `time_window`,
    which the planner threads through to the agent's `window_duration`
    and the ASAPQuery aggregation's `windowSize`.

  - `deploy/scripts/run_mvp_demo.sh` — both the controller plan POST
    and the inline `replay-queries.json` heredoc the replay client
    issues against the backend during the soak.

This is Option 1 from the bug report (workload-spec change) — the
cleanest of the three because it matches the design intent that the
planner pre-computes for the workload, and it touches only two
config files (no controller-code change needed).

New test file `deploy/scripts/tests/test_window_alignment.py` pins
both halves of the alignment:

  1. Static config check: parses `mvp-workload.yaml`,
     `run_mvp_demo.sh`'s embedded JSON, and `backend-streaming.yaml`,
     and asserts every quantile replay range equals the warm
     `windowSize`. Catches future drift on any single surface.

  2. End-to-end rel_err: synthesizes a warm answer at the ε boundary
     and pipes it through `accuracy_reduce.py`, asserting
     rel_err ≤ ε. The negative twin synthesizes the pre-fix
     misaligned-window scenario and confirms rel_err > ε,
     documenting the failure mode.

Expected post-fix rel_err: dominated by the sketch's own ε bound
(≤ 0.01 for DDSketch, ≤ 0.005 for KLL rank-error), down from the
0.126 mean observed pre-fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 305a32d into main May 8, 2026
@zzylol
zzylol deleted the fix/quantile-window-alignment branch May 9, 2026 18:00
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.

MVP demo: test-first validation of ASAPCollector + ASAPQuery-backend

1 participant