Skip to content

test(snapshots): fail on any plan change under STRICT_SNAPSHOTS (nightly); regenerate the 48 stale snapshots - #1550

Merged
zzylol merged 2 commits into
mainfrom
fix/1541-strict-snapshots
Nov 28, 2026
Merged

zzylol merged 2 commits into
mainfrom
fix/1541-strict-snapshots

Conversation

@zzylol

@zzylol zzylol commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: the snapshot harnesses passed a plan that changed at the committed plan's cost, so a PR that moved a tie left the committed snapshots stale. Since perf(stage2): OneEvaluation only for results read twice in one evaluation (search-space pruning rule 5) #1529, chains-10m-5m-3m-10s-mvp selects KLL k = 2863 on its 5-minute chain while the committed file says k = 1404, and the nightly run stays green.
  • Change: with STRICT_SNAPSHOTS=1, which the nightly Corpus snapshots workflow now sets, any difference from a committed snapshot fails. Without it (local runs) the equal-cost pass stays, with a note on stderr. The 48 stale snapshots are regenerated from what main selects.
  • Effect: the PR that moves a tie must update the snapshots; the next PR that regenerates them no longer picks up unexplained plan changes. All 48 regenerated snapshots keep their cost_per_second exactly.

Closes #1541.

Review guide

Base: main (after #1549). Read first:

  1. crates/planner-cli/tests/corpus_snapshots.rs: strict_snapshots, changed_snapshot_passes, and the new test equal_cost_plan_changes_fail_when_strict.
  2. crates/planner-cli/tests/sketch_plan_snapshots.rs: the same switch in sketch_plans_match_snapshots.
  3. .github/workflows/corpus-snapshots.yml: STRICT_SNAPSHOTS: 1 on the check step.
  4. docs/develop_docs/planner-snapshots.md: new "Strict and local runs" section; the "What a snapshot holds" list now matches what the harness writes (it still named display_name, proven_optimal, search_status and tumbling_window_retention_ms, which snapshots no longer hold).

Mechanical: the 48 regenerated *.json snapshots (13 under corpus_snapshots/o11y_bench/, 35 under sketch_plan_snapshots/), written by UPDATE_SNAPSHOTS=1 and summarized under Snapshot changes below.

Behavior: before → after

The committed chains-10m-5m-3m-10s-mvp.json (KLL k = 1404 on node 1), checked on main:

STRICT_SNAPSHOTS=1 cargo test --release -p asap-planner-cli --test corpus_snapshots -- --ignored sketch_plans_match_snapshots
Before After
Nightly workflow (equal-cost change) passes; chains-10m-5m-3m-10s-mvp: plan changed at the committed plan's cost; passes fails: chains-10m-5m-3m-10s-mvp: plan changed at .materialized_views[0].plan_id: - "1dbad9b6..." + "e6bedd52...", regenerated file uploaded
Local run without STRICT_SNAPSHOTS passes, note on stderr unchanged: passes, note says (fails with STRICT_SNAPSHOTS=1)
Cost, accuracy, warning or error change fails fails (unchanged)

The first differing path is the view's plan_id, because the walk visits keys in sorted order and materialized_views sorts before selected; the same file also differs at node 1's KLL k (1404 → 2863).

This serves correctness of the test suite: a committed snapshot is the plan main selects.

Interfaces

None in the planner. The test harness gains one environment variable, STRICT_SNAPSHOTS (any value turns it on), and two private helpers:

crates/planner-cli/tests/corpus_snapshots.rs

+/// Whether equal-cost plan changes fail: `STRICT_SNAPSHOTS` is set, as the
+/// nightly workflow sets it.
+fn strict_snapshots() -> bool;
+
+/// Whether a snapshot whose text changed from `expected` to `actual` still
+/// passes: never when `strict`; otherwise when both select plans of the
+/// same cost ([`equal_cost_plan`]).
+fn changed_snapshot_passes(expected: &str, actual: &str, strict: bool) -> bool;

Usage: the nightly workflow runs cargo test --release --locked -p asap-planner-cli --test corpus_snapshots -- --include-ignored with STRICT_SNAPSHOTS: 1. For each corpus query and each sketch plan workload, the harness plans it with asap_planner --run-until stage3, renders the snapshot, and compares it with the committed file; changed_snapshot_passes(expected, actual, strict = true) returns false for any changed text, so the test fails, names the first differing line (corpus) or JSON path (sketch plans), and writes the regenerated snapshot and its asap_planner document for upload. Locally, strict = false keeps the equal-cost pass.

Algorithm changes

None. Stage 3 selection is unchanged; the tie-break fallback (option 3 of #1541) was not needed, see Decisions.

Decisions and open questions

Needs reviewer decision: None.

Decided (2026-11-28):

  • The stale snapshots come from code, not machines. Regenerating at fix: seal KLL and Count-Min into view layouts; cost sketch states as held #1518, which last wrote them, reproduces every committed file byte for byte.

  • Option 1 of [Bug] Snapshot tests pass silently when the selected plan changes at equal cost, so committed snapshots go stale #1541 (strict on CI, lenient locally), as the issue recommends. Rejected: report-only (option 2, easy to miss) and a deterministic Stage 3 tie-break (option 3), because the selection is already deterministic (below).

  • Determinism check. main was regenerated with UPDATE_SNAPSHOTS=1 twice on each of three eval hosts, the second run pinned to 4 cores (taskset -c 0-3). All runs wrote byte-identical snapshots. The Corpus snapshots workflow was also run on this branch (on the GitHub runner, with STRICT_SNAPSHOTS=1) against the regenerated snapshots: passed with the regenerated snapshots (byte-identical to the eval hosts'). No tie-break or field normalization was added.

  • One switch, set explicitly. STRICT_SNAPSHOTS alone turns strict mode on; the generic CI variable does not, so a local shell that happens to export CI keeps today's behavior.

  • Is KLL k = 2863 vs 1404 really equal cost? Yes, a genuine tie, not a cost-model gap. Node 1 builds 5-minute KLL states for 10,000 groups from 667 rows/s: 667 × 300 / 10,000 ≈ 20 rows per state, and the 10-minute merge holds about 40. Below k rows a KLL never compacts, so kll_view_bytes and kll_open_bytes (crates/cost/src/node/state_bytes/kll.rs) price one level holding every row, whatever k is; the update cost is per row (KLL_UPDATE_OPERATIONS_PER_ROW) and the merge and estimate costs are per byte, so every term is equal. This matches asap_sketchlib, whose KLL grows its buffer with the rows it holds, not with k; both states are exact. The same holds for the other k flips below (KLL 2863 → 1404 in mixed-quantiles-raw-retained; KMV k 26656 ↔ 106263 in three distinct-count workloads, whose states hold far fewer hashes than either k). No issue filed.

Verification

Scope Result Newly failing vs base Notes
cargo fmt --all -- --check passed none
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings passed none
cargo test --workspace --locked (CI's runner, includes goldens) 2180 passed, 0 failed, 17 ignored none run at the first commit; the second changes only docs, comments and the workflow
goldens (within the workspace run) 14 passed none
corpus_snapshots binary, STRICT_SNAPSHOTS=1 -- --include-ignored (release) 11 passed, 0 failed none both snapshot suites and pruning_keeps_every_snapshot_optimum against the regenerated snapshots
Strict run with the old chains-10m-5m-3m-10s-mvp.json (k = 1404) restored fails as expected none names .materialized_views[0].plan_id; without STRICT_SNAPSHOTS the same run passes
Corpus snapshots workflow on this branch (GitHub runner) passed (3.4 min planning) none

New test: equal_cost_plan_changes_fail_when_strict: a snapshot whose plan changes (k 1404 → 2863) at the same cost passes without strict mode and fails with it. Written first: against a changed_snapshot_passes that ignored strict it failed (equal_cost_plan_changes_fail_when_strict ... FAILED), then passed with the change.

Snapshot changes

All 48 changes were already what main selects; none comes from this PR's code. The snapshots were last written by #1518; since then only #1529 changed planning (#1547 and #1548 are docs and a refactor), and regenerating on the commit before #1549 already rewrote the same 48 files, so the cause column says #1529. Its rule 5 removes OneEvaluation twins, which also moves which of several equal-cost plans the MILP returns. Every file keeps its cost_per_second exactly, and its usage except one noted below.

Kind Files Cause
A node's lifetime {"OneEvaluation": "Memory"} → "None" all 48 #1529 (search-space pruning rule 5): a query-time result read once per evaluation is no longer offered as OneEvaluation, whose None twin costs the same
Materialized view plan_id changes 20 follows from the plan text changing (lifetime, or k below)
KLL k 1404 → 2863 (5-minute chain and its readers; the 10-second chain stays 1404) chains-10m-5m-3m-10s-mvp equal-cost tie moved by #1529 (see the KLL answer above)
KLL k 2863 → 1404 mixed-quantiles-raw-retained equal-cost tie moved by #1529
KMV k 26656 → 106263 distinct-over-time-5pct-raw-retained, entropy-and-distinct-raw-retained equal-cost tie moved by #1529
KMV k 106263 → 26656 distinct-two-forms-raw-retained equal-cost tie moved by #1529
A TimeShift node no longer "holds 61000 bytes"; peak_memory_bytes 7808133 → 7747133 o11y_bench/q21 the lifetime change above; cost_per_second unchanged

Corpus files: o11y_bench/q02, q05, q06, q11, q18, q19, q20, q21, q22, q23, q25, q26, q27. Sketch plan files: 35 of the 42 manifest workloads, listed in the diff.

Follow-ups

…nightly; regenerate snapshots (#1541)

The snapshot harnesses passed a plan that changed at the committed plan's
cost, so a PR that moved a tie left the committed snapshots stale. With
STRICT_SNAPSHOTS=1, which the nightly workflow now sets, any difference
fails; without it (local runs) the equal-cost pass stays, noted on stderr.

Regenerates the 48 snapshots that had gone stale on main: 13 corpus
queries and 35 sketch plan workloads, every one at an unchanged
cost_per_second.
…flow comments; print runner CPU and toolchain
@zzylol zzylol added bug Something isn't working testing Corpus, regression, differential, or benchmark tests labels Nov 28, 2026
@zzylol
zzylol merged commit fae6352 into main Nov 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working testing Corpus, regression, differential, or benchmark tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Snapshot tests pass silently when the selected plan changes at equal cost, so committed snapshots go stale

1 participant