Skip to content

impl(029): increment 3, repeat sets - #166

Merged
bartekus merged 1 commit into
mainfrom
impl/029-repeat-sets-3
Oct 22, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/029-repeat-sets-3

Conversation

@bartekus

@bartekus bartekus commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Spec 029 increment 3: repeat sets and rustev.repeat-report/1 (3.1,
3.2.5, 3.5, 3.6). Library only; no CLI, ledger, baseline or gate yet; no
live run, provider call or spend. implementation stays in-progress.

  • rustev-eval/src/repeat.rs (new): repeat(RepeatInputs) over N
    reconciled runs. Refuses the live source (live-source-unavailable),
    N outside 1 to 64, unreconciled case measures (reconcile), runs that
    differ in dataset, split, evaluator configuration, plan or metric list
    or do not list the split's cases in manifest order (mixed-runs), a
    replay set whose runs are not identical (not-reproducible), an
    unreported stability metric or override, and a cohort over the
    bootstrap bound (bootstrap-too-large). The report names the source,
    configurations, dataset, split and fixed role (3.7.1), provenance,
    adapter rules, plan, each run's document digests and run seed, the
    stable cohort, and per cohort (all, then each slice) every metric's
    per-run values, mean, sd, min, max, pooled, interval and band
    with its basis. Slices below their minimum are unknown throughout; a
    metric without a per-case measure (cost totals, brier) has across-run
    statistics in all only. Latency, queue and cost metrics state their
    observation (historical for candidate runs, 3.11.2). A held-out report
    records held_out as unknown until increment 4 adds the ledger.
  • rustev-eval/src/report.rs, eval_cases.rs: cost_per_1000/observed
    and /estimated case measures (3.2.5), unknown unless cost units are
    declared comparable, the observed series unknown for a case with
    liability or an unknown charge; none for a candidate.
  • rustev-eval/src/repeat_stats.rs: across_runs, factored out of
    run_stats unchanged, for metrics stated only by the run reports.
  • Tests (tests/reports.rs): replay set (zero deterministic_replay
    band, pooled equal to the report, distinct run seeds, stable cohort,
    totals and brier, observations, unknown cost_per_1000, a reported
    slice and one below its minimum, round trip and byte determinism);
    captured set with a case losing its bundle (stable cohort, positive
    k_sd band); one captured run (unknown band); differing replays, the
    live source and N of 0 and 65 refused; mixed baseline and candidate
    runs, unreconciled measures and an unreported stability metric refused;
    a candidate set with historical observations and interval_width
    bands.
  • tools/rustev-release/archive-policy.json: src/repeat.rs.
  • Spec 029: increment 3 record and engineering choices.

Still open from increment 2: owner decision D-029-1 (Brier per-case
measures), recorded in spec 029's implementation record.

Local verification (macOS arm64): make gate passes with spec-spine
0.31.0; cargo clippy -p rustev-eval --all-targets -- -D warnings,
cargo test -p rustev-eval and cargo test -p rustev-fp-corpus pass.

Review round 1 (1 finding, not a defect, evidence added): the finding says
a candidate's cases get a known cost_per_1000/observed when costs are
comparable and known. The cost measures sit inside case_measures_of's
if inputs.candidate.is_none() block (opened above the latency loop,
outside the reviewed hunk), so a candidate's cases carry none. A comment
now says so in the hunk, and a new test,
cost_per_1000_is_measured_for_a_baseline_and_never_for_a_candidate,
declares cost units comparable and checks that the baseline's cases carry
cost per 1000 while the candidate's carry none and its repeat report's
cost_per_1000/observed is historical and unknown.

Review round 2: no findings. Rebased onto main after #159 (no conflict).
make code passes locally on this head, except two failures caused by
other worktrees sharing the build target (a test binary removed by a
concurrent cargo clean, and rustev-jev's lodging_swap finding its
output directory already created by a concurrent run); each passes when
rerun alone.

Review round 3 (1 finding, fixed by making the rule explicit): the finding
says cost_unknown_attempts should carry no observation. It is one of the
four cost series a spec 004 candidate report replaces with "the candidate
was not executed; latency and cost are the baseline's", so it is an
observation of the runs and historical for a candidate, as 3.12.4 needs.
observation now lists latency, queue, the four cost series and
cost_per_1000/* by name instead of a cost_ prefix, with that reason in
its comment; the candidate test checks the cost series are historical and
a quality metric has no observation.

Local on this head: make gate passes; cargo test --workspace --no-fail-fast passes except rustev-release --test manifests, which
reports a rustev-aicortex member that exists only in another lane's
worktree sharing the build target, and passes when run alone; clippy,
fmt and boundaries pass.
Rebased onto main after #157 (no conflict); rustev-eval and rustev-release tests (including manifests, now that rustev-aicortex is on main) and rustev-eval clippy pass on the rebased head.
Review round 4: no findings. Rebased onto main after #162 (no conflict).
Review round 5: no findings. Rebased onto main after #160 (no conflict); make code and make gate pass locally on this head.
Review round 6: no findings. Its code run failed in
rustev-remote-http --test runtime_batch
(a_deadline_or_a_cancellation_after_send_ends_every_member_as_independent_calls_do),
a timing test in a crate this PR does not touch. Rebased onto main after
#167, which changes no Rust source, so the previous head's local make code
still covers the Rust tree; make gate passes.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security issues, and spec inconsistencies.

eval_cases.rs — The derived() guard in reconcile correctly skips checking that cost_per_1000/* appear in the run report's metric list, since they are computed from EvalCases cost data, not emitted as standard eval-report metrics. The form_of extension to Form::Mean is consistent.

repeat_stats.rs — Extraction of across_runs looks mechanically correct. The runs variable was just values.len(), so the replacement is equivalent. The new empty-slice guard in across_runs is a clean addition with the right return shape.

repeat.rs — General structure is sound: source check, N bounds, per-run reconcile, mixed-run detection, dataset/split/case-order validation, not-reproducible guard for replay, derived-metric extension of reported, cohort iteration, bootstrap, band and interval assembly, run-ref digest collection.

The observation function is semantically correct: for a non-candidate evaluation the plan being measured is the candidate, so Observation::Candidate; for a candidate evaluation the latency/cost data come from historical runs, so Observation::Historical. Tests at lines 2059 and 2202 verify both branches.

Concrete defect — report.rs, cost measures for candidate evaluations:

The spec text added by this PR (increment 3 description) states:

a candidate's cases carry none [cost measure]. (3.2.5): … unknown, never zero.

The new code in case_measures_of computes:

let observed = match (config.cost_units_comparable, unknown_charge) {
    (false, _) => not_comparable(),
    (true, true) => CaseMeasure::Unknown { … },
    (true, false) => per_1000(run.cost.observed),   // ← bug
};

When cost_units_comparable = true and the historical run record passed in for a candidate evaluation has liability == 0 and no Charge::Unknown attempts, the third arm fires and emits CaseMeasure::Mean { num: 1000.0 * run.cost.observed as f64, den: 1 } — a known value (possibly zero). There is no check for whether the evaluation is a candidate, and the function has no such parameter. For a properly recorded historical run with known costs, unknown_charge is false, so the guard (true, true) never fires. The result contradicts the spec's "unknown, never zero" requirement for candidate cases.

The implementation-notes section of the updated spec also does not mention this case, confirming it was not an intentional choice recorded there.

{"head": "4da3576f56c302c604f707b4fd24b1e4bff67676", "verdict": "findings", "findings": [{"path": "crates/rustev-eval/src/report.rs", "line": 826, "summary": "cost_per_1000/observed is computed as a known value from the historical run record for candidate evaluations when cost_units_comparable=true and the run has no unknown charges and zero liability, contradicting the spec's 'candidate's cases carry none / unknown, never zero' requirement added by this PR."}]}

Subject: 68f40c0...4da3576, diff digest f959182640f4a72663362afe6f72eed5487a4c950a7bd3067e0bad809cc73209, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 22, 2026 04:01 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/029-repeat-sets-3 branch from 4da3576 to ab281e9 Compare October 22, 2026 04:02
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reading through the diff carefully, focusing on correctness, security, and consistency.

repeat.rs — observation() polarity

fn observation(metric: &str, candidate: bool) -> Option<Observation> {
    ...
    observed.then_some(if candidate {
        Observation::Historical
    } else {
        Observation::Candidate
    })
}

The spec note in the diff says: "historical for candidate runs, candidate otherwise (3.11.2)." The tests confirm: a non-candidate run gets Observation::Candidate; a candidate run gets Observation::Historical. Logic is correct.

reconcile skip of derived metrics — the !derived(n) guard is correctly placed; derived metrics have no counterpart in run reports, so skipping them is right.

across_runs extraction — the refactoring moves mean/sd/min/max computation out of run_stats into a standalone function. The values.is_empty() early-return added in across_runs is a safe defensive guard; run_stats already guards on N. The runs variable renamed to values.len() is consistent and correct.

Cost measures in report.rs — observed checks liability and unknown charges before producing a Mean; estimated does not (intentionally — estimated cost is pre-computed and not affected by whether actual charges were resolved). The surrounding inputs.candidate.is_none() block gate is confirmed by the test asserting candidate cases carry no cost_per_1000/* keys.

candidate detection — names.contains(&"candidate_outcome_change") is consistent with how candidate evaluations are distinguished elsewhere in the codebase.

check_metrics includes derived names — derived metrics are added to reported before check_metrics, so they are legal stability-metric values in config. Internally consistent.

decomposable scoping — rebuilt per cohort with members-filtered cases; the intervals slice is always the same length as decomposable, so intervals[i] is safe.

MixedRuns split check — split is part of DatasetId equality, so the split is covered by e.report.dataset == first.report.dataset; the error message mentioning "split" is accurate.

stable.contains(c) in cohort loop — O(n·m) linear scan; a performance concern but not a correctness defect.

No concrete defect found in any of the changed paths.

{"head": "ab281e9544cee719827c51fab5593e95515c82b9", "verdict": "no-findings", "findings": []}

Subject: 68f40c0...ab281e9, diff digest b385feecdbf3552cfa8ba974e85cdc06d8eb7398f2ed6dbb6060210089716a73, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/029-repeat-sets-3 branch from ab281e9 to bdd9d22 Compare October 22, 2026 06:17
@github-actions

Copy link
Copy Markdown

AI review (findings)

Looking at the diff, I'll focus on concrete defects in logic, correctness, and spec consistency.

crates/rustev-eval/src/repeat.rs — observation() prefix is too broad

The function classifies a metric as latency/queue/cost by checking:

let observed = metric.starts_with("latency_ms/")
    || metric.starts_with("queue_ms/")
    || metric.starts_with("cost_");

cost_unknown_attempts begins with "cost_" and will therefore receive Some(Observation::Candidate) (or Historical) on every non-candidate (or candidate) run. That metric is a count of requests with unknown charges, not a cost-amount figure. The spec update says 3.11.2 applies only to latency, queue and cost figures; a count of unknown-charge attempts is not a cost figure in that sense. The test for a_replay_set_has_a_deterministic_band_and_reports_its_slices exercises cost_unknown_attempts but never asserts its observation field, so this annotation goes undetected. The two genuinely affected metrics (cost_per_1000/observed, cost_per_1000/estimated) both have the more-specific prefix "cost_per_1000/", so tightening the match to that prefix would fix the over-match without losing coverage.

No other concrete defects were found: the across_runs extraction is arithmetically equivalent, the derived() guard in reconcile() is consistent with the new case-measure insertions in report.rs, the unknown_charge asymmetry between observed and estimated is consistent with the spec note ("the observed series unknown for a case with liability or an attempt of unknown charge"), and the let-chain syntax is valid for the toolchain implied by the codebase.

{"head": "bdd9d22bbed246050d98a46669091c2b2350b5cf", "verdict": "findings", "findings": [{"path": "crates/rustev-eval/src/repeat.rs", "line": null, "summary": "observation() matches cost_unknown_attempts via the starts_with(\"cost_\") prefix, incorrectly annotating a count metric with a Candidate/Historical observation that 3.11.2 reserves for cost-amount figures."}]}

Subject: 1b0ce68...bdd9d22, diff digest b385feecdbf3552cfa8ba974e85cdc06d8eb7398f2ed6dbb6060210089716a73, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 22, 2026 06:22 — with GitHub Actions Error
@bartekus
bartekus force-pushed the impl/029-repeat-sets-3 branch 2 times, most recently from 2382319 to 64a89c9 Compare October 22, 2026 07:12
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff systematically across the new repeat.rs, the repeat_stats.rs refactor, the report.rs additions, and the spec update.

repeat_stats.rs refactor (across_runs extraction)

The refactoring is mechanical: run_stats previously computed mean/sd/min/max inline using a runs binding equal to n; the extracted across_runs replaces those references with values.len(), which is always equal. The early-return guard for empty input is defensive and correct. No change in semantics.

eval_cases.rs: derived() and reconcile change

Adding !derived(n) to the reconcile predicate correctly skips cost_per_1000/* from the "every case measure must correspond to a reported metric" check, since those metrics are synthesized per-case and never appear in run reports. The form_of extension to return Form::Mean for the two new constants is consistent with how mean-per-comparable-case is handled elsewhere.

report.rs: cost-per-1000 case measures

The block is guarded by inputs.candidate.is_none() (per the inline comment), so candidate evaluations never receive these measures. The test at line ~2261 confirms this. The asymmetry between observed (unknown when liability > 0 or any Charge::Unknown) and estimated (always written when cost_units_comparable, ignoring charge status) appears intentional: estimated is a model prediction, not an actual measurement, and no spec clause observed here restricts it the same way.

repeat.rs: observation() function

The function returns Observation::Historical when candidate = true and Observation::Candidate otherwise. This is correct: for a baseline run the plan being evaluated itself generated the latency/cost figures (Candidate); for a candidate evaluation those figures come from the retained historical run (Historical). Tests at lines ~2095 and ~2158 confirm both directions.

repeat.rs: cohort and metric assembly

  • The candidate flag is derived from the first run's metric list and consistency is enforced by the MixedRuns check that compares every run's metric name sequence to names.
  • stable uses index-safe access d.cases[c] only after the prior check that every d has split_cases.len() cases in manifest order.
  • Derived metrics enter decomposable (since form_of returns Some(Form::Mean) for them), so they take the case-decomposable branch for all cohorts, not the !derived(m) && name == "all" fallback.
  • unknown_metric sets undefined: 0 in IntervalDoc::Unknown, which is semantically correct since no bootstrap resampling was attempted in that path.
  • The held_out field is Some(Unknown) only when split_role == HeldOut, None otherwise, matching 3.7.4.

archive-policy.json: mechanical addition of the new src/repeat.rs source path. No concern.

Spec 029 additions: the increment-3 description, tests summary, and engineering-choices bullets are self-consistent with the code.

No concrete defects found.

{"head": "64a89c9b9c16f2977e24a0d346b604403c0d684f", "verdict": "no-findings", "findings": []}

Subject: 262b37c...64a89c9, diff digest e85d8ff996ec4e3516701fbc594131799ce58ef45bc7c694fdf05d37f9cc8efa, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/029-repeat-sets-3 branch from 64a89c9 to dad31df Compare October 22, 2026 07:28
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR, which adds crates/rustev-eval/src/repeat.rs (the repeat() function and RepeatReport document) along with supporting changes to eval_cases.rs, repeat_stats.rs, and report.rs.

repeat_stats.rs refactor — across_runs is cleanly extracted. All places that previously used the local runs variable (runs as f64, runs == 1, runs - 1) now correctly use values.len(). The refactoring is semantically identical.

eval_cases.rs reconcile guard — The !derived(n) guard on the reconcile check is correct: derived metrics (cost_per_1000/*) are never present in run reports, so skipping them avoids a spurious error. The form_of extension to Form::Mean for both derived constants is consistent.

report.rs cost-per-1000 insertion — The code is correctly inside the inputs.candidate.is_none() guard (per comment), confirmed by the test asserting candidates have no cost_per_1000/* measures. The asymmetric treatment (observed checks unknown_charge, estimated does not) is intentional per the spec: only the observed series is required to be unknown for unknown-charge attempts.

repeat.rs observation logic — Observation::Candidate on a non-candidate run means "these figures come from the directly-executed plan"; Observation::Historical on a candidate run means the baseline's records were used. The sense is confirmed by every test assertion and the spec text ("historical for candidate runs, candidate otherwise").

repeat.rs stable-cohort index arithmetic — stable.contains(c) where c: &&usize compiles correctly via deref coercion (&&usize → &usize). Indices are all in bounds since stable is a subset of 0..split_cases.len() and the case-order check verifies docs align with split_cases.

repeat.rs candidate detection — names.contains(&"candidate_outcome_change") on the first run is the correct proxy; the subsequent mixed-run loop enforces that every run has the same metric list, so the flag is consistent across the set.

repeat.rs NotReproducible check — only compares cases.cases and report; detail is not included. For replayed bundles, an identical report and identical case measures imply an identical detail (both are pure functions of the same retained bundle). Not a concrete defect.

Archive policy — src/repeat.rs is inserted alphabetically between remote_evidence.rs and repeat_config.rs. ✓

No concrete defects found.

{"head": "dad31df087e6223a506de7ff66439fd87978fecc", "verdict": "no-findings", "findings": []}

Subject: 6060167...dad31df, diff digest c057a541bc92b8314ca95ca46586dc33257c30b3ac3808e812873e1e810faa4e, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus force-pushed the impl/029-repeat-sets-3 branch from dad31df to b90a2f3 Compare October 22, 2026 08:28
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

I'll work through the diff systematically, focusing on the new repeat.rs module, the repeat_stats.rs refactor, the cost measure additions in report.rs, and the spec update.

repeat_stats.rs — across_runs extraction

The refactor pulls the mean/sd/min/max computation out of run_stats into a standalone across_runs. Before the refactor, division used runs (= n, the parameter). After, it uses values.len(). Because values is built as (0..n).map(...).collect(), values.len() == n, so the arithmetic is equivalent. The early-return guard for empty values is defensive and correct.

repeat.rs — observation function

observed.then_some(if candidate {
    Observation::Historical
} else {
    Observation::Candidate
})

candidate here means "this is a differential candidate evaluation reusing historical results," so returning Historical is correct for those runs. For baseline runs (candidate=false), returning Candidate ("observed by the plan under evaluation") is correct. The tests confirm both directions. The apparent naming inversion is intentional.

repeat.rs — NotReproducible check uses let-chains

if inputs.source == Source::Replay
    && let Some(r) = runs.iter().position(|r| { ... })

Let-chains were stabilized in Rust 1.88 (May 2025). The repo has a rust-toolchain.toml but its contents are not in the diff, so I cannot verify the pinned version. This is a risk if the toolchain is older than 1.88, but I cannot confirm it as a concrete defect from the evidence provided.

repeat.rs — mixed-run checks completeness

The MixedRuns check verifies dataset, evaluator config, plan, and exact metric name/order equality. Since a candidate evaluation adds candidate_outcome_change to the metric list, mixing baseline and candidate runs is caught. The test confirms.

eval_cases.rs — reconcile skipping derived metrics

The new !derived(n) guard correctly prevents reconcile from complaining that cost_per_1000/observed and /estimated are missing from run report metrics—they are derived for the repeat report only and are intentionally absent from individual run reports.

report.rs — cost per 1000 inside candidate.is_none() block

The cost-per-1000 measures are inserted only for non-candidate evaluations. The test cost_per_1000_is_measured_for_a_baseline_and_never_for_a_candidate verifies that candidate case measures contain no cost_per_1000/ keys.

repeat.rs — stable membership check

let stable_cases = members.iter().filter(|c| stable.contains(c)).count() as u64;

members: Vec<usize>, filter yields &&usize; Rust's deref coercion makes stable.contains(c) valid. Correctness is fine; linear scan is O(n²) in the worst case but bounded by dataset size.

Spec update

The increment-3 description in specs/029-evaluation-repeatability/spec.md matches the implementation: live-source-unavailable, N outside 1–64, reconcile, mixed-runs, not-reproducible, repeat-config, bootstrap-too-large refusals; derived metrics listed; held-out unknown until increment 4; engineering decisions documented.

archive-policy.json — src/repeat.rs correctly added alongside the other eval module sources.

No concrete defects found.

{"head": "b90a2f379e1c0f94f786a6fdb6a6ab13731530b9", "verdict": "no-findings", "findings": []}

Subject: 21a00fc...b90a2f3, diff digest 24024ce2febae051db677c2f276650def20b1064f9e8c14ca41e0d5a1759823b, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus enabled auto-merge (squash) October 22, 2026 08:33
@bartekus
bartekus disabled auto-merge October 22, 2026 08:34
@bartekus
bartekus force-pushed the impl/029-repeat-sets-3 branch from b90a2f3 to 6365f83 Compare October 22, 2026 08:34
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the PR for bugs, security issues, and inconsistencies.

crates/rustev-eval/src/repeat.rs — observation() logic and naming

The function returns Observation::Candidate when the candidate parameter is false (baseline run), and Observation::Historical when it is true. The spec (diff, added paragraph): "Latency, queue and cost metrics state their observation: historical for candidate runs, candidate otherwise (3.11.2)." The implementation matches. The naming is consistent with the tests (assert_eq!(metric_of(all, "latency_ms/p0.5").observation, Some(Observation::Candidate)) for a baseline run). No defect.

repeat_stats.rs refactoring — across_runs extraction

run_stats previously used a local runs counter (equal to n). After extraction, across_runs uses values.len(). Since values is constructed with exactly n entries, the computation is identical. The empty-slice guard is safe: run_stats is always called with validated n ≥ 1, and the guard handles the new public API surface. No defect.

report.rs — cost_per_1000/estimated does not check unknown_charge

The observed series has an unknown_charge guard; estimated does not. The spec text added to 029 explicitly restricts the guard to the observed series ("the observed series unknown for a case with liability or an attempt of unknown charge"). This matches the implementation and is intentional.

eval_cases.rs — reconcile exclusion of derived metrics

The new !derived(n) guard excludes cost_per_1000/* from the reconcile check. These metrics appear in case measures but have no corresponding entry in the run report's metric list, so excluding them is correct.

repeat.rs — candidate detection

candidate = names.contains(&"candidate_outcome_change") is followed by a mixed-runs check that rejects any run whose metric list differs from the first. This ensures candidate is consistent across all runs. Correct.

repeat.rs — bounds safety on d.cases[c]

The earlier check d.cases.len() != split_cases.len() guards every subsequent d.cases[c] access. No out-of-bounds.

repeat.rs — replay reproducibility check

runs.iter().position(|r| r.cases.cases != runs[0].cases.cases || r.evaluated.report != first.report) correctly avoids a spurious mismatch on index 0 because the predicate is false for r == runs[0].

Spec and archive policy

The spec changes document engineering choices and the increment consistently with the code. The archive-policy insertion is in correct alphabetical order.

No concrete defects, security issues, or governance violations found.

{"head": "6365f83139437d8aea26d822526ed7c8653b7ff7", "verdict": "no-findings", "findings": []}

Subject: 63334d6...6365f83, diff digest 24024ce2febae051db677c2f276650def20b1064f9e8c14ca41e0d5a1759823b, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus enabled auto-merge (squash) October 22, 2026 08:41
@bartekus
bartekus merged commit c103390 into main Oct 22, 2026
26 checks passed
@bartekus
bartekus deleted the impl/029-repeat-sets-3 branch October 22, 2026 09:17
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.

1 participant